create angstrom wrapper in Utils for int parser
and other common parsers for the future
This commit is contained in:
parent
8fe7e77b52
commit
63bad67c1b
|
|
@ -7,13 +7,8 @@ module Packet = struct
|
|||
[@@deriving show { with_path = false }]
|
||||
|
||||
let of_str line =
|
||||
let open Angstrom in
|
||||
let int =
|
||||
take_while1 (function
|
||||
| '0' .. '9' -> true
|
||||
| _ -> false)
|
||||
>>= fun s -> return @@ I (int_of_string s) <?> "int"
|
||||
in
|
||||
let open Utils.Parse in
|
||||
let int = int >>= fun i -> return @@ I i in
|
||||
let packet =
|
||||
fix (fun packet ->
|
||||
let lb, delimited, rb = char '[', sep_by (char ','), char ']' in
|
||||
|
|
|
|||
12
src/utils.ml
12
src/utils.ml
|
|
@ -9,3 +9,15 @@ let lines_of_input day =
|
|||
let path = Printf.sprintf "%s/day%d.tt" base_path day in
|
||||
IO.(with_in path read_lines_l)
|
||||
;;
|
||||
|
||||
module Parse = struct
|
||||
include Angstrom
|
||||
|
||||
let int =
|
||||
take_while1 (function
|
||||
| '0' .. '9' -> true
|
||||
| _ -> false)
|
||||
>>| int_of_string
|
||||
<?> "int"
|
||||
;;
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user