Treetop Parser whitespace

Y

Young tae Kim

I can't understand why the following test fails.
Could you tell me why? Thanks, in advance.


# in arithmetic.treetop

grammar Arithmetic
rule white_space
[ \t\n\r]+ {
def value
text_value
end
}
end
end





# in test_parser.rb
require "rubygems"
require "treetop"
require "arithmetic"

parser = ArithmeticParser.new

p parser.parse(" \n\t\r")




# the execution result
$ ruby test_parser.rb
nil
 
C

Clifford Heath

Young said:
I can't understand why the following test fails.
Could you tell me why? Thanks, in advance.

It works for me. What version of Treetop and Polyglot
are you using. Can you please tell us what is printed
by "puts parser.failure_reason"?

Clifford Heath.
 
Y

Young Tae Kim

Clifford said:
It works for me. What version of Treetop and Polyglot
are you using. Can you please tell us what is printed
by "puts parser.failure_reason"?

Clifford Heath.

First of all, many thanks for your reply!

The version of the operating system is Ubuntu 8.10

the ruby version is ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

The following is the result of gem list --local

$ gem list --local

*** LOCAL GEMS ***

actionmailer (2.2.2)
actionpack (2.2.2)
activerecord (2.2.2)
activeresource (2.2.2)
activesupport (2.2.2)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
fastthread (1.0.1)
gem_plugin (0.2.3)
hoe (1.9.0)
mongrel (1.1.5)
polyglot (0.2.5) <----
rails (2.2.2)
rake (0.8.3)
rubyforge (1.0.3)
sqlite3-ruby (1.2.4)
treetop (1.2.4) <----

What's printed by "puts parser.failure_reason" is just "nil".
 
Y

Young Tae Kim

Clifford said:
It works for me. What version of Treetop and Polyglot
are you using. Can you please tell us what is printed
by "puts parser.failure_reason"?

Clifford Heath.

I revised my example like this but it doesn't work as well.

# in arithmetic.treetop

grammar Arithmetic
rule num
[1-9] [0-9]* {
def value
text_value
end
}
end

rule space
[ \t\n\r]+ {
def value
text_value
end
}
end
end



# in test_parser.rb

require "rubygems"
require "treetop"
require "arithmetic"

parser = ArithmeticParser.new

p parser.parse("123")
p parser.parse(" \n\t\r")
puts parser.failure_reason



# the execution result

$ ruby test_parser.rb
SyntaxNode+Num1+Num0 offset=0, "123" (value):
SyntaxNode offset=0, "1"
SyntaxNode offset=1, "23":
SyntaxNode offset=1, "2"
SyntaxNode offset=2, "3"
nil
nil
 
C

Clifford Heath

Young said:
What's printed by "puts parser.failure_reason" is just "nil".

I think that's a bug. I don't have time to investigate it right now.
BTW, if you run the command "tt arithmetic.tt", you'll get the
generated "arithmetic.rb" code that you can explore.

Clifford Heath
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top