Example #1
0
 def customFields():
     return (
         ZeroOrMore(RegExMatch(r'[\w]+')),  # name
         ZeroOrMore('='),
         ZeroOrMore(RegExMatch(r'[\w]+')),  # type
         ZeroOrMore(RegExMatch(r';.*'))  # comment
     )
Example #2
0
 def defHeader():
     return (
         RegExMatch(r'[\w\d]+'),  # name
         "{",
         Optional('//',
                  RegExMatch(r'.*?(#|{})'.format(lineSep))),  # comment
         Optional(RegExMatch(r'#?jadn_opts:{.*}+')),  # jadn options
         OneOrMore(endLine))
Example #3
0
 def defHeader():
     return (
         # matches name: "(NAME) = { ... }"
         ZeroOrMore(RegExMatch(r'^[\w]+')),
         # matches line up to jadn_opts
         ZeroOrMore(RegExMatch(r'.*?(#|{})')),
         # matches jadn_opts
         ZeroOrMore(RegExMatch(r'#?jadn_opts:{.*}+')),
         OneOrMore(endLine))
Example #4
0
def re_match_SA(parser, node, children):
    to_match = children[0]
    regex = RegExMatch(to_match, ignore_case=parser.metamodel.ignore_case)
    try:
        regex.compile()
    except Exception as e:
        line, col = parser.pos_to_linecol(node[1].position)
        raise TextXSyntaxError("{} at {}".format(text(e), text((line, col))),
                               line, col)
    return regex
Example #5
0
 def visit_re_match(self, node, children):
     to_match = node.extra_info.group(1)
     # print("**** visit_re_match, to_match == '{}'".format(to_match))
     regex = RegExMatch(to_match, ignore_case=self.metamodel.ignore_case)
     try:
         regex.compile()
     except Exception as e:
         line, col = self.grammar_parser.pos_to_linecol(node[1].position)
         raise TextXSyntaxError(text(e), line, col)
     return regex
Example #6
0
File: textx.py Project: zeph/textX
def re_match_SA(parser, node, children):
    to_match = children[0]
    regex = RegExMatch(to_match, ignore_case=parser.metamodel.ignore_case)
    try:
        regex.compile()
    except Exception as e:
        line, col = parser.pos_to_linecol(node[1].position)
        raise TextXSyntaxError(
            "{} at {}"
            .format(text(e), text((line, col))), line, col)
    return regex
Example #7
0
 def defHeader():
     return (
         # match - word or digit character one or more times
         RegExMatch(r'[\w\d]+'),  # name
         "{",
         # match - Any character (except line terminator) until # or line terminator
         Optional('//',
                  RegExMatch(r'.*?(#|{})'.format(lineSep))),  # comment
         # match - Capture jadn_opts within comment, last } is matched one or more times
         Optional(RegExMatch(r'#?jadn_opts:{.*}+')),  # jadn options
         OneOrMore(endLine))
