Skip to content

Instantly share code, notes, and snippets.

@PollRobots
Created January 18, 2013 05:44
Show Gist options
  • Select an option

  • Save PollRobots/4562607 to your computer and use it in GitHub Desktop.

Select an option

Save PollRobots/4562607 to your computer and use it in GitHub Desktop.
| ZeroOrMore x ->
let rec parseList off =
seq {
match parse off x with
| (Unmatched, _) -> ()
| (y, z) -> yield (y, z)
yield! parseList z
}
let s = List.ofSeq <| parseList offset
if List.isEmpty s then (EmptyMatch, offset)
else (Production <| List.map fst s, snd <| List.maxBy snd s)
| OneOrMore x ->
let rec parseList off =
seq {
match parse off x with
| (Unmatched, _) -> ()
| (y, z) -> yield (y, z)
yield! parseList z
}
let s = List.ofSeq <| parseList offset
if List.isEmpty s then (Unmatched, offset)
else (Production <| List.map fst s, snd <| List.maxBy snd s)
| Optional x ->
match parse offset x with
| (Unmatched, _) -> (EmptyMatch, offset)
| y -> y
| And x ->
match parse offset x with
| (Unmatched, _) -> (Unmatched, offset)
| _ -> (EmptyMatch, offset)
| Not x ->
match parse offset x with
| (Unmatched, _) -> (EmptyMatch, offset)
| _ -> (Unmatched, offset)
parse 0 grammar.[start]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment