2

With Ruby's regular expressions I could write /[0-9]{3,}/ I can't figure out how to write this in treetop other than:

rule at_least_three_digit_number
  [0-9] [0-9] [0-9]+
end

Is there a 'match [at least|most] n' rule for treetop?

Samuel Danielson
  • 5,231
  • 3
  • 35
  • 37

2 Answers2

1

It looks like PEGs don't have some of the RE convenience operators, but in return you do get a much more powerful expression matcher.

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329
  • 1
    I belive this is a implementation issue, one could definitely write `a{2,3}` instead of `aa / aaa` if the implementations allows it (treetop does not afaik). – clyfe Mar 09 '10 at 20:29
  • Nope, it _is_ possible with treetop. See Luke's answer. – Bart Kiers Sep 29 '11 at 18:47
1

http://treetop.rubyforge.org/syntactic_recognition.html

A generalised repetition count (minimum, maximum) is also available.

'foo' 2.. matches 'foo' two or more times

'foo' 3..5 matches 'foo' from three to five times

'foo' ..4 matches 'foo' from zero to four times

Community
  • 1
  • 1
Luke Imhoff
  • 802
  • 10
  • 11