I have a SQl language where it allows strings that are double- or single-quoted, i.e., 'hello' and "hello". Additionally, it may have a JSON object, and within a JSON object, only a double-quoted string is valid, so we can have something like this in SQL:
SELECT "one", 'two', JSON "hello", JSON {"x": 2}
In other words, I'd like to have two string-constructions:
String_Literal_SQL: " ... " | ' ... ';
String_Literal_JSON: " ... ";
But, these would be 'fighting' to pick up the double-quoted string. Is the answer to this to push the rule from the Lexer to the Parser, and have different tokens for the strings, i.e., doing:
string_literal_SQL: Double_Quoted_String | Single_Quoted_String;
string_literal_JSON: Double_Quoted_String;
For whatever reason the above feels a bit hack-ish, but then again I don't think there's a way to consume a single token two ways.