[Saga-devel] saga SVN commit 3294: /trunk/saga/impl/packages/sd/

paul.livesey at stfc.ac.uk paul.livesey at stfc.ac.uk
Thu Jan 15 06:53:10 CST 2009


User: svn_plivesey
Date: 2009/01/15 06:53 AM

Modified:
 /trunk/saga/impl/packages/sd/
  sd_grammar.g, sd_leafnode.hpp

Log:
 Added handling for vector attributes, including the addition
 of the ANY and ALL keywords.
 A few bugs have been removed including nested VO filters not working
 due to a misspelt LPAREN token (was LPARAN).

File Changes:

Directory: /trunk/saga/impl/packages/sd/
========================================

File [modified]: sd_grammar.g
Delta lines: +320 -155
===================================================================
--- trunk/saga/impl/packages/sd/sd_grammar.g	2009-01-15 12:46:32 UTC (rev 3293)
+++ trunk/saga/impl/packages/sd/sd_grammar.g	2009-01-15 12:53:02 UTC (rev 3294)
@@ -1,21 +1,25 @@
-header {
-  #include "sd_leafnode.hpp"
-  #include "sd_internalnode.hpp"
-  #include <iostream>
-  #include <string>
-  #include <list>
-  #include <math.h>
-  using namespace std;
+header
+{
+   #include "sd_leafnode.hpp"
+   #include "sd_internalnode.hpp"
+   #include <iostream>
+   #include <string>
+   #include <list>
+   #include <math.h>
+   #include <utility>
+   using namespace std;
 }
 
-options {
+options
+{
    language=Cpp;
 }
 
 class sd_parser extends Parser;
 
-options {
-   k = 3; 
+options
+{
+   k = 3;
    exportVocab = sd;
    buildAST = true;
 }
@@ -23,6 +27,7 @@
 tokens {
 K_IN  = "in";
 K_LIKE = "like";
+K_ESCAPE = "escape";
 K_NOT  = "not";
 K_AND = "and" <AST=sd_internalnode>;
 K_OR = "or" <AST=sd_internalnode>;
@@ -34,199 +39,359 @@
 K_ENDPOINT = "endpoint";
 K_SITE = "site";
 K_SERVICE = "related_services";
+K_ALL ="all";
+K_ANY ="any";
+K_STRING_LIST;
 SVC_CMP<AST=sd_leafnode>;
 DATA_CMP<AST=sd_leafnode>;
 }
 
-service_keyword! returns [int tok_type = 0] : 
-                                      k1:K_TYPE! { tok_type = k1->getType(); } 
-                                    | k2:K_NAME! { tok_type = k2->getType(); } 
-                                    | k3:K_SITE! { tok_type = k3->getType(); } 
-                                    | k4:K_ENDPOINT! { tok_type = k4->getType(); } 
-                                    | k5:K_SERVICE! { tok_type = k5->getType(); } 
-                                    | k6:K_UID! { tok_type = k6->getType(); } 
-                                    | k7:K_URI! { tok_type = k7->getType(); } 
-                                    ;
+service_keyword! returns [int tok_type = 0] :
+   k1:K_TYPE! { tok_type = k1->getType(); } |
+   k2:K_NAME! { tok_type = k2->getType(); } |
+   k3:K_SITE! { tok_type = k3->getType(); } |
+   k4:K_ENDPOINT! { tok_type = k4->getType(); } |
+   k5:K_SERVICE! { tok_type = k5->getType(); } |
+   k6:K_UID! { tok_type = k6->getType(); } |
+   k7:K_URI! { tok_type = k7->getType(); }
+   ;
 
 service_filter : service_filter_expression ;
 
 service_filter_expression : service_and_expression ( K_OR^ service_and_expression )*  ;
 
-service_and_expression : service_expression ( K_AND^ service_expression)* ; 
+service_and_expression : service_expression ( K_AND^ service_expression)* ;
 
-service_expression  { int knot=0; int lhs, op; string rhs, comp; Refsd_leafnode myRef; std::list<std::string> slist; std::string s; } : 
-                     lhs=service_keyword slist=in_clause[&knot]
-                     { 
-                        #service_expression = #([SVC_CMP]); 
-                        myRef = (Refsd_leafnode)#service_expression;   
-                        myRef->setLValue(lhs);
-			myRef->setOpType(K_IN);
-                        //myRef->setList(&slist);
-                        while (slist.size() > 0)
-                        {
-                           s = slist.front(); 
-                           myRef->addListElement(s);
-                           slist.pop_front();
-                        }
-                        if (knot)
-                           myRef->setNotPrefix(); 
-                        //std::cout << "front list element : " << myRef->frontListElement() << endl; 
-                        //std::cout << "list size : " << myRef->getListSize() << endl; 
-                        //std::cout << "in clause parsed" << endl;
-                     }
+service_expression
+{ int knot = 0; int lhs; int op;
+  std::pair<std::string, char> rhs;
+  std::list<std::string> slist;
+  std::string s;
+  Refsd_leafnode myRef;
+} :
+(
+   lhs=service_keyword (K_NOT! {knot=1;})? K_IN! slist=in_clause
+   {
+      #service_expression = #([SVC_CMP]);
+      myRef = (Refsd_leafnode)#service_expression;
+      myRef->setLValue(lhs);
+      myRef->setOpType(K_IN);
+      myRef->setRValType(K_STRING_LIST);
 
-                   | lhs=service_keyword rhs=like_clause[&knot] 
-                     { 
-                        #service_expression = #([SVC_CMP]); 
-                        myRef = (Refsd_leafnode)#service_expression;   
-                        myRef->setLValue(lhs);
-			myRef->setOpType(K_LIKE);
-                        myRef->setRValue(rhs);
-                        if (knot)
-                           myRef->setNotPrefix();
-                     }
-                   | lhs=service_keyword op=eqop rval:S_CHAR_LITERAL!
-                     {
-                        #service_expression = #([SVC_CMP]); 
-                        myRef = (Refsd_leafnode)#service_expression;   
-                        myRef->setLValue(lhs);
-                        //std::cout << "keyword type " << lhs << endl;
-                        myRef->setOpType(op);
-                        //std::cout << "op type " << op << endl;
-                        myRef->setRValue(rval->getText());
-                        //std::cout << "literal " << rval->getText() << endl;
-                     }
-                   | LPAREN! service_filter_expression RPAREN! 
-                   ;
+      while (slist.size() > 0)
+      {
+         s = slist.front();
+         myRef->addListElement(s);
+         slist.pop_front();
+      }
 
-like_clause! [int *knot] returns [string s]  
-                     : (K_NOT {*knot = 1; } )?   
-                       K_LIKE rhs:S_CHAR_LITERAL! 
-                       { 
-         		   s = rhs->getText();
-                       }
-		       ;
+      if ( knot )
+      {
+         myRef->setNotPrefix();
+      }
+      //std::cout << "front list element : "
+      //          << myRef->frontListElement() << endl;
+      //std::cout << "list size : "
+      //          << myRef->getListSize() << endl;
+      //std::cout << "in clause parsed" << endl;
+   } |
 
-in_clause! [int *knot] returns [std::list<std::string> slist] { string list; } : 
-                    (K_NOT! { *knot = 1;})?   
-                     K_IN! LPAREN! lit:S_CHAR_LITERAL!  
-                            { 
-                              slist.push_back(lit->getText()); 
-                            }
-                            ( COMMA! lit2:S_CHAR_LITERAL! 
-                            { 
-                              slist.push_back(lit2->getText()); 
-                            } 
-                            )* RPAREN! 
-                    ; 
+   lhs=service_keyword (K_NOT! {knot = 1;})? K_LIKE! rhs=like_clause
+   {
+      #service_expression = #([SVC_CMP]);
+      myRef = (Refsd_leafnode)#service_expression;
+      myRef->setLValue(lhs);
+      myRef->setOpType(K_LIKE);
+      myRef->setRValue(rhs.first);
 
-string_literal_list!  : lit:S_CHAR_LITERAL! 
-                     //{ 
-                       //s = lit->getText(); 
-                       //myRef->addListElement(lit->getText());
-                       //std::cout << lit->getText() << "  " << myRef->getListSize() <<endl;
-                     //} 
-                     ( COMMA! lit2:S_CHAR_LITERAL!  
-                       { 
-                         //s = s + "," + lit2->getText(); 
-                         //std::cout << myRef->getListSize() <<endl;
-                         //myRef->addListElement(lit2->getText());
-                         //std::cout << lit2->getText() <<endl;
-                       } 
-                     )*    
-                     ;
+      //Set the escape character
+      //for the 'LIKE' clause
+      myRef->setEscapeChar(rhs.second);
 
+      if ( knot )
+      {
+         myRef->setNotPrefix();
+      }
+   } |
+
+   lhs=service_keyword op=eqop rval:S_CHAR_LITERAL!
+   {
+      #service_expression = #([SVC_CMP]);
+      myRef = (Refsd_leafnode)#service_expression;
+      myRef->setLValue(lhs);
+      //std::cout << "keyword type " << lhs << endl;
+      myRef->setOpType(op);
+      //std::cout << "op type " << op << endl;
+      myRef->setRValue(rval->getText());
+      //std::cout << "literal " << rval->getText() << endl;
+   } |
+
+   LPAREN! service_filter_expression RPAREN!
+)
+   ;
+
+like_clause returns [pair<string, char> s] :
+   rhs:S_CHAR_LITERAL!
+   {
+      s.first = rhs->getText();
+      s.second = '\0';
+   }
+   (K_ESCAPE esc:S_CHAR_LITERAL!
+   {
+      //Check there are at least three characters
+      //to allow for the quotes
+      if ( esc->getText().size() > 2 )
+      {
+         //Character [1] to allow for the quote
+         s.second = esc->getText()[1];
+      }
+
+      else
+      {
+         s.second = '\0';
+      }
+   })?
+   ;
+
+//You don't need to quote numbers
+in_clause returns [std::list<std::string> slist] :
+   slist=bracketed_list
+   ;
+
+//This should match a bracketed list
+//('string', num, num, 'string', etc.)
+bracketed_list  returns [std::list<std::string> slist] :
+   LPAREN
+
+   (lit:S_CHAR_LITERAL! {slist.push_back(lit->getText());} |
+    num:S_NUMBER! {slist.push_back(num->getText());} )
+
+   (COMMA! (lit2:S_CHAR_LITERAL! {slist.push_back(lit2->getText());} |
+            num2:S_NUMBER! {slist.push_back(num2->getText());}) )*
+   RPAREN
+   ;
+
+string_literal_list!  : lit:S_CHAR_LITERAL!
+//{
+//s = lit->getText();
+//myRef->addListElement(lit->getText());
+//std::cout << lit->getText() << "  " << myRef->getListSize() <<endl;
+//}
+   ( COMMA! lit2:S_CHAR_LITERAL!
+   {
+      //s = s + "," + lit2->getText();
+      //std::cout << myRef->getListSize() <<endl;
+      //myRef->addListElement(lit2->getText());
+      //std::cout << lit2->getText() <<endl;
+   } )*
+;
+
 vo_filter : vo_filter_expression
-          ;
+;
 
 vo_filter_expression : vo_and_expression (K_OR^ vo_and_expression )*
-                     ;
+;
 
 vo_and_expression : vo_expression ( K_AND^ vo_expression )*
-                    ;
+;
 
-vo_expression { int knot=0; int op; string rhs, comp; Refsd_leafnode myRef; list<string> slist; string s; } :
-              K_VO! slist=in_clause[&knot]
+vo_expression
+{
+   int knot = 0;
+   int op;
+   string rhs;
+   string comp;
+   string s;
+   Refsd_leafnode myRef;
+   list<string> slist;
+   std::pair<std::string, char> rhsLike;
+} :
+              K_VO! (K_NOT! {knot=1;})? K_IN! slist=in_clause
               {
                  #vo_expression = #([SVC_CMP]);
                  myRef = (Refsd_leafnode)#vo_expression;
                  myRef->setLValue(K_VO);
                  myRef->setOpType(K_IN);
-                 while (slist.size() > 0)
+                 myRef->setRValType(K_STRING_LIST);
+
+                 while ( slist.size() > 0 )
                  {
                      s = slist.front();
                      myRef->addListElement(s);
                      slist.pop_front();
                  }
-                 if (knot)
-                     myRef->setNotPrefix();
 
+                 if ( knot )
+                 {
+                    myRef->setNotPrefix();
+                 }
+
                }
-               | K_VO! op=eqop rval:S_CHAR_LITERAL! 
+               | K_VO! (K_NOT! {knot = 1;})? K_LIKE rhsLike=like_clause
                {
+                  #vo_expression = #([SVC_CMP]);
+                  myRef = (Refsd_leafnode)#vo_expression;
+                  myRef->setLValue(K_VO);
+                  myRef->setOpType(K_LIKE);
+                  myRef->setRValue(rhsLike.first);
+
+                  //Set the escape character
+                  //for the 'LIKE' clause
+                  myRef->setEscapeChar(rhsLike.second);
+
+                  if ( knot )
+                  {
+                     myRef->setNotPrefix();
+                  }
+               }
+               | K_VO! op=eqop rval:S_CHAR_LITERAL!
+               {
                  #vo_expression = #([SVC_CMP]);
                  myRef = (Refsd_leafnode)#vo_expression;
                  myRef->setLValue(K_VO);
                  myRef->setOpType(op);
-		 myRef->setRValue(rval->getText());
+                 myRef->setRValue(rval->getText());
                }
-               | LPARAN! vo_filter_expression RPAREN!
-               ;                  
+               | LPAREN! vo_filter_expression RPAREN!
+               ;
 
-data_filter : data_filter_expression 
-            ;
+data_filter : data_filter_expression
+;
 
-data_filter_expression : data_and_expression ( K_OR^ data_and_expression )* 
-                       ;
+data_filter_expression : data_and_expression ( K_OR^ data_and_expression )*
+;
 
-data_and_expression : data_expression ( K_AND^ data_expression )* 
-                    ;
+data_and_expression : data_expression ( K_AND^ data_expression )*
+;
 
-data_expression : data_comparison 
-                | LPAREN! data_filter_expression RPAREN! 
-                ;
+data_expression : data_comparison | LPAREN! data_filter_expression RPAREN!
+;
 
-eqop! returns [int tok_type = 0] : o1:NE! { tok_type = o1->getType(); } 
-                             | o2:EQ! { tok_type = o2->getType(); }
-                           ;
+eqop returns [int tok_type = 0] :
+   o1:NE! { tok_type = o1->getType(); } |
+   o2:EQ! { tok_type = o2->getType(); }
+;
 
-relop! returns [int tok_type = 0] :  o1:EQ   { tok_type = o1->getType(); } 
-                               | o2:LESS { tok_type = o2->getType(); } 
-                               | o3:GT   { tok_type = o3->getType(); } 
-                               | o4:NE   { tok_type = o4->getType(); } 
-                               | o5:LE   { tok_type = o5->getType(); } 
-                               | o6:GE   { tok_type = o6->getType(); } 
-                               ;
+relop! returns [int tok_type = 0] :
+   o1:EQ   { tok_type = o1->getType(); } |
+   o2:LESS { tok_type = o2->getType(); } |
+   o3:GT   { tok_type = o3->getType(); } |
+   o4:NE   { tok_type = o4->getType(); } |
+   o5:LE   { tok_type = o5->getType(); } |
+   o6:GE   { tok_type = o6->getType(); }
+;
 
-data_comparison { int op; int rhs1 = 0; double dval; Refsd_leafnode myRef; } : 
-                              lhs:S_IDENTIFIER! op=relop (lit:S_CHAR_LITERAL! { rhs1 = 1; } | num:S_NUMBER!)
-                              {
-				#data_comparison = #([DATA_CMP]);
-                                myRef = (Refsd_leafnode)#data_comparison;
-                                myRef->setLKey(lhs->getText());
-                                myRef->setOpType(op);
-                                if (rhs1)
-                                {
-                                     myRef->setRValType(S_CHAR_LITERAL);
-				     myRef->setRValue(lit->getText());
-                                }
-				else
-                                {
-                                     myRef->setRValType(S_NUMBER);
-				     dval = atof(num->getText().c_str());
-                                     myRef->setRValNum(dval);
-                                }
-			      }
-                              ;
+data_comparison
+{
+   bool allVal = false;
+   bool anyVal = false;
+   int op; int rhs1 = 0; int knot = 0;
+   double dval;
+   Refsd_leafnode myRef;
+   std::list<std::string> slist;
+   std::string s;
+   std::pair<std::string, char> likePair;
+   std::string likeString;
+} :
+   //Check for ANY/ALL clause
+   (K_ANY! {anyVal = true;} |
+    K_ALL! {allVal = true;})?
 
+   lhs:S_IDENTIFIER! (K_NOT! {knot=1;})? K_IN! slist=in_clause
+   {
+      //Deal with the 'IN' oerator
+      #data_comparison = #([DATA_CMP]);
+      myRef = (Refsd_leafnode)#data_comparison;
+      myRef->setLKey(lhs->getText());
+      myRef->setOpType(K_IN);
+      myRef->setRValType(K_STRING_LIST);
+
+      //Add everything in the 'IN' list to this element
+      while ( slist.size() > 0 )
+      {
+         s = slist.front();
+         myRef->addListElement(s);
+         slist.pop_front();
+      }
+
+      //Deal with the NOT condition
+      if ( knot )
+      {
+         myRef->setNotPrefix();
+      }
+   } |
+
+   lhs0:S_IDENTIFIER (K_NOT! {knot = 1;})? K_LIKE likePair=like_clause
+   {
+      //Deal with the 'LIKE' oerator
+      likeString = likePair.first;
+      #data_comparison = #([DATA_CMP]);
+      myRef = (Refsd_leafnode)#data_comparison;
+      myRef->setLKey(lhs0->getText());
+      myRef->setOpType(K_LIKE);
+      myRef->setRValue(likeString);
+
+      //Set the escape character
+      //for the 'LIKE' clause
+      myRef->setEscapeChar(likePair.second);
+
+      //Deal with the NOT condition
+      if ( knot )
+      {
+         myRef->setNotPrefix();
+      }
+   } |
+
+   lhs1:S_IDENTIFIER! op=relop (lit:S_CHAR_LITERAL! { rhs1 = 1; } | num:S_NUMBER!)
+   {
+      //Deal with the remaining operators
+      #data_comparison = #([DATA_CMP]);
+      myRef = (Refsd_leafnode)#data_comparison;
+      myRef->setLKey(lhs1->getText());
+      myRef->setOpType(op);
+
+      if ( rhs1 )
+      {
+         myRef->setRValType(S_CHAR_LITERAL);
+         myRef->setRValue(lit->getText());
+      }
+
+      else
+      {
+         myRef->setRValType(S_NUMBER);
+         dval = atof(num->getText().c_str());
+         myRef->setRValNum(dval);
+      }
+   } |
+
+   lhs2:S_IDENTIFIER! op=eqop slist=bracketed_list
+   {
+      //Deal with the remaining operators
+      #data_comparison = #([DATA_CMP]);
+      myRef = (Refsd_leafnode)#data_comparison;
+      myRef->setLKey(lhs2->getText());
+      myRef->setOpType(op);
+      myRef->setRValType(K_STRING_LIST);
+
+      //Add everything in the 'IN' list to this element
+      while ( slist.size() > 0 )
+      {
+         s = slist.front();
+         myRef->addListElement(s);
+         slist.pop_front();
+      }
+   }
+;
+
 class sd_lexer extends Lexer;
 
-options {
-    k = 2;
-    caseSensitive = false;
-    exportVocab = sd;
-    testLiterals = false;
-    caseSensitiveLiterals = false;
+options
+{
+   k = 2;
+   caseSensitive = false;
+   exportVocab = sd;
+   testLiterals = false;
+   caseSensitiveLiterals = false;
 }
 
 WS_ options { paraphrase = "white space"; } : (' ' | '\t' | '\n' | '\r') { _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; } ;

File [modified]: sd_leafnode.hpp
Delta lines: +33 -0
===================================================================
--- trunk/saga/impl/packages/sd/sd_leafnode.hpp	2009-01-15 12:46:32 UTC (rev 3293)
+++ trunk/saga/impl/packages/sd/sd_leafnode.hpp	2009-01-15 12:53:02 UTC (rev 3294)
@@ -12,9 +12,20 @@
 class sd_leafnode : public sd_node {
 
 public:
+        typedef enum
+        {
+           ANY_VALUE = 0,
+           ALL_VALUE
+        } ANYALLTYPE;
+
         sd_leafnode()
         {
            not_prefix = 0;
+           //Default to Any value for vector operations
+           setAnyAllValue(ANY_VALUE);
+
+           //Default 'LIKE' escape char to '\0'
+           setEscapeChar('\0');
         }
 
         void setRValue(const ANTLR_USE_NAMESPACE(std)string& rval) 
@@ -139,6 +150,26 @@
                 CommonAST::initialize(tok);
         }
 
+        ANYALLTYPE getAnyValue()
+        {
+           return AAValue;
+        }
+
+        void setAnyAllValue(ANYALLTYPE AAVal)
+        {
+           AAValue = AAVal;
+        }
+
+        char getEscapeChar()
+        {
+           return escapeChar;
+        }
+
+        void setEscapeChar(char escChar)
+        {
+           escapeChar = escChar;
+        }
+
 private:
         string rvalue;       // Literal
         int lvalue;   	     // Service keyword token type
@@ -148,6 +179,8 @@
         string lkey;         // GlueDataKey
         list<string> in_list;// List of literals for IN operator   
         int not_prefix;      // NOT prefix for IN and LIKE operator
+        ANYALLTYPE AAValue;  // Is this working on any vector value
+        char escapeChar;
 };
 
 typedef ANTLR_USE_NAMESPACE(antlr)ASTRefCount<sd_leafnode> Refsd_leafnode;



More information about the saga-devel mailing list