Esempio n. 1
0
 protected function matchCurrent($type)
 {
     if ($this->lexer->getToken()->type != $type) {
         $this->lexer->debug('parse Error');
         throw new ExtracterException('Parse Error: ' . $type . ' expected aber. ' . $this->lexer->getToken()->type . ' gefunden');
     }
     return $this->lexer->moveNext();
 }
Esempio n. 2
0
    public function testLexerInlineCode()
    {
        $code = <<<'CODE'
<?php
$test = function () { // is allowed
};
?>
CODE;
        $lexer = new Lexer();
        $lexer->setParseWhitespace(TRUE);
        $lexer->init($code);
        // assertToken
        $that = $this;
        $assertToken = function ($type, $value, $moveNext = TRUE) use($that, $lexer) {
            if ($moveNext) {
                $lexer->moveNext();
            }
            $token = $lexer->getToken();
            $that->assertTrue(is_object($token));
            $that->assertEquals($type, $token->type);
            $that->assertEquals($value, $token->value);
        };
        $assertToken('T_OPEN_TAG', "<?php\n", FALSE);
        $assertToken('T_VARIABLE', '$test');
        $assertToken(Lexer::T_PLAIN_WHITESPACE, ' ');
        $assertToken(Lexer::T_EQUAL, '=');
        $assertToken(Lexer::T_PLAIN_WHITESPACE, ' ');
        $assertToken('T_FUNCTION', 'function');
        $assertToken(Lexer::T_PLAIN_WHITESPACE, ' ');
        $assertToken(Lexer::T_BRACE_OPEN, '(');
        $assertToken(Lexer::T_BRACE_CLOSE, ')');
        $assertToken(Lexer::T_PLAIN_WHITESPACE, ' ');
        $assertToken(Lexer::T_CBRACE_OPEN, "{");
        $assertToken(Lexer::T_PLAIN_WHITESPACE, ' ');
        $assertToken('T_COMMENT', "// is allowed");
        $assertToken(Lexer::T_EOL, "\n");
        $assertToken(Lexer::T_CBRACE_CLOSE, "}");
        $assertToken(Lexer::T_SEMICOLON, ';');
        $assertToken(Lexer::T_EOL, "\n");
        $assertToken('T_CLOSE_TAG', "?>");
    }