Lexer.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 "Lexer.h"
  27. #include <AK/HashTable.h>
  28. #include <AK/StdLibExtras.h>
  29. #include <AK/String.h>
  30. #include <ctype.h>
  31. namespace Cpp {
  32. Lexer::Lexer(const StringView& input)
  33. : m_input(input)
  34. {
  35. }
  36. char Lexer::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 Lexer::consume()
  43. {
  44. VERIFY(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<Token> Lexer::lex()
  216. {
  217. Vector<Token> tokens;
  218. size_t token_start_index = 0;
  219. Position token_start_position;
  220. auto emit_single_char_token = [&](auto type) {
  221. tokens.empend(type, m_position, m_position, m_input.substring_view(m_index, 1));
  222. consume();
  223. };
  224. auto begin_token = [&] {
  225. token_start_index = m_index;
  226. token_start_position = m_position;
  227. };
  228. auto commit_token = [&](auto type) {
  229. tokens.empend(type, token_start_position, m_previous_position, m_input.substring_view(token_start_index, m_index - token_start_index));
  230. };
  231. auto emit_token_equals = [&](auto type, auto equals_type) {
  232. if (peek(1) == '=') {
  233. begin_token();
  234. consume();
  235. consume();
  236. commit_token(equals_type);
  237. return;
  238. }
  239. emit_single_char_token(type);
  240. };
  241. auto match_escape_sequence = [&]() -> size_t {
  242. switch (peek(1)) {
  243. case '\'':
  244. case '"':
  245. case '?':
  246. case '\\':
  247. case 'a':
  248. case 'b':
  249. case 'f':
  250. case 'n':
  251. case 'r':
  252. case 't':
  253. case 'v':
  254. return 2;
  255. case '0':
  256. case '1':
  257. case '2':
  258. case '3':
  259. case '4':
  260. case '5':
  261. case '6':
  262. case '7': {
  263. size_t octal_digits = 1;
  264. for (size_t i = 0; i < 2; ++i) {
  265. char next = peek(2 + i);
  266. if (next < '0' || next > '7')
  267. break;
  268. ++octal_digits;
  269. }
  270. return 1 + octal_digits;
  271. }
  272. case 'x': {
  273. size_t hex_digits = 0;
  274. while (isxdigit(peek(2 + hex_digits)))
  275. ++hex_digits;
  276. return 2 + hex_digits;
  277. }
  278. case 'u':
  279. case 'U': {
  280. bool is_unicode = true;
  281. size_t number_of_digits = peek(1) == 'u' ? 4 : 8;
  282. for (size_t i = 0; i < number_of_digits; ++i) {
  283. if (!isxdigit(peek(2 + i))) {
  284. is_unicode = false;
  285. break;
  286. }
  287. }
  288. return is_unicode ? 2 + number_of_digits : 0;
  289. }
  290. default:
  291. return 0;
  292. }
  293. };
  294. auto match_string_prefix = [&](char quote) -> size_t {
  295. if (peek() == quote)
  296. return 1;
  297. if (peek() == 'L' && peek(1) == quote)
  298. return 2;
  299. if (peek() == 'u') {
  300. if (peek(1) == quote)
  301. return 2;
  302. if (peek(1) == '8' && peek(2) == quote)
  303. return 3;
  304. }
  305. if (peek() == 'U' && peek(1) == quote)
  306. return 2;
  307. return 0;
  308. };
  309. while (m_index < m_input.length()) {
  310. auto ch = peek();
  311. if (isspace(ch)) {
  312. begin_token();
  313. while (isspace(peek()))
  314. consume();
  315. commit_token(Token::Type::Whitespace);
  316. continue;
  317. }
  318. if (ch == '(') {
  319. emit_single_char_token(Token::Type::LeftParen);
  320. continue;
  321. }
  322. if (ch == ')') {
  323. emit_single_char_token(Token::Type::RightParen);
  324. continue;
  325. }
  326. if (ch == '{') {
  327. emit_single_char_token(Token::Type::LeftCurly);
  328. continue;
  329. }
  330. if (ch == '}') {
  331. emit_single_char_token(Token::Type::RightCurly);
  332. continue;
  333. }
  334. if (ch == '[') {
  335. emit_single_char_token(Token::Type::LeftBracket);
  336. continue;
  337. }
  338. if (ch == ']') {
  339. emit_single_char_token(Token::Type::RightBracket);
  340. continue;
  341. }
  342. if (ch == '<') {
  343. begin_token();
  344. consume();
  345. if (peek() == '<') {
  346. consume();
  347. if (peek() == '=') {
  348. consume();
  349. commit_token(Token::Type::LessLessEquals);
  350. continue;
  351. }
  352. commit_token(Token::Type::LessLess);
  353. continue;
  354. }
  355. if (peek() == '=') {
  356. consume();
  357. commit_token(Token::Type::LessEquals);
  358. continue;
  359. }
  360. if (peek() == '>') {
  361. consume();
  362. commit_token(Token::Type::LessGreater);
  363. continue;
  364. }
  365. commit_token(Token::Type::Less);
  366. continue;
  367. }
  368. if (ch == '>') {
  369. begin_token();
  370. consume();
  371. if (peek() == '>') {
  372. consume();
  373. if (peek() == '=') {
  374. consume();
  375. commit_token(Token::Type::GreaterGreaterEquals);
  376. continue;
  377. }
  378. commit_token(Token::Type::GreaterGreater);
  379. continue;
  380. }
  381. if (peek() == '=') {
  382. consume();
  383. commit_token(Token::Type::GreaterEquals);
  384. continue;
  385. }
  386. commit_token(Token::Type::Greater);
  387. continue;
  388. }
  389. if (ch == ',') {
  390. emit_single_char_token(Token::Type::Comma);
  391. continue;
  392. }
  393. if (ch == '+') {
  394. begin_token();
  395. consume();
  396. if (peek() == '+') {
  397. consume();
  398. commit_token(Token::Type::PlusPlus);
  399. continue;
  400. }
  401. if (peek() == '=') {
  402. consume();
  403. commit_token(Token::Type::PlusEquals);
  404. continue;
  405. }
  406. commit_token(Token::Type::Plus);
  407. continue;
  408. }
  409. if (ch == '-') {
  410. begin_token();
  411. consume();
  412. if (peek() == '-') {
  413. consume();
  414. commit_token(Token::Type::MinusMinus);
  415. continue;
  416. }
  417. if (peek() == '=') {
  418. consume();
  419. commit_token(Token::Type::MinusEquals);
  420. continue;
  421. }
  422. if (peek() == '>') {
  423. consume();
  424. if (peek() == '*') {
  425. consume();
  426. commit_token(Token::Type::ArrowAsterisk);
  427. continue;
  428. }
  429. commit_token(Token::Type::Arrow);
  430. continue;
  431. }
  432. commit_token(Token::Type::Minus);
  433. continue;
  434. }
  435. if (ch == '*') {
  436. emit_token_equals(Token::Type::Asterisk, Token::Type::AsteriskEquals);
  437. continue;
  438. }
  439. if (ch == '%') {
  440. emit_token_equals(Token::Type::Percent, Token::Type::PercentEquals);
  441. continue;
  442. }
  443. if (ch == '^') {
  444. emit_token_equals(Token::Type::Caret, Token::Type::CaretEquals);
  445. continue;
  446. }
  447. if (ch == '!') {
  448. emit_token_equals(Token::Type::ExclamationMark, Token::Type::ExclamationMarkEquals);
  449. continue;
  450. }
  451. if (ch == '=') {
  452. emit_token_equals(Token::Type::Equals, Token::Type::EqualsEquals);
  453. continue;
  454. }
  455. if (ch == '&') {
  456. begin_token();
  457. consume();
  458. if (peek() == '&') {
  459. consume();
  460. commit_token(Token::Type::AndAnd);
  461. continue;
  462. }
  463. if (peek() == '=') {
  464. consume();
  465. commit_token(Token::Type::AndEquals);
  466. continue;
  467. }
  468. commit_token(Token::Type::And);
  469. continue;
  470. }
  471. if (ch == '|') {
  472. begin_token();
  473. consume();
  474. if (peek() == '|') {
  475. consume();
  476. commit_token(Token::Type::PipePipe);
  477. continue;
  478. }
  479. if (peek() == '=') {
  480. consume();
  481. commit_token(Token::Type::PipeEquals);
  482. continue;
  483. }
  484. commit_token(Token::Type::Pipe);
  485. continue;
  486. }
  487. if (ch == '~') {
  488. emit_single_char_token(Token::Type::Tilde);
  489. continue;
  490. }
  491. if (ch == '?') {
  492. emit_single_char_token(Token::Type::QuestionMark);
  493. continue;
  494. }
  495. if (ch == ':') {
  496. begin_token();
  497. consume();
  498. if (peek() == ':') {
  499. consume();
  500. if (peek() == '*') {
  501. consume();
  502. commit_token(Token::Type::ColonColonAsterisk);
  503. continue;
  504. }
  505. commit_token(Token::Type::ColonColon);
  506. continue;
  507. }
  508. commit_token(Token::Type::Colon);
  509. continue;
  510. }
  511. if (ch == ';') {
  512. emit_single_char_token(Token::Type::Semicolon);
  513. continue;
  514. }
  515. if (ch == '.') {
  516. begin_token();
  517. consume();
  518. if (peek() == '*') {
  519. consume();
  520. commit_token(Token::Type::DotAsterisk);
  521. continue;
  522. }
  523. commit_token(Token::Type::Dot);
  524. continue;
  525. }
  526. if (ch == '#') {
  527. begin_token();
  528. consume();
  529. if (is_valid_first_character_of_identifier(peek()))
  530. while (peek() && is_valid_nonfirst_character_of_identifier(peek()))
  531. consume();
  532. auto directive = StringView(m_input.characters_without_null_termination() + token_start_index, m_index - token_start_index);
  533. if (directive == "#include") {
  534. commit_token(Token::Type::IncludeStatement);
  535. begin_token();
  536. while (isspace(peek()))
  537. consume();
  538. commit_token(Token::Type::Whitespace);
  539. begin_token();
  540. if (peek() == '<' || peek() == '"') {
  541. char closing = consume() == '<' ? '>' : '"';
  542. while (peek() && peek() != closing && peek() != '\n')
  543. consume();
  544. if (peek() && consume() == '\n') {
  545. commit_token(Token::Type::IncludePath);
  546. continue;
  547. }
  548. commit_token(Token::Type::IncludePath);
  549. begin_token();
  550. }
  551. } else {
  552. while (peek() && peek() != '\n')
  553. consume();
  554. commit_token(Token::Type::PreprocessorStatement);
  555. }
  556. continue;
  557. }
  558. if (ch == '/' && peek(1) == '/') {
  559. begin_token();
  560. while (peek() && peek() != '\n')
  561. consume();
  562. commit_token(Token::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(Token::Type::Comment);
  582. continue;
  583. }
  584. if (ch == '/') {
  585. emit_token_equals(Token::Type::Slash, Token::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(Token::Type::DoubleQuotedString);
  596. begin_token();
  597. for (size_t i = 0; i < escape; ++i)
  598. consume();
  599. commit_token(Token::Type::EscapeSequence);
  600. begin_token();
  601. continue;
  602. }
  603. }
  604. // If string is not terminated - stop before EOF
  605. if (!peek(1))
  606. break;
  607. if (consume() == '"')
  608. break;
  609. }
  610. commit_token(Token::Type::DoubleQuotedString);
  611. continue;
  612. }
  613. if (size_t prefix = match_string_prefix('R'); prefix > 0 && peek(prefix) == '"') {
  614. begin_token();
  615. for (size_t i = 0; i < prefix + 1; ++i)
  616. consume();
  617. size_t prefix_start = m_index;
  618. while (peek() && peek() != '(')
  619. consume();
  620. StringView prefix_string = m_input.substring_view(prefix_start, m_index - prefix_start);
  621. while (peek()) {
  622. if (consume() == '"') {
  623. VERIFY(m_index >= prefix_string.length() + 2);
  624. VERIFY(m_input[m_index - 1] == '"');
  625. if (m_input[m_index - 1 - prefix_string.length() - 1] == ')') {
  626. StringView suffix_string = m_input.substring_view(m_index - 1 - prefix_string.length(), prefix_string.length());
  627. if (prefix_string == suffix_string)
  628. break;
  629. }
  630. }
  631. }
  632. commit_token(Token::Type::RawString);
  633. continue;
  634. }
  635. if (size_t prefix = match_string_prefix('\''); prefix > 0) {
  636. begin_token();
  637. for (size_t i = 0; i < prefix; ++i)
  638. consume();
  639. while (peek()) {
  640. if (peek() == '\\') {
  641. if (size_t escape = match_escape_sequence(); escape > 0) {
  642. commit_token(Token::Type::SingleQuotedString);
  643. begin_token();
  644. for (size_t i = 0; i < escape; ++i)
  645. consume();
  646. commit_token(Token::Type::EscapeSequence);
  647. begin_token();
  648. continue;
  649. }
  650. }
  651. if (consume() == '\'')
  652. break;
  653. }
  654. commit_token(Token::Type::SingleQuotedString);
  655. continue;
  656. }
  657. if (isdigit(ch) || (ch == '.' && isdigit(peek(1)))) {
  658. begin_token();
  659. consume();
  660. auto type = ch == '.' ? Token::Type::Float : Token::Type::Integer;
  661. bool is_hex = false;
  662. bool is_binary = false;
  663. auto match_exponent = [&]() -> size_t {
  664. char ch = peek();
  665. if (ch != 'e' && ch != 'E' && ch != 'p' && ch != 'P')
  666. return 0;
  667. type = Token::Type::Float;
  668. size_t length = 1;
  669. ch = peek(length);
  670. if (ch == '+' || ch == '-') {
  671. ++length;
  672. }
  673. for (ch = peek(length); isdigit(ch); ch = peek(length)) {
  674. ++length;
  675. }
  676. return length;
  677. };
  678. auto match_type_literal = [&]() -> size_t {
  679. size_t length = 0;
  680. for (;;) {
  681. char ch = peek(length);
  682. if ((ch == 'u' || ch == 'U') && type == Token::Type::Integer) {
  683. ++length;
  684. } else if ((ch == 'f' || ch == 'F') && !is_binary) {
  685. type = Token::Type::Float;
  686. ++length;
  687. } else if (ch == 'l' || ch == 'L') {
  688. ++length;
  689. } else
  690. return length;
  691. }
  692. };
  693. if (peek() == 'b' || peek() == 'B') {
  694. consume();
  695. is_binary = true;
  696. for (char ch = peek(); ch == '0' || ch == '1' || (ch == '\'' && peek(1) != '\''); ch = peek()) {
  697. consume();
  698. }
  699. } else {
  700. if (peek() == 'x' || peek() == 'X') {
  701. consume();
  702. is_hex = true;
  703. }
  704. for (char ch = peek(); (is_hex ? isxdigit(ch) : isdigit(ch)) || (ch == '\'' && peek(1) != '\'') || ch == '.'; ch = peek()) {
  705. if (ch == '.') {
  706. if (type == Token::Type::Integer) {
  707. type = Token::Type::Float;
  708. } else
  709. break;
  710. };
  711. consume();
  712. }
  713. }
  714. if (!is_binary) {
  715. size_t length = match_exponent();
  716. for (size_t i = 0; i < length; ++i)
  717. consume();
  718. }
  719. size_t length = match_type_literal();
  720. for (size_t i = 0; i < length; ++i)
  721. consume();
  722. commit_token(type);
  723. continue;
  724. }
  725. if (is_valid_first_character_of_identifier(ch)) {
  726. begin_token();
  727. while (peek() && is_valid_nonfirst_character_of_identifier(peek()))
  728. consume();
  729. auto token_view = StringView(m_input.characters_without_null_termination() + token_start_index, m_index - token_start_index);
  730. if (is_keyword(token_view))
  731. commit_token(Token::Type::Keyword);
  732. else if (is_known_type(token_view))
  733. commit_token(Token::Type::KnownType);
  734. else
  735. commit_token(Token::Type::Identifier);
  736. continue;
  737. }
  738. dbgln("Unimplemented token character: {}", ch);
  739. emit_single_char_token(Token::Type::Unknown);
  740. }
  741. return tokens;
  742. }
  743. }