cjheath / treetop

A Ruby-based parsing DSL based on parsing expression grammars.
https://cjheath.github.io/treetop
MIT License
306 stars 22 forks source link

Parsing rule not working for similar words #21

Closed senyan closed 9 years ago

senyan commented 9 years ago

Having a rule like following

        rule a
          'sponser' /  'sponsered' / 'sponsers'
        end

It works if I do parser.parse('sponser') but not working for parser.parse('sponsered') or parser.parse('sponsers').

Please let me know if it is just something I did not do properly.

cjheath commented 9 years ago

Treetop, like all packrat parsers, choose the first option that matches and never considers another. Change the order and it will work.

senyan commented 9 years ago

yeah,

        rule a
          'sponsored' /  'sponsors' / 'sponsor'
        end

this works. Thanks.

cjheath commented 9 years ago

Oh, and you might want to spell "sponsor" correctly. "sponser" isn't a word.

senyan commented 9 years ago

Hehe, definetely.