madlisp/repl.php

33 lines
744 B
PHP
Raw Normal View History

2020-05-26 08:43:59 +00:00
<?php
2020-05-28 04:55:58 +00:00
require('bootstrap.php');
2020-05-27 09:27:47 +00:00
2020-06-04 09:46:23 +00:00
list($lisp, $rootEnv) = ml_get_lisp();
2020-06-06 13:12:45 +00:00
// Read history
$historyFile = $_SERVER['HOME'] . '/.madlisp_history';
if (is_readable($historyFile)) {
readline_read_history($historyFile);
}
2020-06-04 09:46:23 +00:00
// Create new env for user definitions
2020-06-06 08:31:09 +00:00
$userEnv = new MadLisp\Env('repl', $rootEnv);
2020-05-26 08:43:59 +00:00
while (true) {
$input = readline('> ');
try {
2020-06-04 09:46:23 +00:00
$lisp->rep($input, $userEnv);
2020-06-06 13:12:45 +00:00
if ($input) {
readline_add_history($input);
readline_write_history($historyFile);
}
2020-05-28 06:59:36 +00:00
} catch (MadLisp\MadLispException $ex) {
2020-05-26 08:43:59 +00:00
print('error: ' . $ex->getMessage());
2020-06-02 02:51:21 +00:00
} catch (TypeError $ex) {
print('error: invalid argument type: ' . $ex->getMessage());
2020-05-26 08:43:59 +00:00
}
print(PHP_EOL);
}