Title: [591] trunk/qdox/src/grammar: improved annotation-recognition in lexer
Revision
591
Author
rfscholte
Date
2009-04-20 13:36:41 -0500 (Mon, 20 Apr 2009)

Log Message

improved annotation-recognition in lexer

Modified Paths


Diff

Modified: trunk/qdox/src/grammar/lexer.flex (590 => 591)

--- trunk/qdox/src/grammar/lexer.flex	2009-04-16 18:34:21 UTC (rev 590)
+++ trunk/qdox/src/grammar/lexer.flex	2009-04-20 18:36:41 UTC (rev 591)
@@ -22,12 +22,11 @@
     private int codeblockDepth = 0;
     private int[] stateStack = new int[10];
     private int braceMode = CODEBLOCK;
+    private int parenMode = -1;
     private String className;
     private boolean javaDocNewLine;
     private boolean javaDocStartedContent;
     private StringBuffer codeBody = new StringBuffer(8192);
-	  private boolean at;
-	  private boolean annotation;
     private boolean newMode;
     private boolean bracketMode;
     private boolean anonymousMode;
@@ -88,6 +87,7 @@
 						  ( ([0-9])+ ({Exponent})? [dD] )
 UnicodeChar = \\u[a-fA-F0-9]{4}						  
 Id						= ([:jletter:]|{UnicodeChar}) ([:jletterdigit:]|{UnicodeChar})*
+Annotation = "@" {WhiteSpace}* {Id} ("."{Id})* {WhiteSpace}*
 
 %state JAVADOC CODEBLOCK PARENBLOCK ASSIGNMENT STRING CHAR SINGLELINECOMMENT MULTILINECOMMENT ANNOTATION ANNOSTRING ANNOCHAR ENUM
 
@@ -129,7 +129,7 @@
       	classDepth++;
         braceMode = YYINITIAL;
         return Parser.ANNOINTERFACE;
-	}
+	  }
 
     "class"             {
         classDepth++;
@@ -148,12 +148,14 @@
         braceMode = ENUM;
         return Parser.ENUM;
     }
-
+    {Annotation} "(" {
+        parenMode = ANNOTATION;
+        yypushback(text().length()-1);
+        return Parser.AT;
+    }
     "@"                 {
-        at = true;                
         return Parser.AT;
     }
-
     "{"                 {
         if(braceMode >= 0) {
           if(braceMode == ENUM) {
@@ -198,24 +200,18 @@
         pushState(ASSIGNMENT);
     }
     {Id} {
-        annotation |= at;
-        at = false;
-        
         return Parser.IDENTIFIER;
     }
-    {Eol} {
-       annotation = false;
-    }
 }
 <YYINITIAL> {
     ";"  { return Parser.SEMI; }
     "("  {
             nestingDepth++;
-            if( annotation ) {
+            if( parenMode >= 0 ) {
               annotationDepth = nestingDepth;
-                pushState(ANNOTATION);
+              pushState(parenMode);
+              parenMode = -1;
             }
-            annotation = false;
             return Parser.PARENOPEN;
           }
 }

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/parser/LexerTest.java (590 => 591)

--- trunk/qdox/src/test/com/thoughtworks/qdox/parser/LexerTest.java	2009-04-16 18:34:21 UTC (rev 590)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/parser/LexerTest.java	2009-04-20 18:36:41 UTC (rev 591)
@@ -703,6 +703,17 @@
     	assertLex(Parser.IDENTIFIER, lexer);
     	assertLex(Parser.IDENTIFIER, lexer);
     	assertLex(Parser.PARENCLOSE, lexer);
-
     }
+    
+    public void testMultipleRowAnnotation() throws Exception {
+    	String in = "@JSFComponent\n  (name = \"h:inputHidden\")";
+    	Lexer lexer = new JFlexLexer(new StringReader(in));
+    	assertLex(Parser.AT, lexer);
+    	assertLex(Parser.IDENTIFIER, lexer);
+    	assertLex(Parser.PARENOPEN, lexer);
+    	assertLex(Parser.IDENTIFIER, lexer);
+    	assertLex(Parser.EQUALS, lexer);
+    	assertLex(Parser.STRING_LITERAL, lexer);
+    	assertLex(Parser.PARENCLOSE, lexer);
+    }
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to