File: 001_basic_d.swift

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 (92 lines) | stat: -rw-r--r-- 2,381 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Generated by re2swift */
#sourceLocation(file: "codegen/swift/001_basic_d.re", line: 1)
// re2swift $INPUT -o $OUTPUT --api generic -d

func lex(_ s: UnsafeBufferPointer<UInt8>) -> Bool {
  var cursor = 0, marker = 0

  
#sourceLocation(file: "codegen/swift/001_basic_d.swift", line: 10)
  var yych: UInt8 = 0
  var yystate: UInt = 0
  yyl: while true {
    switch yystate {
      case 0:
        print("lex: '\(yych)' int state \(0)")
        yych = s[cursor]
        cursor += 1
        switch yych {
          case 0x30...0x39:
            yystate = 3
            continue yyl
          default:
            yystate = 1
            continue yyl
        }
      case 1:
        print("lex: '\(yych)' int state \(1)")
        yystate = 2
        continue yyl
      case 2:
        print("lex: '\(yych)' int state \(2)")
#sourceLocation(file: "codegen/swift/001_basic_d.re", line: 17)
        return false
#sourceLocation(file: "codegen/swift/001_basic_d.swift", line: 35)
      case 3:
        print("lex: '\(yych)' int state \(3)")
        marker = cursor
        yych = s[cursor]
        switch yych {
          case 0x00:
            cursor += 1
            yystate = 4
            continue yyl
          case 0x30...0x39:
            cursor += 1
            yystate = 5
            continue yyl
          default:
            yystate = 2
            continue yyl
        }
      case 4:
        print("lex: '\(yych)' int state \(4)")
#sourceLocation(file: "codegen/swift/001_basic_d.re", line: 16)
        return true
#sourceLocation(file: "codegen/swift/001_basic_d.swift", line: 57)
      case 5:
        print("lex: '\(yych)' int state \(5)")
        yych = s[cursor]
        switch yych {
          case 0x00:
            cursor += 1
            yystate = 4
            continue yyl
          case 0x30...0x39:
            cursor += 1
            yystate = 5
            continue yyl
          default:
            yystate = 6
            continue yyl
        }
      case 6:
        print("lex: '\(yych)' int state \(6)")
        cursor = marker
        yystate = 2
        continue yyl
      default: fatalError("internal lexer error")
    }
  }
#sourceLocation(file: "codegen/swift/001_basic_d.re", line: 18)

}

@main struct Program {
  static func main() {
    let s: StaticString = "123\0"
    s.withUTF8Buffer {
      assert(lex($0), "expected 123")
    }
  }
}