示例#1
0
 def __operation():
     return OrderedChoice([
         (Grammar.__mappingOp),
         (Grammar.__processingOp),
         (Grammar.__sharedCoreOp),
         (Grammar.__isEqualOp),
     ])
示例#2
0
def choice_SA(parser, node, children):
    # If there is only one child reduce as
    # this ordered choice is unnecessary
    if len(children) > 1:
        return OrderedChoice(nodes=children[:])
    else:
        return children[0]
示例#3
0
def _class_gram():
    return OrderedChoice([
        _class_base_stub,
        _class_base_impl,
        _class_inh_stub,
        _class_inh_impl,
    ])
示例#4
0
 def visit_ordered_choice(self, node, children):
     if len(children) > 1:
         retval = OrderedChoice(nodes=children[:])
     else:
         # If only one child rule exists reduce.
         retval = children[0]
     return retval
示例#5
0
 def wrappedDef():
     return (
         'message',
         # match - any word or digit character one or more word or digit characters until a non word/digit character
         RegExMatch(r'[\w\d]+'),
         '{',
         OrderedChoice(Optional(oneofDef), Optional(repeatedDef)),
         '}')
示例#6
0
def _cgs_block():
    return '{', ZeroOrMore(
        OrderedChoice([
            _cgs_var_stub,
            _cgs_var_ready,
            _cgs_async_gram,
            _cgs_sync_gram,
        ])), '}'
示例#7
0
def match_rule_body_SA(parser, node, children):
    # This is a match rule
    parser._current_cls._tx_type = RULE_MATCH
    # String representation of match alternatives.
    # Used in visualizations and debugging
    parser._current_cls._match_str = \
        "|".join([text(match) for match in children])
    return OrderedChoice(nodes=children[:])
示例#8
0
def _grammar():
    return ZeroOrMore(
        OrderedChoice([
            _class_gram,
            _single_gram,
            _generic_gram,
            _alias_gram,
            _flow_gram,
        ]), ), EOF
示例#9
0
def _cb_grammar():
    return '{', ZeroOrMore(
        OrderedChoice([
            _cb_sync_copy,
            _cb_sync_from,
            _cb_var_stub,
            _cb_var_ready,
            _cb_var_async_set,
            _cb_var_sync_set,
            _cb_async_from,
            _cb_note,
        ])), Optional([
            _cb_return,
        ]), '}'
示例#10
0
 def __expression():
     return OrderedChoice([
         (
             ("("),
             Grammar.__expression,
             (")"),
             Grammar.__relation,
             ("("),
             Grammar.__expression,
             (")"),
         ),
         Grammar.__andExpression,
         Grammar.__orExpression,
         Grammar.__operation,
     ])
示例#11
0
def element():
    # Without an enclosing list for 'words, newline', OrderedChoice
    #   implicitly becomes Sequence !
    return OrderedChoice([words, blank_line, newline], rule_name='element')
示例#12
0
def compare():
    return OrderedChoice(['>=', '<=', '<', '=', '>'])
示例#13
0
def term():
    return Optional(["+", "-"]), OrderedChoice([(ZeroOrMore([gennum]),
                                                 Optional(['*']), varname),
                                                gennum])
示例#14
0
def gennum():
    return OrderedChoice([scinot, number])
示例#15
0
def argument():
    # EOF causes hang in optional/required
    return Sequence((wx, OrderedChoice([option, operand, command])),
                    rule_name="argument",
                    skipws=True)
示例#16
0
def term():
    # EOF causes hang in optional/required
    return OrderedChoice([options_shortcut, optional, required, argument],
                         rule_name="term",
                         skipws=True)
示例#17
0
 def customDef():
     return OrderedChoice(ZeroOrMore(commentBlock), ZeroOrMore(commentLine))
def ol_first_option():
    return Sequence ( ( And(ws), OrderedChoice( [ _long, _short ] ) ),
                      rule_name='ol_first_option', skipws=False )
示例#19
0
def element():
    # To work properly, first argumnet of OrderedChoice must be a
    # list.  IF not, it implicitly becomes Sequence !
    return OrderedChoice ( [ *grammar_elements ], rule_name='element' )
示例#20
0
 def visit_textx_rule_body(self, node, children):
     if len(children) == 1:
         return children[0]
     return OrderedChoice(nodes=children[:])
示例#21
0
 def grammar():
     return Sequence((OneOrMore(OrderedChoice(elements)), EOF),
                     rule_name="grammar")
示例#22
0
 def grammar(_words):
     body = OneOrMore(OrderedChoice([rule, _words, catchall, newline]))
     return Sequence((body, EOF))
示例#23
0
 def visit_choice(self, node, children):
     # If there is only one child reduce as
     # this ordered choice is unnecessary
     if len(children) == 1:
         return children[0]
     return OrderedChoice(nodes=children[:])
示例#24
0
def abstract_rule_body_SA(parser, node, children):
    # This is a body of an abstract rule so set
    # the proper type
    parser._current_cls._tx_type = RULE_ABSTRACT
    return OrderedChoice(nodes=children[:])
示例#25
0
def comment_line():
    return _(r'//.*?$')


def comment_block():
    return _(r'/\*(.|\n)*?\*/')


# Special rules - primitive types
ID = _(r'[^\d\W]\w*\b', rule_name='ID', root=True)
BOOL = _(r'(True|true|False|false|0|1)\b', rule_name='BOOL', root=True)
INT = _(r'[-+]?[0-9]+\b', rule_name='INT', root=True)
FLOAT = _(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\b', 'FLOAT', root=True)
STRING = _(r'("(\\"|[^"])*")|(\'(\\\'|[^\'])*\')', 'STRING', root=True)
NUMBER = OrderedChoice(nodes=[FLOAT, INT], rule_name='NUMBER', root=True)
BASETYPE = OrderedChoice(nodes=[NUMBER, BOOL, ID, STRING],
                         rule_name='BASETYPE',
                         root=True)

BASE_TYPE_RULES = {
    rule.rule_name: rule
    for rule in [ID, BOOL, INT, FLOAT, STRING, NUMBER, BASETYPE]
}
BASE_TYPE_NAMES = BASE_TYPE_RULES.keys()

PRIMITIVE_PYTHON_TYPES = [int, float, text, bool]

for regex in [ID, BOOL, INT, FLOAT, STRING]:
    regex.compile()
示例#26
0
def body():
    return Sequence(OneOrMore(OrderedChoice([option, operand, ws])),
                    EOF,
                    rule_name='body',
                    skipws=False)
示例#27
0
def MyOrderedChoice(*args, **kwargs):
    return OrderedChoice([*args], **kwargs)
示例#28
0
def grammar():
    return Sequence(OneOrMore(OrderedChoice([option, operand, ws])),
                    EOF,
                    rule_name='grammar',
                    skipws=False)
示例#29
0
 def headerComments():
     return (OrderedChoice(ZeroOrMore(commentBlock),
                           ZeroOrMore(commentLine)))
示例#30
0
def usage_line():
    # usage_line = usage_pattern newline / usage_pattern EOF
    return OrderedChoice([(usage_pattern, newline), (usage_pattern, EOF)],
                         rule_name="usage_line",
                         skipws=True)