Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmGeneratorExpressionLexer.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2012 Stephen Kelly <steveire@gmail.com>
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmGeneratorExpressionLexer.h"
13
14
15 //----------------------------------------------------------------------------
16 cmGeneratorExpressionLexer::cmGeneratorExpressionLexer()
17   : SawBeginExpression(false), SawGeneratorExpression(false)
18 {
19
20 }
21
22 //----------------------------------------------------------------------------
23 static void InsertText(const char *upto, const char *c,
24                         std::vector<cmGeneratorExpressionToken> &result)
25 {
26   if (upto != c)
27     {
28     result.push_back(cmGeneratorExpressionToken(
29                           cmGeneratorExpressionToken::Text, upto, c - upto));
30     }
31 }
32
33 //----------------------------------------------------------------------------
34 std::vector<cmGeneratorExpressionToken>
35 cmGeneratorExpressionLexer::Tokenize(const char *input)
36 {
37   std::vector<cmGeneratorExpressionToken> result;
38   if (!input)
39     return result;
40
41   const char *c = input;
42   const char *upto = c;
43
44   for ( ; *c; ++c)
45   {
46   if(c[0] == '$' && c[1] == '<')
47     {
48     InsertText(upto, c, result);
49     upto = c;
50     result.push_back(cmGeneratorExpressionToken(
51                       cmGeneratorExpressionToken::BeginExpression, upto, 2));
52     upto = c + 2;
53     ++c;
54     SawBeginExpression = true;
55     }
56   else if(c[0] == '>')
57     {
58     InsertText(upto, c, result);
59     upto = c;
60     result.push_back(cmGeneratorExpressionToken(
61                         cmGeneratorExpressionToken::EndExpression, upto, 1));
62     upto = c + 1;
63     SawGeneratorExpression = SawBeginExpression;
64     }
65   else if(c[0] == ':')
66     {
67     InsertText(upto, c, result);
68     upto = c;
69     result.push_back(cmGeneratorExpressionToken(
70                         cmGeneratorExpressionToken::ColonSeparator, upto, 1));
71     upto = c + 1;
72     }
73   else if(c[0] == ',')
74     {
75     InsertText(upto, c, result);
76     upto = c;
77     result.push_back(cmGeneratorExpressionToken(
78                         cmGeneratorExpressionToken::CommaSeparator, upto, 1));
79     upto = c + 1;
80     }
81   }
82   InsertText(upto, c, result);
83
84   return result;
85 }