def __operation(): return OrderedChoice([ (Grammar.__mappingOp), (Grammar.__processingOp), (Grammar.__sharedCoreOp), (Grammar.__isEqualOp), ])
def choice_SA(parser, node, children): # If there is only one child reduce as # this ordered choice is unnecessary if len(children) > 1: return OrderedChoice(nodes=children[:]) else: return children[0]
def _class_gram(): return OrderedChoice([ _class_base_stub, _class_base_impl, _class_inh_stub, _class_inh_impl, ])
def visit_ordered_choice(self, node, children): if len(children) > 1: retval = OrderedChoice(nodes=children[:]) else: # If only one child rule exists reduce. retval = children[0] return retval
def wrappedDef(): return ( 'message', # match - any word or digit character one or more word or digit characters until a non word/digit character RegExMatch(r'[\w\d]+'), '{', OrderedChoice(Optional(oneofDef), Optional(repeatedDef)), '}')
def _cgs_block(): return '{', ZeroOrMore( OrderedChoice([ _cgs_var_stub, _cgs_var_ready, _cgs_async_gram, _cgs_sync_gram, ])), '}'
def match_rule_body_SA(parser, node, children): # This is a match rule parser._current_cls._tx_type = RULE_MATCH # String representation of match alternatives. # Used in visualizations and debugging parser._current_cls._match_str = \ "|".join([text(match) for match in children]) return OrderedChoice(nodes=children[:])
def _grammar(): return ZeroOrMore( OrderedChoice([ _class_gram, _single_gram, _generic_gram, _alias_gram, _flow_gram, ]), ), EOF
def _cb_grammar(): return '{', ZeroOrMore( OrderedChoice([ _cb_sync_copy, _cb_sync_from, _cb_var_stub, _cb_var_ready, _cb_var_async_set, _cb_var_sync_set, _cb_async_from, _cb_note, ])), Optional([ _cb_return, ]), '}'
def __expression(): return OrderedChoice([ ( ("("), Grammar.__expression, (")"), Grammar.__relation, ("("), Grammar.__expression, (")"), ), Grammar.__andExpression, Grammar.__orExpression, Grammar.__operation, ])
def element(): # Without an enclosing list for 'words, newline', OrderedChoice # implicitly becomes Sequence ! return OrderedChoice([words, blank_line, newline], rule_name='element')
def compare(): return OrderedChoice(['>=', '<=', '<', '=', '>'])
def term(): return Optional(["+", "-"]), OrderedChoice([(ZeroOrMore([gennum]), Optional(['*']), varname), gennum])
def gennum(): return OrderedChoice([scinot, number])
def argument(): # EOF causes hang in optional/required return Sequence((wx, OrderedChoice([option, operand, command])), rule_name="argument", skipws=True)
def term(): # EOF causes hang in optional/required return OrderedChoice([options_shortcut, optional, required, argument], rule_name="term", skipws=True)
def customDef(): return OrderedChoice(ZeroOrMore(commentBlock), ZeroOrMore(commentLine))
def ol_first_option(): return Sequence ( ( And(ws), OrderedChoice( [ _long, _short ] ) ), rule_name='ol_first_option', skipws=False )
def element(): # To work properly, first argumnet of OrderedChoice must be a # list. IF not, it implicitly becomes Sequence ! return OrderedChoice ( [ *grammar_elements ], rule_name='element' )
def visit_textx_rule_body(self, node, children): if len(children) == 1: return children[0] return OrderedChoice(nodes=children[:])
def grammar(): return Sequence((OneOrMore(OrderedChoice(elements)), EOF), rule_name="grammar")
def grammar(_words): body = OneOrMore(OrderedChoice([rule, _words, catchall, newline])) return Sequence((body, EOF))
def visit_choice(self, node, children): # If there is only one child reduce as # this ordered choice is unnecessary if len(children) == 1: return children[0] return OrderedChoice(nodes=children[:])
def abstract_rule_body_SA(parser, node, children): # This is a body of an abstract rule so set # the proper type parser._current_cls._tx_type = RULE_ABSTRACT return OrderedChoice(nodes=children[:])
def comment_line(): return _(r'//.*?$') def comment_block(): return _(r'/\*(.|\n)*?\*/') # Special rules - primitive types ID = _(r'[^\d\W]\w*\b', rule_name='ID', root=True) BOOL = _(r'(True|true|False|false|0|1)\b', rule_name='BOOL', root=True) INT = _(r'[-+]?[0-9]+\b', rule_name='INT', root=True) FLOAT = _(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\b', 'FLOAT', root=True) STRING = _(r'("(\\"|[^"])*")|(\'(\\\'|[^\'])*\')', 'STRING', root=True) NUMBER = OrderedChoice(nodes=[FLOAT, INT], rule_name='NUMBER', root=True) BASETYPE = OrderedChoice(nodes=[NUMBER, BOOL, ID, STRING], rule_name='BASETYPE', root=True) BASE_TYPE_RULES = { rule.rule_name: rule for rule in [ID, BOOL, INT, FLOAT, STRING, NUMBER, BASETYPE] } BASE_TYPE_NAMES = BASE_TYPE_RULES.keys() PRIMITIVE_PYTHON_TYPES = [int, float, text, bool] for regex in [ID, BOOL, INT, FLOAT, STRING]: regex.compile()
def body(): return Sequence(OneOrMore(OrderedChoice([option, operand, ws])), EOF, rule_name='body', skipws=False)
def MyOrderedChoice(*args, **kwargs): return OrderedChoice([*args], **kwargs)
def grammar(): return Sequence(OneOrMore(OrderedChoice([option, operand, ws])), EOF, rule_name='grammar', skipws=False)
def headerComments(): return (OrderedChoice(ZeroOrMore(commentBlock), ZeroOrMore(commentLine)))
def usage_line(): # usage_line = usage_pattern newline / usage_pattern EOF return OrderedChoice([(usage_pattern, newline), (usage_pattern, EOF)], rule_name="usage_line", skipws=True)