for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of Railt package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Railt\Lexer\Driver;
use Railt\Io\Readable;
use Railt\Lexer\LexerInterface;
use Railt\Lexer\TokenInterface;
* Class BaseLexer
abstract class Lexer implements LexerInterface
{
* @var array|string[]
protected $skipped = [];
protected $tokens = [];
* @param Readable $input
* @return \Traversable|TokenInterface[]
public function lex(Readable $input): \Traversable
foreach ($this->exec($input) as $token) {
if (! \in_array($token->getName(), $this->skipped, true)) {
yield $token;
}
* @param string $token
* @param string $pcre
* @return LexerInterface
public function add(string $token, string $pcre): LexerInterface
$this->tokens[$token] = $pcre;
return $this;
* @param string $name
public function skip(string $name): LexerInterface
$this->skipped[] = $name;
* @param Readable $file
abstract protected function exec(Readable $file): \Traversable;