Fix missing braces and contents for PYACC.Text.ValueReference etc, add tag_name
authorNick Downing <downing.nick@gmail.com>
Fri, 20 Jul 2018 12:02:58 +0000 (22:02 +1000)
committerNick Downing <downing.nick@gmail.com>
Fri, 20 Jul 2018 12:02:58 +0000 (22:02 +1000)
src/parse-gram.c
src/parse-gram.y
src/scan-code.c
src/scan-code.l
src/scan-gram.c

index 10c0939..1fa0db6 100644 (file)
@@ -2438,11 +2438,11 @@ yyreduce:
     {
       /* Do not invoke muscle_percent_code_grow here since it invokes
          muscle_user_name_list_grow.  */
- code_piece_append("<PYACC_BracedCode>");
+ code_piece_append("<PYACC_BracedCode>{");
       muscle_code_grow ("percent_code()",
                         translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
       code_scanner_last_string_free ();
- code_piece_append("</PYACC_BracedCode>");
+ code_piece_append("}</PYACC_BracedCode>");
  code_piece_pack();
  free(gram_piece[gram_piece2 + 2]);
  gram_piece[gram_piece2 + 2] = strdup(code_piece[code_piece0 - 1]);
@@ -2455,10 +2455,10 @@ yyreduce:
   case 39:
 #line 520 "src/parse-gram.y" /* yacc.c:1648  */
     {
- code_piece_append("<PYACC_BracedCode>");
+ code_piece_append("<PYACC_BracedCode>{");
       muscle_percent_code_grow ((yyvsp[-1].uniqstr), (yylsp[-1]), translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
       code_scanner_last_string_free ();
- code_piece_append("</PYACC_BracedCode>");
+ code_piece_append("}</PYACC_BracedCode>");
  code_piece_pack();
  free(gram_piece[gram_piece2 + 4]);
  gram_piece[gram_piece2 + 4] = strdup(code_piece[code_piece0 - 1]);
@@ -2498,10 +2498,10 @@ yyreduce:
 #line 556 "src/parse-gram.y" /* yacc.c:1648  */
     {
       union_seen = true;
- code_piece_append("<PYACC_BracedCode>");
+ code_piece_append("<PYACC_BracedCode>{");
       muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0]));
       code_scanner_last_string_free ();
- code_piece_append("</PYACC_BracedCode>");
+ code_piece_append("}</PYACC_BracedCode>");
  code_piece_pack();
  free(gram_piece[gram_piece2 + 4]);
  gram_piece[gram_piece2 + 4] = strdup(code_piece[code_piece0 - 1]);
index 056f19b..f53592e 100644 (file)
@@ -505,11 +505,11 @@ grammar_declaration:
     {
       /* Do not invoke muscle_percent_code_grow here since it invokes
          muscle_user_name_list_grow.  */
- code_piece_append("<PYACC_BracedCode>");
+ code_piece_append("<PYACC_BracedCode>{");
       muscle_code_grow ("percent_code()",
                         translate_code_braceless ($2, @2), @2);
       code_scanner_last_string_free ();
- code_piece_append("</PYACC_BracedCode>");
+ code_piece_append("}</PYACC_BracedCode>");
  code_piece_pack();
  free(gram_piece[gram_piece2 + 2]);
  gram_piece[gram_piece2 + 2] = strdup(code_piece[code_piece0 - 1]);
@@ -518,10 +518,10 @@ grammar_declaration:
     }
 | "%code" ID "{...}"
     {
- code_piece_append("<PYACC_BracedCode>");
+ code_piece_append("<PYACC_BracedCode>{");
       muscle_percent_code_grow ($2, @2, translate_code_braceless ($3, @3), @3);
       code_scanner_last_string_free ();
- code_piece_append("</PYACC_BracedCode>");
+ code_piece_append("}</PYACC_BracedCode>");
  code_piece_pack();
  free(gram_piece[gram_piece2 + 4]);
  gram_piece[gram_piece2 + 4] = strdup(code_piece[code_piece0 - 1]);
@@ -555,10 +555,10 @@ grammar_declaration:
   "%union" union_name "{...}"
     {
       union_seen = true;
- code_piece_append("<PYACC_BracedCode>");
+ code_piece_append("<PYACC_BracedCode>{");
       muscle_code_grow ("union_members", translate_code_braceless ($3, @3), @3);
       code_scanner_last_string_free ();
- code_piece_append("</PYACC_BracedCode>");
+ code_piece_append("}</PYACC_BracedCode>");
  code_piece_pack();
  free(gram_piece[gram_piece2 + 4]);
  gram_piece[gram_piece2 + 4] = strdup(code_piece[code_piece0 - 1]);
index f24439e..5d02560 100644 (file)
@@ -704,8 +704,8 @@ int code__flex_debug = 1;
 
 static yyconst flex_int16_t yy_rule_linenum[18] =
     {   0,
-      118,  128,  129,  139,  144,  149,  155,  156,  157,  158,
-      160,  168,  177,  190,  201,  214,  217
+      117,  127,  128,  138,  143,  148,  154,  155,  156,  157,
+      159,  167,  174,  185,  202,  215,  218
     } ;
 
 /* The intent behind this definition is that it'll catch
@@ -784,7 +784,6 @@ static bool untyped_var_seen;
 
 /* Nick */
 int no_handle_action;
-const char *before_tag, *after_tag;
 
 /* C and C++ comments in code. */
 
@@ -802,7 +801,7 @@ of $ and @.  */
 /* C style identifier. Must start with letter. Will be used for
    named symbol references. Shall be kept synchronized with
    scan-gram.l "letter" and "id". */
-#line 725 "src/scan-code.c"
+#line 724 "src/scan-code.c"
 
 #define INITIAL 0
 #define SC_COMMENT 1
@@ -1053,7 +1052,7 @@ YY_DECL
        register int yy_act;
     
 /* %% [7.0] user's declarations go here */
-#line 100 "src/scan-code.l"
+#line 99 "src/scan-code.l"
 
 
 
@@ -1070,7 +1069,7 @@ YY_DECL
   | Scanning a C comment.  The initial '/ *' is already eaten.  |
   `------------------------------------------------------------*/
 
-#line 993 "src/scan-code.c"
+#line 992 "src/scan-code.c"
 
        if ( !(yy_init) )
                {
@@ -1188,7 +1187,7 @@ do_action:        /* This label is used only to access EOF actions. */
 case 1:
 /* rule 1 can match eol */
 YY_RULE_SETUP
-#line 118 "src/scan-code.l"
+#line 117 "src/scan-code.l"
 STRING_GROW; BEGIN sc_context;
        YY_BREAK
 
@@ -1200,13 +1199,13 @@ STRING_GROW; BEGIN sc_context;
 case 2:
 /* rule 2 can match eol */
 YY_RULE_SETUP
-#line 128 "src/scan-code.l"
+#line 127 "src/scan-code.l"
 STRING_GROW; BEGIN sc_context;
        YY_BREAK
 case 3:
 /* rule 3 can match eol */
 YY_RULE_SETUP
-#line 129 "src/scan-code.l"
+#line 128 "src/scan-code.l"
 STRING_GROW;
        YY_BREAK
 
@@ -1218,7 +1217,7 @@ STRING_GROW;
 case 4:
 /* rule 4 can match eol */
 YY_RULE_SETUP
-#line 139 "src/scan-code.l"
+#line 138 "src/scan-code.l"
 STRING_GROW;
        YY_BREAK
 
@@ -1226,7 +1225,7 @@ STRING_GROW;
 
 case 5:
 YY_RULE_SETUP
-#line 144 "src/scan-code.l"
+#line 143 "src/scan-code.l"
 STRING_GROW; BEGIN sc_context;
        YY_BREAK
 
@@ -1234,7 +1233,7 @@ STRING_GROW; BEGIN sc_context;
 
 case 6:
 YY_RULE_SETUP
-#line 149 "src/scan-code.l"
+#line 148 "src/scan-code.l"
 STRING_GROW; BEGIN sc_context;
        YY_BREAK
 
@@ -1242,29 +1241,29 @@ STRING_GROW; BEGIN sc_context;
 
 case 7:
 YY_RULE_SETUP
-#line 155 "src/scan-code.l"
+#line 154 "src/scan-code.l"
 STRING_GROW; BEGIN SC_CHARACTER;
        YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 156 "src/scan-code.l"
+#line 155 "src/scan-code.l"
 STRING_GROW; BEGIN SC_STRING;
        YY_BREAK
 case 9:
 /* rule 9 can match eol */
 YY_RULE_SETUP
-#line 157 "src/scan-code.l"
+#line 156 "src/scan-code.l"
 STRING_GROW; BEGIN SC_COMMENT;
        YY_BREAK
 case 10:
 /* rule 10 can match eol */
 YY_RULE_SETUP
-#line 158 "src/scan-code.l"
+#line 157 "src/scan-code.l"
 STRING_GROW; BEGIN SC_LINE_COMMENT;
        YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 160 "src/scan-code.l"
+#line 159 "src/scan-code.l"
 {
     complain (loc, Wother, _("stray '%s'"), code_text);
     obstack_escape (&obstack_for_string, code_text);
@@ -1275,28 +1274,24 @@ YY_RULE_SETUP
 
 case 12:
 YY_RULE_SETUP
-#line 168 "src/scan-code.l"
+#line 167 "src/scan-code.l"
 {
     ref_tail_fields = NULL;
     handle_action_dollar (self->rule, code_text, *loc);
+ code_text = yy_c_buf_p;
     if (ref_tail_fields)
       obstack_sgrow (&obstack_for_string, ref_tail_fields);
- code_piece_append(before_tag);
- flush();
- code_piece_append(after_tag);
   }
        YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 177 "src/scan-code.l"
+#line 174 "src/scan-code.l"
 {
     ref_tail_fields = NULL;
     handle_action_at (self->rule, code_text, *loc);
+ code_text = yy_c_buf_p;
     if (ref_tail_fields)
       obstack_sgrow (&obstack_for_string, ref_tail_fields);
- code_piece_append(before_tag);
- flush();
- code_piece_append(after_tag);
   }
        YY_BREAK
 
@@ -1304,22 +1299,28 @@ YY_RULE_SETUP
 
 case 14:
 YY_RULE_SETUP
-#line 190 "src/scan-code.l"
+#line 185 "src/scan-code.l"
 {
+ int i = sprintf(code_piece_temp, "<PYACC_Text_ValueReference tag_name=\"");
+ int j = i + sprintf(code_piece_temp + i, "%s", code_text + 2);
+ while (j > i && code_piece_temp[--j] != '>')
+  ;
+ sprintf(code_piece_temp + j, "\">");
+ code_piece_append(code_piece_temp);
+ code_piece_esc(code_text, strlen(code_text));
+ code_piece_append("</PYACC_Text_ValueReference>");
     const char *type_name = NULL;
     fetch_type_name (code_text + 1, &type_name, *loc)[-1] = 0;
     obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
     obstack_quote (&obstack_for_string, type_name);
     obstack_sgrow (&obstack_for_string, ")[");
     self->is_value_used = true;
- code_piece_append("<PYACC_Text_ValueReference>");
- flush();
- code_piece_append("</PYACC_Text_ValueReference>");
+ code_text = yy_c_buf_p;
   }
        YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 201 "src/scan-code.l"
+#line 202 "src/scan-code.l"
 {
     obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
     muscle_percent_define_ensure("locations", the_location, true);
@@ -1334,14 +1335,14 @@ YY_RULE_SETUP
 /* Escape M4 quoting characters in C code.  */
 case 16:
 YY_RULE_SETUP
-#line 214 "src/scan-code.l"
+#line 215 "src/scan-code.l"
 obstack_escape (&obstack_for_string, code_text);
        YY_BREAK
 /* By default, grow the string obstack with the input.  */
 case 17:
 /* rule 17 can match eol */
 YY_RULE_SETUP
-#line 217 "src/scan-code.l"
+#line 218 "src/scan-code.l"
 STRING_GROW;
        YY_BREAK
 /* End of processing. */
@@ -1352,16 +1353,16 @@ case YY_STATE_EOF(SC_STRING):
 case YY_STATE_EOF(SC_CHARACTER):
 case YY_STATE_EOF(SC_RULE_ACTION):
 case YY_STATE_EOF(SC_SYMBOL_ACTION):
-#line 220 "src/scan-code.l"
+#line 221 "src/scan-code.l"
 STRING_FINISH; /*code_piece_pack(); --code_piece0;*/ return last_string;
        YY_BREAK
 
 case 18:
 YY_RULE_SETUP
-#line 223 "src/scan-code.l"
+#line 224 "src/scan-code.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
        YY_BREAK
-#line 1279 "src/scan-code.c"
+#line 1280 "src/scan-code.c"
 
        case YY_END_OF_BUFFER:
                {
@@ -2448,7 +2449,7 @@ void code_free (void * ptr )
 
 /* %ok-for-header */
 
-#line 223 "src/scan-code.l"
+#line 224 "src/scan-code.l"
 
 
 
@@ -2900,13 +2901,24 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
                  rule->midrule_parent_rhs_index, text, dollar_loc, '$');
 #if 1
  if (n == LHS_REF) {
-  before_tag = "<PYACC_Text_ValueReference>";
-  after_tag = "</PYACC_Text_ValueReference>";
+  int i = sprintf(code_piece_temp, "<PYACC_Text_ValueReference tag_name=\"");
+  int j = i + sprintf(code_piece_temp + i, "%s", code_text + 2);
+  while (j > i && code_piece_temp[--j] != '>')
+   ;
+  sprintf(code_piece_temp + j, "\">");
+  code_piece_append(code_piece_temp);
+  code_piece_esc(code_text, code_leng);
+  code_piece_append("</PYACC_Text_ValueReference>");
  }
  else {
-  sprintf(code_piece_temp, "<PYACC_Text_StackReference index=\"%d\">", n);
-  before_tag = code_piece_temp;
-  after_tag = "</PYACC_Text_StackReference>";
+  int i = sprintf(code_piece_temp, "<PYACC_Text_StackReference tag_name=\"");
+  int j = i + sprintf(code_piece_temp + i, "%s", code_text + 2);
+  while (j > i && code_piece_temp[--j] != '>')
+   ;
+  sprintf(code_piece_temp + j, "\" index=\"%d\">", n);
+  code_piece_append(code_piece_temp);
+  code_piece_esc(code_text, code_leng);
+  code_piece_append("</PYACC_Text_StackReference>");
  }
  if (no_handle_action)
   return;
@@ -3007,13 +3019,15 @@ handle_action_at (symbol_list *rule, char *text, location at_loc)
                        rule->midrule_parent_rhs_index, text, at_loc, '@');
 #if 1
  if (n == LHS_REF) {
-  before_tag = "<PYACC_Text_ValueLocation>";
-  after_tag = "</PYACC_Text_ValueLocation>";
+  code_piece_append("<PYACC_Text_ValueLocation>");
+  code_piece_esc(code_text, strlen(code_text));
+  code_piece_append("</PYACC_Text_ValueLocation>");
  }
  else {
   sprintf(code_piece_temp, "<PYACC_Text_StackLocation index=\"%d\">", n);
-  before_tag = code_piece_temp;
-  after_tag = "</PYACC_Text_StackLocation>";
+  code_piece_append(code_piece_temp);
+  code_piece_esc(code_text, strlen(code_text));
+  code_piece_append("</PYACC_Text_StackLocation>");
  }
  if (no_handle_action)
   return;
index 7706770..d390578 100644 (file)
@@ -68,7 +68,6 @@ static bool untyped_var_seen;
 
 /* Nick */
 int no_handle_action;
-const char *before_tag, *after_tag;
 
 %}
  /* C and C++ comments in code. */
@@ -168,35 +167,37 @@ ref      -?[0-9]+|{id}|"["{id}"]"|"$"
   "$"("<"{tag}">")?{ref}  {
     ref_tail_fields = NULL;
     handle_action_dollar (self->rule, yytext, *loc);
+ yytext = yy_c_buf_p;
     if (ref_tail_fields)
       obstack_sgrow (&obstack_for_string, ref_tail_fields);
- code_piece_append(before_tag);
- flush();
- code_piece_append(after_tag);
   }
   "@"{ref} {
     ref_tail_fields = NULL;
     handle_action_at (self->rule, yytext, *loc);
+ yytext = yy_c_buf_p;
     if (ref_tail_fields)
       obstack_sgrow (&obstack_for_string, ref_tail_fields);
- code_piece_append(before_tag);
- flush();
- code_piece_append(after_tag);
   }
 }
 
 <SC_SYMBOL_ACTION>
 {
   "$"("<"{tag}">")?"$" {
+ int i = sprintf(code_piece_temp, "<PYACC_Text_ValueReference tag_name=\"");
+ int j = i + sprintf(code_piece_temp + i, "%s", yytext + 2);
+ while (j > i && code_piece_temp[--j] != '>')
+  ;
+ sprintf(code_piece_temp + j, "\">");
+ code_piece_append(code_piece_temp);
+ code_piece_esc(yytext, strlen(yytext));
+ code_piece_append("</PYACC_Text_ValueReference>");
     const char *type_name = NULL;
     fetch_type_name (yytext + 1, &type_name, *loc)[-1] = 0;
     obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar(");
     obstack_quote (&obstack_for_string, type_name);
     obstack_sgrow (&obstack_for_string, ")[");
     self->is_value_used = true;
- code_piece_append("<PYACC_Text_ValueReference>");
- flush();
- code_piece_append("</PYACC_Text_ValueReference>");
+ yytext = yy_c_buf_p;
   }
   "@$" {
     obstack_sgrow (&obstack_for_string, "]b4_at_dollar[");
@@ -670,13 +671,24 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
                  rule->midrule_parent_rhs_index, text, dollar_loc, '$');
 #if 1
  if (n == LHS_REF) {
-  before_tag = "<PYACC_Text_ValueReference>";
-  after_tag = "</PYACC_Text_ValueReference>";
+  int i = sprintf(code_piece_temp, "<PYACC_Text_ValueReference tag_name=\"");
+  int j = i + sprintf(code_piece_temp + i, "%s", yytext + 2);
+  while (j > i && code_piece_temp[--j] != '>')
+   ;
+  sprintf(code_piece_temp + j, "\">");
+  code_piece_append(code_piece_temp);
+  code_piece_esc(yytext, yyleng);
+  code_piece_append("</PYACC_Text_ValueReference>");
  }
  else {
-  sprintf(code_piece_temp, "<PYACC_Text_StackReference index=\"%d\">", n);
-  before_tag = code_piece_temp;
-  after_tag = "</PYACC_Text_StackReference>";
+  int i = sprintf(code_piece_temp, "<PYACC_Text_StackReference tag_name=\"");
+  int j = i + sprintf(code_piece_temp + i, "%s", yytext + 2);
+  while (j > i && code_piece_temp[--j] != '>')
+   ;
+  sprintf(code_piece_temp + j, "\" index=\"%d\">", n);
+  code_piece_append(code_piece_temp);
+  code_piece_esc(yytext, yyleng);
+  code_piece_append("</PYACC_Text_StackReference>");
  }
  if (no_handle_action)
   return;
@@ -777,13 +789,15 @@ handle_action_at (symbol_list *rule, char *text, location at_loc)
                        rule->midrule_parent_rhs_index, text, at_loc, '@');
 #if 1
  if (n == LHS_REF) {
-  before_tag = "<PYACC_Text_ValueLocation>";
-  after_tag = "</PYACC_Text_ValueLocation>";
+  code_piece_append("<PYACC_Text_ValueLocation>");
+  code_piece_esc(yytext, strlen(yytext));
+  code_piece_append("</PYACC_Text_ValueLocation>");
  }
  else {
   sprintf(code_piece_temp, "<PYACC_Text_StackLocation index=\"%d\">", n);
-  before_tag = code_piece_temp;
-  after_tag = "</PYACC_Text_StackLocation>";
+  code_piece_append(code_piece_temp);
+  code_piece_esc(yytext, strlen(yytext));
+  code_piece_append("</PYACC_Text_StackLocation>");
  }
  if (no_handle_action)
   return;
index d6d5fa7..63bca81 100644 (file)
@@ -2502,7 +2502,7 @@ YY_RULE_SETUP
         STRING_FREE;
         BEGIN INITIAL;
 #if 1
- gram_piece_append("</PYACC_Text");
+ gram_piece_append("</PYACC_Text>");
  gram_piece_esc(gram_text, strlen(gram_text));
  gram_piece_append("</PYACC_Tag>");
  gram_piece_pack();