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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
# Generated by re2py
# re2py $INPUT -o $OUTPUT
from collections import namedtuple
SemVer = namedtuple('SemVer', 'major minor patch')
NONE = -1
def parse(yyinput):
yycursor = 0
yystate = 0
while True:
match yystate:
case 0:
yych = yyinput[yycursor]
if yych <= 0x2F:
yycursor += 1
yystate = 1
continue
if yych <= 0x39:
yyt1 = yycursor
yycursor += 1
yystate = 3
continue
yycursor += 1
yystate = 1
continue
case 1:
yystate = 2
continue
case 2:
return None
case 3:
yymarker = yycursor
yych = yyinput[yycursor]
if yych == 0x2E:
yycursor += 1
yystate = 4
continue
if yych <= 0x2F:
yystate = 2
continue
if yych <= 0x39:
yycursor += 1
yystate = 6
continue
yystate = 2
continue
case 4:
yych = yyinput[yycursor]
if yych <= 0x2F:
yystate = 5
continue
if yych <= 0x39:
yyt2 = yycursor
yycursor += 1
yystate = 7
continue
yystate = 5
continue
case 5:
yycursor = yymarker
yystate = 2
continue
case 6:
yych = yyinput[yycursor]
if yych == 0x2E:
yycursor += 1
yystate = 4
continue
if yych <= 0x2F:
yystate = 5
continue
if yych <= 0x39:
yycursor += 1
yystate = 6
continue
yystate = 5
continue
case 7:
yych = yyinput[yycursor]
if yych <= 0x2E:
if yych <= 0x00:
yyt3 = yycursor
yyt4 = -1
yyt5 = -1
yycursor += 1
yystate = 8
continue
if yych <= 0x2D:
yystate = 5
continue
yyt3 = yycursor
yyt5 = yycursor
yycursor += 1
yystate = 9
continue
else:
if yych <= 0x2F:
yystate = 5
continue
if yych <= 0x39:
yycursor += 1
yystate = 7
continue
yystate = 5
continue
case 8:
yytl1 = yyt1
yytl2 = yyt2
yytr2 = yyt3
yytl3 = yyt5
yytr3 = yyt4
yytl0 = yyt1
yytr0 = yycursor
yytr1 = yyt2
yytr1 -= 1
major = int(yyinput[yytl1:yytr1])
minor = int(yyinput[yytl2:yytr2])
patch = 0 if yytl3 == NONE else int(yyinput[yytl3 + 1:yytr3])
return SemVer(major, minor, patch)
case 9:
yych = yyinput[yycursor]
if yych <= 0x00:
yystate = 5
continue
yystate = 11
continue
case 10:
yych = yyinput[yycursor]
yystate = 11
continue
case 11:
if yych <= 0x00:
yyt4 = yycursor
yycursor += 1
yystate = 8
continue
if yych <= 0x2F:
yystate = 5
continue
if yych <= 0x39:
yycursor += 1
yystate = 10
continue
yystate = 5
continue
case _:
raise "internal lexer error"
assert parse(b"23.34\0") == SemVer(23, 34, 0)
assert parse(b"1.2.99999\0") == SemVer(1, 2, 99999)
assert parse(b"1.a\0") == None
|