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