-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
100 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
module Arg = Cmdliner.Arg | ||
module Cmd = Cmdliner.Cmd | ||
module Term = Cmdliner.Term | ||
|
||
let ( & ), ( $ ) = Arg.(( & )), Cmdliner.Term.(( $ )) | ||
|
||
let year = | ||
let doc = "Year to run" in | ||
Arg.value & Arg.opt Arg.int 2022 & Arg.info [ "y"; "year" ] ~docv:"YEAR" ~doc | ||
let year_arg = | ||
Command.Arg_type.create (fun year_str -> | ||
match Int.of_string_opt year_str with | ||
| Some year when year = 2022 || year = 2023 -> year | ||
| _ -> failwith "Year must be [2022, 2023]") | ||
;; | ||
|
||
let day = | ||
let doc = "Day to run (1 - 25)" in | ||
let days = List.map ~f:(fun d -> Int.to_string d, d) (List.init 25 ~f:Int.succ) in | ||
Arg.required | ||
& Arg.opt (Arg.some & Arg.enum days) None | ||
& Arg.info [ "d"; "day" ] ~docv:"DAY" ~doc | ||
let day_arg = | ||
Command.Arg_type.create (fun day_str -> | ||
match Int.of_string_opt day_str with | ||
| Some day when 1 <= day && day <= 25 -> day | ||
| _ -> failwith "Day must be between 1 - 25") | ||
;; | ||
|
||
let part = | ||
let doc = "Part to run (1 or 2)" in | ||
let parts = [ "1", 1; "2", 2 ] in | ||
Arg.required | ||
& Arg.opt (Arg.some & Arg.enum parts) None | ||
& Arg.info [ "p"; "part" ] ~docv:"PART" ~doc | ||
let part_arg = | ||
Command.Arg_type.create (fun part_str -> | ||
match Int.of_string_opt part_str with | ||
| Some part when part = 1 || part = 2 -> part | ||
| _ -> failwith "Part must be 1 or 2") | ||
;; | ||
|
||
let aoc_t = Term.const Runner.run $ year $ day $ part | ||
|
||
let cmd = | ||
let doc = "Run aoc solution" in | ||
let info = Cmd.info "aoc" ~version:"1.0.0" ~doc in | ||
Cmd.v info aoc_t | ||
let command_param = | ||
let open Command.Let_syntax in | ||
let module P = Command.Param in | ||
let%map year = | ||
P.flag | ||
"year" | ||
(P.optional_with_default 2022 year_arg) | ||
~doc:"int year to run (default: 2022)" | ||
~aliases:[ "y" ] | ||
and day = | ||
P.flag "day" (P.required day_arg) ~aliases:[ "d" ] ~doc:"int day to run (1 - 25)" | ||
and part = | ||
P.flag "part" (P.required part_arg) ~aliases:[ "p" ] ~doc:"int part to run (1 or 2)" | ||
in | ||
fun _ -> Runner.run year day part | ||
;; | ||
|
||
let () = Stdlib.exit (Cmd.eval cmd) | ||
let () = Command_unix.run (Command.basic command_param ~summary:"Run aoc solution") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,6 @@ | |
|
||
angstrom | ||
core | ||
cmdliner | ||
core_unix | ||
ppx_jane | ||
re)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
core | ||
year2022 | ||
year2023) | ||
(preprocess | ||
(pps | ||
ppx_jane)) | ||
(flags | ||
-open Core)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
module A = Angstrom | ||
include Angstrom | ||
|
||
module Syntax = struct | ||
module Let_syntax = A.Let_syntax.Let_syntax | ||
module Let_syntax = Angstrom.Let_syntax.Let_syntax | ||
|
||
let ( let+ ) = A.( let+ ) | ||
let ( and+ ) = A.( and+ ) | ||
let ( let* ) = A.( let* ) | ||
let ( let+ ) = ( let+ ) | ||
let ( and+ ) = ( and+ ) | ||
let ( let* ) = ( let* ) | ||
|
||
let ( >>| ), ( *> ), ( <* ), ( <|> ), ( <$> ) = | ||
A.(( >>| ), ( *> ), ( <* ), ( <|> ), ( <$> )) | ||
( >>| ), ( *> ), ( <* ), ( <|> ), ( <$> ) | ||
;; | ||
|
||
let ( $> ) p a = p >>| const a | ||
let ( <$ ) a p = p >>| const a | ||
end | ||
|
||
open Syntax | ||
|
||
let integerP = | ||
let integer = | ||
let open Syntax in | ||
let%map tokens = | ||
A.take_while1 (function | ||
take_while1 (function | ||
| '0' .. '9' -> true | ||
| _ -> false) | ||
in | ||
Int.of_string tokens | ||
;; | ||
|
||
let parse_exn parser input = | ||
input |> parse_string ~consume:Prefix parser |> Result.ok_or_failwith | ||
;; | ||
|
||
let parse_all_exn parser input = | ||
input |> parse_string ~consume:All parser |> Result.ok_or_failwith | ||
;; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters