aboutsummaryrefslogtreecommitdiff
path: root/src/z/js/parser/builtin.zig
blob: fc96fc3e2752dafc18a1499fd4940497d87a3cc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const std = @import("std");

const parser = @import("root.zig");
const Parser = parser.Parser;
const Result = parser.Result;

pub fn literal(lit: []const u8) Parser(void) {
    return .fromType(struct {
        pub fn parse(buffer: []const u8) !Result(void) {
            if (std.mem.startsWith(u8, buffer, lit)) {
                return .{ void{}, buffer[lit.len..] };
            }

            return error.Literal;
        }
    });
}