[antlr-interest] parsing just a subset of a grammar

Bernard Kaiflin bkaiflin.ruby at gmail.com
Tue Nov 20 12:25:59 PST 2012


A. I confirm that, if the central rule, in this case acl, does not match
exactly the input, the whole input is consumed by the first .*?.

>Was the resolution for '1) ID is built character by character, it would be
better to group them' to move all fragments to the very end of the grammar?

B. Putting all the fragments at the end is just my personal preference.

C. The trace
enter CHAR b line=1:6
exit CHAR o line=1:7
gave me the feeling that ID is constructed painfuly character by character.
Rewriting CHAR as
CHAR: ( 'a'..'z' | 'A'..'Z' | '_' | '-' | '.' | '+' | '/' | ':' | '%' )
    {System.out.println("--- CHAR " + $text);}
    ;
shows
enter ID b line=1:6
enter CHAR b line=1:6
--- CHAR b
exit CHAR o line=1:7
enter CHAR o line=1:7
--- CHAR bo
exit CHAR o line=1:8
enter CHAR o line=1:8
--- CHAR boo
exit CHAR t line=1:9
enter CHAR t line=1:9
--- CHAR boot
exit CHAR p line=1:10
enter CHAR p line=1:10
--- CHAR bootp
exit CHAR   line=1:11
--- ID bootp

But also with fragment CHAR, or putting a print in fragment LETTER shows
that ID is built character by character. So you can forget my remark 1). I
have been fooled by the trace
enter ID b line=1:6
--- ID bootp
exit ID   line=1:11
that looked shorter because fragments are not traced. In your version, CHAR
is a lexer rule and is traced in detail.


2012/11/20 Alexander Kostikov <alex.kostikov at gmail.com>

>
> Was the resolution for '1) ID is built character by character, it
> would be better to group them' to move all fragments to the very end
> of the grammar?
>
> --
> Alexander
>
>


More information about the antlr-interest mailing list