[antlr-interest] Dealing with issues in non-greedy (.)* rules

Marc-André Laverdière ma_laver at ciise.concordia.ca
Thu May 10 12:08:35 PDT 2007


Hello,

I just wanted to a) share a hack and b) ask for some help dealing with 
blob-matching rules.

I have the following rule:
sh_code_blob
	:	( options {greedy=false;} : . )*
            {if (false) throw new RecognitionException();};

a) you will notice the "if (false) throw new RecognitionException();"
This hack takes care of the compilation exception in the generated 
parser for this rule, since the generated code tries to catch an 
exception that won't ever be thrown.

I'm not impressed by Sun's compiler for not figuring out that invariant, 
but it works!

Ter, should we update the StringTemplate to include this by default? 
This would probably save you from having to have a different template 
just for this one case.

b) this rule will however emit error messages. These error messages will
refer to the last character match. The call reportError() is not called 
however. (I validated this)

Do we have a "quiet" option that we can set for this rule? I don't see 
anything in the documentation nor in the BaseRecognizer class.

Thanks in advance for the help. I hope that my hack will help someone.

Regards,

-- 
Marc-André LAVERDIÈRE, B. Eng., M. A. Sc. (in progress)
Computer Security Laboratory - Laboratoire de sécurité informatique
CIISE, Université Concordia University, Montréal, Québec, Canada
www.ciise.concordia.ca

/"\
\ /    ASCII Ribbon Campaign
  X      against HTML e-mail
/ \

"Perseverance must finish its work so that you may be mature and 
complete, not lacking anything." -James 1:4



More information about the antlr-interest mailing list