[opengtl-commits] [731] implement a lexer for the templates

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


Revision: 731
Author:   cyrille
Date:     2009-05-06 20:04:33 +0200 (Wed, 06 May 2009)

Log Message:
-----------
implement a lexer for the templates

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/compiler/LexerNG.h
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer_p.h


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/compiler/LexerNG.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/compiler/LexerNG.h	2009-05-06 14:06:10 UTC (rev 730)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/compiler/LexerNG.h	2009-05-06 18:04:33 UTC (rev 731)
@@ -30,6 +30,7 @@
 namespace OpenCTL {
   class Compiler;
   /**
+   * @internal
    * This class defines a lexer for CTL.
    */
   class LexerNG : public GTLCore::LexerBase {

Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp	2009-05-06 14:06:10 UTC (rev 730)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer.cpp	2009-05-06 18:04:33 UTC (rev 731)
@@ -0,0 +1,55 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "TemplateLexer_p.h"
+#include <GTLCore/Token_p.h>
+
+using namespace OpenCTL;
+
+TemplateLexer::TemplateLexer(std::istream* sstream) : LexerBase(sstream)
+{
+}
+
+TemplateLexer::~TemplateLexer()
+{
+}
+
+GTLCore::Token TemplateLexer::nextToken()
+{
+  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 );
+  GTLCore::String str;
+  str = lastChar;
+  while (not eof() )
+  {
+    lastChar = getNextChar();
+    if( lastChar == '@' or lastChar == '(' or lastChar == ')' )
+    {
+      unget();
+      break;
+    } else {
+      str += lastChar;
+    }
+  }
+  return GTLCore::Token(GTLCore::Token::IDENTIFIER, str, line(), initial_col);
+}

Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer_p.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer_p.h	2009-05-06 14:06:10 UTC (rev 730)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateLexer_p.h	2009-05-06 18:04:33 UTC (rev 731)
@@ -0,0 +1,44 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPENCTL_TEMPLATE_LEXER_H_
+#define _OPENCTL_TEMPLATE_LEXER_H_
+
+#include <GTLCore/LexerBase_p.h>
+
+namespace OpenCTL {
+  /**
+   * @internal
+   * Lexer for the CTL template.
+   */
+  class TemplateLexer : public GTLCore::LexerBase {
+    public:
+      TemplateLexer(std::istream* sstream);
+      ~TemplateLexer();
+      /**
+       * @return the next token
+       */
+      GTLCore::Token nextToken();
+    private:
+      TemplateLexer(const TemplateLexer& rhs) : LexerBase(rhs) {}
+      TemplateLexer& operator=(const TemplateLexer& ) { return *this; }
+  };
+}
+
+#endif


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