[opengtl-commits] [506] add a parser and lexer of metdata

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


Revision: 506
Author:   cyrille
Date:     2008-11-27 20:23:04 +0100 (Thu, 27 Nov 2008)

Log Message:
-----------
add a parser and lexer of metdata

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/Version.h
    trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex
    trunk/OpenGTL/OpenShiva/tests/library/TestOpenShiva.cpp

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.h
    trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.h
    trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.h
    trunk/OpenGTL/OpenShiva/tests/library/TestMetadataLexer.h
    trunk/OpenGTL/OpenShiva/tests/library/TestMetadataParser.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-11-27 19:22:37 UTC (rev 505)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-11-27 19:23:04 UTC (rev 506)
@@ -15,6 +15,10 @@
   Kernel_p.cpp
   Library.cpp
   LibrariesManager.cpp
+# Metadata
+  MetadataLexer_p.cpp
+  MetadataParser_p.cpp
+  KernelMetadata.cpp
 # Wrap
   wrappers/ImageWrap_p.cpp
   wrappers/PixelWrap_p.cpp
@@ -39,7 +43,7 @@
 
 # Install target
 install(TARGETS OpenShiva  DESTINATION ${LIB_INSTALL_DIR} )
-install( FILES Kernel.h Library.h Version.h DESTINATION ${INCLUDE_INSTALL_DIR}/OpenShiva )
+install( FILES Kernel.h KernelMetadata.h Library.h LibrariesManager.h Version.h DESTINATION ${INCLUDE_INSTALL_DIR}/OpenShiva )
 
 # Create and install pc file
 configure_file("OpenShiva.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/OpenShiva.pc" @ONLY)

