From 85bcada8cf78bdf2bfb3be583289686026e0f25e Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 1 Feb 2025 12:47:35 +0100 Subject: screen: start drm implementation --- src/estd/parser/common.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/estd/parser/common.zig (limited to 'src/estd/parser/common.zig') diff --git a/src/estd/parser/common.zig b/src/estd/parser/common.zig new file mode 100644 index 0000000..986af58 --- /dev/null +++ b/src/estd/parser/common.zig @@ -0,0 +1,28 @@ +const std = @import("std"); +const root = @import("root.zig"); +const Context = @import("context.zig").Context; +const ParseFn = root.ParseFn; + +pub fn LiteralFn(comptime I: type, comptime O: type) type { + return *const fn (comptime literal: []const I, value: O) ParseFn(I, O); +} + +pub fn Literal(comptime I: type, comptime O: type) LiteralFn(I, O) { + return struct { + pub fn literal(comptime lit: []const I, value: O) ParseFn(I, O) { + return struct { + pub fn parse(ctx: *Context(I)) !O { + const snapshot = ctx.cursor.snapshot(); + errdefer ctx.cursor.rollback(snapshot); + + const slice = try ctx.cursor.consume(lit.len); + if (std.mem.eql(I, lit, slice)) { + return value; + } + + return error.UnexpectedLiteral; + } + }.parse; + } + }.literal; +} -- cgit v1.2.3-70-g09d2