2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2012-09-11 17:53:38 +00:00
|
|
|
#include "cmGeneratorExpressionLexer.h"
|
|
|
|
|
|
|
|
cmGeneratorExpressionLexer::cmGeneratorExpressionLexer()
|
2016-05-16 14:34:04 +00:00
|
|
|
: SawBeginExpression(false)
|
|
|
|
, SawGeneratorExpression(false)
|
2012-09-11 17:53:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
static void InsertText(const char* upto, const char* c,
|
|
|
|
std::vector<cmGeneratorExpressionToken>& result)
|
2012-09-11 17:53:38 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (upto != c) {
|
2012-09-11 17:53:38 +00:00
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorExpressionToken::Text, upto, c - upto));
|
|
|
|
}
|
2012-09-11 17:53:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<cmGeneratorExpressionToken> cmGeneratorExpressionLexer::Tokenize(
|
|
|
|
const std::string& input)
|
2012-09-11 17:53:38 +00:00
|
|
|
{
|
|
|
|
std::vector<cmGeneratorExpressionToken> result;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* c = input.c_str();
|
|
|
|
const char* upto = c;
|
2012-09-11 17:53:38 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (; *c; ++c) {
|
|
|
|
switch (*c) {
|
2014-02-08 17:01:30 +00:00
|
|
|
case '$':
|
2016-05-16 14:34:04 +00:00
|
|
|
if (c[1] == '<') {
|
2014-02-08 17:01:30 +00:00
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorExpressionToken::BeginExpression, c, 2));
|
2014-02-08 17:01:30 +00:00
|
|
|
upto = c + 2;
|
|
|
|
++c;
|
|
|
|
SawBeginExpression = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-02-08 17:01:30 +00:00
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorExpressionToken::EndExpression, c, 1));
|
2014-02-08 17:01:30 +00:00
|
|
|
upto = c + 1;
|
|
|
|
SawGeneratorExpression = SawBeginExpression;
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorExpressionToken::ColonSeparator, c, 1));
|
2014-02-08 17:01:30 +00:00
|
|
|
upto = c + 1;
|
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
result.push_back(cmGeneratorExpressionToken(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorExpressionToken::CommaSeparator, c, 1));
|
2014-02-08 17:01:30 +00:00
|
|
|
upto = c + 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-09-11 17:53:38 +00:00
|
|
|
}
|
|
|
|
InsertText(upto, c, result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|