2

I have a parser for language that looks like this:

[nodeType OPTIONAL STUFF]

There are a few node typed, such as "ask" and "set", so currently ask and set are defined as keywords. This causes problems in other parts of the parser.

Is there a way to define a token parser that accepts only tokens who contain specific text?

4

1 回答 1

0

是的。您可以查看Terminals类,教程中也对此进行了说明

实际上,jparsec 结合了传统上在 lex 和 yacc 中分离的两个解析过程:词法分析阶段(例如Terminals)解析 aString并返回Tokens 流,句法分析(其他Parser实例)解析Tokens 流并解释它们,通常直接构建 AST 或嵌入语义。

于 2016-05-05T06:44:42.357 回答