Problem upgrading past ANTLR 4.5.3

23 views
Skip to first unread message

Brian Demers

unread,
Oct 25, 2022, 7:13:21 AM10/25/22
to antlr-discussion
Hello All!

I've run into a problem trying to update the version ANTLR that
Apache SCIMple uses.  It looks like something changed just after ANTLR 4.5.3.

After digging into it for a few hours, I'm still scratching my head.
I don't know enough about ANTLR "modes" to be useful.

I created a stand-alone example that reproduces the issue. 

https://github.com/bdemers/antlr-problem (see README for instructions,
TL;DR `mvn verify`)

The grammar files are located here:
https://github.com/bdemers/antlr-problem/blob/master/src/main/antlr4/org/example/phonenumber/

The basic gist of the problem:
The phone number "tel:+358-4x-123-4" failed to parse on
previous versions.  With current versions, it parses to: "tel:+358-4"
(The previous versions would raise an error on the `x`, whereas the
newer versions seem to ignore it?)

I would have expected the same behavior as the previous version.

Any ideas?
-Brian

Mike Cargal

unread,
Oct 25, 2022, 10:41:19 AM10/25/22
to ANTLR List
This looks like a typical case of using a start rule that does not end in EOF.   Without asking the start rule to match EOF, ANTLR will parse as much as it can recognize and the return that.

Try changing:
phoneNumber: PrefixTel (global=globalNumber | local=localNumber);

To:
phoneNumber: PrefixTel (global=globalNumber | local=localNumber) EOF;

(I’m not sure why you saw different behavior prior to 4.5.3)

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/c0f2a6c5-6a84-47d9-acfa-532454ba4259n%40googlegroups.com.

Brian Demers

unread,
Oct 26, 2022, 8:25:13 AM10/26/22
to antlr-discussion

Thank you! It looks like that fixed it!
Reply all
Reply to author
Forward
0 new messages