moved exprs into nodes with code position

This commit is contained in:
Moritz Gmeiner 2024-08-17 13:32:59 +02:00
commit a8290a4104
6 changed files with 155 additions and 49 deletions

View file

@ -21,7 +21,21 @@ module ParserError = struct
Printf.printf "ParserError at line %d, column %d: %s\n" e.pos.line e.pos.col e.msg
end
type lox_error = LexerError of lexer_error list | ParserError of parser_error list
type interpreter_error = { pos : code_pos; msg : string }
module InterpreterError = struct
type t = parser_error
let make (pos : code_pos) (msg : string) : interpreter_error = { pos; msg }
let print (e : interpreter_error) =
Printf.printf "InterpreterError at line %d, column %d: %s\n" e.pos.line e.pos.col e.msg
end
type lox_error =
| LexerError of lexer_error list
| ParserError of parser_error list
| InterpreterError of interpreter_error
let print_error (e : lox_error) =
match e with
@ -37,6 +51,8 @@ let print_error (e : lox_error) =
Printf.printf "found %d %s:\n" num_errors
(if num_errors = 1 then "ParserError" else "ParserErrors");
List.iter ParserError.print es
| InterpreterError e -> InterpreterError.print e
let of_lexer_error e = Result.map_error (fun e -> LexerError e) e
let of_parser_error e = Result.map_error (fun e -> ParserError e) e
let of_interpreter_error e = Result.map_error (fun e -> InterpreterError e) e