Treetop: parsing single node returns nil
- by Matchu
I'm trying to get the basic of Treetop parsing. Here's a very simple bit of grammar so that I can say ArithmeticParser.parse('2+2').value == 4.
grammar Arithmetic
rule additive
first:number '+' second:number {
def value
first.value + second.value
end
}
end
rule number
[1-9] [0-9]* {
def value
text_value.to_i
end
}
end
end
Parsing 2+2 works correctly. However, parsing 2 or 22 returns nil.
What did I miss?