// __author__ = Juan Carlos De Abreu (jcabreur@gmail.com)

#include "SceneDriver.h"
#include "scene.parser.hh"
#include "../Base/LogManagement.h"
#include "../app.h"

//BEGIN_TEG_NAMESPACE();

// SceneDriver constructor.
SceneDriver::SceneDriver() : trace_scanning(false), trace_parsing(false), bError(false) { }

// SceneDriver destructor.
SceneDriver::~SceneDriver() { }

// Method to parse a file.
void SceneDriver::parse(const std::string &f) {
  file = f;
  scan_begin();
  yy::SceneParser parser(*this);
  parser.set_debug_level(trace_parsing);
  parser.parse();
  scan_end();

  // Eliminar las variables creadas temporales creadas...
  VARS::GetInstance().datas.clear();
  COLLECT_GARBAGE();
}

// Method to report an error in the parsing.
void SceneDriver::error(const yy::location& l, const std::string& m) {
  // Report the error and finish the app.
  PRINT_LOG(TYPE_ERROR,
      "Parser error: %s(%d) : %s\n",
      l.begin.filename->c_str(),
      l.begin.line,
      m.c_str());
  AppWindow::GetInstance().abort(); bError = true;
}

// Method to report a error in the lexical analizer.
void SceneDriver::error(const std::string& m) {
  // Report the error and finish the app.
  PRINT_LOG(TYPE_ERROR, "Lexer error: %s", m.c_str());
  AppWindow::GetInstance().abort(); bError = true;
}

//END_TEG_NAMESPACE();
