@@ -1015,21 +1015,6 @@ std::optional<std::string_view> Token::getString() const {
10151015 return {};
10161016}
10171017
1018- std::optional<std::string_view> Token::getID () const {
1019- if (auto * tok = std::get_if<IdTok>(&data)) {
1020- if (tok->str ) {
1021- return std::string_view (*tok->str );
1022- }
1023- if (tok->isStr ) {
1024- // Remove '$' and quotes.
1025- return span.substr (2 , span.size () - 3 );
1026- }
1027- // Remove '$'.
1028- return span.substr (1 );
1029- }
1030- return {};
1031- }
1032-
10331018void Lexer::skipSpace () {
10341019 while (true ) {
10351020 if (auto ctx = annotation (next ())) {
@@ -1069,6 +1054,26 @@ bool Lexer::takeRParen() {
10691054 return false ;
10701055}
10711056
1057+ std::optional<Name> Lexer::takeID () {
1058+ if (curr) {
1059+ return std::nullopt ;
1060+ }
1061+ if (auto result = ident (next ())) {
1062+ index += result->span .size ();
1063+ advance ();
1064+ if (result->str ) {
1065+ return Name (*result->str );
1066+ }
1067+ if (result->isStr ) {
1068+ // Remove '$' and quotes.
1069+ return Name (result->span .substr (2 , result->span .size () - 3 ));
1070+ }
1071+ // Remove '$'.
1072+ return Name (result->span .substr (1 ));
1073+ }
1074+ return std::nullopt ;
1075+ }
1076+
10721077std::optional<std::string_view> Lexer::takeKeyword () {
10731078 if (curr) {
10741079 return std::nullopt ;
@@ -1123,9 +1128,7 @@ std::optional<uint32_t> Lexer::takeAlign() {
11231128void Lexer::lexToken () {
11241129 // TODO: Ensure we're getting the longest possible match.
11251130 Token tok;
1126- if (auto t = ident (next ())) {
1127- tok = Token{t->span , IdTok{t->isStr , t->str }};
1128- } else if (auto t = integer (next ())) {
1131+ if (auto t = integer (next ())) {
11291132 tok = Token{t->span , IntTok{t->n , t->sign }};
11301133 } else if (auto t = float_ (next ())) {
11311134 tok = Token{t->span , FloatTok{t->nanPayload , t->d }};
@@ -1186,8 +1189,6 @@ std::ostream& operator<<(std::ostream& os, const TextPos& pos) {
11861189 return os << pos.line << " :" << pos.col ;
11871190}
11881191
1189- std::ostream& operator <<(std::ostream& os, const IdTok&) { return os << " id" ; }
1190-
11911192std::ostream& operator <<(std::ostream& os, const IntTok& tok) {
11921193 return os << (tok.sign == Pos ? " +" : tok.sign == Neg ? " -" : " " ) << tok.n ;
11931194}
0 commit comments