KEYWORDS with or without quotes in ANTLR4 #4173
Unanswered
techpranav
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I am not sure if this is your entire grammar or not, but your lexer does not handle quotes at all as it stands. Here are some generic observations:
Rewriting the above:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a requirement like grammar should parse all the keywords irrespective of quotes.
e.g.:
ADD_ : 'add';
DELETE_: ''delete;
INSERT_: 'insert';
KEYWORDS: ( ADD_ | DELETE_ | INSERT_ );
TYPE_ : 'type';
stmt : (KEYWORDS) TYPE_ ANY_STRING;
ANY_STRING : (ALPHA | DIGIT | SYMBOL)+;
SYMBOL : [\p{P}\p{S}];
ALPHA : [\p{L}\p{Nl}];
DIGIT : [\p{Nd}];
===============================
Below are some sample valid statements -
add type Test;
"add" type Test;
'add' ' type' Test;
add "type" Test;
===============================
How can I implement this logic ?
Note: I have bunch of queries like this , so looking for some generic solution?
Beta Was this translation helpful? Give feedback.
All reactions