Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Praspel\Bin\Shell Class Reference
Inheritance diagram for Hoa\Praspel\Bin\Shell:

Public Member Functions

 main ()
 
 usage ()
 
- Public Member Functions inherited from Hoa\Console\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 getOption (&$optionValue, $short=null)
 
 setOptions (Array $options)
 
 makeUsageOptionsList (Array $definitions=[])
 
 resolveOptionAmbiguity (Array $solutions)
 
 status ($text, $status)
 
 readLine ($prefix=null)
 
 readPassword ($prefix=null)
 
- Public Member Functions inherited from Hoa\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 construct ()
 

Protected Attributes

 $options
 
- Protected Attributes inherited from Hoa\Console\Dispatcher\Kit
 $options = null
 
 $_options = null
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Console\Dispatcher\Kit
 $parser = null
 
- Public Attributes inherited from Hoa\Dispatcher\Kit
 $router = null
 
 $dispatcher = null
 
 $view = null
 
 $data = null
 

Detailed Description

Class .

Interactive Praspel shell.

Definition at line 55 of file Shell.php.

Member Function Documentation

Hoa\Praspel\Bin\Shell::main ( )

The entry method.

Returns
int

Definition at line 74 of file Shell.php.

75  {
76  while (false !== $c = $this->getOption($v)) {
77  switch ($c) {
78  case 'h':
79  case '?':
80  return $this->usage();
81 
82  case '__ambiguous':
83  $this->resolveOptionAmbiguity($v);
84 
85  break;
86  }
87  }
88 
89  Realdom::setDefaultSampler(new Math\Sampler\Random());
90 
91  $compiler = Compiler\Llk::load(
92  new File\Read('hoa://Library/Praspel/Grammar.pp')
93  );
94  $interpreter = new Praspel\Visitor\Interpreter();
95  $dump = new Praspel\Visitor\Compiler();
96  $interpreter->visit($compiler->parse('@requires;'));
97  $words = [];
98 
99  from('Hoathis or Hoa')
100  -> foreachImport('Realdom.*', function ($classname) use (&$words) {
101  $class = new \ReflectionClass($classname);
102 
103  if ($class->isSubclassOf('\Hoa\Realdom')) {
104  $words[] = $classname::NAME;
105  }
106 
107  return;
108  });
109 
110  $readline = new Console\Readline();
111  $readline->setAutocompleter(
112  new Console\Readline\Autocompleter\Word($words)
113  );
114 
115  $expression = '.h';
116 
117  do {
118  try {
119  if ('.' === $expression[0]) {
120  @list($expression, $tail) = explode(' ', $expression);
121  }
122 
123  switch ($expression) {
124  case '.h':
125  case '.help':
126  echo
127  'Usage:', "\n",
128  ' .h[elp] to print this help;', "\n",
129  ' .c[lear] to clear the screen;', "\n",
130  ' .v[ariables] to print all variables;', "\n",
131  ' .s[ample] to sample a value of a variable;', "\n",
132  ' .u[nset] to unset a variable;', "\n",
133  ' .d[ump] to dump the tree of the expression;', "\n",
134  ' .q[uit] to quit.', "\n";
135 
136  break;
137 
138  case '.c':
139  case '.clear':
140  Console\Cursor::clear('↕');
141 
142  break;
143 
144  case '.v':
145  case '.variables':
146  foreach ($interpreter->getClause() as $variable) {
147  echo
148  $variable->getName(), ': ',
149  $variable->getHeld()->toPraspel(), "\n";
150  }
151 
152  break;
153 
154  case '.s':
155  case '.sample':
156  if (null === $tail) {
157  echo 'You must precise a variable name.', "\n";
158 
159  break;
160  }
161 
162  $_clause = $interpreter->getClause();
163 
164  if (!isset($_clause[$tail])) {
165  echo 'Variable ', $tail, ' does not exist.', "\n";
166 
167  break;
168  }
169 
170  $_variable = $_clause[$tail];
171  var_export($_variable->sample());
172  echo "\n";
173  $_variable->reset();
174 
175  break;
176 
177  case '.u':
178  case '.unset':
179  if (null === $tail) {
180  echo 'You must precise a variable name.', "\n";
181 
182  break;
183  }
184 
185  $_clause = $interpreter->getClause();
186  unset($_clause[$tail]);
187 
188  break;
189 
190  case '.d':
191  case '.dump':
192  echo $dump->visit($interpreter->getRoot());
193 
194  break;
195 
196  case '.q':
197  case '.quit':
198  break 2;
199 
200  default:
201  if (null === $expression) {
202  break;
203  }
204 
205  $interpreter->visit(
206  $compiler->parse($expression, 'expression')
207  );
208 
209  break;
210 
211  }
212  } catch (\Exception $e) {
213  echo $e->getMessage(), "\n";
214  }
215 
216  echo "\n";
217  } while (false !== $expression = $readline->readLine('> '));
218 
219  return;
220  }
static setDefaultSampler(Math\Sampler $sampler)
Definition: Realdom.php:529
static clear($parts= 'all')
Definition: Cursor.php:271
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190

Here is the call graph for this function:

Hoa\Praspel\Bin\Shell::usage ( )

The command usage.

Returns
int

Definition at line 227 of file Shell.php.

228  {
229  echo
230  'Usage : praspel:shell <options> [expression]', "\n",
231  'Options :', "\n",
232  $this->makeUsageOptionsList([
233  'help' => 'This help.'
234  ]), "\n";
235 
236  return;
237  }
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa\Praspel\Bin\Shell::$options
protected
Initial value:

Definition at line 62 of file Shell.php.


The documentation for this class was generated from the following file: