directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r267349 - in /directory/shared/ldap/trunk/common/src: antlr/ java/org/apache/ldap/common/subtree/ test/org/apache/ldap/common/subtree/
Date Fri, 02 Sep 2005 23:47:38 GMT
Author: akarasulu
Date: Fri Sep  2 16:47:31 2005
New Revision: 267349

URL: http://svn.apache.org/viewcvs?rev=267349&view=rev
Log:
Applied Ersin Er's patch for fixing white space issues with the subtree 
specification parser in DIREVE-52 here:

    http://issues.apache.org/jira/browse/DIRLDAP-52


Modified:
    directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
    directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java

Modified: directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g?rev=267349&r1=267348&r2=267349&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g (original)
+++ directory/shared/ldap/trunk/common/src/antlr/subtree-specification.g Fri Sep  2 16:47:31
2005
@@ -1,7 +1,7 @@
 header
 {
 /*
- *   Copyright 2004 The Apache Software Foundation
+ *   Copyright 2005 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@
 
 options
 {
-    k = 3;
+    k = 2;
 
     defaultErrorHandler = false;
 }
@@ -76,6 +76,8 @@
     private static final Logger log = LoggerFactory.getLogger( AntlrSubtreeSpecificationParser.class
);
     private DnParser dnParser;
     
+    private boolean matchedAnyComponentYet = false;
+    
     private boolean isNormalizing = false;
     NameComponentNormalizer normalizer;
     
@@ -150,25 +152,76 @@
     ss = null;
     ssModifier = new SubtreeSpecificationModifier();
 } :
-    LBRACKET
-        ( SP ss_base )?
-        ( SEP SP ss_specificExclusions )?
-        ( SEP SP ss_minimum )?
-        ( SEP SP ss_maximum )?
-        ( SEP SP ss_specificationFilter )?
-    SP RBRACKET
+    LBRACKET ( SP )*
+        (
+            (
+              ss_base ss_base_follower
+            | ss_specificExclusions ss_specificExclusions_follower
+            | ss_minimum ss_minimum_follower
+            | ss_maximum ss_maximum_follower
+            | ss_specificationFilter
+            )
+            ( SP )*
+        )?
+    RBRACKET
     {
         ss = ssModifier.getSubtreeSpecification();
     }
     ;
 
+    
+ss_base_follower
+    :
+    ( SEP ( SP )*
+        (
+            ss_specificExclusions ss_specificExclusions_follower
+            | ss_minimum ss_minimum_follower
+            | ss_maximum ss_maximum_follower
+            | ss_specificationFilter
+        )
+    )?
+    ;
+
+    
+ss_specificExclusions_follower
+    :
+    ( SEP ( SP )*
+        (
+            ss_minimum ss_minimum_follower
+            | ss_maximum ss_maximum_follower
+            | ss_specificationFilter
+        )
+    )?
+    ;
+
+    
+ss_minimum_follower
+    :
+    ( SEP ( SP )*
+        (
+            ss_maximum ss_maximum_follower
+            | ss_specificationFilter
+        )
+    )?
+    ;
+
+    
+ss_maximum_follower
+    :
+    ( SEP ( SP )*
+        (
+            ss_specificationFilter
+        )
+    )?
+    ;
+
 
 ss_base
 {
     log.debug( "entered ss_base()" );
     Name base = null;
 } :
-    "base" (SP)+ base=localName
+    "base" ( SP )+ base=localName
     {
         ssModifier.setBase( base );
     }
@@ -192,8 +245,8 @@
     log.debug( "entered specificExclusions()" );
 } :
     LBRACKET
-        ( SP specificExclusion
-            (SEP SP specificExclusion)*
+        ( ( SP )* specificExclusion
+            ( SEP ( SP )* specificExclusion )*
         )?
     SP RBRACKET
     ;
@@ -260,10 +313,10 @@
     log.debug( "entered ss_specificationFilter()" );
     ExprNode theRefinement = null;
 }:
-    ( "specificationFilter" ( SP )+ theRefinement=refinement
+    "specificationFilter" ( SP )+ theRefinement=refinement
     {
         ssModifier.setRefinement( theRefinement );
-    } )?
+    }
     ;
 
 
@@ -386,11 +439,11 @@
         {
             tempChildren.add( child );
         }
-        ( SEP SP child=refinement
+        ( SEP ( SP )* child=refinement
         {
             tempChildren.add( child );
         } )*
-    )? SP RBRACKET
+    )? ( SP )* RBRACKET
     {
         children = tempChildren;
     }
@@ -417,7 +470,7 @@
 
 options
 {
-    k = 3;
+    k = 2;
 
     charVocabulary = '\u0001'..'\u0127';
 
@@ -438,7 +491,7 @@
 // attribute description lexer rules from models
 // ----------------------------------------------------------------------------
 
-SP : ' ' ;
+SP : ' ';
 
 COLON : ':' { log.debug( "matched COLON(':')" ); } ;
 

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java?rev=267349&r1=267348&r2=267349&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationLexer.java
Fri Sep  2 16:47:31 2005
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2004 The Apache Software Foundation
+ *   Copyright 2005 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java?rev=267349&r1=267348&r2=267349&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/ReusableAntlrSubtreeSpecificationParser.java
Fri Sep  2 16:47:31 2005
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2004 The Apache Software Foundation
+ *   Copyright 2005 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java?rev=267349&r1=267348&r2=267349&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/subtree/SubtreeSpecificationParser.java
Fri Sep  2 16:47:31 2005
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2004 The Apache Software Foundation
+ *   Copyright 2005 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -123,7 +123,13 @@
             String msg = "Parser failure on subtree specification:\n\t" + spec ;
             msg += "\nAntlr exception trace:\n" + e.getMessage();
             throw new ParseException( msg, e.getColumn() );
-        }   
+        }  
+        catch ( Exception e )
+        {
+            String msg = "Parser failure on subtree specification:\n\t" + spec ;
+            msg += "\nAntlr exception trace:\n" + e.getMessage();
+            throw new ParseException( msg, 0 );
+        }
 
         return ss;
     }

Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java?rev=267349&r1=267348&r2=267349&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
(original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/subtree/SubtreeSpecificationParserTest.java
Fri Sep  2 16:47:31 2005
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2004 The Apache Software Foundation
+ *   Copyright 2005 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -46,10 +46,6 @@
     /** A valid empty specification with single white space between brackets */
     private static final String EMPTY_SPEC =
         "{ }";
-    
-    /** An invalid empty specification with two white spaces between brackets */
-    private static final String INVALID_EMPTY_SPEC_WITH_EXTRA_WS =
-        "{  }";
 
     /** A valid specification only with base set */
     private static final String SPEC_WITH_BASE =
@@ -58,22 +54,18 @@
     /** An invalid specification with missing white space and base set */
     private static final String INVALID_SPEC_WITH_BASE_AND_MISSING_WS =
         "{ base\"ou=system\"}";
-    
-    /** An invalid specification with extra whitespace and base set */
-    private static final String INVALID_SPEC_WITH_BASE_AND_EXTRA_WS =
-        "{ base ou=system\" }    ";
 
     /** A valid specification with some specific exclusions set */
     private static final String SPEC_WITH_SPECIFICEXCLUSIONS =
-        "{, specificExclusions { chopAfter:\"ef=gh\", chopBefore:\"ab=cd\" } }";
+        "{ specificExclusions { chopAfter:\"ef=gh\", chopBefore:\"ab=cd\" } }";
     
     /** A valid specification with empty specific exclusions set */
     private static final String SPEC_WITH_EMPTY_SPECIFICEXCLUSIONS =
-        "{, specificExclusions { } }";
+        "{ specificExclusions { } }";
 
     /** A valid specification with minimum and maximum set */
     private static final String SPEC_WITH_MINIMUM_AND_MAXIMUM =
-        "{, minimum 1, maximum 2 }";
+        "{ minimum 1, maximum 2 }";
     
     /** A valid specification with base and minimum and maximum set */
     private static final String SPEC_WITH_BASE_AND_MINIMUM_AND_MAXIMUM =
@@ -100,9 +92,11 @@
         ", minimum 7, maximum   77" + 
         ", specificationFilter     and:{ and:{ item:1.2.3, or:{ item:4.5.6, item:7.8.9 }
}, not:{ item:10.11.12 } } }";
     
