Skip to content

Instantly share code, notes, and snippets.

@melwyn95
Created December 6, 2020 05:31
Show Gist options
  • Save melwyn95/82d91d05bdbe81714dbf301a7b5ed758 to your computer and use it in GitHub Desktop.
Save melwyn95/82d91d05bdbe81714dbf301a7b5ed758 to your computer and use it in GitHub Desktop.
open Angstrom;
type line =
| NewLine
| PassPort(string);
let newLine = char('\n') *> return(NewLine);
let passPort =
take_while(char => {char != '\n'}) >>= (s => return(PassPort(s)));
let parse = sep_by(newLine, passPort);
let string = "eyr:2021 hgt:168cm hcl:#fffffd pid:180778832 byr:1923 ecl:amb iyr:2019 cid:241
hcl:#341e13 ecl:lzr eyr:2024 iyr:2014 pid:161cm byr:1991 cid:59 hgt:150cm
iyr:2018 eyr:2027
hgt:153cm
pid:642977294 ecl:gry hcl:#c0946f byr:1999
pid:#534f2e eyr:2022
ecl:amb cid:268
iyr:2028 hcl:2b079f
byr:2008
hgt:185cm
";
let run = () => {
// Util.Fs.readLines("/home/a-c-sreedhar-reddy/aoc/src/lib/DayFour.txt");
let lines =
switch (parse_string(~consume=All, parse, string)) {
| Ok(p) => p
| Error(msg) => failwith(msg)
};
lines
|> List.iter(l =>
switch (l) {
| NewLine => print_newline()
| PassPort(p) => print_endline(p)
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment