[antlr-interest] Parsing AspectJ pointcuts

mzukowski at yci.com mzukowski at yci.com
Thu May 15 08:10:29 PDT 2003


Literals get tested at the very end of a rule.  So in my gcc grammar I have
a couple of rules as follows.  I'm calling ID from IDMEAT so that the
literals table gets tested and if it was a keyword then the type has been
set appropriately.  So in IDMEAT I test that type and if it was
"__extension__" I decide to skip it (here you could switch lexers),
otherwise I reassign the type so it is preserved.  Otherwise the type will
get assigned as the rule name IDMEAT.

IDMEAT
        :
                i:ID                {
                                        
                                        if ( i.getType() ==
LITERAL___extension__ ) {
                                                $setType(Token.SKIP);
                                        }
                                        else {
                                                $setType(i.getType());
                                        }
                                        
                                    }
        ;

protected ID
        options 
                {
                testLiterals = true; 
                }
        :       ( 'a'..'z' | 'A'..'Z' | '_' | '$')
                ( 'a'..'z' | 'A'..'Z' | '_' | '$' | '0'..'9' )*
        ;

Monty

-----Original Message-----
From: mstrzer [mailto:stoerzer at fmi.uni-passau.de]
Sent: Thursday, May 15, 2003 6:50 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Parsing AspectJ pointcuts


Hi everybody!

I'm just trying to write a parser for AspectJ based on ANTLR. Now
AspectJ has some weired syntax, at least from parsing point of view,
so I ran into a bunch of problems.

AspectJ extends Java by allowing pointcuts which look like this

pointcut myPointcut(<arglist>): 
    call(!public SomeQualifiedReturnType*with..patterns*
         someMethodName*withPatterns(..));

All those patterns interfere with (qualified) identifiers, arithmetic
expressions (*) and so on, a real mess. So I thought it would be a
good idea to use a different lexer here. 

Now, as I learned from studying the documentation and some earlier
posts, it is not possible (or recommendable) to try to switch the
lexer from the parser.

On the other hand, I have no single token where I can switch the lexer
in the lexer grammar, besides some keywords ("pointcut").

However, I couldn't figure out, how to associate a action (like
switching the lexer) with a keyword.


Can anyone help me with this problem?

Thanks in advance, best regards,

    Max 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list