Use % for context instead of @
This commit is contained in:
parent
ef27bb5c21
commit
466a15f3cb
2 changed files with 8 additions and 6 deletions
|
@ -3,7 +3,7 @@ const std = @import("std");
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
try execute(
|
try execute(
|
||||||
std.io.getStdOut().writer(),
|
std.io.getStdOut().writer(),
|
||||||
.{ .test_tmpl = "{.x} {@context_foo}" },
|
.{ .test_tmpl = "{.x} {%context_foo}" },
|
||||||
@embedFile("./test.tmp.html"),
|
@embedFile("./test.tmp.html"),
|
||||||
.{
|
.{
|
||||||
.community = .{ .name = "abcd" },
|
.community = .{ .name = "abcd" },
|
||||||
|
@ -389,6 +389,7 @@ fn parseTemplateTokens(comptime tokens: ControlTokenIter) []const TemplateToken
|
||||||
.equals => items = items ++ [_]TemplateToken{.{ .text = "=" }},
|
.equals => items = items ++ [_]TemplateToken{.{ .text = "=" }},
|
||||||
.at => items = items ++ [_]TemplateToken{.{ .text = "@" }},
|
.at => items = items ++ [_]TemplateToken{.{ .text = "@" }},
|
||||||
.comma => items = items ++ [_]TemplateToken{.{ .text = "," }},
|
.comma => items = items ++ [_]TemplateToken{.{ .text = "," }},
|
||||||
|
.percent => items = items ++ [_]TemplateToken{.{ .text = "%" }},
|
||||||
};
|
};
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
@ -411,7 +412,7 @@ fn parseExpression(comptime tokens: ControlTokenIter) ParseResult(ControlTokenIt
|
||||||
iter = names.new_iter;
|
iter = names.new_iter;
|
||||||
break .{ .capture_deref = names.item };
|
break .{ .capture_deref = names.item };
|
||||||
},
|
},
|
||||||
.at => {
|
.percent => {
|
||||||
const names = parseDeref(iter);
|
const names = parseDeref(iter);
|
||||||
iter = names.new_iter;
|
iter = names.new_iter;
|
||||||
break .{ .context_deref = names.item };
|
break .{ .context_deref = names.item };
|
||||||
|
@ -485,7 +486,7 @@ fn parseControlBlock(comptime tokens: ControlTokenIter) ParseResult(ControlToken
|
||||||
.@"if" => break .{ .end_if = {} },
|
.@"if" => break .{ .end_if = {} },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.period, .dollar, .at => {
|
.period, .dollar, .percent => {
|
||||||
iter.putBack(token);
|
iter.putBack(token);
|
||||||
const expr = parseExpression(iter);
|
const expr = parseExpression(iter);
|
||||||
iter = expr.new_iter;
|
iter = expr.new_iter;
|
||||||
|
@ -587,9 +588,9 @@ fn tryParseCapture(comptime tokens: ControlTokenIter) ?ParseResult(ControlTokenI
|
||||||
|
|
||||||
iter = skipWhitespace(iter);
|
iter = skipWhitespace(iter);
|
||||||
if ((iter.next() orelse return null) != .pipe) return null;
|
if ((iter.next() orelse return null) != .pipe) return null;
|
||||||
iter = skipWhitespace(iter);
|
|
||||||
var captures: []const []const u8 = &.{};
|
var captures: []const []const u8 = &.{};
|
||||||
while (true) {
|
while (true) {
|
||||||
|
iter = skipWhitespace(iter);
|
||||||
if ((iter.next() orelse return null) != .dollar) return null;
|
if ((iter.next() orelse return null) != .dollar) return null;
|
||||||
iter = skipWhitespace(iter);
|
iter = skipWhitespace(iter);
|
||||||
const name = switch (iter.next() orelse return null) {
|
const name = switch (iter.next() orelse return null) {
|
||||||
|
@ -604,7 +605,6 @@ fn tryParseCapture(comptime tokens: ControlTokenIter) ?ParseResult(ControlTokenI
|
||||||
.comma => {},
|
.comma => {},
|
||||||
else => return null,
|
else => return null,
|
||||||
}
|
}
|
||||||
iter = skipWhitespace(iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
@ -786,6 +786,7 @@ const ControlToken = union(enum) {
|
||||||
equals: void,
|
equals: void,
|
||||||
at: void,
|
at: void,
|
||||||
comma: void,
|
comma: void,
|
||||||
|
percent: void,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ControlTokenIter = struct {
|
const ControlTokenIter = struct {
|
||||||
|
@ -817,6 +818,7 @@ const ControlTokenIter = struct {
|
||||||
'=' => return .{ .equals = {} },
|
'=' => return .{ .equals = {} },
|
||||||
'@' => return .{ .at = {} },
|
'@' => return .{ .at = {} },
|
||||||
',' => return .{ .comma = {} },
|
',' => return .{ .comma = {} },
|
||||||
|
'%' => return .{ .percent = {} },
|
||||||
' ', '\t', '\n', '\r' => {
|
' ', '\t', '\n', '\r' => {
|
||||||
var idx: usize = 0;
|
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) {}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<template>{#template test_tmpl .bar}</template>
|
<template>{#template test_tmpl .bar}</template>
|
||||||
<template>{#template test_tmpl .}</template>
|
<template>{#template test_tmpl .}</template>
|
||||||
|
|
||||||
{@context_foo}
|
{%context_foo}
|
||||||
</section>
|
</section>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue