Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def term14():
    return [(term15, Optional('..', Optional(term15))), ('..', term15)]
Ejemplo n.º 3
0
def term4():
    return Optional(ident, ':='), term6
Ejemplo n.º 4
0
def expression():
    return [
        assignment,
        (Optional(syntactic_predicate),
         [simple_match, rule_ref, bracketed_choice])
    ]
Ejemplo n.º 5
0
def term19a():
    return term20, Optional('#', ident)
Ejemplo n.º 6
0
def textx_rule():
    return rule_name, Optional(rule_params), ":", textx_rule_body, ";"
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
def destructor() -> GrammarType:
    return (ZeroOrMore(['priv', 'inline']), 'dtor', Optional(control_structure_body_stub))
Ejemplo n.º 9
0
def eh_class() -> GrammarType:
    return 'class', identifier, Optional('{', ZeroOrMore(class_contents), '}')
Ejemplo n.º 10
0
def enum() -> GrammarType:
    return 'enum', identifier, Optional('{', ZeroOrMore(identifier), '}')
Ejemplo n.º 11
0
def constructor() -> GrammarType:
    return (ZeroOrMore(['priv', 'inline']), 'ctor', '(', function_arguments, ')',
            Optional(control_structure_body_stub))
Ejemplo n.º 12
0
def union() -> GrammarType:
    return 'union', identifier, Optional('{', ZeroOrMore(variable_declaration), '}')
Ejemplo n.º 13
0
def struct() -> GrammarType:
    return 'struct', identifier, Optional('{', ZeroOrMore(variable_declaration), '}')
Ejemplo n.º 14
0
def function_declaration() -> GrammarType:
    return Optional('cdecl'), function_prototype, Not('{')
Ejemplo n.º 15
0
def obj_ref():
    return '[', class_name, Optional('|', obj_ref_rule), ']'
Ejemplo n.º 16
0
def foo():      return 'r', bar, Optional(qux), baz, Optional(ham), Optional(buz), EOF
def bar():      return 'BAR'
Ejemplo n.º 17
0
def reference_stm():
    return ('reference', language_name, Optional(language_alias))
Ejemplo n.º 18
0
def exact_match_term():
    return ([
        (Optional(['+', '-']), [('"', _(r'((\\")|[^"])+'), '"'),
                                ("'", _(r"((\\')|[^'])+"), "'")]),
        (['+', '-'], common.correctly_parenthesised_non_space_char_sequence)
    ], common.term_end_lookahead)
Ejemplo n.º 19
0
def rule_param():
    return param_name, Optional('=', string_value)
Ejemplo n.º 20
0
def rrel_navigation():
    return Optional('~'), rrel_id
Ejemplo n.º 21
0
def repeatable_expr():
    return expression, Optional(repeat_operator), Optional('-')
Ejemplo n.º 22
0
def rrel_path():
    return Optional(['^', rrel_dots]), ArpeggioZeroOrMore(
        [rrel_zero_or_more, rrel_path_element], '.'), Optional(
        [rrel_zero_or_more, rrel_path_element])
Ejemplo n.º 23
0
def factor():     return Optional(["+","-"]), [number, ("(", expression, ")")]
def term():       return factor, ZeroOrMore(["*","/"], factor)
Ejemplo n.º 24
0
def rrel_expression():
    return Optional("+m:"), rrel_sequence
Ejemplo n.º 25
0
def term18a():
    return term19, ZeroOrMore('(', Optional(expression), ')')
Ejemplo n.º 26
0
def repeat_operator():
    return ['*', '?', '+', '#'], Optional(repeat_modifiers)
Ejemplo n.º 27
0
def term6():
    return term7, Optional('?', term6, ':', term6)
Ejemplo n.º 28
0
def assignment_rhs():
    return [simple_match, reference], Optional(repeat_modifiers)
Ejemplo n.º 29
0
def ifterm():
    return 'if', '(', expression, ')', term1, Optional('else', term1)
Ejemplo n.º 30
0
def trailing_comma() -> GrammarType:
    return Optional(',')