The issue we're having with ANTLR is that we have a grammar that's parsing something like this:
Hello, my name is bob.
bob offset: 5
Keep in mind that the "bob." in the first line is dynamic, and could be anything. One of those things is "bob". The "bob offset" line is not dynamic, and is in every file of the type that we are parsing.
So, to parse this, we have a couple of rules:
greeting: 'Hello, my name is' id1=IDENT '.' NEWLINE
{ System.out.println("Name: " + $id1.text"); }
;
bob_offset: 'bob offset:' id1=5 NEWLINE
{ System.out.println("bob offset: " + $id1.text); }
;
So, the issue is that 'bob offset:' is a token that the lexer reads. Now, when the greeting
rule goes, an error is thrown because it's trying to match 'bob' to 'bob offset:', but it can't.
The solution that would be ideal is if ANTLR had some way to specify context- or parser rule-specific lexer rules. This way, the 'bob offset:' token wouldn't be mistaken anywhere else in the grammar.
Any thoughts on this issue would be appreciated.
'Hello, my name is'
and'??? offset:'
(ie. multiple words containing spaces) is not the way to go. If I were you, I'd rethink my approach. – Bart Kiers"Hello , my name is ..."
(the space before the comma would break it). – Bart Kiers