This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
let () = Calc.Cli.main ()
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(public_name calc)
|
||||
(libraries calc))
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
let rec eval = function Ast.Int n -> n | Add (a, b) -> eval a + eval b
|
||||
|
||||
let info = Cmdliner.Cmd.info "calc"
|
||||
|
||||
let eval_lb lb =
|
||||
let e = Parser.main Lexer.token lb in
|
||||
Printf.printf "%d\n" (eval e)
|
||||
|
||||
let repl () =
|
||||
while true do
|
||||
Printf.printf ">> %!";
|
||||
let lb = Lexing.from_channel Stdlib.stdin in
|
||||
eval_lb lb
|
||||
done
|
||||
|
||||
let term =
|
||||
let open Cmdliner.Term.Syntax in
|
||||
let+ expr_opt =
|
||||
let open Cmdliner.Arg in
|
||||
value & opt (some string) None & info [ "e" ]
|
||||
in
|
||||
match expr_opt with
|
||||
| Some s -> eval_lb (Lexing.from_string s)
|
||||
| None -> repl ()
|
||||
|
||||
let cmd = Cmdliner.Cmd.v info term
|
||||
let main () = Cmdliner.Cmd.eval cmd |> Stdlib.exit
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(library
|
||||
(name calc)
|
||||
(libraries cmdliner))
|
||||
|
||||
(ocamllex lexer)
|
||||
|
||||
(menhir
|
||||
(modules parser))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ calc -e '1+2'
|
||||
3
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(cram
|
||||
(deps %{bin:calc}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue