| ... | @@ -8,6 +8,7 @@ | ... | @@ -8,6 +8,7 @@ |
| 8 | //! https://handlebarsjs.com/ | 8 | //! https://handlebarsjs.com/ |
| 9 | | 9 | |
| 10 | const std = @import("std"); | 10 | const std = @import("std"); |
| | 11 | const string = []const u8; |
| 11 | const range = @import("range").range; | 12 | const range = @import("range").range; |
| 12 | const htmlentities = @import("htmlentities"); | 13 | const htmlentities = @import("htmlentities"); |
| 13 | const root = @import("root"); | 14 | const root = @import("root"); |
| ... | @@ -15,7 +16,7 @@ const root = @import("root"); | ... | @@ -15,7 +16,7 @@ const root = @import("root"); |
| 15 | const tokenize = @import("./tokenize.zig"); | 16 | const tokenize = @import("./tokenize.zig"); |
| 16 | const astgen = @import("./astgen.zig"); | 17 | const astgen = @import("./astgen.zig"); |
| 17 | | 18 | |
| 18 | pub fn parse(comptime input: []const u8) astgen.Value { | 19 | pub fn parse(comptime input: string) astgen.Value { |
| 19 | return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.', '<', '>' })) }; | 20 | return astgen.Value{ .element = astgen.do(tokenize.do(input, &.{ '[', '=', ']', '(', ')', '{', '}', '#', '/', '.', '<', '>' })) }; |
| 20 | } | 21 | } |
| 21 | | 22 | |
| ... | @@ -180,7 +181,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va | ... | @@ -180,7 +181,7 @@ fn do(comptime Ctx: type, alloc: std.mem.Allocator, writer: anytype, comptime va |
| 180 | } | 181 | } |
| 181 | } | 182 | } |
| 182 | | 183 | |
| 183 | fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(ctx), args) { | 184 | fn search(comptime args: []const string, ctx: anytype) FieldSearch(@TypeOf(ctx), args) { |
| 184 | if (args.len == 0) return ctx; | 185 | if (args.len == 0) return ctx; |
| 185 | if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\""); | 186 | if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\""); |
| 186 | const f = @field(ctx, args[0]); | 187 | const f = @field(ctx, args[0]); |
| ... | @@ -188,12 +189,12 @@ fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(c | ... | @@ -188,12 +189,12 @@ fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(c |
| 188 | return search(args[1..], f); | 189 | return search(args[1..], f); |
| 189 | } | 190 | } |
| 190 | | 191 | |
| 191 | fn FieldSearch(comptime T: type, comptime args: []const []const u8) type { | 192 | fn FieldSearch(comptime T: type, comptime args: []const string) type { |
| 192 | if (args.len > 0 and args[0][0] == '"') return []const u8; | 193 | if (args.len > 0 and args[0][0] == '"') return string; |
| 193 | return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]); | 194 | return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]); |
| 194 | } | 195 | } |
| 195 | | 196 | |
| 196 | fn Field(comptime T: type, comptime field_name: []const u8) type { | 197 | fn Field(comptime T: type, comptime field_name: string) type { |
| 197 | if (std.meta.trait.isIndexable(T) and std.mem.eql(u8, field_name, "len")) { | 198 | if (std.meta.trait.isIndexable(T) and std.mem.eql(u8, field_name, "len")) { |
| 198 | return usize; | 199 | return usize; |
| 199 | } | 200 | } |
| ... | @@ -203,7 +204,7 @@ fn Field(comptime T: type, comptime field_name: []const u8) type { | ... | @@ -203,7 +204,7 @@ fn Field(comptime T: type, comptime field_name: []const u8) type { |
| 203 | @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) })); | 204 | @compileError(std.fmt.comptimePrint("pek: unknown field {s} on type {s}", .{ field_name, @typeName(T) })); |
| 204 | } | 205 | } |
| 205 | | 206 | |
| 206 | fn entityLookupBefore(in: []const u8) ?htmlentities.Entity { | 207 | fn entityLookupBefore(in: string) ?htmlentities.Entity { |
| 207 | for (htmlentities.ENTITIES) |e| { | 208 | for (htmlentities.ENTITIES) |e| { |
| 208 | if (!std.mem.endsWith(u8, e.entity, ";")) { | 209 | if (!std.mem.endsWith(u8, e.entity, ";")) { |
| 209 | continue; | 210 | continue; |
| ... | @@ -249,7 +250,7 @@ const HtmlVoidElements = enum { | ... | @@ -249,7 +250,7 @@ const HtmlVoidElements = enum { |
| 249 | wbr, | 250 | wbr, |
| 250 | }; | 251 | }; |
| 251 | | 252 | |
| 252 | fn contains(haystack: []const []const u8, needle: []const u8) bool { | 253 | fn contains(haystack: []const string, needle: string) bool { |
| 253 | for (haystack) |v| { | 254 | for (haystack) |v| { |
| 254 | if (std.mem.eql(u8, v, needle)) { | 255 | if (std.mem.eql(u8, v, needle)) { |
| 255 | return true; | 256 | return true; |