/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This file contains the implementation of the CRendererLexer class.  //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
#include <memory>
#include "tokens.hpp"
#include "CRendererLexer.hpp"
#include "CRegExMatcher.hpp"
using std::auto_ptr;




/////////////////////////////////////////////////////////////////////////
//                                                                     //
// Class    : CRendererLexer                                           //
//                                                                     //
// Function : CRendererLexer (constructor)                             //
//                                                                     //
// Comments : This constructor sets the necessary information that the //
//            specific CRendererLexer gives to the base class to work. //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
CRendererLexer::CRendererLexer(ILexerStream *pStream)
  : CLexer(pStream)
{
  // Character to ignore and that acts as separators
  addToIgnoreChar(' ');
  addToIgnoreChar('\t');
  addToIgnoreChar('\n');
  addToIgnoreChar('\r');
  addSeparatorChar(' ');
  addSeparatorChar('\t');
  addSeparatorChar('\n');
  addSeparatorChar('\r');


  // Token definitions
  ADD_STRING_TOKEN(TOKEN_GENERAL               , "General");
  ADD_STRING_TOKEN(TOKEN_GENERAL               , "Stereogram");
  ADD_STRING_TOKEN(TOKEN_GENERAL               , "Shader");

  ADD_STRING_TOKEN(TOKEN_SMALLREAL             , "SmallReal");
  ADD_STRING_TOKEN(TOKEN_WIDTH                 , "Width");
  ADD_STRING_TOKEN(TOKEN_HEIGHT                , "Height");
  ADD_STRING_TOKEN(TOKEN_BACKCOLOR             , "BackColor");
  ADD_STRING_TOKEN(TOKEN_CAMERAPOS             , "CameraPos");
  ADD_STRING_TOKEN(TOKEN_CAMERATARGET          , "CameraTarget");
  ADD_STRING_TOKEN(TOKEN_UPVECTOR              , "UpVector");
  ADD_STRING_TOKEN(TOKEN_FOCALE                , "Focale");
  ADD_STRING_TOKEN(TOKEN_FSTOP                 , "Fstop");
  ADD_STRING_TOKEN(TOKEN_DIMFILM               , "DimFilm");
  ADD_STRING_TOKEN(TOKEN_GENREFRINDEX          , "GenRefrIndex");
  ADD_STRING_TOKEN(TOKEN_MAX_LEVEL             , "MaxLevel");
  ADD_STRING_TOKEN(TOKEN_MIN_ENERGY            , "MinEnergy");

  ADD_STRING_TOKEN(TOKEN_NEW                   , "new");
  ADD_STRING_TOKEN(TOKEN_SPHERE                , "Sphere");
  ADD_STRING_TOKEN(TOKEN_PLANE                 , "Plane");
  ADD_STRING_TOKEN(TOKEN_TRIANGLE              , "Triangle");
  ADD_STRING_TOKEN(TOKEN_QUADRIC               , "Quadric");
  ADD_STRING_TOKEN(TOKEN_UNION                 , "Union");
  ADD_STRING_TOKEN(TOKEN_DIFFERENCE            , "Difference");
  ADD_STRING_TOKEN(TOKEN_INTERSECTION          , "Intersection");

  ADD_STRING_TOKEN(TOKEN_TRANSLATE             , "Translate");
  ADD_STRING_TOKEN(TOKEN_SCALE                 , "Scale");
  ADD_STRING_TOKEN(TOKEN_ROTATE                , "Rotate");

  ADD_STRING_TOKEN(TOKEN_SURFACECOLOR          , "SurfaceColor");
  ADD_STRING_TOKEN(TOKEN_AMBIENTCOEF           , "AmbientCoef");
  ADD_STRING_TOKEN(TOKEN_DIFFUSECOEF           , "DiffuseCoef");
  ADD_STRING_TOKEN(TOKEN_SPECULARCOEF          , "SpecularCoef");
  ADD_STRING_TOKEN(TOKEN_SHININESSCOEF         , "ShininessCoef");
  ADD_STRING_TOKEN(TOKEN_REFLEXIONCOEF         , "ReflexionCoef");
  ADD_STRING_TOKEN(TOKEN_REFRACTIONCOEF        , "RefractionCoef");
  ADD_STRING_TOKEN(TOKEN_NEARCLIPPLANE         , "NearClipPlane");
  ADD_STRING_TOKEN(TOKEN_FARCLIPPLANE          , "FarClipPlane");
  ADD_STRING_TOKEN(TOKEN_REFRACTIONINDEX       , "RefractionIndex");

  ADD_STRING_TOKEN(TOKEN_PRECISIONU            , "PrecisionU");
  ADD_STRING_TOKEN(TOKEN_PRECISIONV            , "PrecisionV");
  ADD_STRING_TOKEN(TOKEN_CENTER                , "Center");
  ADD_STRING_TOKEN(TOKEN_RADIUS                , "Radius");
  ADD_STRING_TOKEN(TOKEN_NORMAL                , "Normal");
  ADD_STRING_TOKEN(TOKEN_CONSTANT              , "Constant");
  ADD_STRING_TOKEN(TOKEN_SIZE                  , "Size");
  ADD_STRING_TOKEN(TOKEN_QUADRATIC             , "Quadratic");
  ADD_STRING_TOKEN(TOKEN_LINEAR                , "Linear");
  ADD_STRING_TOKEN(TOKEN_MIX                   , "Mix");
  ADD_STRING_TOKEN(TOKEN_VERTEX0               , "Vertex0");
  ADD_STRING_TOKEN(TOKEN_VERTEX1               , "Vertex1");
  ADD_STRING_TOKEN(TOKEN_VERTEX2               , "Vertex2");

  ADD_STRING_TOKEN(TOKEN_INSTANCE              , "Instance");

  ADD_STRING_TOKEN(TOKEN_POSITION              , "Position");
  ADD_STRING_TOKEN(TOKEN_LIGHTCOLOR            , "LightColor");
  ADD_STRING_TOKEN(TOKEN_INTENSITY             , "Intensity");

  ADD_STRING_TOKEN(TOKEN_LIGHT                 , "Light");

  ADD_STRING_TOKEN(TOKEN_MODE_RAYTRACE         , "ModeRaytrace");
  ADD_STRING_TOKEN(TOKEN_MODE_OPENGL           , "ModeOpenGL");
  ADD_STRING_TOKEN(TOKEN_MODE_DEPTH            , "ModeDepth");
  ADD_STRING_TOKEN(TOKEN_MODE_STEREOGRAM       , "ModeStereogram");
  ADD_STRING_TOKEN(TOKEN_MODE_SHADERRENDER     , "ModeShaderRender");
  ADD_STRING_TOKEN(TOKEN_MODE_SHADERTEXT       , "ModeShaderText");

  ADD_STRING_TOKEN(TOKEN_PATTERN_FILE          , "PatternFile");
  ADD_STRING_TOKEN(TOKEN_RANDOM_PATTERN_WIDTH  , "RandomPatternWidth")
  ADD_STRING_TOKEN(TOKEN_RANDOM_PATTERN_HEIGHT , "RandomPatternHeight")
  ADD_STRING_TOKEN(TOKEN_NEAREST_DEPTH         , "NearestDepth");
  ADD_STRING_TOKEN(TOKEN_FARTHEST_DEPTH        , "FarthestDepth");
  ADD_STRING_TOKEN(TOKEN_NEAREST_MAPS_TO       , "NearestMapsTo");
  ADD_STRING_TOKEN(TOKEN_FARTHEST_MAPS_TO      , "FarthestMapsTo");

  ADD_STRING_TOKEN(TOKEN_REFLECTION_ENABLED    , "ReflectionEnabled");
  ADD_STRING_TOKEN(TOKEN_REFRACTION_ENABLED    , "RefractionEnabled");
  ADD_STRING_TOKEN(TOKEN_RAY_OFFSET            , "RayOffset");
  ADD_STRING_TOKEN(TOKEN_SHADOW_TYPE           , "ShadowType");



  auto_ptr<ITokenMatcher> pTokenMatcher;

  pTokenMatcher.reset(new CRegExMatcher(TOKEN_INTEGER, "-?[0-9]+"));
  addMatcher(pTokenMatcher.get());
  pTokenMatcher.release();
  addTokenDescription(TOKEN_INTEGER, "TOKEN_INTEGER");

  pTokenMatcher.reset(new CRegExMatcher(TOKEN_REAL, "-?[0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?"));
  addMatcher(pTokenMatcher.get());
  pTokenMatcher.release();
  addTokenDescription(TOKEN_REAL, "TOKEN_REAL");

  pTokenMatcher.reset(new CMatcher(TOKEN_NAME));
  addMatcher(pTokenMatcher.get());
  pTokenMatcher.release();
  addTokenDescription(TOKEN_NAME, "TOKEN_NAME");
}
