[antlr-interest] case-insensitive parsing

Bob Sole bob.sole at googlemail.com
Thu Apr 23 04:11:31 PDT 2009


I'm trying to write a parser for PL/SQL package header files but I'm banging
my head against the wall with a basic problem to do with case-insensitive
parsing. I'm using Jim Idle's NoCaseFileStream to convert tokens into upper
case, but I'm finding that the parser gets confused when it comes across
language keywords that are embedded within comments. Here's some example
input which has the OR keyword embedded within the package comment. The
"create or replace package" statement is deliberately messed up - the parser
handles this correctly, but it stumbles against the first 'or' on line 2:

/**
blah blah or blah
*/
create Or rePlace PACKAGE
test IS

Here's the grammar:

grammar Test;

input: statement+ ;

statement: pkgComment | pkgStmt ;

pkgComment: '/**' description '*/' ;

pkgStmt: 'CREATE' ('OR' 'REPLACE') 'PACKAGE' ID ('AS' | 'IS')
               {System.out.println("found package: "+$ID.text); }
        ;

descrption: (ID {System.out.println("description: ID="+$ID.text);})+ ;

ID: Letter (Letter | Digit)* ;

NUMBER: Digit Digit* ('.' Digit*)? ;

fragment
Digit: '0'..'9' ;

fragment
Letter: 'a'..'z' | 'A'..'Z' | '_' ;

NL: ('\r'? '\n') { skip();} ;
WS: (' '| '\t') {skip();} ;

EVERYTHING_ELSE: . ;


I get the following output which shows that the pkgStmt parsing is ok, but
the pkgComment isn't working:

line 11:2 mismatched character '-' expecting '*'
description: ID=blah
description: ID=blah
line 2:10 mismatched input 'or' expecting '*/'
found package: test

I'm slowly working my way through the book, and I've looked through the wiki
FAQs and postings here but haven't found anything that'll help me (that I
can understand, at least!) - any suggestions would be most appreciated!

Thanks in advance!
Bob.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090423/9ff992d6/attachment.html 


More information about the antlr-interest mailing list