I'm trying to define the language of XQuery and XPath in test.g4
. The part of the file relevant to my question looks like:
grammar test;
ap: 'doc' '(' '"' FILENAME '"' ')' '/' rp
| 'doc' '(' '"' FILENAME '"' ')' '//' rp
;
rp: ...;
f: ...;
xq: STRING
| ...
;
FILENAME : [a-zA-Z0-9/_]+ '.xml' ;
STRING : '"' [a-zA-Z0-9~!@#$%^&*()=+._ -]+ '"';
WS: [ \n\t\r]+ -> skip;
I tried to parse something like doc("movies.xml")//TITLE
, but it gives
line 1:4 no viable alternative at input 'doc("movies.xml"'
But if I remove the STRING
parser rule, it works fine. And since FILENAME
appears before STRING
, I don't know why it fails to match doc("movies.xml")//TITLE
with the FILENAME
parser rule. How can I fix this? Thank you!