| author | |
| committer | |
| log | fd7533f6dad7cb1f6d390d3485a3d0ab832dc5d3 |
| tree | d5a6e505f892c34902f9aecf3c76e4bc43275ce5 |
| parent | 499071c2903ee2b67460c0c3e8f0446cd232702f |
2 files changed, 13 insertions(+), 2 deletions(-)
src/astgen.zig+11-2| ... | @@ -185,10 +185,15 @@ const Parser = struct { | ... | @@ -185,10 +185,15 @@ const Parser = struct { |
| 185 | temp = temp ++ &[_]string{self.eat(.word)}; | 185 | temp = temp ++ &[_]string{self.eat(.word)}; |
| 186 | } else { | 186 | } else { |
| 187 | ret = ret ++ &[_][]const string{temp}; | 187 | ret = ret ++ &[_][]const string{temp}; |
| 188 | temp = &.{self.eat(.word)}; | 188 | temp = &.{}; |
| 189 | if (comptime self.nextIs(.string)) { | ||
| 190 | ret = ret ++ &[_][]const string{&.{self.eat(.string)}}; | ||
| 191 | } else { | ||
| 192 | temp = &.{self.eat(.word)}; | ||
| 193 | } | ||
| 189 | } | 194 | } |
| 190 | } | 195 | } |
| 191 | ret = ret ++ &[_][]const string{temp}; | 196 | if (temp.len > 0) ret = ret ++ &[_][]const string{temp}; |
| 192 | return ret; | 197 | return ret; |
| 193 | } | 198 | } |
| 194 | 199 | ||
| ... | @@ -211,4 +216,8 @@ const Parser = struct { | ... | @@ -211,4 +216,8 @@ const Parser = struct { |
| 211 | } | 216 | } |
| 212 | return @field(tok.data, @tagName(typ)); | 217 | return @field(tok.data, @tagName(typ)); |
| 213 | } | 218 | } |
| 219 | |||
| 220 | fn nextIs(comptime self: *Parser, comptime typ: std.meta.Tag(Token.Data)) bool { | ||
| 221 | return self.tokens[self.index].data == typ; | ||
| 222 | } | ||
| 214 | }; | 223 | }; |
src/lib.zig+2| ... | @@ -160,12 +160,14 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value, | ... | @@ -160,12 +160,14 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value, |
| 160 | 160 | ||
| 161 | fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(ctx), args) { | 161 | fn search(comptime args: []const []const u8, ctx: anytype) FieldSearch(@TypeOf(ctx), args) { |
| 162 | if (args.len == 0) return ctx; | 162 | if (args.len == 0) return ctx; |
| 163 | if (args[0][0] == '"') return std.mem.trim(u8, args[0], "\""); | ||
| 163 | const f = @field(ctx, args[0]); | 164 | const f = @field(ctx, args[0]); |
| 164 | if (args.len == 1) return f; | 165 | if (args.len == 1) return f; |
| 165 | return search(args[1..], f); | 166 | return search(args[1..], f); |
| 166 | } | 167 | } |
| 167 | 168 | ||
| 168 | fn FieldSearch(comptime T: type, comptime args: []const []const u8) type { | 169 | fn FieldSearch(comptime T: type, comptime args: []const []const u8) type { |
| 170 | if (args.len > 0 and args[0][0] == '"') return []const u8; | ||
| 169 | return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]); | 171 | return if (args.len == 0) T else if (args.len == 1) Field(T, args[0]) else FieldSearch(Field(T, args[0]), args[1..]); |
| 170 | } | 172 | } |
| 171 | 173 |