@@ -49,11 +49,17 @@ |
||
49 | 49 | return fgets(STDIN); |
50 | 50 | } |
51 | 51 | |
52 | + /** |
|
53 | + * @param string $input |
|
54 | + */ |
|
52 | 55 | private function isExitCommand($input) |
53 | 56 | { |
54 | 57 | return $input == "exit\n"; |
55 | 58 | } |
56 | 59 | |
60 | + /** |
|
61 | + * @param string $input |
|
62 | + */ |
|
57 | 63 | private function shouldBeProcessed($input) |
58 | 64 | { |
59 | 65 | return !empty($input) && !preg_match('/^;/', $input); |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Desmond; |
3 | 3 | use Desmond\Desmond; |
4 | -use Desmond\data_types\VoidType; |
|
5 | 4 | |
6 | 5 | class Repl |
7 | 6 | { |
@@ -5,57 +5,57 @@ |
||
5 | 5 | |
6 | 6 | class Repl |
7 | 7 | { |
8 | - private $desmond; |
|
9 | - |
|
10 | - public function __construct() |
|
11 | - { |
|
12 | - $this->desmond = new Desmond(); |
|
13 | - } |
|
14 | - |
|
15 | - public function start() |
|
16 | - { |
|
17 | - $this->welcome(); |
|
18 | - do { |
|
19 | - $input = $this->promptForInput(); |
|
20 | - |
|
21 | - if ($this->isExitCommand($input)) { |
|
22 | - exit("Later, guy.\n"); |
|
23 | - } |
|
24 | - |
|
25 | - if ($this->shouldBeProcessed($input)) { |
|
26 | - try { |
|
27 | - $return = $this->desmond->pretty( |
|
28 | - $this->desmond->run($input)); |
|
29 | - } catch (Exception $exception) { |
|
30 | - echo "#! {$exception->getMessage()}\n"; |
|
31 | - continue; |
|
32 | - } |
|
33 | - echo $return . "\n"; |
|
34 | - } |
|
35 | - } while (!feof(STDIN)); |
|
36 | - } |
|
37 | - |
|
38 | - private function welcome() |
|
39 | - { |
|
40 | - echo " |
|
8 | + private $desmond; |
|
9 | + |
|
10 | + public function __construct() |
|
11 | + { |
|
12 | + $this->desmond = new Desmond(); |
|
13 | + } |
|
14 | + |
|
15 | + public function start() |
|
16 | + { |
|
17 | + $this->welcome(); |
|
18 | + do { |
|
19 | + $input = $this->promptForInput(); |
|
20 | + |
|
21 | + if ($this->isExitCommand($input)) { |
|
22 | + exit("Later, guy.\n"); |
|
23 | + } |
|
24 | + |
|
25 | + if ($this->shouldBeProcessed($input)) { |
|
26 | + try { |
|
27 | + $return = $this->desmond->pretty( |
|
28 | + $this->desmond->run($input)); |
|
29 | + } catch (Exception $exception) { |
|
30 | + echo "#! {$exception->getMessage()}\n"; |
|
31 | + continue; |
|
32 | + } |
|
33 | + echo $return . "\n"; |
|
34 | + } |
|
35 | + } while (!feof(STDIN)); |
|
36 | + } |
|
37 | + |
|
38 | + private function welcome() |
|
39 | + { |
|
40 | + echo " |
|
41 | 41 | Copyright 2017, Scott Christianson |
42 | 42 | Version 0.3.0 |
43 | 43 | Welcome to Desmond's REPL.\n\n"; |
44 | - } |
|
45 | - |
|
46 | - private function promptForInput() |
|
47 | - { |
|
48 | - echo '/user λ '; |
|
49 | - return fgets(STDIN); |
|
50 | - } |
|
51 | - |
|
52 | - private function isExitCommand($input) |
|
53 | - { |
|
54 | - return $input == "exit\n"; |
|
55 | - } |
|
56 | - |
|
57 | - private function shouldBeProcessed($input) |
|
58 | - { |
|
59 | - return !empty($input) && !preg_match('/^;/', $input); |
|
60 | - } |
|
44 | + } |
|
45 | + |
|
46 | + private function promptForInput() |
|
47 | + { |
|
48 | + echo '/user λ '; |
|
49 | + return fgets(STDIN); |
|
50 | + } |
|
51 | + |
|
52 | + private function isExitCommand($input) |
|
53 | + { |
|
54 | + return $input == "exit\n"; |
|
55 | + } |
|
56 | + |
|
57 | + private function shouldBeProcessed($input) |
|
58 | + { |
|
59 | + return !empty($input) && !preg_match('/^;/', $input); |
|
60 | + } |
|
61 | 61 | } |