Created
January 16, 2018 15:52
-
-
Save prepor/6f2f1836dca44101a4667c8ad07bceb0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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