0

I'm trying to modifying this grammar to parse Solidity comments.

I want to obtain two type of comment: multi-line comment, that is in the form '/* any string */', and the single-line comment, that is in the form '// any string NEWLINE'.

I modified the comments line with the following code:

comment
  : '/*' (. | '@' | '\'' | '¯' | '┌' | '┐' | '│' | '└' | '┘' | '─' | '┬' | '├' | '▼' | '►')*? '*/';

LINE_COMMENT
    : '//' ~[\r\n]*
    ;

lineComment
    : LINE_COMMENT
    ;

The first problem is that it seems I have to insert manually several special characters, like '@', using OR, because the wildcard '.' seems not work.

The second is that i'm not able to correctly intercept comment lines like:

/*//////////////////////////////////////////////////////////////
                          COMMENT
//////////////////////////////////////////////////////////////*/

because the parser doesn't correctly analyze the close character '*/'

2
  • You should not move recognizing comments to a parser rule. Inside a parser rule, the . does not match "any character", but matches "any token". Why doe you want to move this from the lexer to the parser? Commented Apr 7, 2024 at 6:56
  • Antlr does not have "out of band" parser rules, where you could define comments but not change the rest of the parser rules to now handle where comments can occur. A better solution is to use two parsers, the first to parser Solidity, the second to parse comments that are in the parse tree from the first pass. Commented Apr 7, 2024 at 12:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.