Rename statement -> ControlBlock
This commit is contained in:
parent
1a7db9a834
commit
52bb8739f8
1 changed files with 15 additions and 16 deletions
|
@ -26,7 +26,7 @@ fn executeTemplate(writer: anytype, comptime items: []const TemplateItem, args:
|
|||
};
|
||||
}
|
||||
|
||||
fn executeStatement(writer: anytype, comptime stmt: ExecutableStatement, args: anytype, captures: anytype) !void {
|
||||
fn executeStatement(writer: anytype, comptime stmt: Statement, args: anytype, captures: anytype) !void {
|
||||
switch (stmt) {
|
||||
.expression => |expr| {
|
||||
const val = evaluateExpression(expr, args, captures);
|
||||
|
@ -142,9 +142,9 @@ fn parseTemplate(comptime tokens: TokenIter, comptime template_type: TemplateTyp
|
|||
items = items ++ [_]TemplateItem{.{ .text = current_text }};
|
||||
current_text = "";
|
||||
}
|
||||
const result = parseStatement(iter);
|
||||
const result = parseControlBlock(iter);
|
||||
iter = result.new_iter;
|
||||
const stmt = result.item.executable;
|
||||
const stmt = result.item.statement;
|
||||
if (stmt == .end_for) {
|
||||
if (template_type == .for_block) break :parse_loop else @compileError("Unexpected end statement");
|
||||
} else if (stmt == .end_if) {
|
||||
|
@ -203,12 +203,12 @@ fn parseExpression(comptime tokens: TokenIter) ParseResult(Expression) {
|
|||
}
|
||||
}
|
||||
|
||||
fn parseStatement(comptime tokens: TokenIter) ParseResult(Statement) {
|
||||
fn parseControlBlock(comptime tokens: TokenIter) ParseResult(ControlBlock) {
|
||||
comptime {
|
||||
var iter = tokens;
|
||||
var first_token: bool = true;
|
||||
var strip_before: bool = false;
|
||||
var stmt: ExecutableStatement = while (iter.next()) |token| {
|
||||
var stmt: Statement = while (iter.next()) |token| {
|
||||
defer first_token = false;
|
||||
switch (token) {
|
||||
.equals => {
|
||||
|
@ -230,7 +230,7 @@ fn parseStatement(comptime tokens: TokenIter) ParseResult(Statement) {
|
|||
return .{
|
||||
.new_iter = result.new_iter,
|
||||
.item = .{
|
||||
.executable = .{ .for_loop = result.item },
|
||||
.statement = .{ .for_loop = result.item },
|
||||
.strip_before = false,
|
||||
.strip_after = false,
|
||||
},
|
||||
|
@ -241,7 +241,7 @@ fn parseStatement(comptime tokens: TokenIter) ParseResult(Statement) {
|
|||
return .{
|
||||
.new_iter = result.new_iter,
|
||||
.item = .{
|
||||
.executable = .{ .if_statement = result.item },
|
||||
.statement = .{ .if_statement = result.item },
|
||||
.strip_before = false,
|
||||
.strip_after = false,
|
||||
},
|
||||
|
@ -288,7 +288,7 @@ fn parseStatement(comptime tokens: TokenIter) ParseResult(Statement) {
|
|||
.close_bracket => return .{
|
||||
.new_iter = iter,
|
||||
.item = .{
|
||||
.executable = stmt,
|
||||
.statement = stmt,
|
||||
.strip_before = strip_before,
|
||||
.strip_after = strip_after,
|
||||
},
|
||||
|
@ -315,7 +315,7 @@ fn skipWhitespace(comptime tokens: TokenIter) TokenIter {
|
|||
}
|
||||
}
|
||||
|
||||
fn endStatement(comptime tokens: TokenIter) TokenIter {
|
||||
fn endControlBlock(comptime tokens: TokenIter) TokenIter {
|
||||
comptime {
|
||||
var iter = skipWhitespace(tokens);
|
||||
|
||||
|
@ -348,7 +348,7 @@ fn parseForLoop(comptime tokens: TokenIter) ParseResult(ForLoop) {
|
|||
const token = iter.next() orelse @compileError("Unexpected end of template");
|
||||
if (token != .pipe) @compileError("Unexpected token");
|
||||
}
|
||||
iter = endStatement(iter);
|
||||
iter = endControlBlock(iter);
|
||||
|
||||
const subtemplate = parseTemplate(iter, .for_block);
|
||||
|
||||
|
@ -363,7 +363,7 @@ fn parseForLoop(comptime tokens: TokenIter) ParseResult(ForLoop) {
|
|||
fn parseIfStatement(comptime tokens: TokenIter) ParseResult(IfStatement) {
|
||||
comptime {
|
||||
const condition = parseExpression(tokens);
|
||||
var iter = endStatement(condition.new_iter);
|
||||
var iter = endControlBlock(condition.new_iter);
|
||||
|
||||
const subtemplate = parseTemplate(iter, .if_block);
|
||||
|
||||
|
@ -407,7 +407,7 @@ fn ParseResult(comptime T: type) type {
|
|||
|
||||
const TemplateItem = union(enum) {
|
||||
text: []const u8,
|
||||
statement: ExecutableStatement,
|
||||
statement: Statement,
|
||||
};
|
||||
|
||||
const Expression = union(enum) {
|
||||
|
@ -426,8 +426,7 @@ const IfStatement = struct {
|
|||
condition: Expression,
|
||||
};
|
||||
|
||||
const ExecutableStatement =
|
||||
union(enum) {
|
||||
const Statement = union(enum) {
|
||||
expression: Expression,
|
||||
for_loop: ForLoop,
|
||||
end_for: void,
|
||||
|
@ -435,8 +434,8 @@ const ExecutableStatement =
|
|||
end_if: void,
|
||||
};
|
||||
|
||||
const Statement = struct {
|
||||
executable: ExecutableStatement,
|
||||
const ControlBlock = struct {
|
||||
statement: Statement,
|
||||
strip_before: bool,
|
||||
strip_after: bool,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue