lark-parser

Priority in grammar using Lark

人盡茶涼 提交于 2020-01-03 19:28:21
问题 I have a priority problem in my grammar, and I don't have any more idea to fix it. I'm using Lark Here is the thing (I have simplified the problem as much as I can): from lark import Lark parser = Lark(r""" start: set | set_mul set_mul: [nb] set set: [nb] "foo" nb: INT "x" %import common.INT %import common.WS %ignore WS """, start='start') input = "3xfoo" p = parser.parse(input) print(p.pretty()) The output is : start set_mul set nb 3 But what I want is : start set_mul nb 3 set I tried to put

Correctly set priorities between rules and terminals in a grammar for lark

给你一囗甜甜゛ 提交于 2019-12-11 06:56:00
问题 This is my first time writing a parser using a grammar and a parser generator. I want to parse some kind of asn.1 format using the lark python module. Here is an example of the data I'm trying to parse: text = """ start_thing { literal { length 100, fuzz lim unk, seq-data gap { type fragment, linkage linked, linkage-evidence { { type unspecified } } } }, loc int { from 0, to 1093, strand plus, id gi 384632836 } } """ The structure can contain all sorts of nodes, and I can't know in advance