mirror of
https://github.com/MorizzG/MLox.git
synced 2025-12-06 04:22:41 +00:00
26 lines
661 B
OCaml
26 lines
661 B
OCaml
|
|
let ( let* ) = Result.bind
|
||
|
|
|
||
|
|
module Lexer = Lexer
|
||
|
|
module Error = Error
|
||
|
|
|
||
|
|
type token = Lexer.token
|
||
|
|
type lox_error = Error.lox_error
|
||
|
|
type lox_value = Nil
|
||
|
|
|
||
|
|
let run (source : string) : (unit, lox_error) result =
|
||
|
|
let* tokens = Error.of_lexer_error (Lexer.tokenize source) in
|
||
|
|
let f token = Printf.printf "%s " (Lexer.show_token token) in
|
||
|
|
Printf.printf "Got %d tokens\n" (List.length tokens);
|
||
|
|
List.iter f tokens;
|
||
|
|
print_endline "";
|
||
|
|
Ok ()
|
||
|
|
|
||
|
|
let runRepl () : unit =
|
||
|
|
try
|
||
|
|
while true do
|
||
|
|
print_string "> ";
|
||
|
|
let line = read_line () in
|
||
|
|
let result = run line in
|
||
|
|
Result.iter_error Error.print_error result
|
||
|
|
done
|
||
|
|
with End_of_file -> ()
|