File: basic.zig

package info (click to toggle)
re2c 4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,512 kB
  • sloc: cpp: 34,160; ml: 8,494; sh: 5,311; makefile: 1,014; haskell: 611; python: 431; ansic: 234; javascript: 113
file content (53 lines) | stat: -rw-r--r-- 957 bytes parent folder | download
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
// Generated by re2zig
// re2zig $INPUT -o $OUTPUT --recursive-functions

const std = @import("std");

const State = struct {
    str: [:0]const u8,
    cur: u32,
};

const SyntaxError = error {
    UnexpectedCharacter
};


fn yy0(st: *State) SyntaxError!void {
    const yych = st.str[st.cur];
    st.cur += 1;
    switch (yych) {
        0x31...0x39 => { return try yy2(st); },
        else => { return try yy1(st); },
    }
}

fn yy1(st: *State) SyntaxError!void {
    _ = st; return SyntaxError.UnexpectedCharacter;
}

fn yy2(st: *State) SyntaxError!void {
    const yych = st.str[st.cur];
    switch (yych) {
        0x30...0x39 => {
            st.cur += 1;
            return try yy2(st);
        },
        else => { return try yy3(st); },
    }
}

fn yy3(st: *State) SyntaxError!void {
    _ = st; return;
}

fn lex(st: *State) SyntaxError!void {
    return try yy0(st);
}



test {
    var st = State{.str = "1234", .cur = 0};
    try lex(&st);
}