1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 "cmExprParserHelper.h"
14 #include "cmSystemTools.h"
15 #include "cmMakefile.h"
17 #include "cmExprLexer.h"
19 int cmExpr_yyparse( yyscan_t yyscanner );
21 cmExprParserHelper::cmExprParserHelper()
28 cmExprParserHelper::~cmExprParserHelper()
30 this->CleanupParser();
33 int cmExprParserHelper::ParseString(const char* str, int verb)
39 //printf("Do some parsing: %s\n", str);
42 this->InputBuffer = str;
43 this->InputBufferPos = 0;
44 this->CurrentLine = 0;
49 cmExpr_yylex_init(&yyscanner);
50 cmExpr_yyset_extra(this, yyscanner);
51 int res = cmExpr_yyparse(yyscanner);
52 cmExpr_yylex_destroy(yyscanner);
55 //str << "CAL_Parser returned: " << res << std::endl;
56 //std::cerr << "When parsing: [" << str << "]" << std::endl;
60 this->CleanupParser();
64 std::cerr << "Expanding [" << str << "] produced: ["
65 << this->Result << "]" << std::endl;
70 void cmExprParserHelper::CleanupParser()
74 int cmExprParserHelper::LexInput(char* buf, int maxlen)
76 //std::cout << "JPLexInput ";
77 //std::cout.write(buf, maxlen);
78 //std::cout << std::endl;
83 if ( this->InputBufferPos < this->InputBuffer.size() )
85 buf[0] = this->InputBuffer[ this->InputBufferPos++ ];
99 void cmExprParserHelper::Error(const char* str)
101 unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
102 cmOStringStream ostr;
103 ostr << str << " (" << pos << ")";
104 this->ErrorString = ostr.str();
107 void cmExprParserHelper::SetResult(int value)
109 this->Result = value;