Questions tagged «lark-parser»

2
如何设置可以处理歧义的语法
我正在尝试创建一种语法来解析我设计的一些类似于Excel的公式,其中字符串开头的特殊字符表示其他来源。例如,$可以表示一个字符串,因此“ $This is text”将被视为程序中的字符串输入,并且&可以表示一个函数,因此&foo()可以被视为对内部函数的调用foo。 我面临的问题是如何正确构建语法。例如,这是MWE的简化版本: grammar = r'''start: instruction ?instruction: simple | func STARTSYMBOL: "!"|"#"|"$"|"&"|"~" SINGLESTR: (LETTER+|DIGIT+|"_"|" ")* simple: STARTSYMBOL [SINGLESTR] (WORDSEP SINGLESTR)* ARGSEP: ",," // argument separator WORDSEP: "," // word separator CONDSEP: ";;" // condition separator STAR: "*" func: STARTSYMBOL SINGLESTR "(" [simple|func] (ARGSEP simple|func)* ")" %import common.LETTER …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.