Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmExprParserHelper.cxx
blob1e8107edeae423ddea11b8b17516b93a7f96a43b
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmExprParserHelper.cxx,v $
5 Language: C++
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()
28 this->FileLine = -1;
29 this->FileName = 0;
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)
46 if ( !str)
48 return 0;
50 //printf("Do some parsing: %s\n", str);
52 this->Verbose = verb;
53 this->InputBuffer = str;
54 this->InputBufferPos = 0;
55 this->CurrentLine = 0;
57 this->Result = 0;
59 yyscan_t yyscanner;
60 cmExpr_yylex_init(&yyscanner);
61 cmExpr_yyset_extra(this, yyscanner);
62 int res = cmExpr_yyparse(yyscanner);
63 cmExpr_yylex_destroy(yyscanner);
64 if ( res != 0 )
66 //str << "CAL_Parser returned: " << res << std::endl;
67 //std::cerr << "When parsing: [" << str << "]" << std::endl;
68 return 0;
71 this->CleanupParser();
73 if ( Verbose )
75 std::cerr << "Expanding [" << str << "] produced: ["
76 << this->Result << "]" << std::endl;
78 return 1;
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;
90 if ( maxlen < 1 )
92 return 0;
94 if ( this->InputBufferPos < this->InputBuffer.size() )
96 buf[0] = this->InputBuffer[ this->InputBufferPos++ ];
97 if ( buf[0] == '\n' )
99 this->CurrentLine ++;
101 return(1);
103 else
105 buf[0] = '\n';
106 return( 0 );
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;