3

Its been years since I used Antlr2, now its Antlr4. I'm modifying the tsql parser and would like to keep block and line comments in the parse tree.

Most grammar's lexer rules push comments to a hidden channel or skip eg:

BLOCK_COMMENT: '/*' (COMMENT | .)*? '*/' -> channel(HIDDEN); LINE_COMMENT: '//' ~[\r\n]* -> skip;

Since comment occur on any line, or in the middle of a line, how can I keep the comments in the parse tree ?

garyM
  • 802
  • 2
  • 12
  • 29
  • http://meri-stuff.blogspot.com/2012/09/tackling-comments-in-antlr-compiler.html?m=1 this might be useful – 138 Mar 27 '18 at 09:18
  • Looks like a duplicate indeed. I added a short answer to it fwiw. – Jiri Tousek Mar 27 '18 at 09:28
  • Aight, closed it :) – Bart Kiers Mar 27 '18 at 09:28
  • Wait, I thought @garyM also mentioned it was a duplicate in the comments (perhaps deleted now?). If I was too soon closing this, just give a shout and I'll re-open. – Bart Kiers Mar 27 '18 at 09:29
  • @Bart Yeah, the comment maybe got eaten up by the closure (it removes the "Possible duplicate of ..." auto-comment, perhaps it removes all comments with a link to dupe). – Jiri Tousek Mar 27 '18 at 17:55
  • The duplicate is for Antlr2 and Antlr3, and not for Antlr4. I'll try both and post the most viable for Antlr4.7.1 BTW, the method in Terrance Parr's book defining channels results in Antlr compiler errors when used with combined grammars (separate lexer and parser files). – garyM Mar 27 '18 at 19:55

0 Answers0