1. Go to this page and download the library: Download railt/lexer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
interface TokenInterface
{
public function getName(): string;
public function getOffset(): int;
public function getValue(int $group = 0): ?string;
public function getGroups(): iterable;
public function getBytes(): int;
public function getLength(): int;
}
use Railt\Component\Lexer\Driver\NativeRegex;
use Railt\Component\Io\File;
$lexer = new NativeRegex(['T_WHITESPACE' => '\s+', 'T_DIGIT' => '\d+'], ['T_WHITESPACE', 'T_EOI']);
foreach ($lexer->lex(File::fromSources('23 42')) as $token) {
echo $token->getName() . ' -> ' . $token->getValue() . ' at ' . $token->getOffset() . "\n";
}
// Outputs:
// T_DIGIT -> 23 at 0
// T_DIGIT -> 42 at 3
use Railt\Component\Lexer\Driver\ParleLexer;
use Railt\Component\Io\File;
$lexer = new ParleLexer(['T_WHITESPACE' => '\s+', 'T_DIGIT' => '\d+'], ['T_WHITESPACE', 'T_EOI']);
foreach ($lexer->lex(File::fromSources('23 42')) as $token) {
echo $token->getName() . ' -> ' . $token->getValue() . ' at ' . $token->getOffset() . "\n";
}
// Outputs:
// T_DIGIT -> 23 at 0
// T_DIGIT -> 42 at 3
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.