1

I'm looking for a way to write Treetop rules which will find some values in any order. So:

rule top
  # ?
end    

rule gender
  ('women'/'men') / ''
end

rule age_under
  ('under' age) / ''
end

rule age
  [0-9]+
end

I would like to parse these inputs:

"women under 10"
"under 10 women"
"under 10"
"women"

How can I achieve this ? Thanks

Leszek Andrukanis
  • 2,114
  • 2
  • 19
  • 30

1 Answers1

1

Here's an example of parsing in any order. The only trouble is you would have to handle duplicates by hand since Treetop doesn't have a rule for unordered-non-repeating elements.

rule top
 ((gender / age_under) ' '?)*
end

rule gender
 'women' / 'men'
end

rule age_under
 'under ' age
end

rule age
 [0-9]+
end
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
  • That's incredible how poorly Treetop is documented taking into consideration how good this library is. – Leszek Andrukanis Jul 22 '14 at 18:30
  • Yeah, it is pretty poor. Did you see the [homepage](http://cjheath.github.io/treetop/)? [Here](http://po-ru.com/diary/getting-started-with-treetop/) is a quick tutorial as well. – Josh Voigts Jul 22 '14 at 18:44