Title: [577] trunk/qdox/src/grammar: lexer extended with ENUM-state.
Revision
577
Author
rfscholte
Date
2009-03-08 17:49:24 -0500 (Sun, 08 Mar 2009)

Log Message

lexer extended with ENUM-state. Better control of braces for enums.

Modified Paths


Diff

Modified: trunk/qdox/src/grammar/lexer.flex (576 => 577)

--- trunk/qdox/src/grammar/lexer.flex	2009-03-07 11:52:21 UTC (rev 576)
+++ trunk/qdox/src/grammar/lexer.flex	2009-03-08 22:49:24 UTC (rev 577)
@@ -20,6 +20,8 @@
     private int assignmentDepth = 0;
     private int stateDepth = 0;
     private int[] stateStack = new int[10];
+    private int braceMode = CODEBLOCK;
+    private String className;
     private boolean javaDocNewLine;
     private boolean javaDocStartedContent;
     private StringBuffer codeBody = new StringBuffer(8192);
@@ -31,6 +33,7 @@
     private boolean enumMode;
     private boolean appendingToCodeBody;
     private boolean shouldCaptureCodeBody;
+    private boolean isConstructor;
 
     public void setCaptureCodeBody(boolean shouldCaptureCodeBody) {
         this.shouldCaptureCodeBody = shouldCaptureCodeBody;
@@ -85,12 +88,11 @@
 						  ( ([0-9])+ ({Exponent})? [dD] )
 Id						= [:jletter:] [:jletterdigit:]*
 
-%state JAVADOC CODEBLOCK PARENBLOCK ASSIGNMENT STRING CHAR SINGLELINECOMMENT MULTILINECOMMENT ANNOTATION ANNOSTRING ANNOCHAR
+%state JAVADOC CODEBLOCK PARENBLOCK ASSIGNMENT STRING CHAR SINGLELINECOMMENT MULTILINECOMMENT ANNOTATION ANNOSTRING ANNOCHAR ENUM
 
 %%
 
-<YYINITIAL> {
-    ";"                 { enumMode = false; return Parser.SEMI; }
+<YYINITIAL, ENUM> {
     "."                 { return Parser.DOT; }
     "..."               { return Parser.DOTDOTDOT; }
     ","                 { return Parser.COMMA; }
@@ -116,7 +118,7 @@
 
     "["                 { nestingDepth++; return Parser.SQUAREOPEN; }
     "]"                 { nestingDepth--; return Parser.SQUARECLOSE; }
-    "("                 {
+/*    "("                 {
         nestingDepth++;
 		
         if( annotation ) {
@@ -132,7 +134,7 @@
           return Parser.PARENOPEN;
         }
     }
-    
+*/    
     ")"                 { nestingDepth--; return Parser.PARENCLOSE; }
     "<"                 { return Parser.LESSTHAN; }
     ">"                 { return Parser.GREATERTHAN; }
@@ -140,26 +142,26 @@
     "?"                 { return Parser.QUERY; }
 
     "@" {WhiteSpace}* "interface" {
-    	classDepth++;
-    	enumMode = false;
+      	classDepth++;
+        braceMode = CODEBLOCK;
         return Parser.ANNOINTERFACE;
 	}
 
     "class"             {
         classDepth++;
-        enumMode = false;
+        braceMode = CODEBLOCK;
         return Parser.CLASS; 
     }
     
     "interface"         { 
         classDepth++;
-     	enumMode = false;
+        braceMode = CODEBLOCK;
         return Parser.INTERFACE;
     }
     
     "enum"              {
         classDepth++;
-        enumMode = true;
+        braceMode = ENUM;
         return Parser.ENUM;
     }
 
@@ -169,17 +171,28 @@
     }
 
     "{"                 {
-        nestingDepth++;
-        if (nestingDepth == classDepth + 1) {
-        	getCodeBody(); /* reset codebody */
-            appendingToCodeBody = true;
-            pushState(CODEBLOCK);
+        if(braceMode == ENUM) { /* when fulle supported braceMode >= 0 */
+          if(braceMode == ENUM) {
+            isConstructor = true;
+          }
+          else if(braceMode == CODEBLOCK) { } /* todo */        
+          pushState(braceMode);
+          braceMode = -1;
+          yypushback(1);
         }
         else {
-            return Parser.BRACEOPEN;
+          nestingDepth++;
+          if (nestingDepth == classDepth + 1) {
+            getCodeBody(); /* reset codebody */
+              appendingToCodeBody = true;
+              pushState(CODEBLOCK);
+          }
+          else {
+              return Parser.BRACEOPEN;
+          }
         }
     }
-    
+/*    
     "}"                 { 
         nestingDepth--;
         if (nestingDepth == classDepth - 1) {
@@ -187,7 +200,7 @@
         }
         return Parser.BRACECLOSE; 
     }
-
+*/
     "/*" "*"+           { 
         pushState(JAVADOC); 
         javaDocNewLine = true; 
@@ -199,13 +212,11 @@
         appendingToCodeBody = true;
         pushState(ASSIGNMENT);
     }
-
     "default"           { 
         assignmentDepth = nestingDepth;
         appendingToCodeBody = true;
         pushState(ASSIGNMENT);
     }
-
     {Id} {
         annotation = at;
         at = false;
@@ -213,7 +224,46 @@
         return Parser.IDENTIFIER;
     }
 }
+<YYINITIAL> {
+    ";"  { return Parser.SEMI; }
+    "}"  { 
+        nestingDepth--;
+        if (nestingDepth == classDepth - 1) {
+            classDepth--;
+        }
+        return Parser.BRACECLOSE; 
+    }
+        "("                 {
+        nestingDepth++;
+    
+        if( annotation ) {
+          annotationDepth = nestingDepth;
+            pushState(ANNOTATION);
+        }
 
+        annotation = false;
+
+        return Parser.PARENOPEN;
+    }
+}
+<ENUM> {
+    ";"  { isConstructor = false; return Parser.SEMI; }
+    "}"  { 
+        nestingDepth--;
+        classDepth--;
+        popState();
+        return Parser.BRACECLOSE; 
+    }
+    "("  {
+        nestingDepth++;
+        if(isConstructor) {
+          pushState(PARENBLOCK);
+        }
+        else {
+          return Parser.PARENOPEN;
+        }
+    }
+}
 <JAVADOC> {
     "*"+ "/"            { popState(); return Parser.JAVADOCEND; }
     ^ [ \t]* "*"+ / [^/*] { /* ignore */ }

Modified: trunk/qdox/src/test/com/thoughtworks/qdox/EnumsTest.java (576 => 577)

--- trunk/qdox/src/test/com/thoughtworks/qdox/EnumsTest.java	2009-03-07 11:52:21 UTC (rev 576)
+++ trunk/qdox/src/test/com/thoughtworks/qdox/EnumsTest.java	2009-03-08 22:49:24 UTC (rev 577)
@@ -93,7 +93,7 @@
         String source = ""
                 + "public enum Animal {\n"
                 + "    \n"
-                + "    DUCK { public void speak() { System.out.println(\"quack!\"); } },\n"
+                + "    DUCK    { public void speak() { System.out.println(\"quack!\"); } },\n"
                 + "    CHICKEN { public void speak() { System.out.println(\"cluck!\"); } };\n"
                 + "\n"
                 + "    public abstract void speak();\n"
@@ -160,7 +160,7 @@
    }
     
     //for QDOX-153
-    public void todo_testAnotherEnumTest() throws Exception {
+    public void testAnotherEnumTest() throws Exception {
     	String source = "package org.apache.myfaces.el.unified.resolver;\n" +
     			"public final class FacesCompositeELResolver extends org.apache.myfaces.el.CompositeELResolver\n" +
     			"{\n" +


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to