directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 54212 - in incubator/directory/eve/trunk/backend/tools/src: antlr test/org/apache/eve/tools/schema
Date Sun, 10 Oct 2004 04:09:38 GMT
Author: akarasulu
Date: Sat Oct  9 21:09:38 2004
New Revision: 54212

Modified:
   incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g
   incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
Log:
works now with attributeTypes

Modified: incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g	(original)
+++ incubator/directory/eve/trunk/backend/tools/src/antlr/openldap.g	Sat Oct  9 21:09:38 2004
@@ -42,7 +42,7 @@
 class antlrOpenLdapSchemaLexer extends Lexer ;
 
 options    {
-    k = 4 ;
+    k = 7 ;
     exportVocab=antlrOpenLdapSchema ;
     charVocabulary = '\3'..'\377' ;
     caseSensitive = false ;
@@ -64,7 +64,10 @@
 QUOTE              : '\''
     ;
 
-OPEN_PAREN         : '(' 
+DIGIT              : '0' .. '9'
+    ;
+
+OPEN_PAREN         : '('
     ;
 
 CLOSE_PAREN        : ')'
@@ -79,7 +82,6 @@
 protected NUMERIC_STRING : ('0' .. '9')+
     ;
 
-
 NUMERICOID         :
         NUMERIC_STRING ( '.' NUMERIC_STRING )+
     ;
@@ -89,7 +91,15 @@
         ( 'a' .. 'z') ( 'a' .. 'z' | '0' .. '9' | '-' | ';' )*
     ;
 
+DESC
+    :
+        "desc" WS QUOTE ( ~'\'' )+ QUOTE
+    ;
 
+SYNTAX
+    :
+        "syntax" WS NUMERICOID OPEN_BRACKET ( DIGIT )+ CLOSE_BRACKET
+    ;
 
 class antlrOpenLdapSchemaParser extends Parser ;
 
@@ -275,7 +285,7 @@
         type = new MutableAttributeType( oid.getText() );
     }
         ( names[type] )?
-        ( "DESC" QUOTE desc:IDENTIFIER { type.setDescription( desc.getText() ); } QUOTE )?
+        ( desc[type] )?
         ( "OBSOLETE" { type.setObsolete( true ); } )?
         ( superior[type] )?
         ( equality[type] )?
@@ -290,6 +300,15 @@
     CLOSE_PAREN ;
 
 
+desc [MutableAttributeType type]
+{
+}
+    : d:DESC
+    {
+        type.setDescription( d.getText().split( "'" )[1] );
+    }
+    ;
+
 superior [MutableAttributeType type]
 {
     matchedProduction( "superior()" ) ;
@@ -400,17 +419,24 @@
 {
     matchedProduction( "syntax()" ) ;
 }
-    : "SYNTAX"
-    (
-        oid:NUMERICOID
+    : token:SYNTAX
+    {
+        String[] comps = token.getText().split( " " );
+
+        int index = comps[1].indexOf( "{" );
+        if ( index == -1 )
         {
-            type.setSyntax( new MutableSyntax( oid.getText() ) );
+            type.setSyntax( new MutableSyntax( comps[1] ) );
+            return;
         }
-        ( OPEN_BRACKET length:NUMERIC_STRING
-        {
-            type.setLength( Integer.parseInt( length.getText() ) );
-        } OPEN_BRACKET )?
-    );
+
+        String oid = comps[1].substring( 0, index );
+        String length = comps[1].substring( index + 1, comps[1].length() - 1 );
+
+        type.setSyntax( new MutableSyntax( oid ) );
+        type.setLength( Integer.parseInt( length ) );
+    }
+    ;
 
 usage [MutableAttributeType type]
 {

Modified: incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
(original)
+++ incubator/directory/eve/trunk/backend/tools/src/test/org/apache/eve/tools/schema/AttributeTypeParserTest.java
Sat Oct  9 21:09:38 2004
@@ -34,11 +34,9 @@
     public void testParser() throws Exception
     {
         String attributeTypeData = "attributetype ( 2.5.4.2 NAME 'knowledgeInformation'\n"
+
-            //"        DESC 'RFC2256: knowledge information'\n" +
-            //"        EQUALITY caseIgnoreMatch\n" +
-            //"        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
-
-            ")";
+            "        DESC 'RFC2256: knowledge information'\n" +
+            "        EQUALITY caseIgnoreMatch\n" +
+            "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )";
         ByteArrayInputStream in = new ByteArrayInputStream( attributeTypeData.getBytes()
);
         antlrOpenLdapSchemaLexer lexer = new antlrOpenLdapSchemaLexer( in );
         antlrOpenLdapSchemaParser parser = new antlrOpenLdapSchemaParser( lexer );
@@ -54,5 +52,12 @@
         registry.register( "caseIgnoreMatch", "1.1.1.1.1.1" );
         parser.setOidRegistry( registry );
         AttributeType type = parser.attributeType();
+
+        assertEquals( "2.5.4.2", type.getOid() );
+        assertEquals( "knowledgeInformation", type.getName() );
+        assertEquals( "RFC2256: knowledge information", type.getDescription() );
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.15",
+            type.getSyntax().getOid() );
+        assertEquals( 32768, type.getLength() );
     }
 }

Mime
View raw message