Rationalize option sense handling, fix a few bugs and typos
authorNick Downing <nick@ndcode.org>
Sun, 20 Jan 2019 02:16:55 +0000 (13:16 +1100)
committerNick Downing <nick@ndcode.org>
Sun, 20 Jan 2019 02:20:08 +0000 (13:20 +1100)
bootstrap/parse.y
bootstrap/scan.l

index 9d60865..27f2008 100644 (file)
@@ -132,7 +132,7 @@ sect2end
       global yychar
       if yychar == YYEMPTY:
         yychar = lex_yy.flexscan()
-        #print('yyy yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', yytext)
+        #print('yyy yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', lex_yy.yytext)
       insert_before(1, '</AST_Section3>')
       insert_after(0, '<AST_Section3>')
     }
@@ -351,7 +351,7 @@ scon
       #$$ = scon_stk_ptr
       if yychar == YYEMPTY:
         yychar = lex_yy.flexscan()
-        #print('xxx yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', yytext)
+        #print('xxx yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', lex_yy.yytext)
       temp = lex_yy.piece[piece2 + 1]
       lex_yy.piece[piece2 + 1] = lex_yy.piece[piece2]
       lex_yy.piece[piece2] = lex_yy.piece[piece2 - 1]
index b1cf64e..e45cc38 100644 (file)
@@ -311,16 +311,16 @@ M4QEND      "]""]"
 
  /* Nick added ("no"*) prefix to all, instead of it being a separate rule */
 <OPTION>{
-  ("no"*){NL} {
+  {NL} {
     state.linenum += 1
     BEGIN(INITIAL)
   }
-  ("no"*){WS} {
+  {WS} {
     #global option_sense
     #option_sense = True
   }
 
-  ("no"*)"="                   return ord('=')
+  "="                  return ord('=')
 
   /*no {
     global option_sense
@@ -441,7 +441,7 @@ M4QEND      "]""]"
     piece_append('</AST_Section1_Options_BisonLocations>')
     return y_tab.TOK_OPTION_OTHER # Nick
   }
-  "c++" {
+  ("no"*)"c++" {
     option_sense = (len(yy_groups[1]) & 2) == 0
     #C_plus_plus = option_sense
     piece_append(
@@ -1222,12 +1222,12 @@ M4QEND      "]""]"
     return y_tab.TOK_OPTION_OTHER # Nick
   }
 
-  ("no"*)extra-type            return y_tab.TOK_EXTRA_TYPE
-  ("no"*)outfile                       return y_tab.TOK_OUTFILE
-  ("no"*)prefix                        return y_tab.TOK_PREFIX
-  ("no"*)yyclass                       return y_tab.TOK_YYCLASS
-  ("no"*)header(-file)?                return y_tab.TOK_HEADER_FILE
-  ("no"*)tables-file           return y_tab.TOK_TABLES_FILE
+  extra-type           return y_tab.TOK_EXTRA_TYPE
+  outfile              return y_tab.TOK_OUTFILE
+  prefix               return y_tab.TOK_PREFIX
+  yyclass              return y_tab.TOK_YYCLASS
+  header(-file)?       return y_tab.TOK_HEADER_FILE
+  tables-file          return y_tab.TOK_TABLES_FILE
   ("no"*)tables-verify {
     option_sense = (len(yy_groups[1]) & 2) == 0
     #tablesverify = option_sense
@@ -1243,8 +1243,7 @@ M4QEND      "]""]"
     return y_tab.TOK_OPTION_OTHER # Nick
   }
 
-
-  ("no"*)\"[^"\n]*\" {
+  \"[^"\n]*\" {
     state.nmstr = yytext[1:-1]
     piece_pack()
     piece_append('<AST_String>"<AST_Text>')
@@ -1254,7 +1253,7 @@ M4QEND      "]""]"
     return ~y_tab.NAME
   }
 
-  ("no"*)(([a-mo-z]|n[a-np-z])[[:alpha:]\-+]*)|. {
+  (([a-mo-z]|n[a-np-z])[[:alpha:]\-+]*)|. {
     state.synerr('unrecognized %option: {0:s}'.format(yytext))
     BEGIN(RECOVER)
   }
@@ -1607,7 +1606,7 @@ M4QEND      "]""]"
     yy_push_state(ACTION_GROUP)
     bracelevel = 1
     piece_flush(len(yytext))
-    piece_append('<RegexGroupAction_Text>')
+    markup_stack.append(len(piece)) # <RegexGroupAction_Text>
   }
   "E{" {
     global bracelevel
@@ -1615,7 +1614,7 @@ M4QEND      "]""]"
     yy_push_state(ELEMENT_GROUP)
     bracelevel = 1
     piece_flush(len(yytext))
-    piece_append('<RegexGroupElement_Text>')
+    markup_stack.append(len(piece)) # <RegexGroupElement_Text>
   }
   ":" {
     BEGIN(SECT2)
@@ -1867,7 +1866,7 @@ M4QEND      "]""]"
   "'"([^\'\\\n]|\\.)"'"                #add_action(yytext)
   "'" {
     #add_action(yytext)
-    BEGIN(y_tab.CHARACTER_CONSTANT)
+    BEGIN(CHARACTER_CONSTANT)
   }
   \" {
     #add_action(yytext)
@@ -1983,8 +1982,9 @@ M4QEND      "]""]"
     bracelevel -= 1
     if bracelevel == 0:
       yy_pop_state()
+      piece_insert(markup_stack.pop(), '<RegexGroupAction_Text>')
       piece_append('</RegexGroupAction_Text>')
-      return TOK_ACTION_GROUP
+      return y_tab.TOK_ACTION_GROUP
   }
 }
 <ELEMENT_GROUP>{
@@ -1993,8 +1993,9 @@ M4QEND      "]""]"
     bracelevel -= 1
     if bracelevel == 0:
       yy_pop_state()
+      piece_insert(markup_stack.pop(), '<RegexGroupElement_Text>')
       piece_append('</RegexGroupElement_Text>')
-      return TOK_ELEMENT_GROUP
+      return y_tab.TOK_ELEMENT_GROUP
   }
 }
 <ACTION_GROUP,ELEMENT_GROUP>{