def typeDefs(): return OneOrMore( UnorderedGroup( ZeroOrMore(messageDef), ZeroOrMore(wrappedDef), ZeroOrMore(enumDef), ))
def visit_repeatable_expr(self, node, children): expr = children[0] rule = expr repeat_op = False suppress = False if len(children) > 1: # We can have repeat operator and/or suppression operator if len(children) > 2: repeat_op = children[1] suppress = True else: if children[1] == '-': suppress = True else: repeat_op = children[1] if repeat_op: if len(repeat_op) > 1: repeat_op, modifiers = repeat_op else: repeat_op = repeat_op[0] modifiers = None if repeat_op == '?': rule = Optional(nodes=[expr]) elif repeat_op == '*': rule = ZeroOrMore(nodes=[expr]) elif repeat_op == '+': rule = OneOrMore(nodes=[expr]) else: rule = UnorderedGroup(nodes=expr.nodes) if modifiers: modifiers, position = modifiers # Sanity check. Modifiers do not make # sense for ? operator at the moment. if repeat_op == '?': line, col = \ self.grammar_parser.pos_to_linecol(position) raise TextXSyntaxError( 'Modifiers are not allowed for "?" operator at {}'. format(text((line, col))), line, col) # Separator modifier rule.sep = modifiers.get('sep', None) # End of line termination modifier if 'eolterm' in modifiers: rule.eolterm = True # Mark rule for suppression rule.suppress = suppress return rule
def visit_sufix(self, node, children): if len(children) == 2: if type(children[0]) is list: nodes = children[0] else: nodes = [children[0]] if children[1] == ZERO_OR_MORE: retval = ZeroOrMore(nodes=nodes) elif children[1] == ONE_OR_MORE: retval = OneOrMore(nodes=nodes) elif children[1] == OPTIONAL: retval = Optional(nodes=nodes) else: retval = UnorderedGroup(nodes=nodes[0].nodes) else: retval = children[0] return retval
def typeDefs(): return OneOrMore( UnorderedGroup(ZeroOrMore(structDef), ZeroOrMore(enumDef), ZeroOrMore(wrappedDef)))
def grammar(): return UnorderedGroup("a", "b", "c", sep=StrMatch(",")), EOF
def grammar(): return UnorderedGroup("a", "b", "c"), EOF
def grammar(): return UnorderedGroup("a", Optional("b"), "c", sep=","), EOF
def root(): return 'word1', UnorderedGroup(some_rule, 'word2', some_rule), EOF
def grammar(): return UnorderedGroup('a', 'b', 'c', sep=[',', ';']), EOF
def header(): return UnorderedGroup(syntax, package, headerComments, ZeroOrMore(pkgImports))
def typeDefs(): return (OneOrMore( UnorderedGroup(ZeroOrMore(recordDef), ZeroOrMore(enumDef), ZeroOrMore(arrayOfDef))))