Example #8
0
 def enumField():
     return (
         RegExMatch(r'\w[\w\d]*?\s'),  # name
         '=',
         number,  # field number
         ';',
         Optional(
             '//',
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #9
0
 def defField():
     return (
         number,  # field number
         ':',
         RegExMatch(r'\w[\w\d\.]*?\s'),  # option
         RegExMatch(r'\w[\w\d\.]*?\s|list\<([\w\d]+)\>*?\s'),  # type
         RegExMatch(r'(\w[\w\d]*?);'),  # name
         Optional(
             '//',
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #10
0
def str_match_SA(parser, node, children):
    to_match = children[0]

    # Support for autokwd metamodel param.
    if parser.metamodel.autokwd:
        match = parser.keyword_regex.match(to_match)
        if match and match.span() == (0, len(to_match)):
            regex_match = RegExMatch(r'{}\b'.format(to_match),
                                     ignore_case=parser.metamodel.ignore_case,
                                     str_repr=to_match)
            regex_match.compile()
            return regex_match
    return StrMatch(to_match, ignore_case=parser.metamodel.ignore_case)
Example #11
0
 def visit_re_match(self, node, children):
     try:
         to_match = children[0]
     except:
         to_match = ''
     regex = RegExMatch(to_match, ignore_case=self.metamodel.ignore_case)
     try:
         regex.compile()
     except Exception as e:
         line, col = self.grammar_parser.pos_to_linecol(node[1].position)
         raise TextXSyntaxError(
             "{} at {}".format(text(e), text((line, col))), line, col)
     return regex
Example #12
0
File: textx.py Project: zeph/textX
def str_match_SA(parser, node, children):
    to_match = children[0]

    # Support for autokwd metamodel param.
    if parser.metamodel.autokwd:
        match = parser.keyword_regex.match(to_match)
        if match and match.span() == (0, len(to_match)):
            regex_match = RegExMatch(r'{}\b'.format(to_match),
                                     ignore_case=parser.metamodel.ignore_case,
                                     str_repr=to_match)
            regex_match.compile()
            return regex_match
    return StrMatch(to_match, ignore_case=parser.metamodel.ignore_case)
Example #13
0
 def defField():
     return (
         Optional('?'),
         # matches (TYPE) : ...
         RegExMatch(r'\s*[\w]+'),  # type
         # matches type : (NAME), ...
         RegExMatch(r':\s*[\w]+\s*,*'),  # name
         Optional('//'),
         Optional(
             ';',
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #14
0
 def defHeader():
     return (
         # match - word or digit character one or more times
         RegExMatch(r'[\w\d]+'),  # name
         "{",
         Optional(
             '//',
             # match - any character (except line terminator) until # or line terminator
             RegExMatch(r'.*?(#|{})'.format(lineSep))  # comment
         ),
         # match - (#)jadn_opts:{JADN OPTS}
         # last } is matched one or more times
         Optional(RegExMatch(r'#?jadn_opts:{.*}+')),  # jadn options
         OneOrMore(endLine))
Example #15
0
 def enumField():
     return (
         # matches (ENUM) = ...
         RegExMatch(r'[\w]+'),  # enum name
         Optional('/='),
         Optional('='),
         # matches ... = (NAME)
         RegExMatch(r'\"[\w]+\"'),  # item name
         ';',
         Optional(
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #16
0
 def enumField():
     return (
         # match - Any group until space
         RegExMatch(r'\w[\w\d]*?\s'),  # name
         '=',
         number,  # field number
         ';',
         Optional(
             '//',
             # match - Any character (except line terminator) until # or line terminator
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             # match - Capture jadn_opts within comment, last } is matched one or more times
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #17
0
 def visit_re_match(self, node, children):
     try:
         to_match = children[0]
     except IndexError:
         to_match = ''
     regex = RegExMatch(to_match,
                        ignore_case=self.metamodel.ignore_case)
     try:
         regex.compile()
     except Exception as e:
         line, col = self.grammar_parser.pos_to_linecol(node[1].position)
         raise TextXSyntaxError(
             "{} at {}"
             .format(text(e), text((line, col))), line, col)
     return regex
Example #18
0
 def enumField():
     return (
         # match - any word character followed by one or more word or digit characters until a space
         RegExMatch(r'\w[\w\d]*?\s'),  # name
         '=',
         number,  # field number
         ';',
         Optional(
             '//',
             # match - any character (except line terminator) until # or line terminator
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             # match - (#)jadn_opts:{JADN OPTS}
             # last } is matched one or more times
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #19
0
 def wrappedDef():
     return (
         'struct',
         # match - Any group until a non word/digit
         RegExMatch(r'[\w\d]+'),
         '{',
         Optional(repeatedDef),
         '}')
Example #20
0
    def visit_str_match(self, node, children):
        try:
            to_match = children[0][1:-1]
        except IndexError:
            to_match = ''

        # Support for autokwd metamodel param.
        if self.metamodel.autokwd:
            match = self.keyword_regex.match(to_match)
            if match and match.span() == (0, len(to_match)):
                regex_match = RegExMatch(
                    r'{}\b'.format(to_match),
                    ignore_case=self.metamodel.ignore_case,
                    str_repr=to_match)
                regex_match.compile()
                return regex_match
        return StrMatch(to_match, ignore_case=self.metamodel.ignore_case)
Example #21
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)),
         '}')
Example #22
0
    def visit_str_match(self, node, children):
        try:
            to_match = children[0][1:-1]
        except IndexError:
            to_match = ''

        # Support for autokwd metamodel param.
        if self.metamodel.autokwd:
            match = self.keyword_regex.match(to_match)
            if match and match.span() == (0, len(to_match)):
                regex_match = RegExMatch(
                    r'{}\b'.format(to_match),
                    ignore_case=self.metamodel.ignore_case,
                    str_repr=to_match)
                regex_match.compile()
                return regex_match
        return StrMatch(to_match, ignore_case=self.metamodel.ignore_case)
Example #23
0
 def defField():
     return (
         number,  # field number
         ':',
         # match - Any group until space
         RegExMatch(r'\w[\w\d\.]*?\s'),  # option
         # match - Any group until space OR any group enclosed within 'list<>'
         RegExMatch(r'\w[\w\d\.]*?\s|list\<([\w\d]+)\>*?\s'),  # type
         # match - Any group until space
         RegExMatch(r'(\w[\w\d]*?);'),  # name
         Optional(
             '//',
             # match - Any character (except line terminator) until # or line terminator
             RegExMatch(r'.*?(#|{})'.format(lineSep)),  # comment
             # match - Capture jadn_opts within comment, last } is matched one or more times
             Optional(RegExMatch(r'jadn_opts:{.*}+'))  # jadn options
         ),
         OneOrMore(endLine))
Example #24
0
    def check_parse(self, fcn, rule_f, rule, words, text, expect_list):
        # Unused: fcn, rule_f
        newline = common.newline()
        catchall = RegExMatch(r'.*', rule_name='catch_all')
        elements = [rule, words, catchall, newline]

        def grammar():
            return Sequence((OneOrMore(OrderedChoice(elements)), EOF),
                            rule_name="grammar")

        self.verify_grammar(grammar, text, expect_list, skipws=False)
Example #25
0
def ReservedWord():
    '''Matches identifiers that aren't allowed as variable names.'''
    command_word_parsers = []
    for cmd_type in Command():
        cmd_parser = cmd_type()
        if isinstance(cmd_parser, tuple):
            command_word_parsers.append(cmd_parser[0])
        else:
            command_word_parsers.append(cmd_parser)
    return ([
        # Starts with a roll expression
        RollExpr,
        # Matches a command word exactly
        (command_word_parsers, [RegExMatch('[^A-Za-z0-9_]'), EOF]),
    ])
Example #26
0
def numeric():
    return RegExMatch(r'[0-9]+(\.[0-9]*)?')
Example #27
0
def roman():
    return RegExMatch(r'(I[VX]|VI{0,3}|I{1,3})([Aa]?[Bb]?)')
 def grammar():
     return ZeroOrMore("a", sep=RegExMatch(",?")), EOF
Example #29
0
def word():
    return RegExMatch(r"\w+")
 def grammar():
     return OneOrMore("a", sep=RegExMatch(",?")), "b"
Example #31
0
 def endLine():
     # match - Line terminator
     return RegExMatch(r'({})?'.format(lineSep))
Example #32
0
 def commentLine():
     # match - Any character, non line terminator
     return '//', RegExMatch(r'.*')
Example #33
0
 def commentBlock():
     # match - Any group of characters that are commented (/* & * & */)
     return RegExMatch(r'\/\*(.|{})*?\*\/'.format(lineSep)),
Example #34
0
 def number():
     # match - Numbers
     return RegExMatch(r'\d*\.\d*|\d+')