HPCW 3.0
Loading...
Searching...
No Matches
CMakeLexer Class Reference

Public Types

enum  Token {
  TOK_EOF = -1 , TOK_EOL = -2 , TOK_MACRO = -3 , TOK_ENDMACRO = -4 ,
  TOK_FUNCTION = -5 , TOK_ENDFUNCTION = -6 , TOK_DOXYGEN_COMMENT = -7 , TOK_SET = -8 ,
  TOK_STRING_LITERAL = -100 , TOK_NUMBER_LITERAL = -102 , TOK_IDENTIFIER = -200
}
 

Public Member Functions

 CMakeLexer (std::istream &is)
 
int getToken ()
 
std::string getIdentifier () const
 
int curLine () const
 
int curCol () const
 
int getChar ()
 

Detailed Description

Definition at line 74 of file CMakeDoxygenFilter.cpp.

Member Enumeration Documentation

◆ Token

Enumerator
TOK_EOF 
TOK_EOL 
TOK_MACRO 
TOK_ENDMACRO 
TOK_FUNCTION 
TOK_ENDFUNCTION 
TOK_DOXYGEN_COMMENT 
TOK_SET 
TOK_STRING_LITERAL 
TOK_NUMBER_LITERAL 
TOK_IDENTIFIER 

Definition at line 78 of file CMakeDoxygenFilter.cpp.

Constructor & Destructor Documentation

◆ CMakeLexer()

CMakeLexer::CMakeLexer ( std::istream & is)
inline

Definition at line 94 of file CMakeDoxygenFilter.cpp.

95 : _lastChar(' '), _is(is), _line(1), _col(1)
96 {}

Member Function Documentation

◆ curCol()

int CMakeLexer::curCol ( ) const
inline

Definition at line 202 of file CMakeDoxygenFilter.cpp.

203 { return _col; }

◆ curLine()

int CMakeLexer::curLine ( ) const
inline

Definition at line 199 of file CMakeDoxygenFilter.cpp.

200 { return _line; }

◆ getChar()

int CMakeLexer::getChar ( )
inline

Definition at line 205 of file CMakeDoxygenFilter.cpp.

206 {
207 int c = _is.get();
208 updateLoc(c);
209 return c;
210 }

◆ getIdentifier()

std::string CMakeLexer::getIdentifier ( ) const
inline

Definition at line 194 of file CMakeDoxygenFilter.cpp.

195 {
196 return std::string(_identifier.c_str());
197 }

◆ getToken()

int CMakeLexer::getToken ( )
inline

Definition at line 98 of file CMakeDoxygenFilter.cpp.

99 {
100 // skip whitespace
101 while (isspace(_lastChar) && _lastChar != '\r' && _lastChar != '\n')
102 {
103 _lastChar = getChar();
104 }
105
106 if (isalpha(_lastChar) || _lastChar == '_')
107 {
108 _identifier = _lastChar;
109 while (isalnum(_lastChar = getChar()) || _lastChar == '-' || _lastChar == '_')
110 {
111 _identifier += _lastChar;
112 }
113
114 if (_identifier == "set")
115 return TOK_SET;
116 if (_identifier == "function")
117 return TOK_FUNCTION;
118 if (_identifier == "macro")
119 return TOK_MACRO;
120 if (_identifier == "endfunction")
121 return TOK_ENDFUNCTION;
122 if (_identifier == "endmacro")
123 return TOK_ENDMACRO;
124 return TOK_IDENTIFIER;
125 }
126
127 if (isdigit(_lastChar))
128 {
129 // very lax!! number detection
130 _identifier = _lastChar;
131 while (isalnum(_lastChar = getChar()) || _lastChar == '.' || _lastChar == ',')
132 {
133 _identifier += _lastChar;
134 }
135 return TOK_NUMBER_LITERAL;
136 }
137
138 if (_lastChar == '#')
139 {
140 _lastChar = getChar();
141 if (_lastChar == '!')
142 {
143 // found a doxygen comment marker
144 _identifier.clear();
145
146 _lastChar = getChar();
147 while (_lastChar != EOF && _lastChar != '\n' && _lastChar != '\r')
148 {
149 _identifier += _lastChar;
150 _lastChar = getChar();
151 }
152 return TOK_DOXYGEN_COMMENT;
153 }
154
155 // skip the comment
156 while (_lastChar != EOF && _lastChar != '\n' && _lastChar != '\r')
157 {
158 _lastChar = getChar();
159 }
160 }
161
162 if (_lastChar == '"')
163 {
164 _lastChar = getChar();
165 _identifier.clear();
166 while (_lastChar != EOF && _lastChar != '"')
167 {
168 _identifier += _lastChar;
169 _lastChar = getChar();
170 }
171
172 // eat the closing "
173 _lastChar = getChar();
174 return TOK_STRING_LITERAL;
175 }
176
177 // don't eat the EOF
178 if (_lastChar == EOF) return TOK_EOF;
179
180 // don't eat the EOL
181 if (_lastChar == '\r' || _lastChar == '\n')
182 {
183 if (_lastChar == '\r') _lastChar = getChar();
184 if (_lastChar == '\n') _lastChar = getChar();
185 return TOK_EOL;
186 }
187
188 // return the character as its ascii value
189 int thisChar = _lastChar;
190 _lastChar = getChar();
191 return thisChar;
192 }

The documentation for this class was generated from the following file: