Example #1
0
File: Neon.php Project: rezon/sugi
 /**
  * Decodes a NEON string.
  * @param  string
  * @return mixed
  */
 public static function decode($input)
 {
     if (!is_string($input)) {
         throw new \InvalidArgumentException("Argument must be a string, " . gettype($input) . " given.");
     }
     if (!self::$re) {
         self::$re = '~(' . implode(')|(', self::$patterns) . ')~Ami';
     }
     $parser = new self();
     $parser->tokenize($input);
     $res = $parser->parse(0);
     while (isset($parser->tokens[$parser->n])) {
         if ($parser->tokens[$parser->n][0] === "\n") {
             $parser->n++;
         } else {
             $parser->error();
         }
     }
     return $res;
 }
 /**
  * Shortcut to instantiate, tokenize, parse and evaluate
  *
  * @param string $expression
  * @param array $values
  * @return boolean
  */
 public static function run($expression, $values)
 {
     $evaluator = new self();
     $evaluator->parse($evaluator->tokenize($expression));
     return $evaluator->evaluate($values);
 }