1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmExprParserHelper.cxx,v $
6 Date: $Date: 2006-05-11 14:45:28 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmExprParserHelper.h"
19 #include "cmSystemTools.h"
20 #include "cmExprLexer.h"
22 #include "cmMakefile.h"
24 int cmExpr_yyparse( yyscan_t yyscanner
);
26 cmExprParserHelper::cmExprParserHelper()
33 cmExprParserHelper::~cmExprParserHelper()
35 this->CleanupParser();
38 void cmExprParserHelper::SetLineFile(long line
, const char* file
)
40 this->FileLine
= line
;
41 this->FileName
= file
;
44 int cmExprParserHelper::ParseString(const char* str
, int verb
)
50 //printf("Do some parsing: %s\n", str);
53 this->InputBuffer
= str
;
54 this->InputBufferPos
= 0;
55 this->CurrentLine
= 0;
60 cmExpr_yylex_init(&yyscanner
);
61 cmExpr_yyset_extra(this, yyscanner
);
62 int res
= cmExpr_yyparse(yyscanner
);
63 cmExpr_yylex_destroy(yyscanner
);
66 //str << "CAL_Parser returned: " << res << std::endl;
67 //std::cerr << "When parsing: [" << str << "]" << std::endl;
71 this->CleanupParser();
75 std::cerr
<< "Expanding [" << str
<< "] produced: ["
76 << this->Result
<< "]" << std::endl
;
81 void cmExprParserHelper::CleanupParser()
85 int cmExprParserHelper::LexInput(char* buf
, int maxlen
)
87 //std::cout << "JPLexInput ";
88 //std::cout.write(buf, maxlen);
89 //std::cout << std::endl;
94 if ( this->InputBufferPos
< this->InputBuffer
.size() )
96 buf
[0] = this->InputBuffer
[ this->InputBufferPos
++ ];
110 void cmExprParserHelper::Error(const char* str
)
112 unsigned long pos
= static_cast<unsigned long>(this->InputBufferPos
);
113 cmOStringStream ostr
;
114 ostr
<< str
<< " (" << pos
<< ")";
115 this->ErrorString
= ostr
.str();
118 void cmExprParserHelper::SetResult(int value
)
120 this->Result
= value
;