Treetop question

L

Lex Williams

Hi guys !

I started to learn to use treetop , so I would have a question :

if I create a grammar this way :

grammar Tester
rule basic
([a-f] [a-f] [a-f] [a-f] [a-f]) {
def val
text_value
end
}
end
end

and use it in the following code :
require "rubygems"
require "treetop"
Treetop.load "tester"

parser = TesterParser.new
puts parser.parse("abcde").val

I get the following error : x.rb:6: undefined method `val' for
#<Treetop::Runtime::SyntaxNode:0xb7ccd4b0> (NoMethodError) . However ,
if I replace this :

([a-f] [a-f] [a-f] [a-f] [a-f])

with

([a-f] [a-f] [a-f] [a-f] [a-f] / '')

then everything works . Could you explain why this happens ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top