Treetop 语法中的空白
当指定允许或不允许空格时,我需要有多明确?例如,这些规则是否
rule lambda
'lambda' ( '(' params ')' )? block
end
rule params
# ...
end
rule block
'{' # ... '}'
end
足以匹配
lambda {
}
基本上我是否需要指定可能出现的所有可选空格?
How explicit do I need to be when specifying were whitespace is or is not allowed? For instance would these rules:
rule lambda
'lambda' ( '(' params ')' )? block
end
rule params
# ...
end
rule block
'{' # ... '}'
end
be sufficient to match
lambda {
}
Basically do I need to specify everywhere optional whitespace may appear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你知道。在这些规则中,您需要跳过空格,但是,例如,当您解析可能包含空格的字符串时,您希望保留它们;这就是为什么你必须指定。
但是,在将 Treetop 应用于字符串之前,您可以尝试运行一个“快速而肮脏”的基于正则表达式的算法,该算法会丢弃可选位置的空格。尽管如此,这可能比在语法中指定空格要困难得多。
Yes, you do. In these rules you need to skip whitespace, but, for instance, when you parse strings, which may contain whitespace, you would like to retain them; that's why you have to specify.
However, before applying treetop to your string, you may try to run a "quick and dirty" regexp-based algorithm that discards whitespace from the places where they're optional. Still, this may be much harder that specifying whitespaces in your grammar.