22 const std::string_view Src;
23 std::vector<Diagnostic> &Diags;
27 void consume(std::size_t N = 1) {
28 assert(Cur.Offset + N <= Src.length());
30 for (std::size_t I = 0; I < N; ++I) {
31 if (Src[Cur.Offset + I] ==
'\n') {
45 Tok = tok::tok_unknown;
52 Src.substr(TokStartPtr.Offset, Cur.Offset - TokStartPtr.Offset),
58 bool consumeWhitespaces();
59 bool consumeComments();
61 [[nodiscard]]
bool eof(std::size_t Offset)
const {
62 return Offset >= Src.length();
65 [[nodiscard]]
bool eof()
const {
return eof(Cur.Offset); }
67 bool consumeEOL() {
return consumePrefix(
"\r\n") || consumePrefix(
"\n"); }
72 std::optional<LexerCursorRange> consumePrefix(std::string_view Prefix);
74 bool consumeOne(
char C);
76 std::optional<char> consumeOneOf(std::string_view Chars);
78 std::optional<LexerCursorRange> consumeManyOf(std::string_view Chars);
80 std::optional<LexerCursorRange> consumeManyDigits() {
81 return consumeManyOf(
"0123456789");
84 std::optional<LexerCursorRange> consumeManyPathChar();
87 bool peekPrefix(std::string_view Prefix);
89 bool consumePathStart();
103 [[nodiscard]] std::string_view tokStr()
const {
104 return Src.substr(TokStartPtr.Offset, Cur.Offset - TokStartPtr.Offset);
107 [[nodiscard]] std::string_view remain()
const {
108 return Src.substr(Cur.Offset);
113 [[nodiscard]]
char peekUnwrap()
const {
return Src[Cur.Offset]; }
115 [[nodiscard]] std::optional<char> peek()
const {
122 Lexer(std::string_view Src, std::vector<Diagnostic> &Diags)
123 : Src(Src), Diags(Diags), Cur() {}
127 assert(Src.begin() + NewCur.Offset <= Src.end());