CppLexer.cpp 23 KB

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