How do I write following BNF Grammar in ANTLR?
literal = "{" number "}" CRLF *CHAR8
; Number represents the number of CHAR8s
For example {6}\r\nLENGTH
should be mapped to "LENGTH"
string.
Will following work?
literal:
| '{' ('0'..'9')+ '}\r\n'
{
// C# Code for Lexer
Text = Text.Trim();
int n = int.Parse(Text.Substring(1,Text.Length-2));
Text = "";
for(int i=0;i<n;i++){
input.Consume();
}
}
;
I am getting this working as a Lexer rule, but problem is I am getting mismatched token, I am not getting token as literal.