%%
goal
- : initlex sect1 sect1end sect2 initforrule
+ : initlex sect1 sect1end sect2 sect2end initforrule
{
#def_rule = None
#pat = cclinit()
#else:
# add_action('ECHO')
#add_action(';\n\tYY_BREAK]]\n')
+ insert_before(4, '</AST_Section2>')
+ insert_after(2, '<AST_Section2>')
+ insert_before(2, '</AST_Section1>')
+ insert_before(0, '<AST_Section1>')
}
;
}
;
+/* Nick */
+sect2end
+ : SECTEND
+ {
+ global yychar
+ if yychar == YYEMPTY:
+ yychar = lex_yy.flexscan()
+ #print('yyy yychar', yychar, 'yylval', yylval, 'yylloc', yylloc, 'lex_yy.yytext', yytext)
+ insert_before(1, '</AST_Section3>')
+ insert_after(0, '<AST_Section3>')
+ }
+ |
+ ;
+
startconddecl
: SCDECL
{
piece = []
piece0 = 0
+ markup_stack = []
# these should be yylex()-local, but moved to here, see further down:
bracelevel = 0
yy_push_state(CODEBLOCK)
indented_code = True
#add_action(yytext)
- piece_append('<AST_Section1Or2_CodeBlock>')
- piece_append('<AST_Text>')
+ markup_stack.append(len(piece)) # <AST_Section1Or2_CodeBlock>
+ markup_stack.append(len(piece)) # <AST_Text>
}
^"/*" {
#add_action('/*[' '[')
#add_action('[' '[')
yy_push_state(CODEBLOCK)
indented_code = False
- piece_append('<AST_Section1Or2_CodeBlock>')
+ markup_stack.append(len(piece)) # <AST_Section1Or2_CodeBlock>
piece_flush(len(yytext))
- piece_append('<AST_Text>')
+ markup_stack.append(len(piece)) # <AST_Text>
}
^"%top"[[:blank:]]*"{"[[:blank:]]*{NL} {
global brace_start_line, brace_depth
#mark_defs1()
#line_directive_out(None, 1)
BEGIN(SECT2PROLOG)
- piece_append('</AST_Section1>')
- piece_pack()
- piece_escape(yytext)
- piece_append('<AST_Section2>')
- piece_pack()
- return ~y_tab.SECTEND
+ return y_tab.SECTEND
}
^"%pointer".*{NL} {
<CODEBLOCK>{
^"%}".*{NL} {
state.linenum += 1
+ piece_insert(markup_stack.pop(), '<AST_Text>')
piece_append('</AST_Text>')
piece_flush(len(yytext))
yy_pop_state()
#add_action(']' ']')
#if not indented_code:
# line_directive_out(None, 0)
+ piece_insert(markup_stack.pop(), '<AST_Section1Or2_CodeBlock>')
piece_append('</AST_Section1Or2_CodeBlock>')
}
[^\n%\[\]]* #add_action(yytext)
#add_action(yytext)
if indented_code:
piece_flush(len(yytext))
+ piece_insert(markup_stack.pop(), '<AST_Text>')
piece_append('</AST_Text>')
yy_pop_state()
#add_action(']' ']')
#if not indented_code:
# line_directive_out(None, 0)
+ piece_insert(markup_stack.pop(), '<AST_Section1Or2_CodeBlock>')
piece_append('</AST_Section1Or2_CodeBlock>')
}
}
yy_push_state(CODEBLOCK)
indented_code = True
#add_action(yytext)
- piece_append('<AST_Section1Or2_CodeBlock>')
- piece_append('<AST_Text>')
+ markup_stack.append(len(piece)) # <AST_Section1Or2_CodeBlock>
+ markup_stack.append(len(piece)) # <AST_Text>
}
^{NOT_WS}.* {
yy_push_state(CODEBLOCK)
indented_code = True
#add_action(yytext)
- piece_append('<AST_Section1Or2_CodeBlock>')
- piece_append('<AST_Text>')
+ markup_stack.append(len(piece)) # <AST_Section1Or2_CodeBlock>
+ markup_stack.append(len(piece)) # <AST_Text>
}
. #add_action(yytext)
#mark_prolog()
sectnum = 0
piece_pack()
- piece_append('</AST_Section2>')
- piece_pack()
return ~YY_NULL
}
}
bracelevel = 1
BEGIN(PERCENT_BRACE_ACTION)
piece_flush(len(yytext) - 2)
- piece_append('<AST_Section1Or2_CodeBlock>')
+ markup_stack.append(len(piece)) # <AST_Section1Or2_CodeBlock>
piece_flush(2)
- piece_append('<AST_Text>')
+ markup_stack.append(len(piece)) # <AST_Text>
}
^{OPTWS}"<" {
bracelevel = 1
BEGIN(PERCENT_BRACE_ACTION)
piece_flush(len(yytext) - 2)
- piece_append('<AST_Section2_Rule_Action>')
+ markup_stack.append(len(piece)) # <AST_Section2_Rule_Action>
assert state.in_rule # should do error message here
doing_rule_action = True
state.in_rule = False
piece_flush(2)
- piece_append('<AST_Text>')
+ markup_stack.append(len(piece)) # <AST_Text>
}
{WS}"|".*{NL} {
if state._sf_stk[-1] & 4:
sectnum = 3
BEGIN(SECT3_NOESCAPE if state.no_section3_escape else SECT3)
#outn('/* Begin user sect3 */')
- piece_append('</AST_Section2>')
- piece_flush(len(yytext))
- piece_append('<AST_Section3>')
+ return y_tab.SECTEND
}
"["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})* {
. {
y_tab.yylval = ord(yytext[0])
return y_tab.CHAR
- }
-
- /* Nick added this rule for consistency with rest of scanner */
- <<EOF>> {
- sectnum = 0
- piece_pack()
- piece_append('</AST_Section2>')
- piece_pack()
- return ~YY_NULL
}
}
{OPTWS}"%}".* {
global bracelevel
bracelevel = 0
+ piece_insert(markup_stack.pop(), '<AST_Text>')
piece_append('</AST_Text>')
}
doing_rule_action = False
BEGIN(SECT2)
if doing_codeblock:
+ piece_insert(markup_stack.pop(), '<AST_Section1Or2_CodeBlock>')
piece_append('</AST_Section1Or2_CodeBlock>')
doing_codeblock = False
else:
+ piece_insert(markup_stack.pop(), '<AST_Section2_Rule_Action>')
piece_append('</AST_Section2_Rule_Action>')
return ord('\n')
}
<<EOF>> {
sectnum = 0
piece_pack()
- piece_append('</AST_Section3>')
- piece_pack()
return ~YY_NULL
}
}
<<EOF>> {
sectnum = 0
piece_pack()
- piece_append('</AST_Section3>')
- piece_pack()
return ~YY_NULL
}
}