Change syntax for end_for statement
This commit is contained in:
parent
67ad5bfa48
commit
5bb9742ab9
2 changed files with 21 additions and 5 deletions
|
@ -150,6 +150,7 @@ fn parseTemplate(comptime tokens: TokenIter, comptime template_type: TemplateTyp
|
|||
.pound => current_text = current_text ++ "#",
|
||||
.pipe => current_text = current_text ++ "|",
|
||||
.dollar => current_text = current_text ++ "$",
|
||||
.slash => current_text = current_text ++ "/",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +181,6 @@ fn parseExpressionOrStatement(
|
|||
const keyword = std.meta.stringToEnum(Keyword, text) orelse @compileError("Unknown keyword: " ++ text);
|
||||
|
||||
switch (keyword) {
|
||||
.end_for => break .{ .end_for = {} },
|
||||
.@"for" => {
|
||||
const result = parseForLoop(iter);
|
||||
// statemnt already finished so just return
|
||||
|
@ -193,6 +193,17 @@ fn parseExpressionOrStatement(
|
|||
//else => @compileError("TODO"),
|
||||
}
|
||||
},
|
||||
.slash => {
|
||||
if (!as_statement) !@compileError("Unexpected Token");
|
||||
const next = iter.next() orelse @compileError("Unexpected end of template");
|
||||
if (next != .text) @compileError("Expected keyword following '/' character");
|
||||
const text = next.text;
|
||||
const keyword = std.meta.stringToEnum(EndKeyword, text) orelse @compileError("Unknown keyword: " ++ text);
|
||||
|
||||
switch (keyword) {
|
||||
.@"for" => break .{ .end_for = {} },
|
||||
}
|
||||
},
|
||||
.period => {
|
||||
const names = parseDeref(iter);
|
||||
iter = names.new_iter;
|
||||
|
@ -336,7 +347,10 @@ const Statement = union(enum) {
|
|||
|
||||
const Keyword = enum {
|
||||
@"for",
|
||||
end_for,
|
||||
};
|
||||
|
||||
const EndKeyword = enum {
|
||||
@"for",
|
||||
};
|
||||
|
||||
const Token = union(enum) {
|
||||
|
@ -348,6 +362,7 @@ const Token = union(enum) {
|
|||
pound: void,
|
||||
pipe: void,
|
||||
dollar: void,
|
||||
slash: void,
|
||||
};
|
||||
|
||||
const TokenIter = struct {
|
||||
|
@ -375,6 +390,7 @@ const TokenIter = struct {
|
|||
'#' => return .{ .pound = {} },
|
||||
'|' => return .{ .pipe = {} },
|
||||
'$' => return .{ .dollar = {} },
|
||||
'/' => return .{ .slash = {} },
|
||||
' ', '\t', '\n', '\r' => {
|
||||
var idx: usize = 0;
|
||||
while (idx < remaining.len and std.mem.indexOfScalar(u8, " \t\n\r", remaining[idx]) != null) : (idx += 1) {}
|
||||
|
@ -386,7 +402,7 @@ const TokenIter = struct {
|
|||
},
|
||||
else => {
|
||||
var idx: usize = 0;
|
||||
while (idx < remaining.len and std.mem.indexOfScalar(u8, "{}.#|$ \t\n\r", remaining[idx]) == null) : (idx += 1) {}
|
||||
while (idx < remaining.len and std.mem.indexOfScalar(u8, "{}.#|$/ \t\n\r", remaining[idx]) == null) : (idx += 1) {}
|
||||
|
||||
self.start += idx - 1;
|
||||
return .{ .text = remaining[0..idx] };
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
<h2> {{ REAL BRACKETS }} </h2>
|
||||
|
||||
<section>
|
||||
{#for .baz |$f|}{#for $f |$b|}{$b}:{#end_for}
|
||||
{#end_for}
|
||||
{#for .baz |$f|}{#for $f |$b|}{$b}:{/for}
|
||||
{/for}
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue