Forum: Ruby Treetop Parser whitespace

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1de5617efb013ca7c9cf8e5646818ffa?d=identicon&s=25 Young Tae Kim (philos99)
on 2009-03-09 19:49
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
163755a5d3a5c57bd79c4f41bdda7a22?d=identicon&s=25 Clifford Heath (Guest)
on 2009-03-09 22:45
(Received via mailing list)
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.
1de5617efb013ca7c9cf8e5646818ffa?d=identicon&s=25 Young Tae Kim (philos99)
on 2009-03-10 00:22
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".
1de5617efb013ca7c9cf8e5646818ffa?d=identicon&s=25 Young Tae Kim (philos99)
on 2009-03-10 00:38
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
163755a5d3a5c57bd79c4f41bdda7a22?d=identicon&s=25 Clifford Heath (Guest)
on 2009-03-10 01:55
(Received via mailing list)
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
1de5617efb013ca7c9cf8e5646818ffa?d=identicon&s=25 Young Tae Kim (philos99)
on 2009-03-10 02:51
I got an answer. If you face the same problem, please refer to the
following site.

http://groups.google.com/group/treetop-dev/browse_...
This topic is locked and can not be replied to.