3

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?

ravinggenius
  • 816
  • 1
  • 6
  • 14

1 Answers1

2

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.

P Shved
  • 96,026
  • 17
  • 121
  • 165