15 D << std::move(As) +
" expression";
20void Parser::pushState(ParserState NewState) {
25void Parser::popState() {
30Parser::StateRAII Parser::withState(ParserState NewState) {
35Parser::SyncRAII Parser::withSync(
TokenKind Kind) {
return {*
this, Kind}; }
38 std::vector<Diagnostic> &Diags) {
44 auto Expr = parseExpr();
45 if (
Token Tok = peek(); Tok.
kind() != tok::tok_eof) {
48 Diags.emplace_back(Diagnostic::DK_UnexpectedText, Tok.range());
53void Parser::resetLookAheadBuf() {
54 if (!LookAheadBuf.empty()) {
55 Token Tok = LookAheadBuf.front();
63Token Parser::peek(std::size_t N) {
64 while (N >= LookAheadBuf.size()) {
65 switch (State.top()) {
67 LookAheadBuf.emplace_back(Lex.
lex());
70 LookAheadBuf.emplace_back(Lex.
lexString());
76 LookAheadBuf.emplace_back(Lex.
lexPath());
80 return LookAheadBuf[N];
83std::optional<LexerCursorRange> Parser::consumeAsUnknown() {
85 bool Consumed =
false;
86 for (
Token Tok = peek(); Tok.
kind() != tok_eof; Tok = peek()) {
87 if (SyncTokens.contains(Tok.
kind()))
94 assert(LastToken &&
"LastToken should be set after consume()");
98Parser::ExpectResult Parser::expect(
TokenKind Kind) {
99 auto Sync = withSync(Kind);
100 if (
Token Tok = peek(); Tok.
kind() == Kind) {
105 if (removeUnexpected()) {
106 if (
Token Tok = peek(); Tok.
kind() == Kind) {
Fix & fix(std::string Message)
Fix & edit(TextEdit Edit)
A point in the source file.
void setCur(const LexerCursor &NewCur)
Reset the cursor at source offset (zero-based indexing)
std::shared_ptr< Expr > parse()
Top-level parsing.
static TextEdit mkInsertion(LexerCursor P, std::string NewText)
A token. With it's kind, and the range in source code.
tok::TokenKind kind() const
Diagnostic & diagNullExpr(std::vector< Diagnostic > &Diags, LexerCursor Loc, std::string As)
constexpr std::string_view spelling(TokenKind Kind)
std::shared_ptr< Node > parse(std::string_view Src, std::vector< Diagnostic > &Diags)
Parse a string.
Parser for the Nix expression language.