Skip to content

Commit

Permalink
Dev Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Apr 12, 2015
1 parent 4d139e4 commit 7f4cd27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions application/libraries/ExpressionManager/Parser.php
Expand Up @@ -38,12 +38,13 @@ public function parse($string) {
$this->tokenizer = new Tokenizer();
$tokens = $this->tokenizer->tokenize($string);
$stack = new Stack();
while($this->parseExpression($tokens, $stack)) {}
$color = isset($this->error['token']) ? '#ff0000' : '#00ff00';
$result = $this->parseExpression($tokens, $stack) && $tokens->end();
$color = !$result ? '#ff0000' : '#00ff00';
echo "<pre style='background-color: $color;'>";
echo "$string\n";
if (isset($this->error['token'])) {
echo "Error in expression, expected {$this->error['expected']} got {$this->error['token']->type}\n";
if (!$result) {
$got = isset($this->error['token']) ? $this->error['token']->type: 'NULL';
echo "Error in expression, expected {$this->error['expected']} got {$got}\n";
}
$parts = [];
foreach($tokens->getItems() as $token) {
Expand All @@ -55,7 +56,9 @@ public function parse($string) {
}
echo implode(' ', $parts) . "\n";
echo '</pre>';
return $stack->pop();
if ($result) {
return $stack->pop();
}
}


Expand All @@ -66,7 +69,7 @@ public function parse($string) {
* @param array $stack
*/
protected function parseExpression(TokenStream $tokens, Stack $stack) {
echo "Parsing {$tokens->getRest()}\n";
// echo "Parsing {$tokens->getRest()}\n";
return $this->parseLogicExpression($tokens, $stack);
}

Expand Down Expand Up @@ -247,6 +250,8 @@ protected function parseUnaryExpression(TokenStream $tokens, Stack $stack, $type
*/
protected function parseFunc(TokenStream $tokens, Stack $stack)
{
echo "Parsing function .. {$tokens->getRest()}\n";
;
if ((
$tokens->begin() && $stack->begin()
&& $this->parseToken('WORD', $tokens, $stack, 'FUNC')
Expand Down
4 changes: 4 additions & 0 deletions application/libraries/ExpressionManager/Stack.php
Expand Up @@ -45,4 +45,8 @@ public function commit() {
$this->transactions->pop();
return true;
}

public function count() {
return count($this->items);
}
}

0 comments on commit 7f4cd27

Please sign in to comment.