删除空格,但最后还是删除吗?
我正在尝试解析 Lua,它在某些情况下依赖于空格,因为它不使用大括号作为范围。我认为只有当另一个规则不匹配时才抛出空格是最好的方法,但我不知道如何做到这一点。有人可以帮助我吗?
I am attempting to parse Lua, which depends on whitespace in some cases due to the fact that it doesn't use braces for scope. I figure that by throwing out whitespace only if another rule doesn't match is the best way, but i have no clue how to do that. Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看Lua的文档,我发现没有必要考虑空格。
解析器规则
ifStatement
:应匹配:
和:
无需考虑空格,AFAIK。 添加:
所以你可以在你的语法中
。 编辑
ANTLR wiki上似乎有一个Lua语法: http://www.antlr.org/grammar/1178608849736/Lua.g
看来我对 if 语句的建议与上面的语法略有不同:
正如你所看到的,这是正确的。
Looking at Lua's documentation, I see no need to take spaces into account.
The parser rule
ifStatement
:should match both:
and:
No need to take spaces into account, AFAIK. So you can just add:
in your grammar.
EDIT
It seems there is a Lua grammar on the ANTLR wiki: http://www.antlr.org/grammar/1178608849736/Lua.g
And it seems I my suggestion for an if statement slightly differs from the grammar above:
which is the correct one, as you can see.