44 std::vector<Diagnostic> &Diags;
46 std::deque<Token> LookAheadBuf;
47 std::optional<Token> LastToken;
48 std::stack<ParserState> State;
60 std::multiset<TokenKind> SyncTokens;
66 StateRAII(
Parser &P) : P(P) {}
67 ~StateRAII() { P.popState(); }
76 void resetLookAheadBuf();
82 Token peek(std::size_t N = 0);
86 std::optional<LexerCursorRange> consumeAsUnknown();
94 P.SyncTokens.emplace(Kind);
96 ~SyncRAII() { P.SyncTokens.erase(P.SyncTokens.find(Kind)); }
103 std::optional<Token> Tok;
107 ExpectResult(
Token Tok) : Success(true), Tok(Tok), DiagMissing(nullptr) {}
109 : Success(false), DiagMissing(DiagMissing) {}
111 [[nodiscard]]
bool ok()
const {
return Success; }
112 [[nodiscard]]
Token tok()
const {
125 if (LookAheadBuf.empty())
131 LastToken = LookAheadBuf.front();
132 LookAheadBuf.pop_front();
136 bool removeUnexpected() {
137 if (std::optional<LexerCursorRange> UnknownRange = consumeAsUnknown()) {
139 Diags.emplace_back(Diagnostic::DK_UnexpectedText, *UnknownRange);
150 std::shared_ptr<Expr> parseExprOpBP(
unsigned BP);
153 Parser(std::string_view Src, std::vector<Diagnostic> &Diags)
154 : Src(Src), Lex(Src, Diags), Act(Src, Diags), Diags(Diags) {
188 std::shared_ptr<ExprString>
parseString(
bool IsIndented);
261 std::shared_ptr<Expr>
parseExprApp(
int Limit = INT_MAX);
338 std::shared_ptr<Expr>
parse();
static TextEdit mkRemoval(LexerCursorRange RemovingRange)