title: Issues using treetop parser library
body: <p>I am trying to create a simple text parser in ruby using treetop. Although I have followed all steps as mentioned in the <a href="http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-treetop.html" rel="nofollow">blog</a>, I am not being able to run the program. It fails with the error message:</p>
  
  <pre><code>user1-mbp15:source user1$ ruby myParser.rb 
  (eval):28:in `_nt_expression': undefined local variable or method `_nt_space' for #&lt;SexpParser:0x007fad9b92b210&gt; (NameError)
     from /usr/local/lib/ruby/gems/2.3.0/gems/treetop-1.6.5/lib/treetop/runtime/compiled_parser.rb:18:in `parse'
     from myParser.rb:19:in `parse'
     from myParser.rb:31:in `&lt;main&gt;'
  </code></pre>
  
  <p>I could not find a lot of resources on the web on treetop, but would be glad to get some help. Following is the code:</p>
  
  <pre><code>user1-mbp15:source user1$ ls
     myParser.rb
     node_extensions.rb
     sexp_extensions.rb
     sexp_parser.treetop
  </code></pre>
  
  <p>-- myParser.rb --</p>
  
  <pre><code># In file myParser.rb
  require 'treetop'
  
  # Find out what our base path is
  $base_path = File.expand_path(File.dirname(__FILE__))
  
  # Load our custom syntax node classes so the parser can use them
  require File.join($base_path, 'node_extensions.rb')
  class Parser
     # Load the Treetop grammar from the 'sexp_parser' file, and 
     # create a new instance of that parser as a class variable 
     # so we don't have to re-create it every time we need to 
     # parse a string
     Treetop.load(File.join($base_path, 'sexp_parser.treetop'))
     @@parser = SexpParser.new
  
     def self.parse(data)
        # Pass the data over to the parser instance
        tree = @@parser.parse(data)
  
        # If the AST is nil then there was an error during parsing
        # we need to report a simple error message to help the user
        if(tree.nil?)
           raise Exception, "Parse error at offset: #{@@parser.index}"
        end
  
        return tree
     end
  end
  
  Parser.parse('(this "is" a test( 1 2.0 3))')
  </code></pre>
  
  <p>-- node_extensions.rb --</p>
  
  <pre><code>module Sexp
     class IntegerLiteral &lt; Treetop::Runtime::SyntaxNode
     end
  
     class StringLiteral &lt; Treetop::Runtime::SyntaxNode
     end
  
     class FloatLiteral &lt; Treetop::Runtime::SyntaxNode
     end
  
     class Identifier &lt; Treetop::Runtime::SyntaxNode
     end
  
     class Expression &lt; Treetop::Runtime::SyntaxNode
     end
  
     class Body &lt; Treetop::Runtime::SyntaxNode
     end
  end
  </code></pre>
  
  <p>-- sexp_extensions.rb --</p>
  
  <pre><code>grammar Sexp
      rule integer
          ('+' / '-')? [0-9]+ &lt;IntegerLiteral&gt;
      end
  
      rule float
          ('+' / '-')? [0-9]+ (('.' [0-9]+) / ('e' [0-9]+)) &lt;FloatLiteral&gt;
      end
  
      rule string
          '"' ([^"\\] / "\\" . )* '"' &lt;StringLiteral&gt;
      end
  
      rule identifier
          [a-zA-Z\=\*] [a-zA-Z0-9_\=\*]* &lt;Identifier&gt;
      end
  
      rule space
          [\s]+
      end
  end
  </code></pre>
  
  <p>-- sep_parser.treetop --</p>
  
  <pre><code># In file sexp_parser.treetop
  grammar Sexp
      rule expression
          space? '(' body ')' space? &lt;Expression&gt;
      end
  
      rule body
          (expression / identifier / float / integer / string / space )* &lt;Body&gt;
      end
  end
  </code></pre>