A couple of things are going wrong:
tag: '['TAG_TYPE "TAG_VALUE"']';
Why are there double quotes around TAG_VALUE
? Remove the quotes if you want to match the token TAG_VALUE
: tag: '['TAG_TYPE TAG_VALUE ']';
MOVE_NUMBER\. MOVE_DESC MOVE_DESC
If you want to match the literal .
(DOT) you need to put quotes around it (and not escape it!): MOVE_NUMBER '.' MOVE_DESC MOVE_DESC
NEWLINE: \r? \n;
Again, if you want to match the literals, put quotes around it: NEWLINE: '\r'? '\n';
TAG_VALUE: .*; ... MOVE_DESC: .*;
Those rule will gobble up your entire input stream. You need another way to match a tag value and move description than you do now. Do not use .*
.
EDIT
Here’s an existing PGN grammar: https://github.com/antlr/grammars-v4/tree/master/pgn