mirror of
https://github.com/MorizzG/MLox.git
synced 2025-12-06 04:22:41 +00:00
moved exprs into nodes with code position
This commit is contained in:
parent
485ecebdf3
commit
a8290a4104
6 changed files with 155 additions and 49 deletions
18
lib/error.ml
18
lib/error.ml
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue