self.repr_serialize(params)
return 'ast.AST.Section2.Rule.EOFRule({0:s})'.format(', '.join(params))
# GENERATE END
-
+ def post_process(
+ self,
+ _ast,
+ section,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions,
+ parent_start_conditions,
+ continued_action,
+ start_conditions,
+ action
+ ):
+ assert not continued_action
+ if len(start_conditions) == 0:
+ for i in all_start_conditions:
+ if _ast.start_conditions[i].eof_action == 0:
+ _ast.start_conditions[i].eof_action = (
+ len(_ast.eof_actions_text)
+ )
+ else:
+ for i in start_conditions:
+ assert _ast.start_conditions[i].eof_action == 0
+ _ast.start_conditions[i].eof_action = (
+ len(_ast.eof_actions_text)
+ )
+ assert not action.continued
+ _ast.eof_actions_text.append(action[0])
+ return False # continued_action
+
class FLexRule(element.Element):
# GENERATE ELEMENT(bool bol, int action) BEGIN
def __init__(
self.repr_serialize(params)
return 'ast.AST.Section2.Rule.FLexRule({0:s})'.format(', '.join(params))
# GENERATE END
+ def post_process(
+ self,
+ _ast,
+ section,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions,
+ parent_start_conditions,
+ continued_action,
+ start_conditions,
+ action
+ ):
+ for i in (
+ start_conditions
+ if len(start_conditions) else
+ inclusive_start_conditions
+ ):
+ if not self.bol:
+ _ast.start_conditions[i].rules.append(self)
+ _ast.start_conditions[i].bol_rules.append(self)
+ self[0].post_process(
+ caseless = _ast[0].caseless
+ ) # regex
+ self[1].post_process(
+ caseless = _ast[0].caseless
+ ) # trailing context regex
+ self.action = len(_ast.actions_text)
+ if action.continued:
+ continued_action = True
+ else:
+ _ast.actions_text.append(action[0])
+ continued_action = False
+ #def to_text(node):
+ # return ''.join(
+ # [
+ # j
+ # for i in range(len(node))
+ # for j in [element.get_text(node, i), to_text(node[i])]
+ # ] +
+ # [element.get_text(node, len(node))]
+ # )
+ #text = '{0:s}/{1:s}'.format(to_text(self[0]), to_text(self[1]))
+ #element.set_text(
+ # _ast.actions_text[-1],
+ # 0,
+ # 'fprintf(stderr, "%d >>>%s<<< {0:s}\\n", yy_start, yytext);\n{1:s}'.format(
+ # text.replace('\\', '\\\\').replace('"', '\\"').replace('%', '%%'),
+ # element.get_text(_ast.actions_text[-1], 0)
+ # )
+ #)
+ return continued_action
# GENERATE ELEMENT() BEGIN
def __init__(
start_conditions.add(
name_to_start_condition[i.get_text()]
)
- if isinstance(self[1], AST.Section2.Rule.EOFRule):
- assert not continued_action
- if len(start_conditions) == 0:
- for i in all_start_conditions:
- if _ast.start_conditions[i].eof_action == 0:
- _ast.start_conditions[i].eof_action = (
- len(_ast.eof_actions_text)
- )
- else:
- for i in start_conditions:
- assert _ast.start_conditions[i].eof_action == 0
- _ast.start_conditions[i].eof_action = (
- len(_ast.eof_actions_text)
- )
- assert not self[2].continued
- _ast.eof_actions_text.append(self[2][0])
- elif isinstance(self[1], AST.Section2.Rule.FLexRule):
- for i in (
- start_conditions
- if len(start_conditions) else
- inclusive_start_conditions
- ):
- if not self[1].bol:
- _ast.start_conditions[i].rules.append(self[1])
- _ast.start_conditions[i].bol_rules.append(self[1])
- self[1][0].post_process(
- caseless = _ast[0].caseless
- ) # regex
- self[1][1].post_process(
- caseless = _ast[0].caseless
- ) # trailing context regex
- self[1].action = len(_ast.actions_text)
- if self[2].continued:
- continued_action = True
- else:
- _ast.actions_text.append(self[2][0])
- continued_action = False
- #def to_text(node):
- # return ''.join(
- # [
- # j
- # for i in range(len(node))
- # for j in [element.get_text(node, i), to_text(node[i])]
- # ] +
- # [element.get_text(node, len(node))]
- # )
- #text = '{0:s}/{1:s}'.format(to_text(self[1][0]), to_text(self[1][1]))
- #element.set_text(
- # _ast.actions_text[-1],
- # 0,
- # 'fprintf(stderr, "%d >>>%s<<< {0:s}\\n", yy_start, yytext);\n{1:s}'.format(
- # text.replace('\\', '\\\\').replace('"', '\\"').replace('%', '%%'),
- # element.get_text(_ast.actions_text[-1], 0)
- # )
- #)
- else:
- assert False
- return continued_action
-
+ return self[1].post_process(
+ _ast,
+ section,
+ name_to_start_condition,
+ all_start_conditions,
+ inclusive_start_conditions,
+ parent_start_conditions,
+ continued_action,
+ start_conditions,
+ self[2] # action
+ )
+
class StartConditions(element.Element):
# GENERATE ELEMENT(bool wildcard) BEGIN
def __init__(