35 static bool eq(
char c1,
char c2)
36 {
return toupper(c1) == toupper(c2); }
38 static bool ne(
char c1,
char c2)
39 {
return toupper(c1) != toupper(c2); }
41 static bool lt(
char c1,
char c2)
42 {
return toupper(c1) < toupper(c2); }
44 static bool gt(
char c1,
char c2)
45 {
return toupper(c1) > toupper(c2); }
47 static int compare(
const char* s1,
const char* s2, std::size_t n)
51 if (
lt(*s1, *s2))
return -1;
52 if (
gt(*s1, *s2))
return 1;
58 static const char*
find(
const char* s,
int n,
char a)
60 while (n-- > 0 && toupper(*s) != toupper(a))
68typedef std::basic_string<char, ci_char_traits>
ci_string;
95 : _lastChar(
' '), _is(is), _line(1), _col(1)
101 while (isspace(_lastChar) && _lastChar !=
'\r' && _lastChar !=
'\n')
106 if (isalpha(_lastChar) || _lastChar ==
'_')
108 _identifier = _lastChar;
109 while (isalnum(_lastChar =
getChar()) || _lastChar ==
'-' || _lastChar ==
'_')
111 _identifier += _lastChar;
114 if (_identifier ==
"set")
116 if (_identifier ==
"function")
118 if (_identifier ==
"macro")
120 if (_identifier ==
"endfunction")
122 if (_identifier ==
"endmacro")
127 if (isdigit(_lastChar))
130 _identifier = _lastChar;
131 while (isalnum(_lastChar =
getChar()) || _lastChar ==
'.' || _lastChar ==
',')
133 _identifier += _lastChar;
138 if (_lastChar ==
'#')
141 if (_lastChar ==
'!')
147 while (_lastChar != EOF && _lastChar !=
'\n' && _lastChar !=
'\r')
149 _identifier += _lastChar;
156 while (_lastChar != EOF && _lastChar !=
'\n' && _lastChar !=
'\r')
162 if (_lastChar ==
'"')
166 while (_lastChar != EOF && _lastChar !=
'"')
168 _identifier += _lastChar;
178 if (_lastChar == EOF)
return TOK_EOF;
181 if (_lastChar ==
'\r' || _lastChar ==
'\n')
183 if (_lastChar ==
'\r') _lastChar =
getChar();
184 if (_lastChar ==
'\n') _lastChar =
getChar();
189 int thisChar = _lastChar;
196 return std::string(_identifier.c_str());
214 void updateLoc(
int c)
216 if (c ==
'\n' || c ==
'\r')
255 _lastToken = _curToken;
291 }
else if(!parseSet())
312 void printError(
const char* str)
314 std::cerr <<
"Error: " << str <<
" (at line " << _lexer.
curLine() <<
", col " << _lexer.
curCol() <<
")";
321 printError(
"Expected '(' after MACRO");
329 printError(
"Expected macro name");
333 _os << macroName <<
'(';
345 printError(
"Missing expected ')'");
361 printError(
"Expected '(' after SET");
369 printError(
"Expected variable name");
373 _os <<
"CMAKE_VARIABLE " << variableName;
385 printError(
"Missing expected ')'");
401 printError(
"Expected '(' after FUNCTION");
409 printError(
"Expected function name");
413 _os << funcName <<
'(';
425 printError(
"Missing expected ')'");
446#define STRINGIFY(a) #a
447#define DOUBLESTRINGIFY(a) STRINGIFY(a)
453 for (
int i = 1; i < argc; ++i)
455 std::ifstream ifs(argv[i]);
456 std::ostream& os = std::cout;
int main(int argc, char **argv)
std::basic_string< char, ci_char_traits > ci_string
#define DOUBLESTRINGIFY(a)
CMakeLexer(std::istream &is)
std::string getIdentifier() const
void handleDoxygenComment()
CMakeParser(std::istream &is, std::ostream &os)
void handleTopLevelExpression()
static bool lt(char c1, char c2)
static bool ne(char c1, char c2)
static const char * find(const char *s, int n, char a)
static bool eq(char c1, char c2)
static int compare(const char *s1, const char *s2, std::size_t n)
static bool gt(char c1, char c2)