rattler icon indicating copy to clipboard operation
rattler copied to clipboard

Whitespace not handling comments correctly at beginning of parsed source

Open booch opened this issue 10 years ago • 4 comments

I'm trying to add comments to my language. So I added a %whitespace directive, similar to the JSON and INI examples. But when my source code starts with a comment, the parser always reports a syntax error, expecting the source code to end with a comment — even if it does end with a comment.

My RTLR file looks something like this:

%start program
%whitespace ( SPACE+ / comment )*
program             <- expression+ EOF          <AST::Program.new>
expression          <- literal_integer
literal_integer     <- @DIGIT+                  <AST::LiteralInteger.new>
comment             <- ~([#] [^\n]*)

If I try to parse this:

# Comment
123

then I get an error like this:

bundler/gems/rattler-5b3806afad53/lib/rattler/runtime/parser.rb:179:in `raise_error': parse error at line 3, column 1: (Rattler::Runtime::SyntaxError)
 comment expected

booch avatar Apr 01 '14 02:04 booch