darioaxel
darioaxel

Reputation: 35

antlr4 token recognition error at: '$'

Trying to build a grammar for PowerScript language. I split the language in several parts and everything seems to be working except for the simple headers. It seems that the $ simbol can't be recognized. Could anyone help me a little? ( I just copy the small example I'm trying)

grammar PowerScript;

compilationUnit :   Header EOF;

fragment 
Header  : ID '.' ID;

ID : [a-zA-Z0-9$_]+ ;

test file just contains:

$PBExportHeader$n_logversion.sru

Thanks

Upvotes: 2

Views: 4424

Answers (1)

GRosenberg
GRosenberg

Reputation: 5991

The compilationUnit rule is a parser rule. Parser rules cannot refer to lexer fragments. Just remove the fragment qualifier to make Header a proper lexer rule.

Update

Antlr4 is fully Unicode capable. Just include the characters in standard Unicode encoding form:

ID : ( [a-zA-Z0-9$_] | '\uD83D\uDCB2' )+ ; // Unicode heavy Dollar sign

Upvotes: 2

Related Questions