示例#1
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
示例#2
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
示例#3
0
文件: textx.py 项目: 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
示例#4
0
文件: textx.py 项目: 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)
示例#5
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
示例#6
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)
示例#7
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
示例#8
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)
示例#9
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)