mirror of
https://github.com/MorizzG/MLox.git
synced 2025-12-06 04:22:41 +00:00
moved for loop to separate Stmt and added continue
This commit is contained in:
parent
957783a926
commit
be28dad67e
6 changed files with 113 additions and 61 deletions
17
lib/error.ml
17
lib/error.ml
|
|
@ -21,20 +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 runtime_error = { pos : code_pos; msg : string; is_break : bool }
|
||||
(* type runtime_error = { pos : code_pos; msg : string; type_ : runtime_error_type } *)
|
||||
type runtime_error = Error of { pos : code_pos; msg : string } | Break | Continue
|
||||
|
||||
module RuntimeError = struct
|
||||
type t = parser_error
|
||||
|
||||
let make (pos : code_pos) (msg : string) : runtime_error = { pos; msg; is_break = false }
|
||||
|
||||
let break () : runtime_error =
|
||||
let pos = { line = -1; col = -1 } in
|
||||
let msg = "" in
|
||||
{ pos; msg; is_break = true }
|
||||
let make (pos : code_pos) (msg : string) : runtime_error = Error { pos; msg }
|
||||
let break () : runtime_error = Break
|
||||
let continue () : runtime_error = Continue
|
||||
|
||||
let print (e : runtime_error) =
|
||||
Printf.printf "RuntimeError at line %d, column %d: %s\n" e.pos.line e.pos.col e.msg
|
||||
match e with
|
||||
| Error { pos; msg } ->
|
||||
Printf.printf "RuntimeError at line %d, column %d: %s\n" pos.line pos.col msg
|
||||
| Break | Continue -> assert false
|
||||
end
|
||||
|
||||
type lox_error =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue