I have couple of ANTLR rules that I don't know how to make them work
The first rule is:
STRING_LITERAL
: '"' ( EscapeSequence | ~('\\'|'"') )* '"'
;
The second rule is:
element
: name '=' math_formula ;
math_formula
: '"' expression '"';
The expression is a regular C like expression
Example for the syntax
"count" = "array[3]"
count shall be a string, while array[3] shall be an expression
My problem is that the lexer always returns both "count" and "array[3]" as Strings, and the Parser cannot recognize the expression.
I'm using java target.
EDIT: changed "variable_name" to "count".
EDIT2: explained my second attempt below:
I can detect the start of expression with '= "', but I won't be able to detect the end of expression in the Lexer, causing false detection of strings when I have 2 elements separated by ','
"count1" = "array[1]",
"count2" = "array[2]"
if I used '= "' as START_EXPRESSION, the lexer detected the quote ending the first expression, and the quote starting the second string as a string ",\n" which is obviously incorrect.
EDIT 3: Trying Syntactic predicates
I changed the rule for the STRING_LITERAL to
STRING_LITERAL
: (~('=') '"' ( EscapeSequence | ~('\\'|'"') )* '"')=> '"' ( EscapeSequence | ~('\\'|'"') )* '"'
;
Still doesn't work, also I didn't know how to produce the ~('=') in the rule itself by assigning element label to it or somthing