我想通过使用PetitParser来解析编程语言中的标识符。
其中一个要求是标识符的名称不是关键字(例如null),因此null不是有效的标识符。
对于这种情况,我能想到的最小解析器是:
identifier := ('null' asParser not, #word asParser plus)但是,如果输入以关键字开头,则会失败:
identifier end parse: 'nullable'你有什么建议来解决这个问题吗?谢谢!
发布于 2012-12-20 22:21:40
identifier := ('null' asParser, #word asParser plus) /
('null' asParser not, #word asParser plus).
identifier end parse: 'nullable'. "=> #('null' #($a $b $l $e))"
identifier end parse: 'null'. "=> 'at 0'"
identifier end parse: 'foo' "=> #(nil #($f $o $o))"https://stackoverflow.com/questions/13970979
复制相似问题