コード例 #1
0
ファイル: initial.py プロジェクト: dusanmaric90/WebApp
def initial():               return OneOrMore([nclasses,enumeration]),database_config, EOF
def nclasses():              return OneOrMore(nclass)
コード例 #2
0
ファイル: initial.py プロジェクト: dusanmaric90/WebApp
def attributes():            return "[", OneOrMore(attribute), Optional(attribute_label),"]"
def attribute():             return attribute_key, "=", attribute_value
コード例 #3
0
 def recordDef():
     return (defHeader, OneOrMore(defField), Optional('}'), Optional(')'),
             Optional(']'))
コード例 #4
0
 def arrayOfDef():
     return (
         ZeroOrMore(RegExMatch(r'[\w]+')),  # name
         OneOrMore(RegExMatch(r'.*\]')),  # data up to comment
         ZeroOrMore(RegExMatch(r';[\s*\w]+')))
コード例 #5
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def pattern_with_last(): return ("(", OneOrMore(pattern), ".", pattern, ")")
def pattern_datum(): return [string, character, boolean, number]
コード例 #6
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def command_or_definition(): return [expression,
        definition,
        syntax_definition,
        ("(", "begin", OneOrMore(command_or_definition), ")")]
def definition(): return [ ("(", "define", variable, expression, ")"),
コード例 #7
0
 def syntax():
     # match - syntax = ['"]SYNTAX['"](;)
     return RegExMatch(r'syntax\s?=\s?[\'\"].*[\'\"]\;?'), OneOrMore(
         endLine)
コード例 #8
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def cond(): return "(", "cond", OneOrMore([cond_clause, cond_call]), Optional(else_clause), ")"
def cond_clause(): return "(", expression, ZeroOrMore(expression), ")"
コード例 #9
0
def citeString():
    return (keywords, [(Optional(date), OneOrMore(cite)),
                       partialCite], oComma, EOF)
コード例 #10
0
 def oneofDef():
     return ('oneof', defHeader, OneOrMore(defField), '}')
コード例 #11
0
def intraCite():
    return OneOrMore(
        (supraSection, Optional(section), oComma, Optional(inPara)))
コード例 #12
0
ファイル: day3.py プロジェクト: hank/AOC2018
def claims(): return OneOrMore(claim), EOF

class ClaimVisitor(PTNodeVisitor):
コード例 #13
0
ファイル: lang.py プロジェクト: goto40/textX-gui-experiment
def repeat_modifiers():
    return '[', OneOrMore([simple_match, 'eolterm']), ']'
コード例 #14
0
ファイル: lang.py プロジェクト: goto40/textX-gui-experiment
    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
コード例 #15
0
 def package():
     # match - package ('")PACKAGE('")(;)
     return RegExMatch(r'package\s?[\'\"]?.*[\'\"]?\;?'), OneOrMore(endLine)
コード例 #16
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def sequence(): return OneOrMore(expression)

def conditional(): return "(", "if", expression, expression, Optional(expression), ")"
コード例 #17
0
 def pkgImports():
     # match - import ['"]PACKAGE['"](;)
     return RegExMatch(r'import\s?[\'\"].*[\'\"]\;?'), OneOrMore(endLine)
コード例 #18
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def else_clause(): return "(", "else", OneOrMore(expression), ")"
def or_(): return "(", "or", ZeroOrMore(expression), ")"
コード例 #19
0
 def messageDef():
     return ('message', defHeader, OneOrMore(defField), '}')
コード例 #20
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def template_with_last(): return ("(", OneOrMore(template_element), ".", template, ")")
def template_element(): return [template, (template, ellipsis)]
コード例 #21
0
def metalstar():
    return Optional(noprefixstar), OneOrMore(metalsection)
def calc():       return OneOrMore(expression), EOF


def test_pp_construction():
コード例 #23
0
def scrange():
    return [(numeric, '-', Optional(numeric)), (numeric, '+'),
            (numeric, Optional(OneOrMore(' '), '-', OneOrMore(' '), numeric))]
コード例 #24
0
 def enumDef():
     return (defHeader, OneOrMore(enumField), OneOrMore(endLine))
コード例 #25
0
ファイル: parser.py プロジェクト: PatrickDeVries/cs3342_smurf
def integer():
    return (Optional("-"), OneOrMore(nums))
コード例 #26
0
 def typeDefs():
     return (OneOrMore(
         UnorderedGroup(ZeroOrMore(recordDef), ZeroOrMore(enumDef),
                        ZeroOrMore(arrayOfDef))))
コード例 #27
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def _list(): return  [("(", ZeroOrMore(datum), ")"), ("(", OneOrMore(datum), ".", datum, ")")] #, abbreviation]
def abbreviation(): return abbrev_prefix, datum
コード例 #28
0
ファイル: initial.py プロジェクト: dusanmaric90/WebApp
def nclasses():              return OneOrMore(nclass)
def nclass():                return  Optional(ABSTRACT),CLASS, class_name,Optional(":", class_name), ZeroOrMore(attributes)
コード例 #29
0
ファイル: parser.py プロジェクト: ssmi1975/scheme-py
def parameters_with_last(): return "(", OneOrMore(variable), ".", variable, ")"
def body(): return ZeroOrMore(definition), sequence
コード例 #30
0
ファイル: textx.py プロジェクト: zeph/textX
def assignment_SA(parser, node, children):
    """
    Create parser rule for addition and register attribute types
    on metaclass.
    """
    attr_name = children[0]
    op = children[1]
    rhs_rule, modifiers = children[2]
    cls = parser._current_cls
    target_cls = None

    if parser.debug:
        parser.dprint("Processing assignment {}{}...".format(attr_name, op))

    if parser.debug:
        parser.dprint("Creating attribute {}:{}".format(cls.__name__,
                                                        attr_name))
        parser.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 = 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]
        # Must be a many multiplicity.
        # OneOrMore is "stronger" constraint.
        if cls_attr.mult is not MULT_ONEORMORE:
            cls_attr.mult = MULT_ZEROORMORE
    else:
        cls_attr = parser.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 ?= operator at the moment.
        if op == '?=':
            line, col = parser.pos_to_linecol(position)
            raise TextXSyntaxError(
                'Modifiers are not allowed for "?=" operator at {}'
                .format(text((line, col))), line, col)

        # Separator modifier
        if 'sep' in modifiers:
            sep = modifiers['sep']
            assignment_rule = Sequence(
                nodes=[rhs_rule,
                       ZeroOrMore(nodes=[Sequence(nodes=[sep, rhs_rule])])],
                rule_name='__asgn_list', root=True)
            if op == "*=":
                assignment_rule = Optional(nodes=[rhs_rule])
                assignment_rule = Optional(nodes=[Sequence(
                    nodes=[rhs_rule,
                           ZeroOrMore(nodes=[
                               Sequence(nodes=[sep, rhs_rule])])])],
                    rule_name='__asgn_list', root=True)

        # 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'
    cls_attr.cls = ClassCrossRef(cls_name=attr_type, position=node.position)

    if parser.debug:
        parser.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
コード例 #31
0
ファイル: lang.py プロジェクト: goto40/textX-gui-experiment
def sequence():
    return OneOrMore(repeatable_expr)