Draft
Conversation
RyEggGit
reviewed
Apr 9, 2026
src/parser.zig
Outdated
Comment on lines
+38
to
+51
| try tokens.append(allocator, .{ .word = "||" }); | ||
| i += 2; | ||
| } else { | ||
| try tokens.append(allocator, .{ .word = "|" }); | ||
| i += 1; | ||
| } | ||
| }, | ||
| '&' => { | ||
| if (i + 1 < input.len and input[i + 1] == '&') { | ||
| try tokens.append(allocator, .{ .word = "&&" }); | ||
| i += 2; | ||
| } else { | ||
| try tokens.append(allocator, .{ .word = "&" }); | ||
| i += 1; |
Owner
There was a problem hiding this comment.
I think these shoudl return a Token enum
RyEggGit
reviewed
Apr 9, 2026
Comment on lines
+90
to
+115
| fn expectTokens(input: []const u8, expected: []const Token, allocator: std.mem.Allocator) !void { | ||
| const tokens = try tokenize(input, allocator); | ||
| defer allocator.free(tokens); | ||
| try testing.expectEqualDeep(expected, tokens); | ||
| } | ||
|
|
||
| test "canonical example" { | ||
| try expectTokens("echo hello world", &[_]Token{ Token{ .word = "echo" }, Token{ .word = "hello" }, Token{ .word = "world" } }, testing.allocator); | ||
| } | ||
|
|
||
| test "quotes" { | ||
| try expectTokens("echo \"hello world\"", &[_]Token{ Token{ .word = "echo" }, Token{ .word = "hello world" } }, testing.allocator); | ||
| } | ||
|
|
||
| // TODO: Decide if an unmatched quote should be an error or if it should just assume until \n is the quote. | ||
| test "unmatched quote" { | ||
| try expectTokens("echo \"hello world", &[_]Token{ Token{ .word = "echo" }, Token{ .word = "hello world" } }, testing.allocator); | ||
| } | ||
|
|
||
| test "leading and trailing spaces" { | ||
| try expectTokens(" echo hello world ", &[_]Token{ Token{ .word = "echo" }, Token{ .word = "hello" }, Token{ .word = "world" } }, testing.allocator); | ||
| } | ||
|
|
||
| test "pipes and logical operators" { | ||
| try expectTokens("echo hello | grep h && echo done", &[_]Token{ Token{ .word = "echo" }, Token{ .word = "hello" }, Token{ .word = "|" }, Token{ .word = "grep" }, Token{ .word = "h" }, Token{ .word = "&&" }, Token{ .word = "echo" }, Token{ .word = "done" } }, testing.allocator); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I fixed parser.zig - not sure if
isSpecialis how you wanted it. Can make amendments.