2012-09-11 21:53:38 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2012 Stephen Kelly <steveire@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmGeneratorExpressionLexer.h"
|
|
|
|
|
|
|
|
cmGeneratorExpressionLexer::cmGeneratorExpressionLexer()
|
2016-05-16 17:34:04 +03:00
|
|
|
: SawBeginExpression(false)
|
|
|
|
, SawGeneratorExpression(false)
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void InsertText(const char* upto, const char* c,
|
|
|
|
std::vector<cmGeneratorExpressionToken>& result)
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (upto != c) {
|
2012-09-11 21:53:38 +04:00
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpressionToken::Text, upto, c - upto));
|
|
|
|
}
|
2012-09-11 21:53:38 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<cmGeneratorExpressionToken> cmGeneratorExpressionLexer::Tokenize(
|
|
|
|
const std::string& input)
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
|
|
|
std::vector<cmGeneratorExpressionToken> result;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* c = input.c_str();
|
|
|
|
const char* upto = c;
|
2012-09-11 21:53:38 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (; *c; ++c) {
|
|
|
|
switch (*c) {
|
2014-02-08 21:01:30 +04:00
|
|
|
case '$':
|
2016-05-16 17:34:04 +03:00
|
|
|
if (c[1] == '<') {
|
2014-02-08 21:01:30 +04:00
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpressionToken::BeginExpression, c, 2));
|
2014-02-08 21:01:30 +04:00
|
|
|
upto = c + 2;
|
|
|
|
++c;
|
|
|
|
SawBeginExpression = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-08 21:01:30 +04:00
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpressionToken::EndExpression, c, 1));
|
2014-02-08 21:01:30 +04:00
|
|
|
upto = c + 1;
|
|
|
|
SawGeneratorExpression = SawBeginExpression;
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpressionToken::ColonSeparator, c, 1));
|
2014-02-08 21:01:30 +04:00
|
|
|
upto = c + 1;
|
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpressionToken::CommaSeparator, c, 1));
|
2014-02-08 21:01:30 +04:00
|
|
|
upto = c + 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-11 21:53:38 +04:00
|
|
|
}
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|