From 5d227bcd0055d02e1d49a3dcd27e80a756923d5b Mon Sep 17 00:00:00 2001 From: Malte Voos Date: Sun, 23 Jun 2024 23:31:59 +0200 Subject: split code into smaller libraries and make a better repl --- src/parser/Parser.ml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/parser/Parser.ml (limited to 'src/parser/Parser.ml') diff --git a/src/parser/Parser.ml b/src/parser/Parser.ml new file mode 100644 index 0000000..4593d82 --- /dev/null +++ b/src/parser/Parser.ml @@ -0,0 +1,13 @@ +let parse_expr (s : string) : Ast.expr = + let lexbuf = Lexing.from_string s in + let string_source : Asai.Range.string_source = { + title = None; + content = s; + } in + let source = `String string_source in + Eff.run ~env:source @@ fun () -> + try Grammar.start_expr Lexer.token lexbuf with + | Lexer.IllegalCharacter illegal_char -> + Reporter.illegal_character ~loc:(Asai.Range.of_lexbuf ~source lexbuf) illegal_char + | Grammar.Error -> + Reporter.syntax_error ~loc:(Asai.Range.of_lexbuf ~source lexbuf) -- cgit 1.4.1