문제

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?

도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top