예제 #1
0
파일: fammel.php 프로젝트: rgigger/zinc
 function parse($input)
 {
     try {
         global $LINE;
         $tok = new Tokeniser($input);
         $parser = new parse_engine($this->_haml);
         $parser->reset();
         $tokens = $tok->get_all_tokens();
         $tokens = array_merge(array(new Token('INDENT', 0)), $tokens);
         foreach ($tokens as $t) {
             $LINE = $this->_line = $t->line();
             $parser->eat($t->type(), $t->value());
         }
         $parser->eat_eof();
         return true;
     } catch (parse_error $e) {
         $token = $value = '';
         preg_match('/\\((.*?)\\)\\((.*?)\\)/', $e->getMessage(), $matches);
         if ($matches) {
             $token = $matches[1];
             $value = $matches[2];
             $message = "Parse error: unexpected {$token} ('{$value}')";
         } else {
             $message = $e->getMessage();
         }
         $message .= " at line {$this->_line}";
         if ($this->_file) {
             $message .= " in {$this->_file}";
         }
         $message .= "\n";
         throw new FammelParseException($message, $this->_line, $token, $value);
     }
 }
예제 #2
0
<?php

declare (strict_types=1);
namespace ajf\pico8bot;

require_once __DIR__ . "/vendor/autoload.php";
if ($argc < 3) {
    die("gib 2 arguments pl0x\n");
}
$expr = $argv[1];
$out = $argv[2];
$tokeniser = new Tokeniser();
$tokens = $tokeniser->tokenise($expr);
$parser = new Parser();
$ast = $parser->parse($tokens);
$compiler = new Compiler();
$closure = $compiler->compile($ast);
$renderer = new Renderer($closure);
$image = $renderer->renderFrame(0, 320, 320);
\imageGIF($image, $out);
예제 #3
0
 function it_should_return_an_array_of_tokens()
 {
     $tok = new Tokeniser("%tag .class #id :attr-name\n");
     $tokens = $tok->get_all_tokens();
     $this->spec(is_array($tokens))->should->beTrue();
     $this->spec(count($tokens))->should->equal(5);
 }
예제 #4
0
파일: Phil.php 프로젝트: pogotc/phil
 public function run($input)
 {
     $tokens = $this->tokeniser->parse($input);
     $ast = $this->parser->parse($tokens);
     return $this->evaluator->evaluate($ast);
 }