[opengtl-commits] [746] make the lexer recognize templates identifier

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 746
Author:   cyrille
Date:     2009-05-29 10:58:55 +0200 (Fri, 29 May 2009)

Log Message:
-----------
make the lexer recognize templates identifier

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp
    trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h	2009-05-29 08:58:11 UTC (rev 745)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h	2009-05-29 08:58:55 UTC (rev 746)
@@ -149,7 +149,6 @@
       private:
         GTLCore::String m_name;
     };
-    
   }
 }
 

Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp	2009-05-29 08:58:11 UTC (rev 745)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp	2009-05-29 08:58:55 UTC (rev 746)
@@ -35,12 +35,28 @@
   int lastChar = getNextChar();
   int initial_col = column() - 1;
   if( eof() ) return GTLCore::Token(GTLCore::Token::END_OF_FILE, line(), initial_col);
-  CHAR_IS_TOKEN( '@', AROBASE );
   CHAR_IS_TOKEN( '(', STARTBRACKET );
   CHAR_IS_TOKEN( ')', ENDBRACKET );
+  if( lastChar == '@' ) {
+    GTLCore::String identifierStr = getIdentifier(0);
+    IDENTIFIER_IS_KEYWORD( "allchannels", ALLCHANNELS );
+    IDENTIFIER_IS_KEYWORD( "colorchannels", COLORCHANNELS );
+    IDENTIFIER_IS_KEYWORD( "alphachannel", ALPHACHANNEL );
+    IDENTIFIER_IS_KEYWORD( "alpha", ALPHA );
+    IDENTIFIER_IS_KEYWORD( "type", TYPE );
+    IDENTIFIER_IS_KEYWORD( "max", MAX );
+    IDENTIFIER_IS_KEYWORD( "min", MIN );
+    IDENTIFIER_IS_KEYWORD( "unit", UNIT );
+    IDENTIFIER_IS_KEYWORD( "var", VAR );
+    IDENTIFIER_IS_KEYWORD( "out", OUTPUT );
+    IDENTIFIER_IS_KEYWORD( "output", OUTPUT );
+    IDENTIFIER_IS_KEYWORD( "in", INPUT );
+    IDENTIFIER_IS_KEYWORD( "input", INPUT );
+    return GTLCore::Token(GTLCore::Token::STRING_CONSTANT, "@" + identifierStr,line(), initial_col);
+  }
   GTLCore::String str;
   str = lastChar;
-  while (not eof() )
+  while(not eof())
   {
     lastChar = getNextChar();
     if( lastChar == '@' or lastChar == '(' or lastChar == ')' or eof() )

Modified: trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h	2009-05-29 08:58:11 UTC (rev 745)
+++ trunk/OpenGTL/OpenCTL/tests/library/TestTemplateLexer.h	2009-05-29 08:58:55 UTC (rev 746)
@@ -32,14 +32,14 @@
     TestTemplateLexer() : GTLTest::Case("TemplateLexer") {}
     virtual void runTest()
     {
-      std::istringstream iss("I am a string @hello(world) kikoo");
+      std::istringstream iss("I am a string @hello(world) kikoo @allchannels@colorchannels@alphachannel(@alpha)@type@min@max@unit@var@out@output@in@input");
       OpenCTL::TemplateLexer lng(&iss);
       TEST_FOR_TOKEN_STRING("I am a string ");
-      TEST_FOR_TOKEN(AROBASE);
-      TEST_FOR_TOKEN_STRING("hello");
+      TEST_FOR_TOKEN_STRING("@hello");
       TEST_FOR_TOKEN(STARTBRACKET);
       TEST_FOR_TOKEN_STRING("world");
       TEST_FOR_TOKEN(ENDBRACKET);
       TEST_FOR_TOKEN_STRING(" kikoo");
+      TEST_FOR_TOKEN(ALLCHANNELS);
     }
 };


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/