From 27e9ddee53b8fa43725f951434404691d8012190 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sun, 12 Jul 2026 18:27:44 -0300 Subject: language server over stdio, emacs mode with repl and eglot wiring --- lib/front.ml | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'lib/front.ml') diff --git a/lib/front.ml b/lib/front.ml index 7cacc20..b728825 100644 --- a/lib/front.ml +++ b/lib/front.ml @@ -1,14 +1,27 @@ -let parse_string source = +type error = { line : int; column : int; message : string } + +let position lexbuf = + let p = lexbuf.Lexing.lex_curr_p in + (p.Lexing.pos_lnum, p.Lexing.pos_cnum - p.Lexing.pos_bol) + +let parse 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) + let line, column = position lexbuf in + Error { line; column; message } | exception Parser.Error -> - let position = lexbuf.Lexing.lex_curr_p in + let line, column = position lexbuf in Error - (Printf.sprintf "syntax error at line %d, before %S" - position.Lexing.pos_lnum (Lexing.lexeme lexbuf)) + { + line; + column; + message = Printf.sprintf "syntax error before %S" (Lexing.lexeme lexbuf); + } + +let parse_string source = + match parse source with + | Ok statements -> Ok statements + | Error { line; message; _ } -> + Error (Printf.sprintf "line %d: %s" line message) -- cgit v1.2.3