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 20:21:06 GMT
froehlich    01/11/29 12:21:06

  Modified:    apps/db/src/sql/javacc BasicSQLParser.jj
  Log:
  hacking the  "where clause" again <sigh>
  
  Revision  Changes    Path
  1.4       +89 -22    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicSQLParser.jj	2001/11/29 13:31:11	1.3
  +++ BasicSQLParser.jj	2001/11/29 20:21:06	1.4
  @@ -115,6 +115,9 @@
       | <GROUPBY:     "group by">
       | <ORDERBY:     "order by">
       | <DISTINCT:    "distinct">
  +    | <AND:         "and">
  +    | <OR:          "or">
  +    | <NOT:         "not">
   }
   
   TOKEN [IGNORE_CASE] : { /* Operators */
  @@ -132,6 +135,22 @@
       | <#DIGIT: ["0"-"9"]>
   }
   
  +TOKEN : {  /* Literals */
  +
  +    < INTEGER_LITERAL: (["0"-"9"])+ >
  +  | < FLOATING_POINT_LITERAL:
  +          (["0"-"9"])+ "." (["0"-"9"])+ (<EXPONENT>)?
  +        | "." (["0"-"9"])+ (<EXPONENT>)?
  +        | (["0"-"9"])+ <EXPONENT>
  +        | (["0"-"9"])+ (<EXPONENT>)?
  +    >
  +  | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
  +  | < STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" >
  +}
  +
  +
  +
  +
   /**
    * Test Method for command line input
    */
  @@ -160,7 +179,8 @@
           | Commit()
           | Alter()
           */
  -    ) ";"
  +    )
  +    ( ";" | <EOF> )
       { return stm; }
   }
   
  @@ -168,16 +188,15 @@
   { 
       String stm;
       Token token;
  -    ArrayList columns = new ArrayList();
   }
   
   {
       <SELECT>
  -        token = <SELECT> { stm = token.image; }
  -        getColumns(columns)
  +        { stm = "SELECT"; }
  +        getColumns()
       <FROM>
  -
  -    [ Where() ] //process where
  +        getTables()
  +    [ Where() ]
       { return stm; }
   }
   
  @@ -188,10 +207,7 @@
   }
   {
       <UPDATE>
  -        token = <UPDATE>
  -        {
  -            stm = token.image;
  -        }
  +        { stm = "UPDATE"; }
       { return stm; }
   }
   
  @@ -240,30 +256,81 @@
   void Where() :
   {} 
   {
  -    <EOF>
  +    <WHERE>
  +        {
  +            OrExpr();
  +        }
   }
   
  -void getColumns(ArrayList list) :
  +void OrExpr() :
  +{}
   {
  -    String col;
  +    AndExpr()
  +    ( <OR>
  +        AndExpr()
  +        { System.out.println("in or"); }
  +    )*
   }
  +
  +
  +void AndExpr() :
  +{}
  +
   {
  -    col = getSingleColumn() { list.add(col); }
  +    NotExpr()
  +    ( <AND>
  +        { System.out.println("in and"); }
  +    NotExpr() )*
   }
   
  -String getSingleColumn() :
  -{ 
  +void NotExpr() :
  +{}
  +
  +{
  +    [ <NOT> 
  +	    { System.out.println("in not"); }
  +    ] 
  +    CompareExpr() 
  +}
  +
  +void CompareExpr() :
  +{}
  +
  +{
  +    ( 
  +        <IDENTIFIER><EQUAL><STRING_LITERAL> { System.out.println("EQUAL");
}
  +        | <GREATERTHAN> { System.out.println("GREATERTHAN"); }
  +        | <SMALLERTHAN> { System.out.println("SMALLERTHAN"); }
  +        | <GREATERTHANOREQUAL> { System.out.println("GREATERTHANOREQUAL"); }
  +        | <SMALLERTHANOREQUAL> { System.out.println("SMALLERTHANOREQUAL"); }
  +        | <LIKE> { System.out.println("LIKE"); }
  +    )
  +}
  +
  +
  +
  +void getColumns() :
  +{
       String col;
       Token column;
   }
  +{
  +    ( "*" { System.out.println("all columns"); } )
  +    |
  +    column = <IDENTIFIER> {System.out.println("column=" + column.image); }
  +    ( "," { System.out.println(",");}
  +        column = <IDENTIFIER> {System.out.println("column=" + column.image); } )*
  +}
   
  +void getTables() :
  +{
  +    String tab;
  +    Token table;
  +}
   {
  +    table = <IDENTIFIER> {System.out.println("table=" + table.image); }
  +    ( "," { System.out.println(",");}
  +        table = <IDENTIFIER> {System.out.println("table=" + table.image); } )*
   
  -    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