Skip to content

Instantly share code, notes, and snippets.

@objmagic
Last active December 30, 2015 20:56
Show Gist options
  • Select an option

  • Save objmagic/dca9511ccd92eb57036e to your computer and use it in GitHub Desktop.

Select an option

Save objmagic/dca9511ccd92eb57036e to your computer and use it in GitHub Desktop.
note
let gen () =
let t2pc = ref (fun _ -> assert false) in
let t3pc = ref (fun _ -> assert false) in
let anonpc = ref (fun _ -> assert false) in
let _ = t2pc := fun s ->
let res1 = !t3pc s in
match res1 with
| Success (arr, s) -> Success ((A arr), s)
| Failure _ ->
let res2 = !anonpc s in
match res2 with
| Success (c, s) -> Success ((C c), s)
| Failure _ as f -> f in
let _ = t3pc := fun s ->
let ix = s.index in
let f = Failure s in
if ix < s.length then
if '[' = s.input.[ix] then
let s' = {s with row = s.row + 1; index = ix + 1} in
let res2 = !t2pc s' in
match res2 with
| Success (res3, s'') ->
let ix' = s''.index in
let f' = Failure s'' in
if ix' < s''.length then
if ']' = (s'').input.[ix'] then
Success (res3, {s'' with row = s.row + 1; index = ix' + 1})
else f'
else f'
| Failure _ as f -> f
else f
else f in
let _ = anonpc := fun s ->
let ix = s.index in
let f = Failure s in
if ix < s.length then
if 'c' = s.input.[ix] then Success ('c', {s with row = s.row + 1; index = ix + 1}) else f
else f in
(!t2pc, !t3pc, !anonpc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment