Treetop Parser whitespace

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

···

--
Posted via http://www.ruby-forum.com/.

Young tae Kim wrote:

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.

I got an answer. If you face the same problem, please refer to the
following site.

http://groups.google.com/group/treetop-dev/browse_thread/thread/417aaf6fdac25fe3

···

--
Posted via http://www.ruby-forum.com/.

Clifford Heath wrote:

Young tae Kim wrote:

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.

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".

···

--
Posted via http://www.ruby-forum.com/\.

Clifford Heath wrote:

Young tae Kim wrote:

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.

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

···

--
Posted via http://www.ruby-forum.com/\.

Young Tae Kim wrote:

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