+    /** An invalid specification with wrong component order */
     private static final String INVALID_SPEC_WITH_WRONG_COMPONENT_ORDER =
         "{ base \"ou=system\", minimum 3, specificExclusions { chopBefore:\"x=y\" } }";
 
+    /** An invalid specification with completely unrelated content */
     private static final String INVALID_SILLY_THING =
         "How much wood would a wood chuck chuck if a wood chuck would chuck wood?";
 
@@ -153,27 +147,6 @@
         ss = parser.parse( EMPTY_SPEC );
         assertNotNull( ss );
     }
-
-
-    /**
-     * Tests the parser with an invalid empty specification with extra white spaces.
-     */
-    public void testInvalidEmptySpecWithExtraWS() throws Exception
-    {
-        try
-        {
-           SubtreeSpecification ss = parser.parse( INVALID_EMPTY_SPEC_WITH_EXTRA_WS );
-           fail( "testInvalidEmptySpecWithExtraWS() should never come here..." );
-        }
-        catch ( ParseException e )
-        {
-            assertNotNull( e );
-        }
-        catch ( IOException e )
-        {
-            assertNotNull( e );
-        }
-    }
     
     
     /**
@@ -199,31 +172,6 @@
            fail( "testInvalidSpecWithBaseAndMissingWS() should never come here..." );
         }
         catch ( ParseException e )
-        {
-            assertNotNull( e );
-        }
-        catch ( IOException e )
-        {
-            assertNotNull( e );
-        }
-    }
-
-
-    /**
-     * Tests the parser with an invalid specification with extra white spaces and base set.
-     */
-    public void testInvalidSpecWithBaseAndExtraWS() throws Exception
-    {
-        try
-        {
-           SubtreeSpecification ss = parser.parse( INVALID_SPEC_WITH_BASE_AND_EXTRA_WS );
-           fail( "testInvalidSpecWithBaseAndExtraWS() should never come here..." );
-        }
-        catch ( ParseException e )
-        {
-            assertNotNull( e );
-        }
-        catch ( IOException e )
         {
             assertNotNull( e );
         }



Mime
View raw message