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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top