| author | |
| committer | |
| log | 70d6284bd93fa0e3c6c2310e5e62f1a36535b6ca |
| tree | 6682f3f307df172e2d7ea4a35a3293b6d3fc64e8 |
| parent | 8401a1944fff76034468cbc9daf74f19aabfe8fb |
3 files changed, 11 insertions(+), 1 deletions(-)
src/astgen.zig+8-1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Token = @import("./tokenize.zig").Token; | 2 | const Token = @import("./tokenize.zig").Token; |
| 3 | const extras = @import("extras"); | ||
| 3 | 4 | ||
| 4 | const string = []const u8; | 5 | const string = []const u8; |
| 5 | 6 | ||
| ... | @@ -59,6 +60,7 @@ pub const Fn = struct { | ... | @@ -59,6 +60,7 @@ pub const Fn = struct { |
| 59 | pub const Arg = union(enum) { | 60 | pub const Arg = union(enum) { |
| 60 | lookup: []const string, | 61 | lookup: []const string, |
| 61 | plain: string, | 62 | plain: string, |
| 63 | int: u64, | ||
| 62 | }; | 64 | }; |
| 63 | 65 | ||
| 64 | // | 66 | // |
| ... | @@ -209,7 +211,12 @@ const Parser = struct { | ... | @@ -209,7 +211,12 @@ const Parser = struct { |
| 209 | continue; | 211 | continue; |
| 210 | } | 212 | } |
| 211 | if (temp.len == 0 and self.nextIs(.word)) { | 213 | if (temp.len == 0 and self.nextIs(.word)) { |
| 212 | temp = temp ++ &[_]string{self.eat(.word)}; | 214 | const next_word = self.eat(.word); |
| 215 | if (extras.matchesAll(u8, next_word, std.ascii.isDigit)) { | ||
| 216 | ret = ret ++ &[_]Arg{.{ .int = std.fmt.parseUnsigned(u64, next_word, 10) catch unreachable }}; | ||
| 217 | continue; | ||
| 218 | } | ||
| 219 | temp = temp ++ &[_]string{next_word}; | ||
| 213 | } | 220 | } |
| 214 | if (self.tryEatSymbol(".")) { | 221 | if (self.tryEatSymbol(".")) { |
| 215 | temp = temp ++ &[_]string{self.eat(.word)}; | 222 | temp = temp ++ &[_]string{self.eat(.word)}; |
src/lib.zig+2| ... | @@ -251,6 +251,7 @@ fn resolveArg(comptime arg: astgen.Arg, data: anytype, ctx: anytype) ResolveArg( | ... | @@ -251,6 +251,7 @@ fn resolveArg(comptime arg: astgen.Arg, data: anytype, ctx: anytype) ResolveArg( |
| 251 | return switch (arg) { | 251 | return switch (arg) { |
| 252 | .plain => |av| av[1 .. av.len - 1], | 252 | .plain => |av| av[1 .. av.len - 1], |
| 253 | .lookup => |av| if (comptime std.mem.eql(u8, av[0], "this")) search(av[1..], data) else search(av, ctx), | 253 | .lookup => |av| if (comptime std.mem.eql(u8, av[0], "this")) search(av[1..], data) else search(av, ctx), |
| 254 | .int => |av| av, | ||
| 254 | }; | 255 | }; |
| 255 | } | 256 | } |
| 256 | 257 | ||
| ... | @@ -258,6 +259,7 @@ fn ResolveArg(comptime arg: astgen.Arg, comptime This: type, comptime Ctx: type) | ... | @@ -258,6 +259,7 @@ fn ResolveArg(comptime arg: astgen.Arg, comptime This: type, comptime Ctx: type) |
| 258 | return switch (arg) { | 259 | return switch (arg) { |
| 259 | .plain => string, | 260 | .plain => string, |
| 260 | .lookup => |av| if (comptime std.mem.eql(u8, av[0], "this")) FieldSearch(This, av[1..]) else FieldSearch(Ctx, av), | 261 | .lookup => |av| if (comptime std.mem.eql(u8, av[0], "this")) FieldSearch(This, av[1..]) else FieldSearch(Ctx, av), |
| 262 | .int => u64, | ||
| 261 | }; | 263 | }; |
| 262 | } | 264 | } |
| 263 | 265 |
zig.mod+1| ... | @@ -5,3 +5,4 @@ license: AGPL-3.0 | ... | @@ -5,3 +5,4 @@ license: AGPL-3.0 |
| 5 | description: An HTML preprocessor with a builtin template engine. | 5 | description: An HTML preprocessor with a builtin template engine. |
| 6 | dependencies: | 6 | dependencies: |
| 7 | - src: git https://github.com/kivikakk/htmlentities.zig | 7 | - src: git https://github.com/kivikakk/htmlentities.zig |
| 8 | - src: git https://github.com/nektro/zig-extras |