Пример #1
0
ListConfigValue* ConfigMapParser::list() throw(PARSEEXCEPTION_THROW)
{
  expect(T::CMT_ABL);
  ListConfigValue* lcv = new ListConfigValue();
  std::string* currComments = 0;
  try
  {
    if(token.type == T::CMT_COMMENT)
      currComments = comments();
    if(prefixValue(token))
    {
      ConfigValue* cv = value();
      if(currComments)
      {
        cv->setComment(*currComments);
        delete currComments;
        currComments = 0;
      }
      lcv->append(*cv);
      delete cv;
      while(token.type == T::CMT_COMMA)
      {
        nextToken();
        if(token.type == T::CMT_COMMENT)
          currComments = comments();
        if(prefixValue(token))
        {
          ConfigValue* cv = value();
          if(currComments)
          {
            cv->setComment(*currComments);
            delete currComments;
            currComments = 0;
          }
          lcv->append(*cv);
          delete cv;
        }
        else
          break;
      }
    }
    expect(T::CMT_ABR);
  }
  catch(ParseException)
  {
    if(currComments)
      delete currComments;
    delete lcv;
    throw;
  }
  return lcv;
}
Пример #2
0
ConfigMap* ConfigMapParser::map() throw(PARSEEXCEPTION_THROW)
{
  expect(T::CMT_CBL);
  ConfigMap* cm = new ConfigMap();
  std::string* currComments = 0;
  if(token.type == T::CMT_COMMENT)
    currComments = comments();
  try
  {
    while(token.type == T::CMT_KEY)
    {
      std::string key = token.value;
      nextToken();
      try
      {
        expect(T::CMT_EQ);
        if(prefixValue(token))
        {
          ConfigValue* cv = value();
          if(currComments)
            cv->setComment(*currComments);
          try
          {
            (*cm)[key] = *cv;
          }
          catch(invalid_key& ik)
          {
            P_ERROR(ik.what());
          }
          delete cv;
        }
        else
        {
          P_ERROR("Expected begin of a value (`{`, `[` or VALUE), got `" + T::type2str(token.type) + "`");
        }
      }
      catch(ParseException)
      {
        if(currComments) delete currComments;
        throw;
      }
      expect(T::CMT_SEMICOLON);
    }
    expect(T::CMT_CBR);

    if(currComments)
      delete currComments;
    currComments = 0;
    if(token.type == T::CMT_COMMENT)
      currComments = comments();
  }
  catch(ParseException)
  {
    delete cm;
    if(currComments) delete currComments;
    throw;
  }
  if(currComments) delete currComments;
  return cm;
}
Пример #3
0
int ConfigMapParser::file(ConfigMap* configMap) throw(PARSEEXCEPTION_THROW)
{
  size_t size = configMap->length();
  std::string* currComments = 0;
  if(token.type == T::CMT_COMMENT)
    currComments = comments();
  while(token.type == T::CMT_KEY)
  {
    size_t keyLine = token.line;
    size_t keyColumn = token.column;
    std::string key = token.value;
    nextToken();
    try
    {
      expect(T::CMT_EQ);
      if(prefixValue(token))
      {
        ConfigValue* cv = value();
        if(currComments)
          cv->setComment(*currComments);
        try
        {
          (*configMap)[key] = *cv;
        }
        catch(invalid_key& ik)
        {
          std::cout<<"[EXCEPTION ERROR ] ConfigMapParser.cpp 1"<<std::endl;
          throw ParseException(keyLine, keyColumn, ik.what());
        }
        delete cv;
      }
      else
      {
        P_ERROR("Expected begin of a value (`{`, `[` or VALUE), got `" + T::type2str(token.type) + "`");
      }
    }
    catch(ParseException)
    {
      if(currComments) delete currComments;
      throw;
    }
    expect(T::CMT_SEMICOLON);

    if(currComments)
      delete currComments;
    currComments = 0;
    if(token.type == T::CMT_COMMENT)
      currComments = comments();
  }
  expect(T::CMT_EOF);
  if(currComments) delete currComments;
  return configMap->length() - size;
}