Use % for context instead of @

This commit is contained in:
jaina heartles 2022-12-08 03:21:18 -08:00
parent ef27bb5c21
commit 466a15f3cb
2 changed files with 8 additions and 6 deletions

View file

@ -3,7 +3,7 @@ const std = @import("std");
pub fn main() !void {
try execute(
std.io.getStdOut().writer(),
.{ .test_tmpl = "{.x} {@context_foo}" },
.{ .test_tmpl = "{.x} {%context_foo}" },
@embedFile("./test.tmp.html"),
.{
.community = .{ .name = "abcd" },
@ -389,6 +389,7 @@ fn parseTemplateTokens(comptime tokens: ControlTokenIter) []const TemplateToken
.equals => items = items ++ [_]TemplateToken{.{ .text = "=" }},
.at => items = items ++ [_]TemplateToken{.{ .text = "@" }},
.comma => items = items ++ [_]TemplateToken{.{ .text = "," }},
.percent => items = items ++ [_]TemplateToken{.{ .text = "%" }},
};
return items;
@ -411,7 +412,7 @@ fn parseExpression(comptime tokens: ControlTokenIter) ParseResult(ControlTokenIt
iter = names.new_iter;
break .{ .capture_deref = names.item };
},
.at => {
.percent => {
const names = parseDeref(iter);
iter = names.new_iter;
break .{ .context_deref = names.item };
@ -485,7 +486,7 @@ fn parseControlBlock(comptime tokens: ControlTokenIter) ParseResult(ControlToken
.@"if" => break .{ .end_if = {} },
}
},
.period, .dollar, .at => {
.period, .dollar, .percent => {
iter.putBack(token);
const expr = parseExpression(iter);
iter = expr.new_iter;
@ -587,9 +588,9 @@ fn tryParseCapture(comptime tokens: ControlTokenIter) ?ParseResult(ControlTokenI
iter = skipWhitespace(iter);
if ((iter.next() orelse return null) != .pipe) return null;
iter = skipWhitespace(iter);
var captures: []const []const u8 = &.{};
while (true) {
iter = skipWhitespace(iter);
if ((iter.next() orelse return null) != .dollar) return null;
iter = skipWhitespace(iter);
const name = switch (iter.next() orelse return null) {
@ -604,7 +605,6 @@ fn tryParseCapture(comptime tokens: ControlTokenIter) ?ParseResult(ControlTokenI
.comma => {},
else => return null,
}
iter = skipWhitespace(iter);
}
return .{
@ -786,6 +786,7 @@ const ControlToken = union(enum) {
equals: void,
at: void,
comma: void,
percent: void,
};
const ControlTokenIter = struct {
@ -817,6 +818,7 @@ const ControlTokenIter = struct {
'=' => return .{ .equals = {} },
'@' => return .{ .at = {} },
',' => return .{ .comma = {} },
'%' => return .{ .percent = {} },
' ', '\t', '\n', '\r' => {
var idx: usize = 0;
while (idx < remaining.len and std.mem.indexOfScalar(u8, " \t\n\r", remaining[idx]) != null) : (idx += 1) {}

View file

@ -29,7 +29,7 @@
<template>{#template test_tmpl .bar}</template>
<template>{#template test_tmpl .}</template>
{@context_foo}
{%context_foo}
</section>
</body>
</html>