Skip to content

Commit

Permalink
Use a binding operator to try parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon committed Sep 8, 2021
1 parent 81e6941 commit 99076af
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,14 @@ let parse_as_branch s =

let parse_as_pr s = Option.map github_pr (Pull_request.parse s)

let ( let/ ) x f = match x with Some r -> Ok r | None -> f ()

let parse s =
match parse_as_branch_url s with
| Some r -> Ok r
| None -> (
match parse_as_pr_url s with
| Some r -> Ok r
| None -> (
match parse_as_branch s with
| Some r -> Ok r
| None -> (
match parse_as_pr s with Some r -> Ok r | None -> Error `Unknown))
)
let/ () = parse_as_branch_url s in
let/ () = parse_as_pr_url s in
let/ () = parse_as_branch s in
let/ () = parse_as_pr s in
Error `Unknown

let pp ppf = function
| Github_branch branch ->
Expand Down

0 comments on commit 99076af

Please sign in to comment.