Added: trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.cpp	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,86 @@
+/*
+ *  Copyright (c) 2008 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 "KernelMetadata.h"
+
+#include "GTLCore/Value.h"
+#include "GTLCore/Metadata/ValueEntry.h"
+
+#include "Debug.h"
+#include "Version.h"
+
+using namespace OpenShiva;
+using namespace GTLCore::Metadata;
+
+struct KernelMetadata::Private {
+  int version;
+  const Group* infoList;
+  const Group* parametersList;
+};
+
+inline std::list<const Entry*> createList( const Entry* _version, const Group* _infoList, const Group* _parametersList )
+{
+  std::list<const Entry*> list;
+  if( _version )
+  {
+    list.push_back( _version );
+  }
+  if( _infoList )
+  {
+    list.push_back( _infoList );
+  }
+  if( _parametersList )
+  {
+    list.push_back( _parametersList );
+  }
+  return list;
+}
+
+KernelMetadata::KernelMetadata( const Entry* _version, const Group* _infoList, const Group* _parametersList ) : Group( "Kernel", createList( _version, _infoList, _parametersList ) ), d(new Private)
+{
+  d->version = LanguageVersion;
+  if( _version )
+  {
+    const ValueEntry* te = _version->asValueEntry();
+    SHIVA_ASSERT( te );
+    d->version = te->value().asInt32();
+  }
+  d->infoList = _infoList;
+  d->parametersList = _parametersList;
+}
+
+KernelMetadata::~KernelMetadata()
+{
+  delete d;
+}
+
+int KernelMetadata::version() const
+{
+  return d->version;
+}
+const Group* KernelMetadata::infos() const
+{
+  return d->infoList;
+}
+
+const Group* KernelMetadata::parameters() const
+{
+  return d->parametersList;
+}
+


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.h	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,45 @@
+/*
+ *  Copyright (c) 2008 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 _OPENSHIVA_KERNEL_METADATA_H_
+#define _OPENSHIVA_KERNEL_METADATA_H_
+
+#include <GTLCore/Metadata/Group.h>
+
+namespace OpenShiva {
+  namespace Metadata {
+    class Parser;
+  }
+  class KernelMetadata : public GTLCore::Metadata::Group {
+      friend class Metadata::Parser;
+      friend class Kernel;
+      KernelMetadata( const GTLCore::Metadata::Entry* _version, const GTLCore::Metadata::Group* _infoList, const GTLCore::Metadata::Group* _parametersList );
+      ~KernelMetadata();
+    public:
+      int version() const;
+      const GTLCore::Metadata::Group* infos() const;
+      const GTLCore::Metadata::Group* parameters() const;
+    private:
+      struct Private;
+      Private* const d;
+  };
+}
+
+#endif
+


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/KernelMetadata.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.cpp	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (c) 2008 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 "MetadataLexer_p.h"
+
+#include "GTLCore/Token_p.h"
+
+#include "Debug.h"
+
+using namespace OpenShiva::Metadata;
+
+Lexer::Lexer(std::istream* sstream) : LexerBase(sstream)
+{
+}
+
+Lexer::~Lexer()
+{
+}
+
+GTLCore::Token Lexer::nextToken()
+{
+  int lastChar = getNextNonSeparatorChar();
+  int initial_line = line() - 1;
+  int initial_col = column() - 1;
+  if( eof() ) return GTLCore::Token(GTLCore::Token::END_OF_FILE, line(), initial_col);
+  if(isalpha(lastChar))
+  {
+    return GTLCore::Token(GTLCore::Token::IDENTIFIER, getIdentifier(lastChar),line(), initial_col);
+  } else if( isdigit(lastChar) )
+  { // if it's a digit 
+    return getDigit(lastChar);
+  } else if( lastChar == '"' ) {
+    return getString(lastChar);
+  } else {
+    CHAR_IS_TOKEN(';', SEMI );
+    CHAR_IS_TOKEN(':', COLON );
+    CHAR_IS_TOKEN('<', INFERIOR );
+    CHAR_IS_TOKEN('>', SUPPERIOR );
+  }
+  if( lastChar > 128 ) return nextToken();
+  GTL_ABORT("Unknown token : " << lastChar << " at " << initial_line << "," << initial_col);
+  return GTLCore::Token(GTLCore::Token::UNKNOWN, initial_line, initial_col);
+}
+


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.h	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2008 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 _OPENSHIVA_METADATA_LEXER_P_H_
+#define _OPENSHIVA_METADATA_LEXER_P_H_
+
+#include "GTLCore/LexerBase_p.h"
+
+namespace OpenShiva {
+  namespace Metadata {
+    /**
+     * @internal
+     * @ingroup OpenShiva
+     */
+    class Lexer : public GTLCore::LexerBase {
+      public:
+        Lexer(std::istream* sstream);
+        virtual ~Lexer();
+        virtual GTLCore::Token nextToken();
+    };
+  }
+}
+
+#endif


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataLexer_p.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,218 @@
+/*
+ *  Copyright (c) 2008 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 "MetadataParser_p.h"
+
+#include "GTLCore/ErrorMessage.h"
+#include "GTLCore/Macros_p.h"
+#include "GTLCore/Value.h"
+#include "GTLCore/Metadata/TextEntry.h"
+#include "GTLCore/Metadata/ValueEntry.h"
+#include "GTLCore/Metadata/Factory_p.h"
+#include "GTLCore/Metadata/Group.h"
+#include "GTLCore/Metadata/ParameterEntry.h"
+
+#include "Debug.h"
+#include "MetadataLexer_p.h"
+#include "KernelMetadata.h"
+
+using namespace OpenShiva::Metadata;
+
+struct Parser::Private {
+  Lexer* lexer;
+  GTLCore::Token token;
+  std::list<GTLCore::ErrorMessage> errorMessages;
+  GTLCore::String fileName;
+};
+
+Parser::Parser( Lexer* _lexer, const GTLCore::String& fileName) : d(new Private)
+{
+  d->lexer = _lexer;
+  d->fileName = fileName;
+}
+
+Parser::~Parser()
+{
+  delete d->lexer;
+  delete d;
+}
+
+OpenShiva::KernelMetadata* Parser::parse()
+{
+  const GTLCore::Metadata::Entry* version = 0;
+  const GTLCore::Metadata::Group* infoList = 0;
+  const GTLCore::Metadata::Group* parametersList = 0;
+  getNextToken() ;
+  if( currentToken().type != GTLCore::Token::INFERIOR ) return 0;
+  getNextToken();
+  while( currentToken().type != GTLCore::Token::SUPPERIOR and currentToken().type != GTLCore::Token::END_OF_FILE )
+  {
+    if( currentToken().type == GTLCore::Token::IDENTIFIER )
+    {
+      SHIVA_DEBUG( currentToken().string );
+      GTLCore::String str = currentToken().string;
+      getNextToken();
+      isOfType( currentToken(), GTLCore::Token::COLON );
+      getNextToken();
+      if( str == "version" )
+      {
+        version = parseValueEntry("version");
+      } else if( str == "info" ) {
+        infoList = parseGroup("info", false);
+      } else if( str == "parameters" ) {
+        parametersList = parseGroup("parameters", true);
+      } else {
+        reportUnexpected( currentToken() );
+        getNextToken();
+      }
+    } else {
+      reportUnexpected( currentToken() );
+      getNextToken();
+    }
+  }
+  return new KernelMetadata( version, infoList, parametersList );
+}
+
+void Parser::getNextToken()
+{
+  d->token = d->lexer->nextToken();
+}
+
+const GTLCore::Token& Parser::currentToken()
+{
+  return d->token;
+}
+
+void Parser::reportError( const GTLCore::String& errMsg, const GTLCore::Token& token )
+{
+  d->errorMessages.push_back( GTLCore::ErrorMessage( errMsg, token.line, d->fileName ) );
+}
+
+void Parser::reportUnexpected( const GTLCore::Token& token )
+{
+  reportError("Unexpected: " + GTLCore::Token::typeToString( token.type ), token );
+  getNextToken();
+}
+
+const std::list<GTLCore::ErrorMessage>& Parser::errorMessages() const
+{
+  return d->errorMessages;
+}
+
+bool Parser::isOfType( const GTLCore::Token& token, GTLCore::Token::Type type )
+{
+  if( token.type == type )
+  {
+    return true;
+  } else {
+    reportError("Expected " + GTLCore::Token::typeToString(type) + " before " + GTLCore::Token::typeToString(token.type)  + ".", token);
+    return false;
+  }
+}
+
+const GTLCore::Metadata::ParameterEntry* Parser::parseParameterEntry(const GTLCore::String& name)
+{
+  GTL_ABORT("oh");
+  return 0;
+}
+
+const GTLCore::Metadata::TextEntry* Parser::parseTextEntry( const GTLCore::String& name)
+{
+  getNextToken();
+  if( isOfType( currentToken(), GTLCore::Token::STRING_CONSTANT ) )
+  {
+    GTLCore::String v = currentToken().string;
+    getNextToken();
+    if( isOfType( currentToken(), GTLCore::Token::SEMI ) )
+    {
+      getNextToken();
+      return GTLCore::Metadata::Factory::createTextEntry( name, v );
+    }
+  }
+  return 0;
+}
+
+const GTLCore::Metadata::ValueEntry* Parser::parseValueEntry(const GTLCore::String& name)
+{
+  GTLCore::Value val;
+  if( currentToken().type == GTLCore::Token::FLOAT_CONSTANT )
+  {
+    val.setFloat( currentToken().f );
+  } else if( currentToken().type == GTLCore::Token::INTEGER_CONSTANT )
+  {
+    val.setInt32( currentToken().i );
+  } else {
+    reportUnexpected( currentToken() );
+    getNextToken();
+    return 0;
+  }
+  getNextToken();
+  if( isOfType( currentToken(), GTLCore::Token::SEMI ) )
+  {
+    getNextToken();
+    return GTLCore::Metadata::Factory::createValueEntry( name, val );
+  }
+  getNextToken();
+  return 0;
+}
+
+const GTLCore::Metadata::Group* Parser::parseGroup(const GTLCore::String& _name, bool _parameter)
+{
+  std::list< const GTLCore::Metadata::Entry*> entries;
+  if( isOfType( currentToken(), GTLCore::Token::INFERIOR ) )
+  {
+    getNextToken();
+    while( currentToken().type != GTLCore::Token::SUPPERIOR and currentToken().type != GTLCore::Token::END_OF_FILE )
+    {
+      if( isOfType( currentToken(), GTLCore::Token::IDENTIFIER ) )
+      {
+        GTLCore::String str = currentToken().string;
+        getNextToken();
+        if( isOfType( currentToken(), GTLCore::Token::COLON ) )
+        {
+          getNextToken();
+          if( currentToken().type == GTLCore::Token::INFERIOR )
+          {
+            entries.push_back( parseGroup( str, _parameter ) );
+          } else if( not _parameter or str == "description" ) {
+            GTL_DEBUG("t: " << str);
+            entries.push_back( parseTextEntry( str ) );
+          } else {
+            GTL_DEBUG("p: " << str);
+            entries.push_back( parseParameterEntry( str ) );
+          }
+        }
+      }
+      getNextToken();
+    }
+    if( isOfType( currentToken(), GTLCore::Token::COLON ) )
+    {
+      getNextToken();
+      return GTLCore::Metadata::Factory::createGroup( _name, entries );
+    } else {
+      foreach( const GTLCore::Metadata::Entry* entry, entries)
+      {
+        GTLCore::Metadata::Factory::deleteEntry( entry );
+      }
+    }
+  }
+  getNextToken();
+  return 0;
+}
+


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.h	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,70 @@
+/*
+ *  Copyright (c) 2008 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 _OPENSHIVA_METADATA_PARSER_P_H_
+#define _OPENSHIVA_METADATA_PARSER_P_H_
+
+#include <list>
+#include <GTLCore/Token_p.h>
+
+namespace GTLCore {
+  class ErrorMessage;
+  class String;
+  class Token;
+  namespace Metadata {
+    class ParameterEntry;
+    class ValueEntry;
+    class TextEntry;
+    class Group;
+  }
+}
+
+namespace OpenShiva {
+  class KernelMetadata;
+  namespace Metadata {
+    class Lexer;
+    /**
+     * @internal
+     * @ingroup OpenShiva
+     */
+    class Parser {
+      public:
+        Parser( Lexer* _lexer, const GTLCore::String& fileName);
+        ~Parser();
+        KernelMetadata* parse();
+        const std::list<GTLCore::ErrorMessage>& errorMessages() const;
+      private:
+        const GTLCore::Metadata::ValueEntry* parseValueEntry(const GTLCore::String& name);
+        const GTLCore::Metadata::ParameterEntry* parseParameterEntry(const GTLCore::String& name);
+        const GTLCore::Metadata::TextEntry* parseTextEntry(const GTLCore::String& name);
+        const GTLCore::Metadata::Group* parseGroup(const GTLCore::String& name, bool _parameter);
+      private:
+        void getNextToken();
+        const GTLCore::Token& currentToken();
+        void reportError( const GTLCore::String& errMsg, const GTLCore::Token& token );
+        void reportUnexpected( const GTLCore::Token& token );
+        bool isOfType( const GTLCore::Token& , GTLCore::Token::Type type );
+      private:
+        struct Private;
+        Private* const d;
+    };
+  }
+}
+
+#endif


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/MetadataParser_p.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Version.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Version.h	2008-11-27 19:22:37 UTC (rev 505)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Version.h	2008-11-27 19:23:04 UTC (rev 506)
@@ -32,7 +32,7 @@
   /**
    * Give the latest version of the Shiva language supported by this library.
    */
