diff options
Diffstat (limited to 'lib/front.ml')
| -rw-r--r-- | lib/front.ml | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/front.ml b/lib/front.ml new file mode 100644 index 0000000..7cacc20 --- /dev/null +++ b/lib/front.ml @@ -0,0 +1,14 @@ +let parse_string source = + let lexbuf = Lexing.from_string source in + match Parser.program Lexer.token lexbuf with + | statements -> Ok statements + | exception Lexer.Error message -> + let position = lexbuf.Lexing.lex_curr_p in + Error + (Printf.sprintf "lexical error at line %d: %s" + position.Lexing.pos_lnum message) + | exception Parser.Error -> + let position = lexbuf.Lexing.lex_curr_p in + Error + (Printf.sprintf "syntax error at line %d, before %S" + position.Lexing.pos_lnum (Lexing.lexeme lexbuf)) |
