1

The Treetop website gives the following explanation that I don't understand

Ellipsis An empty string matches at any position and consumes no input. It's useful when you wish to treat a single symbol as part of a sequence, for example when an alternate rule will be processed using shared code.

rule alts ( foo bar / baz '' ) { def value elements.map{|e| e.text_value } end } end

when is useful to treat a symbol as a part of sequence? Can anybody provide a meaningful example of that?

RubenLaguna
  • 21,435
  • 13
  • 113
  • 151

1 Answers1

0

I am not familiar with Treetop. From the example it would seem that ( foo bar / baz '' ) would either produce ['foo', 'bar'] or ['baz', ''].

If you remove the ellipsis, you would get either ['foo', 'bar'] or just 'baz' (no sequence/list/array).

Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
  • Ok, so it seems that it just a way to make sure that it produces an array even if there is only one thing. In case that you want to have generic code that always expect input as an array. Now I get it. – RubenLaguna Feb 29 '12 at 14:17