Skip to content

Instantly share code, notes, and snippets.

@prepor
Created January 16, 2018 15:52
Show Gist options
  • Select an option

  • Save prepor/6f2f1836dca44101a4667c8ad07bceb0 to your computer and use it in GitHub Desktop.

Select an option

Save prepor/6f2f1836dca44101a4667c8ad07bceb0 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 read_file_or_stdin = function
| None -> In_channel.input_all In_channel.stdin
| Some f -> In_channel.read_all f
let () =
let open Command.Let_syntax in
Command.basic
~summary: "parser, yeeehaa!"
[%map_open
let input = anon (maybe ("INPUT" %: file)) in
fun () ->
let source = read_file_or_stdin 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