diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-07-12 18:27:44 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-07-12 18:27:44 -0300 |
| commit | 27e9ddee53b8fa43725f951434404691d8012190 (patch) | |
| tree | ea78559da973d4628cf135096488d55c7b7cd35e /lib/front.ml | |
| parent | 257f5288a486740187e44b6ef4cadaad7166930e (diff) | |
| download | SOL-27e9ddee53b8fa43725f951434404691d8012190.tar.gz SOL-27e9ddee53b8fa43725f951434404691d8012190.zip | |
language server over stdio, emacs mode with repl and eglot wiring
Diffstat (limited to 'lib/front.ml')
| -rw-r--r-- | lib/front.ml | 29 |
1 files changed, 21 insertions, 8 deletions
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) |
