[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keep comments



Hi,

I want to generate a java parser that keeps the comments in the AST. I used the java grammar following this link http://sablecc.org/wiki/GrammarPage
I have to modify the grammar in order to keep comments, but until now I'm facing problems with doing this.
Here is the part of the grammar that I modified:


Tokens
..............

 white_space = (sp | ht | ff | line_terminator)*;

  traditional_comment = '/*' not_star+ '*'+ (not_star_not_slash not_star* '*'+)* '/';
  documentation_comment =    '/**' '*'* (not_star_not_slash not_star* '*'+)* '/';
  end_of_line_comment = '//' input_character* line_terminator?;

Ignored Tokens
white_space;


Productions
 compilation_unit =
    package_declaration? [import_declarations]:import_declaration* [type_declarations]:type_declaration*;

comment =
       {javadoc} documentation_comment |
    {line} end_of_line_comment |
    {block}traditional_comment;
...................

I got the following error:
Exception in thread "main" org.sablecc.grammars.java_1_5.parser.ParserException: [1,1] expecting: EOF
    at org.sablecc.grammars.java_1_5.parser.Parser.parse(Parser.java:12254)
    at Main.main(Main.java:49)

Does any one has an idea.
thank you