Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top