CppLexer.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "CppLexer.h"
  27. #include <AK/HashTable.h>
  28. #include <AK/StdLibExtras.h>
  29. #include <AK/String.h>
  30. #include <ctype.h>
  31. namespace GUI {
  32. CppLexer::CppLexer(const StringView& input)
  33. : m_input(input)
  34. {
  35. }
  36. char CppLexer::peek(size_t offset) const
  37. {
  38. if ((m_index + offset) >= m_input.length())
  39. return 0;
  40. return m_input[m_index + offset];
  41. }
  42. char CppLexer::consume()
  43. {
  44. ASSERT(m_index < m_input.length());
  45. char ch = m_input[m_index++];
  46. m_previous_position = m_position;
  47. if (ch == '\n') {
  48. m_position.line++;
  49. m_position.column = 0;
  50. } else {
  51. m_position.column++;
  52. }
  53. return ch;
  54. }
  55. static bool is_valid_first_character_of_identifier(char ch)
  56. {
  57. return isalpha(ch) || ch == '_' || ch == '$';
  58. }
  59. static bool is_valid_nonfirst_character_of_identifier(char ch)
  60. {
  61. return is_valid_first_character_of_identifier(ch) || isdigit(ch);
  62. }
  63. constexpr const char* s_known_keywords[] = {
  64. "alignas",
  65. "alignof",
  66. "and",
  67. "and_eq",
  68. "asm",
  69. "bitand",
  70. "bitor",
  71. "bool",
  72. "break",
  73. "case",
  74. "catch",
  75. "class",
  76. "compl",
  77. "const",
  78. "const_cast",
  79. "constexpr",
  80. "continue",
  81. "decltype",
  82. "default",
  83. "delete",
  84. "do",
  85. "dynamic_cast",
  86. "else",
  87. "enum",
  88. "explicit",
  89. "export",
  90. "extern",
  91. "false",
  92. "final",
  93. "for",
  94. "friend",
  95. "goto",
  96. "if",
  97. "inline",
  98. "mutable",
  99. "namespace",
  100. "new",
  101. "noexcept",
  102. "not",
  103. "not_eq",
  104. "nullptr",
  105. "operator",
  106. "or",
  107. "or_eq",
  108. "override",
  109. "private",
  110. "protected",
  111. "public",
  112. "register",
  113. "reinterpret_cast",
  114. "return",
  115. "signed",
  116. "sizeof",
  117. "static",
  118. "static_assert",
  119. "static_cast",
  120. "struct",
  121. "switch",
  122. "template",
  123. "this",
  124. "thread_local",
  125. "throw",
  126. "true",
  127. "try",
  128. "typedef",
  129. "typeid",
  130. "typename",
  131. "union",
  132. "using",
  133. "virtual",
  134. "volatile",
  135. "while",
  136. "xor",
  137. "xor_eq"
  138. };
  139. constexpr const char* s_known_types[] = {
  140. "ByteBuffer",
  141. "CircularDeque",
  142. "CircularQueue",
  143. "Deque",
  144. "DoublyLinkedList",
  145. "FileSystemPath",
  146. "Array",
  147. "Function",
  148. "HashMap",
  149. "HashTable",
  150. "IPv4Address",
  151. "InlineLinkedList",
  152. "IntrusiveList",
  153. "JsonArray",
  154. "JsonObject",
  155. "JsonValue",
  156. "MappedFile",
  157. "NetworkOrdered",
  158. "NonnullOwnPtr",
  159. "NonnullOwnPtrVector",
  160. "NonnullRefPtr",
  161. "NonnullRefPtrVector",
  162. "Optional",
  163. "OwnPtr",
  164. "RefPtr",
  165. "Result",
  166. "ScopeGuard",
  167. "SinglyLinkedList",
  168. "String",
  169. "StringBuilder",
  170. "StringImpl",
  171. "StringView",
  172. "Utf8View",
  173. "Vector",
  174. "WeakPtr",
  175. "auto",
  176. "char",
  177. "char16_t",
  178. "char32_t",
  179. "char8_t",
  180. "double",
  181. "float",
  182. "i16",
  183. "i32",
  184. "i64",
  185. "i8",
  186. "int",
  187. "int",
  188. "long",
  189. "short",
  190. "signed",
  191. "u16",
  192. "u32",
  193. "u64",
  194. "u8",
  195. "unsigned",
  196. "void",
  197. "wchar_t"
  198. };
  199. static bool is_keyword(const StringView& string)
  200. {
  201. static HashTable<String> keywords(array_size(s_known_keywords));
  202. if (keywords.is_empty()) {
  203. keywords.set_from(s_known_keywords);
  204. }
  205. return keywords.contains(string);
  206. }
  207. static bool is_known_type(const StringView& string)
  208. {
  209. static HashTable<String> types(array_size(s_known_types));
  210. if (types.is_empty()) {
  211. types.set_from(s_known_types);
  212. }
  213. return types.contains(string);
  214. }
  215. Vector<CppToken> CppLexer::lex()
  216. {
  217. Vector<CppToken> tokens;
  218. size_t token_start_index = 0;
  219. CppPosition token_start_position;
  220. auto emit_token = [&](auto type) {
  221. CppToken token;
  222. token.m_type = type;
  223. token.m_start = m_position;
  224. token.m_end = m_position;
  225. tokens.append(token);
  226. consume();
  227. };
  228. auto begin_token = [&] {
  229. token_start_index = m_index;
  230. token_start_position = m_position;
  231. };
  232. auto commit_token = [&](auto type) {
  233. CppToken token;
  234. token.m_type = type;
  235. token.m_start = token_start_position;
  236. token.m_end = m_previous_position;
  237. tokens.append(token);
  238. };
  239. auto emit_token_equals = [&](auto type, auto equals_type) {
  240. if (peek(1) == '=') {
  241. begin_token();
  242. consume();
  243. consume();
  244. commit_token(equals_type);
  245. return;
  246. }
  247. emit_token(type);
  248. };
  249. auto match_escape_sequence = [&]() -> size_t {
  250. switch (peek(1)) {
  251. case '\'':
  252. case '"':
  253. case '?':
  254. case '\\':
  255. case 'a':
  256. case 'b':
  257. case 'f':
  258. case 'n':
  259. case 'r':
  260. case 't':
  261. case 'v':
  262. return 2;
  263. case '0':
  264. case '1':
  265. case '2':
  266. case '3':
  267. case '4':
  268. case '5':
  269. case '6':
  270. case '7': {
  271. size_t octal_digits = 1;
  272. for (size_t i = 0; i < 2; ++i) {
  273. char next = peek(2 + i);
  274. if (next < '0' || next > '7')
  275. break;
  276. ++octal_digits;
  277. }
  278. return 1 + octal_digits;
  279. }
  280. case 'x': {
  281. size_t hex_digits = 0;
  282. while (isxdigit(peek(2 + hex_digits)))
  283. ++hex_digits;
  284. return 2 + hex_digits;
  285. }
  286. case 'u':
  287. case 'U': {
  288. bool is_unicode = true;
  289. size_t number_of_digits = peek(1) == 'u' ? 4 : 8;
  290. for (size_t i = 0; i < number_of_digits; ++i) {
  291. if (!isxdigit(peek(2 + i))) {
  292. is_unicode = false;
  293. break;
  294. }
  295. }
  296. return is_unicode ? 2 + number_of_digits : 0;
  297. }
  298. default:
  299. return 0;
  300. }
  301. };
  302. auto match_string_prefix = [&](char quote) -> size_t {
  303. if (peek() == quote)
  304. return 1;
  305. if (peek() == 'L' && peek(1) == quote)
  306. return 2;
  307. if (peek() == 'u') {
  308. if (peek(1) == quote)
  309. return 2;
  310. if (peek(1) == '8' && peek(2) == quote)
  311. return 3;
  312. }
  313. if (peek() == 'U' && peek(1) == quote)
  314. return 2;
  315. return 0;
  316. };
  317. while (m_index < m_input.length()) {
  318. auto ch = peek();
  319. if (isspace(ch)) {
  320. begin_token();
  321. while (isspace(peek()))
  322. consume();
  323. commit_token(CppToken::Type::Whitespace);
  324. continue;
  325. }
  326. if (ch == '(') {
  327. emit_token(CppToken::Type::LeftParen);
  328. continue;
  329. }
  330. if (ch == ')') {
  331. emit_token(CppToken::Type::RightParen);
  332. continue;
  333. }
  334. if (ch == '{') {
  335. emit_token(CppToken::Type::LeftCurly);
  336. continue;
  337. }
  338. if (ch == '}') {
  339. emit_token(CppToken::Type::RightCurly);
  340. continue;
  341. }
  342. if (ch == '[') {
  343. emit_token(CppToken::Type::LeftBracket);
  344. continue;
  345. }
  346. if (ch == ']') {
  347. emit_token(CppToken::Type::RightBracket);
  348. continue;
  349. }
  350. if (ch == '<') {
  351. begin_token();
  352. consume();
  353. if (peek() == '<') {
  354. consume();
  355. if (peek() == '=') {
  356. consume();
  357. commit_token(CppToken::Type::LessLessEquals);
  358. continue;
  359. }
  360. commit_token(CppToken::Type::LessLess);
  361. continue;
  362. }
  363. if (peek() == '=') {
  364. consume();
  365. commit_token(CppToken::Type::LessEquals);
  366. continue;
  367. }
  368. if (peek() == '>') {
  369. consume();
  370. commit_token(CppToken::Type::LessGreater);
  371. continue;
  372. }
  373. commit_token(CppToken::Type::Less);
  374. continue;
  375. }
  376. if (ch == '>') {
  377. begin_token();
  378. consume();
  379. if (peek() == '>') {
  380. consume();
  381. if (peek() == '=') {
  382. consume();
  383. commit_token(CppToken::Type::GreaterGreaterEquals);
  384. continue;
  385. }
  386. commit_token(CppToken::Type::GreaterGreater);
  387. continue;
  388. }
  389. if (peek() == '=') {
  390. consume();
  391. commit_token(CppToken::Type::GreaterEquals);
  392. continue;
  393. }
  394. commit_token(CppToken::Type::Greater);
  395. continue;
  396. }
  397. if (ch == ',') {
  398. emit_token(CppToken::Type::Comma);
  399. continue;
  400. }
  401. if (ch == '+') {
  402. begin_token();
  403. consume();
  404. if (peek() == '+') {
  405. consume();
  406. commit_token(CppToken::Type::PlusPlus);
  407. continue;
  408. }
  409. if (peek() == '=') {
  410. consume();
  411. commit_token(CppToken::Type::PlusEquals);
  412. continue;
  413. }
  414. commit_token(CppToken::Type::Plus);
  415. continue;
  416. }
  417. if (ch == '-') {
  418. begin_token();
  419. consume();
  420. if (peek() == '-') {
  421. consume();
  422. commit_token(CppToken::Type::MinusMinus);
  423. continue;
  424. }
  425. if (peek() == '=') {
  426. consume();
  427. commit_token(CppToken::Type::MinusEquals);
  428. continue;
  429. }
  430. if (peek() == '>') {
  431. consume();
  432. if (peek() == '*') {
  433. consume();
  434. commit_token(CppToken::Type::ArrowAsterisk);
  435. continue;
  436. }
  437. commit_token(CppToken::Type::Arrow);
  438. continue;
  439. }
  440. commit_token(CppToken::Type::Minus);
  441. continue;
  442. }
  443. if (ch == '*') {
  444. emit_token_equals(CppToken::Type::Asterisk, CppToken::Type::AsteriskEquals);
  445. continue;
  446. }
  447. if (ch == '%') {
  448. emit_token_equals(CppToken::Type::Percent, CppToken::Type::PercentEquals);
  449. continue;
  450. }
  451. if (ch == '^') {
  452. emit_token_equals(CppToken::Type::Caret, CppToken::Type::CaretEquals);
  453. continue;
  454. }
  455. if (ch == '!') {
  456. emit_token_equals(CppToken::Type::ExclamationMark, CppToken::Type::ExclamationMarkEquals);
  457. continue;
  458. }
  459. if (ch == '=') {
  460. emit_token_equals(CppToken::Type::Equals, CppToken::Type::EqualsEquals);
  461. continue;
  462. }
  463. if (ch == '&') {
  464. begin_token();
  465. consume();
  466. if (peek() == '&') {
  467. consume();
  468. commit_token(CppToken::Type::AndAnd);
  469. continue;
  470. }
  471. if (peek() == '=') {
  472. consume();
  473. commit_token(CppToken::Type::AndEquals);
  474. continue;
  475. }
  476. commit_token(CppToken::Type::And);
  477. continue;
  478. }
  479. if (ch == '|') {
  480. begin_token();
  481. consume();
  482. if (peek() == '|') {
  483. consume();
  484. commit_token(CppToken::Type::PipePipe);
  485. continue;
  486. }
  487. if (peek() == '=') {
  488. consume();
  489. commit_token(CppToken::Type::PipeEquals);
  490. continue;
  491. }
  492. commit_token(CppToken::Type::Pipe);
  493. continue;
  494. }
  495. if (ch == '~') {
  496. emit_token(CppToken::Type::Tilde);
  497. continue;
  498. }
  499. if (ch == '?') {
  500. emit_token(CppToken::Type::QuestionMark);
  501. continue;
  502. }
  503. if (ch == ':') {
  504. begin_token();
  505. consume();
  506. if (peek() == ':') {
  507. consume();
  508. if (peek() == '*') {
  509. consume();
  510. commit_token(CppToken::Type::ColonColonAsterisk);
  511. continue;
  512. }
  513. commit_token(CppToken::Type::ColonColon);
  514. continue;
  515. }
  516. commit_token(CppToken::Type::Colon);
  517. continue;
  518. }
  519. if (ch == ';') {
  520. emit_token(CppToken::Type::Semicolon);
  521. continue;
  522. }
  523. if (ch == '.') {
  524. begin_token();
  525. consume();
  526. if (peek() == '*') {
  527. consume();
  528. commit_token(CppToken::Type::DotAsterisk);
  529. continue;
  530. }
  531. commit_token(CppToken::Type::Dot);
  532. continue;
  533. }
  534. if (ch == '#') {
  535. begin_token();
  536. consume();
  537. if (is_valid_first_character_of_identifier(peek()))
  538. while (peek() && is_valid_nonfirst_character_of_identifier(peek()))
  539. consume();
  540. auto directive = StringView(m_input.characters_without_null_termination() + token_start_index, m_index - token_start_index);
  541. if (directive == "#include") {
  542. commit_token(CppToken::Type::IncludeStatement);
  543. begin_token();
  544. while (isspace(peek()))
  545. consume();
  546. commit_token(CppToken::Type::Whitespace);
  547. begin_token();
  548. if (peek() == '<' || peek() == '"') {
  549. char closing = consume() == '<' ? '>' : '"';
  550. while (peek() && peek() != closing && peek() != '\n')
  551. consume();
  552. if (peek() && consume() == '\n') {
  553. commit_token(CppToken::Type::IncludePath);
  554. continue;
  555. }
  556. commit_token(CppToken::Type::IncludePath);
  557. begin_token();
  558. }
  559. }
  560. while (peek() && peek() != '\n')
  561. consume();
  562. commit_token(CppToken::Type::PreprocessorStatement);
  563. continue;
  564. }
  565. if (ch == '/' && peek(1) == '/') {
  566. begin_token();
  567. while (peek() && peek() != '\n')
  568. consume();
  569. commit_token(CppToken::Type::Comment);
  570. continue;
  571. }
  572. if (ch == '/' && peek(1) == '*') {
  573. begin_token();
  574. consume();
  575. consume();
  576. bool comment_block_ends = false;
  577. while (peek()) {
  578. if (peek() == '*' && peek(1) == '/') {
  579. comment_block_ends = true;
  580. break;
  581. }
  582. consume();
  583. }
  584. if (comment_block_ends) {
  585. consume();
  586. consume();
  587. }
  588. commit_token(CppToken::Type::Comment);
  589. continue;
  590. }
  591. if (ch == '/') {
  592. emit_token_equals(CppToken::Type::Slash, CppToken::Type::SlashEquals);
  593. continue;
  594. }
  595. if (size_t prefix = match_string_prefix('"'); prefix > 0) {
  596. begin_token();
  597. for (size_t i = 0; i < prefix; ++i)
  598. consume();
  599. while (peek()) {
  600. if (peek() == '\\') {
  601. if (size_t escape = match_escape_sequence(); escape > 0) {
  602. commit_token(CppToken::Type::DoubleQuotedString);
  603. begin_token();
  604. for (size_t i = 0; i < escape; ++i)
  605. consume();
  606. commit_token(CppToken::Type::EscapeSequence);
  607. begin_token();
  608. continue;
  609. }
  610. }
  611. if (consume() == '"')
  612. break;
  613. }
  614. commit_token(CppToken::Type::DoubleQuotedString);
  615. continue;
  616. }
  617. if (size_t prefix = match_string_prefix('R'); prefix > 0 && peek(prefix) == '"') {
  618. begin_token();
  619. for (size_t i = 0; i < prefix + 1; ++i)
  620. consume();
  621. size_t prefix_start = m_index;
  622. while (peek() && peek() != '(')
  623. consume();
  624. StringView prefix_string = m_input.substring_view(prefix_start, m_index - prefix_start);
  625. while (peek()) {
  626. if (consume() == '"') {
  627. ASSERT(m_index >= prefix_string.length() + 2);
  628. ASSERT(m_input[m_index - 1] == '"');
  629. if (m_input[m_index - 1 - prefix_string.length() - 1] == ')') {
  630. StringView suffix_string = m_input.substring_view(m_index - 1 - prefix_string.length(), prefix_string.length());
  631. if (prefix_string == suffix_string)
  632. break;
  633. }
  634. }
  635. }
  636. commit_token(CppToken::Type::RawString);
  637. continue;
  638. }
  639. if (size_t prefix = match_string_prefix('\''); prefix > 0) {
  640. begin_token();
  641. for (size_t i = 0; i < prefix; ++i)
  642. consume();
  643. while (peek()) {
  644. if (peek() == '\\') {
  645. if (size_t escape = match_escape_sequence(); escape > 0) {
  646. commit_token(CppToken::Type::SingleQuotedString);
  647. begin_token();
  648. for (size_t i = 0; i < escape; ++i)
  649. consume();
  650. commit_token(CppToken::Type::EscapeSequence);
  651. begin_token();
  652. continue;
  653. }
  654. }
  655. if (consume() == '\'')
  656. break;
  657. }
  658. commit_token(CppToken::Type::SingleQuotedString);
  659. continue;
  660. }
  661. if (isdigit(ch) || (ch == '.' && isdigit(peek(1)))) {
  662. begin_token();
  663. consume();
  664. auto type = ch == '.' ? CppToken::Type::Float : CppToken::Type::Integer;
  665. bool is_hex = false;
  666. bool is_binary = false;
  667. auto match_exponent = [&]() -> size_t {
  668. char ch = peek();
  669. if (ch != 'e' && ch != 'E' && ch != 'p' && ch != 'P')
  670. return 0;
  671. type = CppToken::Type::Float;
  672. size_t length = 1;
  673. ch = peek(length);
  674. if (ch == '+' || ch == '-') {
  675. ++length;
  676. }
  677. for (ch = peek(length); isdigit(ch); ch = peek(length)) {
  678. ++length;
  679. }
  680. return length;
  681. };
  682. auto match_type_literal = [&]() -> size_t {
  683. size_t length = 0;
  684. for (;;) {
  685. char ch = peek(length);
  686. if ((ch == 'u' || ch == 'U') && type == CppToken::Type::Integer) {
  687. ++length;
  688. } else if ((ch == 'f' || ch == 'F') && !is_binary) {
  689. type = CppToken::Type::Float;
  690. ++length;
  691. } else if (ch == 'l' || ch == 'L') {
  692. ++length;
  693. } else
  694. return length;
  695. }
  696. };
  697. if (peek() == 'b' || peek() == 'B') {
  698. consume();
  699. is_binary = true;
  700. for (char ch = peek(); ch == '0' || ch == '1' || (ch == '\'' && peek(1) != '\''); ch = peek()) {
  701. consume();
  702. }
  703. } else {
  704. if (peek() == 'x' || peek() == 'X') {
  705. consume();
  706. is_hex = true;
  707. }
  708. for (char ch = peek(); (is_hex ? isxdigit(ch) : isdigit(ch)) || (ch == '\'' && peek(1) != '\'') || ch == '.'; ch = peek()) {
  709. if (ch == '.') {
  710. if (type == CppToken::Type::Integer) {
  711. type = CppToken::Type::Float;
  712. } else
  713. break;
  714. };
  715. consume();
  716. }
  717. }
  718. if (!is_binary) {
  719. size_t length = match_exponent();
  720. for (size_t i = 0; i < length; ++i)
  721. consume();
  722. }
  723. size_t length = match_type_literal();
  724. for (size_t i = 0; i < length; ++i)
  725. consume();
  726. commit_token(type);
  727. continue;
  728. }
  729. if (is_valid_first_character_of_identifier(ch)) {
  730. begin_token();
  731. while (peek() && is_valid_nonfirst_character_of_identifier(peek()))
  732. consume();
  733. auto token_view = StringView(m_input.characters_without_null_termination() + token_start_index, m_index - token_start_index);
  734. if (is_keyword(token_view))
  735. commit_token(CppToken::Type::Keyword);
  736. else if (is_known_type(token_view))
  737. commit_token(CppToken::Type::KnownType);
  738. else
  739. commit_token(CppToken::Type::Identifier);
  740. continue;
  741. }
  742. dbg() << "Unimplemented token character: " << ch;
  743. emit_token(CppToken::Type::Unknown);
  744. }
  745. return tokens;
  746. }
  747. }