What does the dot character actually match?

976 views
Skip to first unread message

Thomas Beale

unread,
Oct 18, 2015, 10:40:50 AM10/18/15
to antlr-discussion
In the Antlr4 book it says that the '.' character matches any character. However, the rule

regex1: ( '\\' . | ~'/' )+ ;

doesn't appear to match the literal '\.' (backslash, dot) within a regex string, but 

regex1: ( '\\.' | '\\' . | ~'/' )+ ;

does, according to my tests with the plugin in IntelliJ.

What's going on?

Jim Idle

unread,
Oct 18, 2015, 12:40:42 PM10/18/15
to antlr-discussion
You are using . In a parser rule. Parser rules do not match characters, they match tokens, so that means match any token.

Jim





--
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.
For more options, visit https://groups.google.com/d/optout.

Thomas Beale

unread,
Oct 18, 2015, 12:49:51 PM10/18/15
to antlr-discussion
Aha. When I first tried that rule (not using a lexer token name, as the rest of the grammar does) I had assumed that it would not even be legal. But the plug-in allows it and then I wrongly understood that to mean that there was some kind of 'in-rule lexing' going on.

I'm still new to Antlr after years of yacc/lex..!

thanks for the steer.
Reply all
Reply to author
Forward
0 new messages