mjackson / citrus

Parsing Expressions for Ruby
http://mjackson.github.io/citrus
405 stars 28 forks source link

Display parse matches or state on ParseError #46

Open aardvarkk opened 10 years ago

aardvarkk commented 10 years ago

I'm really new to PEGs so I'm sure I'm writing some totally messed up grammars. When the parse succeeds, I'm able to tweak things because there's a very helpful dump that shows me exactly the process the parser used to group everything together. The problem lies when the parsing fails. Although a line number and offset is very helpful, I'm unclear on exactly which rule the parser was currently in when it failed, etc.

I would really love some kind of character-by-character dump showing the entire process of what was going on. It would really help clear up all of the stupid mistakes I'm sure I'm making. In other words, I basically want to see the match dump regardless of whether the parsing succeeds.

Is this a challenging feature to add?

aardvarkk commented 10 years ago

I tried adding the line Match.new(input, events, opts[:offset]).dump before the check that raises the ParseError, but the output doesn't appear to show any of my actual input text?

denislins commented 9 years ago

+1 to that. I'm writing a somewhat complex grammar, and I'm stuck for three days in a really strange problem. Adding this would certainly help people in this same situation.

DrOvonN commented 7 years ago

I work since 2 weeks to make a sql grammar but the i get some ParseError but i can't recognize why some query’s work and some not. e.g. p sql_parser = SQLite.parse('Select From user;') # ~> fine p sql_parser = SQLite.parse('SELECT FROM tab1 ,tab2;') # ~> fine too p sql_parser = SQLite.parse('SELECT bla FROM tab2 where schema==1;') # ~> not ^