$rewriter = new Rewriter($this->tokens); $this->tokens = $rewriter->rewrite(); } return $this->tokens; } function value($index = 0, $value = NULL) { $token =& last($this->tokens, $index); if (!is_null($value)) { $token[1] = $value; } return $token[1]; } function unfinished() { return preg_match(self::$LINE_CONTINUER, $this->chunk) || ($prev = last($this->tokens, 1)) && $prev[0] !== t('.') && ($value = $this->value()) && !(isset($value->reserved) && $value->reserved) && preg_match(self::$NO_NEWLINE, $value) && !preg_match(self::$CODE, $value) && !preg_match(self::$ASSIGNED, $this->chunk); } function whitespace_token() { if (!(preg_match(self::$WHITESPACE, $this->chunk, $match) || ($nline = $this->chunk[0] === "\n"))) { return 0; } $prev =& last($this->tokens); if ($prev) { $prev[$match ? 'spaced' : 'newLine'] = TRUE; } return $match ? strlen($match[0]) : 0; } } Lexer::init();
function testException() { $m = ['d' => '[1-9][0-9]*', 'sp' => '(\\s+)', '+' => '\\+']; $lexer = new Lexer(); $lexer->init($m); //$this->setExpectedException('phpcc\\'); try { $lexer->lex('-', function ($name, $value, $line, $offset) { }); $this->fail(); } catch (LexException $e) { $this->assertEquals('-', $e->getChar()); $this->assertEquals(1, $e->getCharLine()); $this->assertEquals(0, $e->getCharOffset()); } try { $lexer->lex('12-12', function ($name, $value, $line, $offset) { }); $this->fail(); } catch (LexException $e) { $this->assertEquals('-', $e->getChar()); $this->assertEquals(1, $e->getCharLine()); $this->assertEquals(2, $e->getCharOffset()); } }