On my assignment, I have this description for the String Lexer:
"String literals consist zero or more characters enclosed by double quotes ("). Use escape sequences (listed below) to represent special characters within a string. It is a compile-time error for a new line or EOF character to appear inside a string literal.
All the supported escape sequences are as follows:
\b backspace
\f formfeed
\r carriage return
\n newline
\t horizontal tab
\" double quote
\ backslash
The following are valid examples of string literals:
"This is a string containing tab \t"
"He asked me: \"Where is John?\""
A string literal has a type of string."
And this is my String lexer:
STRINGLIT: '"'(('\\'('b'|'t'|'n'|'f'|'r'|'\"'|'\\'))|~('\n'))*'"';
Can anybody check for my lexer if it meets the requirement or not? If it's not, please tell me your correction, I don't really understand the requirement and ANTLR4.
"this is a test" + "foo bar baz"
it will match the entire input, not just the first quoted string. You need to exclude"
from characters which can appear within the string (except when escaped). – J Earls