MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / next

Method next

app/src/DataModel/Importers/ProtoImporter.cpp:178–241  ·  view source on GitHub ↗

* @brief Returns the next token from the source buffer, or Eof on end of input. */

Source from the content-addressed store, hash-verified

176 * @brief Returns the next token from the source buffer, or Eof on end of input.
177 */
178Token Lexer::next()
179{
180 skipWsAndComments();
181
182 if (m_pos >= m_src.size())
183 return {Tok::Eof, QString(), m_line};
184
185 const QChar c = m_src[m_pos];
186 const int line = m_line;
187 const int start = m_pos;
188
189 if (c.isLetter() || c == QLatin1Char('_')) {
190 while (m_pos < m_src.size()
191 && (m_src[m_pos].isLetterOrNumber() || m_src[m_pos] == QLatin1Char('_')))
192 ++m_pos;
193 return {Tok::Ident, m_src.mid(start, m_pos - start), line};
194 }
195
196 if (c.isDigit()) {
197 while (m_pos < m_src.size()
198 && (m_src[m_pos].isLetterOrNumber() || m_src[m_pos] == QLatin1Char('.')
199 || m_src[m_pos] == QLatin1Char('+') || m_src[m_pos] == QLatin1Char('-')))
200 ++m_pos;
201 return {Tok::IntLit, m_src.mid(start, m_pos - start), line};
202 }
203
204 if (c == QLatin1Char('"') || c == QLatin1Char('\''))
205 return lexStringLiteral(c, line);
206
207 ++m_pos;
208 switch (c.unicode()) {
209 case '{':
210 return {Tok::LBrace, QStringLiteral("{"), line};
211 case '}':
212 return {Tok::RBrace, QStringLiteral("}"), line};
213 case '[':
214 return {Tok::LBracket, QStringLiteral("["), line};
215 case ']':
216 return {Tok::RBracket, QStringLiteral("]"), line};
217 case '(':
218 return {Tok::LParen, QStringLiteral("("), line};
219 case ')':
220 return {Tok::RParen, QStringLiteral(")"), line};
221 case '<':
222 return {Tok::LAngle, QStringLiteral("<"), line};
223 case '>':
224 return {Tok::RAngle, QStringLiteral(">"), line};
225 case '=':
226 return {Tok::Eq, QStringLiteral("="), line};
227 case ',':
228 return {Tok::Comma, QStringLiteral(","), line};
229 case ';':
230 return {Tok::Semi, QStringLiteral(";"), line};
231 case '.':
232 return {Tok::Dot, QStringLiteral("."), line};
233 case '/':
234 return {Tok::Slash, QStringLiteral("/"), line};
235 case '-':

Callers 15

extractMethod · 0.80
highlightBlockMethod · 0.80
highlightByRegexMethod · 0.80
highlightBlockMethod · 0.80
highlightBlockMethod · 0.80
highlightBlockMethod · 0.80
highlightBlockMethod · 0.80
paintEventMethod · 0.80
highlightBlockMethod · 0.80
highlightBlockMethod · 0.80
tokenizeFunction · 0.80
gatherSearchFilesFunction · 0.80

Calls 1

sizeMethod · 0.45

Tested by 1

extractMethod · 0.64