summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2026-01-06 04:46:19 +0100
committerTaylan Kammer <taylan.kammer@gmail.com>2026-01-06 04:46:19 +0100
commitc44b9eed2c92dfad9313fb28c32321c05b0e317c (patch)
treee0cf118cfe8efdc9e98762fdd7c5cd381637912c /src
parentd2f3a2351271e22248d7c2f11c8f69bbe244e56a (diff)
Parser: Implement changes to grammar.
Diffstat (limited to 'src')
-rw-r--r--src/zisp/io/Parser.zig25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/zisp/io/Parser.zig b/src/zisp/io/Parser.zig
index 4a2ed35..57cdc14 100644
--- a/src/zisp/io/Parser.zig
+++ b/src/zisp/io/Parser.zig
@@ -78,7 +78,6 @@ const GRAVE = value.rune.pack("GRAVE");
const COMMA = value.rune.pack("COMMA");
const SQUARE = value.rune.pack("SQUARE");
const BRACE = value.rune.pack("BRACE");
-const LSTAIL = value.sstr.pack(".");
// zig fmt: on
// We could implement an optimization where we swap in a dummy cons when the
@@ -413,20 +412,16 @@ fn endJoinDatum(p: *Parser) !void {
}
fn parseOneDatum(p: *Parser, c: u8, next: Fn) !void {
- if (isBareChar(c) or c == '.') {
+ if (isBareChar(c)) {
return p.jump(next, try p.parseBareString(c));
}
return p.parseCladDatum(c, next);
}
fn parseBareString(p: *Parser, c1: u8) !Value {
- const allow_dots = std.ascii.isDigit(c1) or switch (c1) {
- '.', '+', '-' => true,
- else => false,
- };
try p.addChar(c1);
while (try p.read()) |c| {
- if (isBareChar(c) or (allow_dots and c == '.')) {
+ if (isBareChar(c)) {
try p.addChar(c);
} else {
p.unread(c);
@@ -674,13 +669,12 @@ fn continueList(p: *Parser) !void {
if (c == close) {
return p.endList();
}
+ if (c == '&') {
+ return p.subr(.parseUnit, .endImproperList);
+ }
return p.err(.InvalidCharacter, "list");
}
- if (p.result.eq(LSTAIL)) {
- return p.subr(.parseUnit, .endImproperList);
- }
-
p.context.val = p.cons(p.result, p.context.val);
var c1 = p.getUnread() orelse try p.read();
@@ -759,10 +753,9 @@ fn checkBlanks(p: *Parser, c: u8) !enum { yes, skip_unit, no } {
switch (c) {
'\t'...'\r', ' ' => return .yes,
';' => {
- const c2 = try p.read() orelse return .yes;
- if (c2 == '\n') return .yes;
+ var c2 = try p.read() orelse return .yes;
if (c2 == '~') return .skip_unit;
- while (try p.read()) |c3| if (c3 == '\n') break;
+ while (c2 != '\n') c2 = try p.read() orelse break;
return .yes;
},
else => return .no,
@@ -772,8 +765,8 @@ fn checkBlanks(p: *Parser, c: u8) !enum { yes, skip_unit, no } {
fn isBareChar(c: u8) bool {
return switch (c) {
// zig fmt: off
- 'a'...'z' , 'A'...'Z' , '0'...'9' , '!' , '$' , '%' , '&' , '*' ,
- '+' , '-' , '/' , '<' , '=' , '>' , '?' , '@' , '^' , '_' , '~' => true,
+ 'a'...'z' , 'A'...'Z' , '0'...'9' , '!' , '$' , '%' , '*' ,'+' ,
+ '-' , '.' , '/' , '<' , '=' , '>' , '?' , '@' , '^' , '_' , '~' => true,
// zig fmt: on
else => false,
};