1#ifndef SPUDPLATE_PARSER_H
2#define SPUDPLATE_PARSER_H
8#include "spudplate/ast.h"
9#include "spudplate/lexer.h"
23 : std::runtime_error(message), line_(
line), column_(
column) {}
26 [[nodiscard]]
int line()
const {
return line_; }
28 [[nodiscard]]
int column()
const {
return column_; }
85 [[nodiscard]]
bool check(TokenType type)
const;
86 bool match(TokenType type);
87 Token expect(TokenType type,
const std::string& message);
91 VarType parse_var_type();
92 std::optional<ExprPtr> parse_when_clause();
93 std::optional<int> parse_mode_clause();
95 void push_quoted_path_segments(
const std::string& raw,
int line,
int column,
96 std::vector<PathSegment>& out);
97 ExprPtr parse_literal();
104 ExprPtr make_string_expression(
const std::string& raw,
int line,
int column);
105 void expect_newline(
const std::string& context);
110 ExprPtr parse_comparison();
111 ExprPtr parse_addition();
112 ExprPtr parse_multiplication();
113 ExprPtr parse_unary();
114 ExprPtr parse_primary();
Tokenises a spudlang source string into a stream of Token values.
Definition lexer.h:18
Exception thrown when the parser encounters invalid spudlang syntax.
Definition parser.h:19
int line() const
1-based line number where the error occurred.
Definition parser.h:26
int column() const
1-based column number where the error occurred.
Definition parser.h:28
ParseError(const std::string &message, int line, int column)
Construct an error tagged with the offending source position.
Definition parser.h:22
Recursive-descent parser that produces an AST from a token stream.
Definition parser.h:44
ExprPtr parseExpression()
Parses a single expression starting at the current token.
Definition parser.cpp:655
StmtPtr parseCopy()
Parses a copy statement.
Definition parser.cpp:446
StmtPtr parseAsk()
Parses an ask statement.
Definition parser.cpp:260
StmtPtr parseRepeat()
Parses a repeat block.
Definition parser.cpp:545
StmtPtr parseStatement()
Dispatches to the appropriate statement parser based on the current token.
Definition parser.cpp:605
StmtPtr parseIf()
Parses an if block.
Definition parser.cpp:575
Program parse()
Parses the full program and returns the top-level AST node.
Definition parser.cpp:642
StmtPtr parseLet()
Parses a let statement.
Definition parser.cpp:335
StmtPtr parseRun()
Parses a run statement.
Definition parser.cpp:467
StmtPtr parseFile()
Parses a file statement.
Definition parser.cpp:401
StmtPtr parseInclude()
Parses an include statement.
Definition parser.cpp:504
StmtPtr parseMkdir()
Parses a mkdir statement.
Definition parser.cpp:366
StmtPtr parseAssign()
Parses a bare assignment statement (name = expr).
Definition parser.cpp:350
A path expression - an ordered sequence of segments.
Definition ast.h:146
The top-level AST node representing a complete .spud program.
Definition ast.h:374
A single lexical token with source location.
Definition token.h:84