Example #1
0
  bool parseFunction()
  {
    if (nextToken() != '(')
    {
      printError("Expected '(' after FUNCTION");
      return false;
    }

    nextToken();
    std::string funcName = _lexer.getIdentifier();
    if (curToken() != CMakeLexer::TOK_IDENTIFIER || funcName.empty())
    {
      printError("Expected function name");
      return false;
    }

    _os << funcName << '(';
    if (nextToken() == CMakeLexer::TOK_IDENTIFIER)
    {
      _os << _lexer.getIdentifier();
      while (nextToken() == CMakeLexer::TOK_IDENTIFIER)
      {
        _os << ", " << _lexer.getIdentifier();
      }
    }

    if (curToken() != ')')
    {
      printError("Missing expected ')'");
    }
    else
    {
      _os << ");";
    }

    // eat the ')'
    nextToken();

    return true;
  }
Example #2
0
  bool parseMacro()
  {
    if (nextToken() != '(')
    {
      printError("Expected '(' after MACRO");
      return false;
    }

    nextToken();
    std::string macroName = _lexer.getIdentifier();
    if (curToken() != CMakeLexer::TOK_IDENTIFIER || macroName.empty())
    {
      printError("Expected macro name");
      return false;
    }

    _os << macroName << '(';
    if (nextToken() == CMakeLexer::TOK_IDENTIFIER)
    {
      _os << _lexer.getIdentifier();
      while (nextToken() == CMakeLexer::TOK_IDENTIFIER)
      {
        _os << ", " << _lexer.getIdentifier();
      }
    }

    if (curToken() != ')')
    {
      printError("Missing expected ')'");
    }
    else
    {
      _os << ");";
    }

    // eat the ')'
    nextToken();
    return true;
  }
  bool parseSet()
  {
    if (nextToken() != '(')
    {
      printError("Expected '(' after SET");
      return false;
    }

    nextToken();
    std::string variableName = _lexer.getIdentifier();
    if (curToken() != CMakeLexer::TOK_IDENTIFIER || variableName.empty())
    {
      printError("Expected variable name");
      return false;
    }

    _os << "CMAKE_VARIABLE " << variableName;

    nextToken();
    while ((curToken() == CMakeLexer::TOK_IDENTIFIER)
           || (curToken() == CMakeLexer::TOK_STRING_LITERAL)
           || (curToken() == CMakeLexer::TOK_NUMBER_LITERAL))
    {
      nextToken();
    }

    if (curToken() != ')')
    {
      printError("Missing expected ')'");
    }
    else
    {
      _os << ";";
    }

    // eat the ')'
    nextToken();
    return true;
  }