-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support colon in unquoted strings
Fix originally implemented by @freylax in #27 so credits should go that user. However, since the author hasn't replied I thought I'd open a new PR for this so we can merge it. Also fixes the tests in main.
- Loading branch information
Showing
4 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
.zigmod | ||
deps.zig | ||
zig-cache | ||
.zig-cache | ||
zig-out |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
From 1ec1b63a89578280ead4dc2793899be7cbe48663 Mon Sep 17 00:00:00 2001 | ||
From: Jonathan Lundholm <[email protected]> | ||
Date: Fri, 22 Nov 2024 13:01:19 +0100 | ||
Subject: [PATCH] fix: support colon in unquoted strings | ||
|
||
Fix originally implemented by @freylax in #27 | ||
so credits should go that user. | ||
|
||
However, since the author hasn't replied I thought | ||
I'd open a new PR for this so we can merge it. | ||
|
||
Also fixes the tests in main. | ||
--- | ||
.gitignore | 1 + | ||
src/Tokenizer.zig | 28 +++++++++++++++++++++++++++- | ||
test/test.zig | 4 ++-- | ||
3 files changed, 30 insertions(+), 3 deletions(-) | ||
|
||
diff --git a/.gitignore b/.gitignore | ||
index 8fb68bf..aca0ff0 100644 | ||
--- a/.gitignore | ||
+++ b/.gitignore | ||
@@ -2,4 +2,5 @@ | ||
.zigmod | ||
deps.zig | ||
zig-cache | ||
+.zig-cache | ||
zig-out | ||
diff --git a/src/Tokenizer.zig b/src/Tokenizer.zig | ||
index c3d7f5b..b758a0b 100644 | ||
--- a/src/Tokenizer.zig | ||
+++ b/src/Tokenizer.zig | ||
@@ -269,7 +269,7 @@ pub fn next(self: *Tokenizer) Token { | ||
}, | ||
|
||
.literal => switch (c) { | ||
- '\r', '\n', ' ', '\'', '"', ':', ']', '}' => { | ||
+ '\r', '\n', ' ', '\'', '"', ']', '}' => { | ||
result.id = .literal; | ||
break; | ||
}, | ||
@@ -279,6 +279,12 @@ pub fn next(self: *Tokenizer) Token { | ||
break; | ||
} | ||
}, | ||
+ ':' => { | ||
+ result.id = .literal; | ||
+ if (self.matchesPattern(": ") or self.matchesPattern(":\n") or self.matchesPattern(":\r")) { | ||
+ break; | ||
+ } | ||
+ }, | ||
else => { | ||
result.id = .literal; | ||
}, | ||
@@ -615,3 +621,23 @@ test "unquoted literals" { | ||
.eof, | ||
}); | ||
} | ||
+ | ||
+test "unquoted literal containing colon" { | ||
+ try testExpected( | ||
+ \\key1: val:ue | ||
+ \\key2: val::ue | ||
+ , &[_]Token.Id{ | ||
+ // key1 | ||
+ .literal, | ||
+ .map_value_ind, | ||
+ .space, | ||
+ .literal, // val:ue | ||
+ .new_line, | ||
+ // key2 | ||
+ .literal, | ||
+ .map_value_ind, | ||
+ .space, | ||
+ .literal, // val::ue | ||
+ .eof, | ||
+ }); | ||
+} | ||
diff --git a/test/test.zig b/test/test.zig | ||
index 41b6a1a..e99cb03 100644 | ||
--- a/test/test.zig | ||
+++ b/test/test.zig | ||
@@ -55,7 +55,7 @@ test "simple" { | ||
defer parsed.deinit(); | ||
|
||
const result = try parsed.parse(Simple); | ||
- const expected = .{ | ||
+ const expected = Simple{ | ||
.names = &[_][]const u8{ "John Doe", "MacIntosh", "Jane Austin" }, | ||
.numbers = &[_]i16{ 10, -8, 6 }, | ||
.nested = .{ | ||
@@ -180,7 +180,7 @@ test "single lib tbd" { | ||
defer parsed.deinit(); | ||
|
||
const result = try parsed.parse(LibTbd); | ||
- const expected = .{ | ||
+ const expected = LibTbd{ | ||
.tbd_version = 4, | ||
.targets = &[_][]const u8{ | ||
"x86_64-macos", | ||
-- | ||
2.43.0 | ||
|
This file contains 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
This file contains 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