aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/Token.zig
blob: 316286947230d85b9d50200f2cebb6cce00fc632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const std = @import("std");
const Allocator = std.mem.Allocator;

pub const Kind = enum {
    literal,
    weak_delimiter,
    strong_delimiter,
    title,
    quote,
    code,
    code_block,
    math,
    math_block,
    image,
    link,
    bold,
    italic,
    ref,
    callout,
    list_ordored,
    list_unordored,
    tag,

    pub inline fn isDelimiter(self: @This()) bool {
        return switch (self) {
            .weak_delimiter, .strong_delimiter => true,
            else => false,
        };
    }

    pub inline fn isPar(self: @This()) bool {
        return switch (self) {
            .literal, .link, .code, .math, .bold, .italic, .ref => true,
            else => false,
        };
    }

    pub inline fn requiresSpace(self: @This()) bool {
        return switch (self) {
            .title, .list_ordored, .list_unordored => true,
            else => false,
        };
    }

    pub inline fn trimSpace(self: @This()) bool {
        return switch (self) {
            .quote, .callout, .code_block => true,
            else => return self.requiresSpace(),
        };
    }
};

kind: Kind,
content: []const u8,

pub fn equals(self: @This(), kind: Kind, v: []const u8) bool {
    if (self.kind != kind) return false;
    return std.mem.eql(u8, self.content, v);
}