Skip to content

Instantly share code, notes, and snippets.

@prepor
Created January 5, 2018 09:55
Show Gist options
  • Save prepor/e43e1107e0d41fd6015b66378df24d8c to your computer and use it in GitHub Desktop.
Save prepor/e43e1107e0d41fd6015b66378df24d8c to your computer and use it in GitHub Desktop.
open! Core
let format_error = function
| `NoInput -> "No input to parse"
| `SyntaxError(file, line, col) -> sprintf "Syntax error in namespace %s at line %i column %i" file (line + 1) col
let () =
let open Command.Let_syntax in
Command.basic
~summary: "parser, yeeehaa!"
[%map_open
let input = anon ("INPUT" %: file) in
fun () ->
let source = In_channel.read_all input in
match Orcml.parse source with
| Ok(parsed) ->
printf "Parsed:\n%s\n" (Orcml.sexp_of_ast parsed |> Sexp.to_string_hum)
| Error(err) ->
printf "Parser error: %s\n" (format_error err)
]
|> Command.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment