I’m attempting to parse one particular (home grown) JavaDoc tag in my JavaScript file and I’m struggling to understand how I can achieve this. Antlr is complaining as documented below:
jsDocComment
: '/**' (importJsDocCommand | ~('*/'))* '*/' <== See note 1
;
importJsDocCommand
: '@import' gav
;
gav
: gavGroup ':' gavArtifact
-> ^(IMPORT gavGroup gavArtifact)
;
gavGroup
: gavIdentifier
;
gavArtifact
: gavIdentifier
;
gavIdentifier
: ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-'|'.')* <== See note 2
;
-
Note 1: The following alternatives can never be matched: 1
-
Note 2: Decision can match input such as “‘_’..’.'” using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input
Here’s what I’m trying to parse:
/** a */
/** @something */
/** @import com.jquery:jquery */
All lines should parse ok, with just the @import statement (along with its Maven group:artifact value) created under an AST tree element named “IMPORT”.
Thanks for your assistance.
My solution to this problem was to use ANTLR’s Lexer without the parser and filter out stuff that I’m not interested in. Here’s what I came up with (it also looks for globally defined variables as well as imports):