avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froehl...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/sql/javacc BasicSQLParser.jj
Date Thu, 29 Nov 2001 13:05:32 GMT
froehlich    01/11/29 05:05:32

  Modified:    apps/db/src/sql/javacc BasicSQLParser.jj
  Log:
  first successful compile of the sql parser, yippie ;-)
  
  Revision  Changes    Path
  1.2       +99 -17    jakarta-avalon-cornerstone/apps/db/src/sql/javacc/BasicSQLParser.jj
  
  Index: BasicSQLParser.jj
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/sql/javacc/BasicSQLParser.jj,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BasicSQLParser.jj	2001/11/28 15:25:37	1.1
  +++ BasicSQLParser.jj	2001/11/29 13:05:32	1.2
  @@ -9,17 +9,45 @@
   PARSER_BEGIN(BasicSQLParser)
   package org.apache.avalon.db.basic.parser;
   
  -import org.apache.avalon.db.server.AbstractSQLParser;
  +import org.apache.avalon.db.server.sql.AbstractSQLParser;
  +import org.apache.avalon.db.server.sql.ParseException;
  +import org.apache.avalon.db.server.sql.SimpleCharStream;
  +import org.apache.avalon.db.server.sql.Token;
  +import org.apache.avalon.db.server.sql.TokenMgrError;
  +import org.apache.avalon.db.server.AbstractRequestHandler;
  +import org.apache.avalon.db.server.stdhandlers.PingHandler;
  +import org.apache.avalon.db.server.stdhandlers.CatalogHandler;
  +import org.apache.avalon.db.server.stdhandlers.EstablishConnectionHandler;
  +import org.apache.avalon.db.transport.Request;
  +import org.apache.avalon.db.basic.handlers.BasicCloseResultSetHandler;
  +import org.apache.avalon.db.actions.Action;
  +import org.apache.avalon.db.actions.ActionException;
   
  +import java.util.ArrayList;
  +
   /**
    * Class BasicSQLParser
    *
    * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
    */
   public class BasicSQLParser extends AbstractSQLParser {
  +
  +    protected void getCustomRequestHandlers(AbstractRequestHandler[] handlers) {
  +    }
  +
  +    public void initializeAction(Action action) throws ActionException {
  +        action.setDatabasePersistor(mDatabasePersistor);
  +        setupLogger(action);
  +        action.initialize();
  +    }
  +
       public static void main(String args[]) {
           BasicSQLParser parser = new BasicSQLParser(System.in);
  -        parser.Test((String)args[0]);
  +        try {
  +            parser.Test((String)args[0]);
  +        } catch(ParseException pe) {
  +            pe.printStackTrace();
  +        }
       }
   }
   
  @@ -98,6 +126,12 @@
       | <LIKE:                "like" >
   }
   
  +TOKEN : { /* Indentifiers */
  +    <IDENTIFIER: <LETTER> ( <LETTER> | <DIGIT> )* >
  +    | <#LETTER: ["a"-"z", "A"-"Z", "_"] >
  +    | <#DIGIT: ["0"-"9"]>
  +}
  +
   /**
    * Test Method for command line input
    */
  @@ -109,12 +143,15 @@
       ) ";"
   }
   
  -void parseSQLString(String sql) :
  -{ }
  +String parseSQLString(String sql) :
   {
  +    String stm;
  +}
  +{
       ( 
  -        Update(sql)
  -        | Select(sql)
  +        stm = Select(sql)
  +        | stm = Update(sql)
  +        /*
           | Rollback(sql)
           | Insert(sql)
           | Grant(sql)
  @@ -122,28 +159,43 @@
           | Delete(sql)
           | Commit(sql)
           | Alter(sql)
  +        */
       ) ";"
  +    { return stm; }
   }
   
  -void Select(String sql) :
  -{ }
  +String Select(String sql) :
  +{ 
  +    String stm;
  +    Token token;
  +    ArrayList columns = new ArrayList();
  +}
  +
   {
       <SELECT>
  +        getColumns(columns)
  +        token = <SELECT>
           {
  -            //Implementation
  +            stm = token.image;
           }
  -
       <FROM>
  -        {
  -            //Implementation
  -        }
  -    //[ Where() ] //process where
  +
  +    [ Where() ] //process where
  +    { return stm; }
   }
   
  -void Update(String sql) :
  -{}
  +String Update(String sql) :
   {
  -    <EOF>   
  +     String stm;
  +     Token token;
  +}
  +{
  +    <UPDATE>
  +        token = <UPDATE>
  +        {
  +            stm = token.image;
  +        }
  +    { return stm; }
   }
   
   void Rollback(String sql) :
  @@ -186,5 +238,35 @@
   {}
   {
       <EOF>   
  +}
  +
  +void Where() :
  +{} 
  +{
  +    <EOF>
  +}
  +
  +void getColumns(ArrayList list) :
  +{
  +    String col;
  +}
  +{
  +    col = getSingleColumn() { list.add(col); }
  +}
  +
  +String getSingleColumn() :
  +{ 
  +    String col;
  +    Token column;
  +}
  +
  +{
  +
  +    column = <IDENTIFIER>
  +        { 
  +            col = column.image;
  +            System.out.println("column=" + col);
  +        }
  +    { return col; }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message