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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
(* Generated by re2ocaml *)
(* re2ocaml $INPUT -o $OUTPUT -i *)
open String
type state = {
yyinput: string;
mutable yycursor: int;
mutable yymarker: int;
yylimit: int;
yyend: int;
}
exception Fill
let rec yy0 (yyrecord : state) : int =
if (yyrecord.yylimit <= yyrecord.yycursor) then (
(yy8 [@tailcall]) yyrecord
) else (
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
yyrecord.yycursor <- yyrecord.yycursor + 1;
match yych with
| 'a' -> (yy3 [@tailcall]) yyrecord
| 'b' -> (yy4 [@tailcall]) yyrecord
| 'c' -> (yy5 [@tailcall]) yyrecord
| _ -> (yy1 [@tailcall]) yyrecord
)
and yy1 (yyrecord : state) : int =
(yy2 [@tailcall]) yyrecord
and yy2 (yyrecord : state) : int =
1
and yy3 (yyrecord : state) : int =
if (yyrecord.yylimit <= yyrecord.yycursor) then (yy9 [@tailcall]) yyrecord
else 3
and yy4 (yyrecord : state) : int =
4
and yy5 (yyrecord : state) : int =
yyrecord.yymarker <- yyrecord.yycursor;
if (yyrecord.yylimit <= yyrecord.yycursor) then (
(yy10 [@tailcall]) yyrecord
) else (
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy6 [@tailcall]) yyrecord
| _ -> (yy2 [@tailcall]) yyrecord
)
and yy6 (yyrecord : state) : int =
if (yyrecord.yylimit <= yyrecord.yycursor) then (
(yy10 [@tailcall]) yyrecord
) else (
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy6 [@tailcall]) yyrecord
| _ -> (yy7 [@tailcall]) yyrecord
)
and yy7 (yyrecord : state) : int =
yyrecord.yycursor <- yyrecord.yymarker;
(yy2 [@tailcall]) yyrecord
and yy8 (yyrecord : state) : int =
0
and yy9 (yyrecord : state) : int =
2
and yy10 (yyrecord : state) : int =
5
and lex_simple (yyrecord : state) : int =
(yy0 [@tailcall]) yyrecord
let test_simple str ret =
let st = {yyinput = str; yycursor = 0; yymarker = 0; yylimit = length str - 1; yyend = -1} in
let result = try lex_simple st with Fill -> -1 in
if not (result = ret) then raise (Failure "error simple")
let rec yy11 (yyrecord : state) : int =
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'a' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy14 [@tailcall]) yyrecord
| 'b' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy15 [@tailcall]) yyrecord
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy16 [@tailcall]) yyrecord
| _ ->
if (yyrecord.yylimit <= yyrecord.yycursor) then (
if (false) then (yy11 [@tailcall]) yyrecord
else (yy19 [@tailcall]) yyrecord
) else (
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy12 [@tailcall]) yyrecord
)
and yy12 (yyrecord : state) : int =
(yy13 [@tailcall]) yyrecord
and yy13 (yyrecord : state) : int =
1
and yy14 (yyrecord : state) : int =
if (yyrecord.yycursor == yyrecord.yylimit) then (yy20 [@tailcall]) yyrecord
else 3
and yy15 (yyrecord : state) : int =
4
and yy16 (yyrecord : state) : int =
yyrecord.yymarker <- yyrecord.yycursor;
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy17 [@tailcall]) yyrecord
| _ ->
if (yyrecord.yylimit <= yyrecord.yycursor) then (
if (false) then (yy16 [@tailcall]) yyrecord
else (yy21 [@tailcall]) yyrecord
) else (
(yy13 [@tailcall]) yyrecord
)
and yy17 (yyrecord : state) : int =
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy17 [@tailcall]) yyrecord
| _ ->
if (yyrecord.yylimit <= yyrecord.yycursor) then (
if (false) then (yy17 [@tailcall]) yyrecord
else (yy21 [@tailcall]) yyrecord
) else (
(yy18 [@tailcall]) yyrecord
)
and yy18 (yyrecord : state) : int =
yyrecord.yycursor <- yyrecord.yymarker;
(yy13 [@tailcall]) yyrecord
and yy19 (yyrecord : state) : int =
0
and yy20 (yyrecord : state) : int =
2
and yy21 (yyrecord : state) : int =
5
and lex_eof (yyrecord : state) : int =
(yy11 [@tailcall]) yyrecord
let test_eof str ret =
let st = {yyinput = str; yycursor = 0; yymarker = 0; yylimit = length str - 1; yyend = -1} in
let result = try lex_eof st with Fill -> -1 in
if not (result = ret) then raise (Failure "error eof")
let yymaxfill = 2
let rec yy22 (yyrecord : state) : int =
if (yyrecord.yycursor == yyrecord.yyend) then (
(yy30 [@tailcall]) yyrecord
) else (
if ((yyrecord.yylimit - yyrecord.yycursor) < 2) then raise Fill;
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
yyrecord.yycursor <- yyrecord.yycursor + 1;
match yych with
| 'a' -> (yy25 [@tailcall]) yyrecord
| 'b' -> (yy26 [@tailcall]) yyrecord
| 'c' -> (yy27 [@tailcall]) yyrecord
| _ -> (yy23 [@tailcall]) yyrecord
)
and yy23 (yyrecord : state) : int =
(yy24 [@tailcall]) yyrecord
and yy24 (yyrecord : state) : int =
1
and yy25 (yyrecord : state) : int =
if (yyrecord.yycursor == yyrecord.yyend) then (yy31 [@tailcall]) yyrecord
else 3
and yy26 (yyrecord : state) : int =
4
and yy27 (yyrecord : state) : int =
yyrecord.yymarker <- yyrecord.yycursor;
if (yyrecord.yycursor == yyrecord.yyend) then (
(yy32 [@tailcall]) yyrecord
) else (
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy28 [@tailcall]) yyrecord
| _ -> (yy24 [@tailcall]) yyrecord
)
and yy28 (yyrecord : state) : int =
if (yyrecord.yycursor == yyrecord.yyend) then (
(yy32 [@tailcall]) yyrecord
) else (
if (yyrecord.yylimit <= yyrecord.yycursor) then raise Fill;
let yych = unsafe_get yyrecord.yyinput yyrecord.yycursor in
match yych with
| 'c' ->
yyrecord.yycursor <- yyrecord.yycursor + 1;
(yy28 [@tailcall]) yyrecord
| _ -> (yy29 [@tailcall]) yyrecord
)
and yy29 (yyrecord : state) : int =
yyrecord.yycursor <- yyrecord.yymarker;
(yy24 [@tailcall]) yyrecord
and yy30 (yyrecord : state) : int =
0
and yy31 (yyrecord : state) : int =
2
and yy32 (yyrecord : state) : int =
5
and lex_scc (yyrecord : state) : int =
(yy22 [@tailcall]) yyrecord
let test_scc str ret =
let buf = cat str (make yymaxfill '\x00') in
let st = {yyinput = buf; yycursor = 0; yymarker = 0; yylimit = length buf; yyend = length str - 1} in
let result = try lex_scc st with Fill -> -1 in
if not (result = ret) then raise (Failure "error scc")
let test str ret =
test_simple str ret;
test_eof str ret;
test_scc str ret
let main () =
test "\x00" 0;
test "a\x00" 2;
test "ax\x00" 3;
test "b\x00" 4;
test "bx\x00" 4;
test "ccc\x00" 5
let _ = main ()
|