def function_arguments() -> GrammarType: return (Optional([Sequence(OneOrMore(variable_declaration_assignable, sep=','), Optional(',', Optional(full_type), function_variadic_dots)), Sequence(Optional(full_type), function_variadic_dots)]), trailing_comma)
def term14(): return [(term15, Optional('..', Optional(term15))), ('..', term15)]
def term4(): return Optional(ident, ':='), term6
def expression(): return [ assignment, (Optional(syntactic_predicate), [simple_match, rule_ref, bracketed_choice]) ]
def term19a(): return term20, Optional('#', ident)
def textx_rule(): return rule_name, Optional(rule_params), ":", textx_rule_body, ";"
def visit_assignment(self, node, children): """ Create parser rule for assignments and register attribute types on metaclass. """ attr_name = children[0] op = children[1] rhs_rule, modifiers = children[2] cls = self._current_cls target_cls = None if self.debug: self.dprint("Processing assignment {}{}...".format(attr_name, op)) if self.debug: self.dprint("Creating attribute {}:{}".format( cls.__name__, attr_name)) self.dprint("Assignment operation = {}".format(op)) if attr_name in cls._tx_attrs: # If attribute already exists in the metamodel it is # multiple assignment to the same attribute. # Cannot use operator ?= on multiple assignments if op == '?=': line, col = self.grammar_parser.pos_to_linecol(node.position) raise TextXSemanticError( 'Cannot use "?=" operator on multiple' ' assignments for attribute "{}" at {}'.format( attr_name, (line, col)), line, col) cls_attr = cls._tx_attrs[attr_name] else: cls_attr = self.metamodel._new_cls_attr(cls, name=attr_name, position=node.position) # Keep track of metaclass references and containments if type(rhs_rule) is tuple and rhs_rule[0] == "obj_ref": cls_attr.cont = False cls_attr.ref = True # Override rhs by its PEG rule for further processing rhs_rule = rhs_rule[1] # Target class is not the same as target rule target_cls = rhs_rule.cls base_rule_name = rhs_rule.rule_name if op == '+=': assignment_rule = OneOrMore(nodes=[rhs_rule], rule_name='__asgn_oneormore', root=True) cls_attr.mult = MULT_ONEORMORE elif op == '*=': assignment_rule = ZeroOrMore(nodes=[rhs_rule], rule_name='__asgn_zeroormore', root=True) if cls_attr.mult is not MULT_ONEORMORE: cls_attr.mult = MULT_ZEROORMORE elif op == '?=': assignment_rule = Optional(nodes=[rhs_rule], rule_name='__asgn_optional', root=True) cls_attr.mult = MULT_OPTIONAL base_rule_name = 'BOOL' # ?= assigment should have default value of False. # so we shall mark it as such. cls_attr.bool_assignment = True else: assignment_rule = Sequence(nodes=[rhs_rule], rule_name='__asgn_plain', root=True) # Modifiers if modifiers: modifiers, position = modifiers # Sanity check. Modifiers do not make # sense for ?= and = operator at the moment. if op == '?=' or op == '=': line, col = self.grammar_parser.pos_to_linecol(position) raise TextXSyntaxError( 'Modifiers are not allowed for "{}" operator at {}'.format( op, text((line, col))), line, col) # Separator modifier assignment_rule.sep = modifiers.get('sep', None) # End of line termination modifier if 'eolterm' in modifiers: assignment_rule.eolterm = True if target_cls: attr_type = target_cls else: # Use STRING as default attr class attr_type = base_rule_name if base_rule_name else 'STRING' if not cls_attr.cls: cls_attr.cls = ClassCrossRef(cls_name=attr_type, position=node.position) else: # cls cross ref might already be set in case of multiple assignment # to the same attribute. If types are not the same we shall use # OBJECT as generic type. if cls_attr.cls.cls_name != attr_type: cls_attr.cls.cls_name = 'OBJECT' if self.debug: self.dprint("Created attribute {}:{}[cls={}, cont={}, " "ref={}, mult={}, pos={}]".format( cls.__name__, attr_name, cls_attr.cls.cls_name, cls_attr.cont, cls_attr.ref, cls_attr.mult, cls_attr.position)) assignment_rule._attr_name = attr_name assignment_rule._exp_str = attr_name # For nice error reporting return assignment_rule
def destructor() -> GrammarType: return (ZeroOrMore(['priv', 'inline']), 'dtor', Optional(control_structure_body_stub))
def eh_class() -> GrammarType: return 'class', identifier, Optional('{', ZeroOrMore(class_contents), '}')
def enum() -> GrammarType: return 'enum', identifier, Optional('{', ZeroOrMore(identifier), '}')
def constructor() -> GrammarType: return (ZeroOrMore(['priv', 'inline']), 'ctor', '(', function_arguments, ')', Optional(control_structure_body_stub))
def union() -> GrammarType: return 'union', identifier, Optional('{', ZeroOrMore(variable_declaration), '}')
def struct() -> GrammarType: return 'struct', identifier, Optional('{', ZeroOrMore(variable_declaration), '}')
def function_declaration() -> GrammarType: return Optional('cdecl'), function_prototype, Not('{')
def obj_ref(): return '[', class_name, Optional('|', obj_ref_rule), ']'
def foo(): return 'r', bar, Optional(qux), baz, Optional(ham), Optional(buz), EOF def bar(): return 'BAR'
def reference_stm(): return ('reference', language_name, Optional(language_alias))
def exact_match_term(): return ([ (Optional(['+', '-']), [('"', _(r'((\\")|[^"])+'), '"'), ("'", _(r"((\\')|[^'])+"), "'")]), (['+', '-'], common.correctly_parenthesised_non_space_char_sequence) ], common.term_end_lookahead)
def rule_param(): return param_name, Optional('=', string_value)
def rrel_navigation(): return Optional('~'), rrel_id
def repeatable_expr(): return expression, Optional(repeat_operator), Optional('-')
def rrel_path(): return Optional(['^', rrel_dots]), ArpeggioZeroOrMore( [rrel_zero_or_more, rrel_path_element], '.'), Optional( [rrel_zero_or_more, rrel_path_element])
def factor(): return Optional(["+","-"]), [number, ("(", expression, ")")] def term(): return factor, ZeroOrMore(["*","/"], factor)
def rrel_expression(): return Optional("+m:"), rrel_sequence
def term18a(): return term19, ZeroOrMore('(', Optional(expression), ')')
def repeat_operator(): return ['*', '?', '+', '#'], Optional(repeat_modifiers)
def term6(): return term7, Optional('?', term6, ':', term6)
def assignment_rhs(): return [simple_match, reference], Optional(repeat_modifiers)
def ifterm(): return 'if', '(', expression, ')', term1, Optional('else', term1)
def trailing_comma() -> GrammarType: return Optional(',')