Exemplo n.º 1
0
def parse_asp_program_by_arpeggio(asp_source_code: str,
                                  do=None,
                                  have_comments: bool = True) -> tuple:
    parser = ap.ParserPython(asp_grammar(),
                             asp_grammar_comments if have_comments else None)
    parse_tree = parser.parse(asp_source_code)
    return ap.visit_parse_tree(parse_tree, visitor=do or CodeAsTuple())
Exemplo n.º 2
0
 def parse_terms(self, string: str) -> frozenset:
     """Return the frozenset computed from given valid ASP-compliant string"""
     parse_tree = ap.ParserPython(self.grammar).parse(string)
     if parse_tree:
         return ap.visit_parse_tree(parse_tree, self.atom_visitor)
     else:
         return frozenset()
Exemplo n.º 3
0
def parse(instruction):
    """Parse vim instruction."""
    def new_rule():
        return (
            arpeggio.ZeroOrMore([
                common.string,
                common.unsigned_float,
                common.signed_float,
                common.unsigned_integer,
                common.signed_integer,]),
            arpeggio.EOF)
    parser = arpeggio.ParserPython(new_rule, ignore_case=True)
    return parser.parse(instruction)
Exemplo n.º 4
0
def parse(instruction):
    """Parse vim instruction."""
    parser = arpeggio.ParserPython(vim_command, ignore_case=True)
    parse_tree = parser.parse(instruction)
Exemplo n.º 5
0
def get_stored_definition_parser() -> arpeggio.Parser:
    return arpeggio.ParserPython(
        omc4py.parser.syntax.stored_definition_withEOF,
        omc4py.parser.syntax.std.CPP_STYLE_COMMENT,
    )
Exemplo n.º 6
0
        info = filter_dict(children)
        if num_column in info:
            self.mess["rotate"] = num_column
        else:
            self.mess["rotate"] = 1
        if direction in info and info[direction] == -1:
            self.mess["rotate"] = 4 - (self.mess["rotate"] % 4)

    def visit_num_column(self, node, children):
        return {num_column: index_column_vocab[node.value]}

    def visit_num_piece(self, node, children):
        return {num_piece: self.pieces[index_piece_vocab[node.value]]}

    def visit_ordinaux(self, node, children):
        return {ordinaux: ordinals_vocab[node.value]}

    def visit_mainrule(self, node, children):
        return children


parser = peg.ParserPython(mainrule, debug=False)
if __name__ == "__main__":
    try:
        parse_tree = parser.parse(argv[1])
        print("parse tree: ", parse_tree)
    except peg.NoMatch as e:
        print(e)
    result = peg.visit_parse_tree(parse_tree, Visit(debug=False))
    print("result: ", result)
Exemplo n.º 7
0
def get_parse_tree(string_data: str, grammar: grammar_basic.GrammarBase):
    """ created the parse tree out of the string
    """
    parser = arp.ParserPython(grammar.grammar, ws=grammar.whitespace)
    parse_tree = parser.parse(string_data)
    return parse_tree
Exemplo n.º 8
0
def parse(instruction, rule):
    """Parse vim instruction."""
    def new_rule():
        return (rule, arpeggio.EOF)
    parser = arpeggio.ParserPython(new_rule, ignore_case=True)
    parser.parse(instruction)
Exemplo n.º 9
0
def parse(asp_source_code:str) -> iter:
    """Parse the source code into hierarchy of lines"""
    parser = ap.ParserPython(line_grammar())
    parse_tree = parser.parse(asp_source_code)
    parsed_lines = ap.visit_parse_tree(parse_tree, LinesExtractor())
    return with_line_number(parsed_lines, asp_source_code)
Exemplo n.º 10
0
def parse_asp_program(asp_source_code:str, do=None) -> tuple:
    parse_tree = ap.ParserPython(asp_grammar()).parse(asp_source_code)
    return ap.visit_parse_tree(parse_tree, visitor=do or CodeAsTuple())
def get_omc_value_parser() -> arpeggio.Parser:
    return arpeggio.ParserPython(
        syntax.omc_value_withEOF,
    )
def get_omc_record_array_parser() -> arpeggio.Parser:
    return arpeggio.ParserPython(
        syntax.omc_component_array_withEOF,
    )
def get_type_specifier_parser() -> arpeggio.Parser:
    return arpeggio.ParserPython(
        syntax.type_specifier_withEOF,
    )
def get_IDENT_parser() -> arpeggio.Parser:
    return arpeggio.ParserPython(
        syntax.IDENT_withEOF,
    )
Exemplo n.º 15
0
def paramsWithArgs():
    return params, space, arg


def classes():
    return _(r'#?\w+')


def arg():
    return ar.Optional(beginTag, plainText, endTag, space)


def keyWords():
    return [paramsWithArgs, classes]


def tagOptions():
    return ar.OneOrMore(space, keyWords, space, sep=",", skipw=True)


def text():
    return ar.ZeroOrMore([defTag, HTMLTag, tag, plainText])


def mspaText():
    return text, ar.EOF


if __name__ == "__main__":
    parser = ar.ParserPython(mspaText, debug=True, skipws=False)