[antlr-interest] OutOfMemoryException when parsing incorrect input
Rob Harrop
rob.harrop at springsource.com
Wed Nov 28 09:55:25 PST 2007
I have written a simple (I think!) grammar to parse some of the
headers in an OSGi bundle manifest. I have included the cut down
version here:
=================================
grammar OsgiPackageHeader;
header : pkg_decl (',' pkg_decl)*
;
pkg_decl
: packageNames (';' parameter) *
;
packageNames
: packageName (';' packageName)*
;
parameter
: directive | attribute
;
directive
: IDENTIFIER ':=' argument
;
attribute
: IDENTIFIER '=' argument
;
argument
: IDENTIFIER | QUOTED_STRING
;
packageName
: IDENTIFIER {this.packageNames.add($IDENTIFIER.text);}
;
QUOTED_STRING
: '"' (~('\\' | '"' | '\r' | '\n') | '\\' ('\\' | '"')) * '"'
{setText(getText().substring(1, getText().length()-1));}
;
IDENTIFIER
: IDENTIFIER_PART ('.' IDENTIFIER_PART) *
;
fragment
IDENTIFIER_PART
: (ALPHA | DIGIT | '_' | '$' | '-') *
;
fragment
DIGIT : '0'..'9'
;
fragment
ALPHA : 'a'..'z' | 'A'..'Z'
;
WS : ' '+ {skip();}
;
=====================
Attempting to invoke header() with incorrect input like "**" results
in an OutOfMemoryException. What am I doing wrong?
Regards,
Rob
Rob Harrop
SpringSource
This e-mail and any attachments transmitted with it are strictly
confidential and intended solely for the person or entity to whom
they are addressed. Unauthorised use, copying, disclosure or
distribution is prohibited. If you receive this e-mail in error
please notify the sender immediately and then delete it along with
any attachments. E-mails should be checked by the recipient to ensure
that there are no viruses and SpringSource does not accept any
responsibility if this is not done. Any views or opinions presented
are solely those of the author and do not necessarily represent those
of SpringSource.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071128/6e717a67/attachment-0001.html
More information about the antlr-interest
mailing list