=begin
I got this recursive decent parser from:
http://www.rubyinside.com/recursive-descent-parser-for-ruby-300.html

I get this syntax error:
C:/rb-play/parser/try.rb:13: syntax error, unexpected ']', expecting
kEND
  g.operation           /[+-*/]/

if I change that line to:
  g.operation           /[+-]/
that line no longer has an error, so the / and * threw it off

then I get an error on another line:

  g.string              %r(["'](.*?[^\]|.*?)["'])
C:/rb-play/parser/try.rb:15: warning: character class has `[' without
escape
C:/rb-play/parser/try.rb:15: unmatched (: /["'](.*?[^\]|.*?)["']/

Any ideas on what to change to make it work ?

thanks

=end

require 'rdparser'

parser = RDParser.new do |g|
  g.main                'line(s)'
  g.line                'expression separator(?) comment(?)'
  g.comment             '"#" rest_of_line'
  g.rest_of_line        /.+$/
  g.separator           /;/
  g.expression          'term operation expression | term'
  g.term                'number | variable | string | brkt_expression'
  g.brkt_expression     '"(" expression ")"'
  g.number              /d+(.d+)?/
  g.operation           /[+-*/]/
  g.variable            /[a-z][a-z0-9]*/
  g.string              %r(["'](.*?[^\]|.*?)["'])
end

content = %q{
  (34 - 3) * 42;   # Comment here..
  "a" + "bcd"
}

syntax_tree = parser.parse(:main, content)
puts RDParser.text_syntax_tree(syntax_tree)