I have some data required to be parsed. I am using ANTLR4 tool to auto generate java parsers and lexers, that I can use to form a structured data from the input data given below Grammar:
grammar SUBDATA;
subdata:
data+;
data:
array;
array:
'[' obj (',' obj)* ']';
intarray:
'[' number (',' number)* ']';
number:
INT;
obj:
'{' pair (',' pair)* '}';
pair:
key '=' value;
key:
WORD;
value:
INT | WORD | intarray;
WORD:
[A-Za-z0-9]+;
INT:
[0-9]+;
WS:
[ \t\n\r]+ -> skip;
Test Input Data:
[
{OmedaDemographicType=1, OmedaDemographicId=100, OmedaDemographicValue=4},
{OmedaDemographicType=1, OmedaDemographicId=101, OmedaDemographicValue=26},
{
OmedaDemographicType=2, OmedaDemographicId=102, OmedaDemographicValue=[16,34]
}
]
Ouput:
line 5:79 mismatched input '16' expecting INT
line 5:82 mismatched input '34' expecting INT
Parser is failing although I have the integer value at the above expected position.