-  int LanguageVersion = 1;
+  int LanguageVersion = 0;
 }
 
 #endif

Modified: trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex
===================================================================
--- trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex	2008-11-27 19:22:37 UTC (rev 505)
+++ trunk/OpenGTL/OpenShiva/doc/specification/ShivaSpec.tex	2008-11-27 19:23:04 UTC (rev 506)
@@ -191,8 +191,8 @@
     info: <
       author: "Joe Doe; Joe Doe Jr";
       vendor: <
-        name: DoeGraphics;
-        address: 1242 Main Street;
+        name: "DoeGraphics";
+        address: "1242 Main Street";
       >
       license: "LGPLv2+";
     >;
@@ -202,10 +202,10 @@
         minValue: 0;
         maxValue: 100;
         defaultValue: 50;
-        description: This is the first parameter;
+        description: "This is the first parameter";
       >;
       categorie2: <
-        description: This is a categorie of parameters
+        description: "This is a categorie of parameters";
         param2: <
           type: curve;
           defaultValue: {{0,0},{1,1}};

Added: trunk/OpenGTL/OpenShiva/tests/library/TestMetadataLexer.h
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/library/TestMetadataLexer.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/library/TestMetadataLexer.h	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,42 @@
+/*
+ *  Copyright (c) 2008 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 "OpenShiva/MetadataLexer_p.h"
+
+class TestMetadataLexer : public GTLTest::Case {
+  public:
+    TestMetadataLexer() : GTLTest::Case("MetadataLexer") {}
+    virtual void runTest()
+    {
+      std::istringstream iss(" < version: 0; info: < \"bouh\"; \"b\\\"o;\" 12.0 >");
+      OpenShiva::Metadata::Lexer lng(&iss);
+      TEST_FOR_TOKEN( INFERIOR );
+      TEST_FOR_TOKEN_AND_VALUE_STRICT( IDENTIFIER, string, "version" );
+      TEST_FOR_TOKEN( COLON );
+      TEST_FOR_TOKEN_AND_VALUE_STRICT( INTEGER_CONSTANT, i, 0);
+      TEST_FOR_TOKEN( SEMI );
+      TEST_FOR_TOKEN_AND_VALUE_STRICT( IDENTIFIER, string, "info" );
+      TEST_FOR_TOKEN( COLON );
+      TEST_FOR_TOKEN( INFERIOR );
+      TEST_FOR_TOKEN_AND_VALUE_STRICT( STRING_CONSTANT, string, "bouh" );
+      TEST_FOR_TOKEN( SEMI );
+      TEST_FOR_TOKEN_AND_VALUE_STRICT( STRING_CONSTANT, string, "b\\\"o;" );
+      TEST_FOR_TOKEN_AND_VALUE( FLOAT_CONSTANT, f, 12.0);
+    }
+};


Property changes on: trunk/OpenGTL/OpenShiva/tests/library/TestMetadataLexer.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/tests/library/TestMetadataParser.h
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/library/TestMetadataParser.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/library/TestMetadataParser.h	2008-11-27 19:23:04 UTC (rev 506)
@@ -0,0 +1,65 @@
+/*
+ *  Copyright (c) 2008 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 "OpenShiva/MetadataParser_p.h"
+#include "OpenShiva/KernelMetadata.h"
+
+#include "GTLCore/ErrorMessage.h"
+
+class TestMetadataParser : public GTLTest::Case {
+  public:
+    TestMetadataParser() : GTLTest::Case("MetadataParser") {}
+    virtual void runTest()
+    {
+      std::istringstream iss(" \
+< \
+  version: 0; \
+  info: < \
+    author: \"Joe Doe; Joe Doe Jr\"; \
+    vendor: < \
+      name: \"DoeGraphics\"; \
+      address: \"1242 Main Street\"; \
+    > \
+    license: \"LGPLv2+\"; \
+  >; \
+  parameters: < \
+    param1: < \
+      type: int; \
+      minValue: 0; \
+      maxValue: 100; \
+      defaultValue: 50; \
+      description: \"This is the first parameter\"; \
+    >; \
+    categorie2: < \
+      description: \"This is a categorie of parameters\"; \
+      param2: < \
+        type: curve; \
+        defaultValue: {{0,0},{1,1}}; \
+      >; \
+    >; \
+  >; \
+>");
+      OpenShiva::Metadata::Lexer* lng = new OpenShiva::Metadata::Lexer(&iss);
+      OpenShiva::Metadata::Parser parser( lng, "");
+      OpenShiva::KernelMetadata* km = parser.parse();
+      GTLTEST_CHECK_EQUAL( parser.errorMessages().size(), 0 );
+      std::cout << parser.errorMessages().begin()->errorMessage() << " " << parser.errorMessages().begin()->line() << std::endl;
+      km->name();
+    }
+};


Property changes on: trunk/OpenGTL/OpenShiva/tests/library/TestMetadataParser.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/OpenGTL/OpenShiva/tests/library/TestOpenShiva.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/library/TestOpenShiva.cpp	2008-11-27 19:22:37 UTC (rev 505)
+++ trunk/OpenGTL/OpenShiva/tests/library/TestOpenShiva.cpp	2008-11-27 19:23:04 UTC (rev 506)
@@ -24,7 +24,11 @@
 using namespace GTLCore;
 
 #include "TestLexer.h"
+#include "TestMetadataLexer.h"
+#include "TestMetadataParser.h"
 
 GTLTEST_MAIN_BEGIN(TestOpenShiva)
 GTLTEST_MAIN_ADD_CASE(TestLexer)
+GTLTEST_MAIN_ADD_CASE(TestMetadataLexer )
+GTLTEST_MAIN_ADD_CASE(TestMetadataParser)
 GTLTEST_MAIN_END()


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