def expand_named_state_definition(source, loc, tokens):
indent = "<STR_LIT:U+0020>" * (pp.col(loc, source) - <NUM_LIT:1>)<EOL>statedef = []<EOL>states = set()<EOL>transitions = set()<EOL>baseStateClass = tokens.name<EOL>fromTo = {}<EOL>for tn in tokens.transitions:<EOL><INDENT>states.add(tn.from_state)<EOL>states.add(tn.to_state)<EOL>transitions.add(tn.transition)<EOL>if tn.from_state in fromTo:<EOL><INDENT>fromTo[tn.from_state][tn.transition] = tn.to_state<EOL><DEDENT>else:<EOL><INDENT>fromTo[tn.from_state] = {tn.transition: tn.to_state}<EOL><DEDENT><DEDENT>for s in states:<EOL><INDENT>if s not in fromTo:<EOL><INDENT>fromTo[s] = {}<EOL><DEDENT><DEDENT>statedef.extend([<EOL>"<STR_LIT>".format(baseStateClass=baseStateClass),<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>])<EOL>statedef.extend(<EOL>"<STR_LIT>".format(tn_name=tn,<EOL>baseStateClass=baseStateClass)<EOL>for tn in transitions)<EOL>statedef.extend("<STR_LIT>".format(tn_name=tn)<EOL>for tn in transitions)<EOL>statedef.extend([<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>])<EOL>statedef.extend([<EOL>"<STR_LIT>" % baseStateClass,<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>])<EOL>statedef.extend(<EOL>"<STR_LIT>".format(tn_name=tn)<EOL>for tn in transitions)<EOL>statedef.extend("<STR_LIT>" % (s, baseStateClass)<EOL>for s in states)<EOL>for s in states:<EOL><INDENT>trns = list(fromTo[s].items())<EOL>statedef.extend("<STR_LIT>" % (s, tn_, to_)<EOL>for tn_, to_ in trns)<EOL><DEDENT>statedef.extend([<EOL>"<STR_LIT>".format(<EOL>baseStateClass=baseStateClass,<EOL>transition_class_list = '<STR_LIT:U+002CU+0020>'.join("<STR_LIT>".format(tn) for tn in transitions)<EOL>),<EOL>"<STR_LIT>".format(<EOL>baseStateClass=baseStateClass<EOL>)<EOL>])<EOL>statedef.extend([<EOL>"<STR_LIT>".format(baseStateClass=baseStateClass),<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>"<EOL>])<EOL>statedef.extend(<EOL>"<STR_LIT>".format(tn_name=tn)<EOL>for tn in transitions<EOL>)<EOL>return indent + ("<STR_LIT:\n>" + indent).join(statedef) + "<STR_LIT:\n>"<EOL>
Parse action to convert statemachine with named transitions to corresponding Python
classes and methods