11#include "spudplate/token.h"
46using ExprPtr = std::unique_ptr<Expr>;
93 std::vector<std::variant<std::string, ExprPtr>>
parts;
109enum class VarType { String, Bool, Int };
137using PathSegment = std::variant<PathLiteral, PathVar, PathInterp>;
164using FileSource = std::variant<FileFromSource, FileContentSource>;
257using StmtPtr = std::unique_ptr<Stmt>;
311 std::optional<PathExpr>
cwd;
An ask statement - declares a variable and prompts the user.
Definition ast.h:178
VarType var_type
Expected type of the answer.
Definition ast.h:181
int line
1-based source line where this node begins.
Definition ast.h:185
std::string name
Variable name to bind the answer to.
Definition ast.h:179
std::optional< ExprPtr > when_clause
Optional condition guarding the prompt.
Definition ast.h:184
int column
1-based source column where this node begins.
Definition ast.h:186
std::vector< ExprPtr > options
Allowed literal values; empty means any.
Definition ast.h:183
std::string prompt
The prompt string shown to the user.
Definition ast.h:180
std::optional< ExprPtr > default_value
Expression evaluated when the user skips the prompt.
Definition ast.h:182
A bare assignment statement - rebinds an existing variable.
Definition ast.h:211
std::string name
Variable name to rebind.
Definition ast.h:212
int column
1-based source column where this node begins.
Definition ast.h:215
int line
1-based source line where this node begins.
Definition ast.h:214
ExprPtr value
Expression whose value replaces the current binding.
Definition ast.h:213
A binary expression node, e.g.
Definition ast.h:61
ExprPtr right
Right-hand operand.
Definition ast.h:64
int column
1-based source column where this node begins.
Definition ast.h:66
ExprPtr left
Left-hand operand.
Definition ast.h:63
int line
1-based source line where this node begins.
Definition ast.h:65
TokenType op
The operator token.
Definition ast.h:62
A bool literal expression node, e.g.
Definition ast.h:30
int line
1-based source line where this node begins.
Definition ast.h:32
int column
1-based source column where this node begins.
Definition ast.h:33
bool value
The literal boolean value.
Definition ast.h:31
A copy statement - copies contents from a source directory into an existing destination directory.
Definition ast.h:287
std::optional< ExprPtr > when_clause
Optional condition guarding the copy.
Definition ast.h:291
int column
1-based source column where this node begins.
Definition ast.h:293
bool verbatim
If true, suppress {var} interpolation.
Definition ast.h:290
int line
1-based source line where this node begins.
Definition ast.h:292
PathExpr destination
Existing destination directory path.
Definition ast.h:289
PathExpr source
Source directory path.
Definition ast.h:288
An expression node wrapping an ExprData variant.
Definition ast.h:104
ExprData data
The concrete expression alternative.
Definition ast.h:105
File source: content comes from an inline expression.
Definition ast.h:159
ExprPtr value
The expression whose string value becomes the file content.
Definition ast.h:160
File source: content comes from an embedded source file.
Definition ast.h:153
PathExpr path
Path to the source file (resolved at compile time).
Definition ast.h:154
bool verbatim
If true, suppress {var} interpolation at runtime.
Definition ast.h:155
A file statement - creates or appends to a file.
Definition ast.h:243
std::optional< int > mode
Optional permission bits.
Definition ast.h:248
PathExpr path
File path expression.
Definition ast.h:244
std::optional< std::string > alias
Optional as <name> binding; empty if no as clause.
Definition ast.h:245
int column
1-based source column where this node begins.
Definition ast.h:251
bool append
If true, append; otherwise create/overwrite.
Definition ast.h:247
std::optional< ExprPtr > when_clause
Optional condition guarding creation.
Definition ast.h:249
int line
1-based source line where this node begins.
Definition ast.h:250
FileSource source
Where the file content comes from.
Definition ast.h:246
A built-in function call expression, e.g.
Definition ast.h:75
int line
1-based source line where this node begins.
Definition ast.h:78
std::string name
Function name.
Definition ast.h:76
std::vector< ExprPtr > arguments
Argument expressions.
Definition ast.h:77
int column
1-based source column where this node begins.
Definition ast.h:79
A variable reference expression node, e.g.
Definition ast.h:37
int line
1-based source line where this node begins.
Definition ast.h:39
std::string name
The variable name.
Definition ast.h:38
int column
1-based source column where this node begins.
Definition ast.h:40
An if statement - executes its body when the condition is true.
Definition ast.h:356
int column
1-based source column where this node begins.
Definition ast.h:360
ExprPtr condition
Expression that must evaluate to bool true to enter the body.
Definition ast.h:357
int line
1-based source line where this node begins.
Definition ast.h:359
std::vector< StmtPtr > body
Statements inside the conditional block.
Definition ast.h:358
An include statement - runs another bundled template inline.
Definition ast.h:331
int column
1-based source column where this node begins.
Definition ast.h:336
std::optional< ExprPtr > when_clause
Optional condition guarding the include.
Definition ast.h:334
std::optional< std::uint32_t > version_pin
Optional @N pin from source. Bundler resolves to that exact installed/archived version.
Definition ast.h:333
int line
1-based source line where this node begins.
Definition ast.h:335
std::string name
Name of the installed template to run.
Definition ast.h:332
An integer literal expression node, e.g.
Definition ast.h:23
int line
1-based source line where this node begins.
Definition ast.h:25
int value
The literal integer value.
Definition ast.h:24
int column
1-based source column where this node begins.
Definition ast.h:26
A let statement - declares a derived variable.
Definition ast.h:194
int line
1-based source line where this node begins.
Definition ast.h:197
std::string name
Variable name to bind.
Definition ast.h:195
ExprPtr value
Expression whose value is assigned.
Definition ast.h:196
int column
1-based source column where this node begins.
Definition ast.h:198
A mkdir statement - creates a directory.
Definition ast.h:226
int line
1-based source line where this node begins.
Definition ast.h:234
int column
1-based source column where this node begins.
Definition ast.h:235
PathExpr path
Directory path expression.
Definition ast.h:227
std::optional< ExprPtr > when_clause
Optional condition guarding creation.
Definition ast.h:233
bool mkdir_p
Always true - create intermediate directories.
Definition ast.h:229
std::optional< PathExpr > from_source
Optional source directory to populate from.
Definition ast.h:230
std::optional< std::string > alias
Optional as <name> binding; empty if no as clause.
Definition ast.h:228
std::optional< int > mode
Optional permission bits (e.g. 0755).
Definition ast.h:232
bool verbatim
If true with from_source, suppress interpolation.
Definition ast.h:231
A path expression - an ordered sequence of segments.
Definition ast.h:146
int column
Column of the first segment.
Definition ast.h:149
std::vector< PathSegment > segments
Ordered path components.
Definition ast.h:147
int line
Line of the first segment.
Definition ast.h:148
An inline {expr} interpolation inside a path, e.g.
Definition ast.h:130
int column
1-based source column where this node begins.
Definition ast.h:133
int line
1-based source line where this node begins.
Definition ast.h:132
ExprPtr expression
The expression whose string value is substituted at runtime.
Definition ast.h:131
A literal component of a path expression, e.g.
Definition ast.h:116
std::string value
Literal text (identifiers, dots, slashes already joined).
Definition ast.h:117
int column
1-based source column where this node begins.
Definition ast.h:119
int line
1-based source line where this node begins.
Definition ast.h:118
A reference to a previously-bound path alias, e.g.
Definition ast.h:123
std::string name
The alias name.
Definition ast.h:124
int column
1-based source column where this node begins.
Definition ast.h:126
int line
1-based source line where this node begins.
Definition ast.h:125
The top-level AST node representing a complete .spud program.
Definition ast.h:374
std::vector< StmtPtr > statements
Ordered list of top-level statements.
Definition ast.h:375
A repeat statement - loops a block N times.
Definition ast.h:269
std::string collection_var
Name of the int variable holding the count.
Definition ast.h:270
int column
1-based source column where this node begins.
Definition ast.h:275
int line
1-based source line where this node begins.
Definition ast.h:274
std::vector< StmtPtr > body
Statements inside the loop body.
Definition ast.h:272
std::optional< ExprPtr > when_clause
Optional condition guarding the whole loop.
Definition ast.h:273
std::string iterator_var
Name of the loop index variable (0-based).
Definition ast.h:271
A run statement - executes a shell command after user authorisation.
Definition ast.h:309
ExprPtr command
Expression whose string value is the command.
Definition ast.h:310
int line
1-based source line where this node begins.
Definition ast.h:314
std::optional< ExprPtr > when_clause
Optional condition guarding execution.
Definition ast.h:313
std::optional< ExprPtr > timeout
Optional timeout <int> override in seconds. Absent means use the run-time default unless --no-timeout...
Definition ast.h:312
std::optional< PathExpr > cwd
Optional in <path> working directory.
Definition ast.h:311
int column
1-based source column where this node begins.
Definition ast.h:315
A statement node wrapping a StmtData variant.
Definition ast.h:369
StmtData data
The concrete statement alternative.
Definition ast.h:370
A string literal expression node, e.g.
Definition ast.h:16
int column
1-based source column where this node begins.
Definition ast.h:19
std::string value
The literal string value (without quotes).
Definition ast.h:17
int line
1-based source line where this node begins.
Definition ast.h:18
A string literal containing one or more {expr} interpolations.
Definition ast.h:92
std::vector< std::variant< std::string, ExprPtr > > parts
Ordered literal/expression segments.
Definition ast.h:93
int line
1-based source line where this node begins.
Definition ast.h:94
int column
1-based source column where this node begins.
Definition ast.h:95
A unary expression node, e.g.
Definition ast.h:49
TokenType op
The operator token (NOT).
Definition ast.h:50
ExprPtr operand
The operand expression.
Definition ast.h:51
int line
1-based source line where this node begins.
Definition ast.h:52
int column
1-based source column where this node begins.
Definition ast.h:53