doctrine/lexer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Doctrine/Lexer positions itself as a robust PHP Lexical analyzer, indispensable for creating top-down or recursive descent parsers. This Lexer forms the backbone of Doctrine's Annotations and ORM (DQL) capabilities and is designed to simplify your parsing experience with its innate functionalities.
To incorporate Doctrine/Lexer in your PHP project, you'll need to add the package via Composer first. Simply run the following command in your project directory:
composer require doctrine/lexer
After installation, you may use the lexer to tokenize your input. Here's a generic usage example:
<?php
use Doctrine\Common\Lexer\AbstractLexer;
class MyLexer extends AbstractLexer {
const MY_TOKEN = 1;
protected function getCatchablePatterns(): array
{
return array(
'[a-z]+',
);
}
protected function getNonCatchablePatterns(): array
{
return array(
'\s+',
);
}
protected function getType(&$value)
{
return self::MY_TOKEN;
}
}
$lexer = new MyLexer();
$lexer->setInput('abc def');
Always remember to extend the AbstractLexer
and define your custom getCatchablePatterns
, getNonCatchablePatterns
, and getType
methods.
The comprehensive documentation for the Doctrine/Lexer, which spans from installation guide to usage instructions, can be accessed on Doctrine's official website at Doctrine Project. The online guide provides extensive insight into the vast capabilities of the Doctrine/Lexer to help both beginner and advanced users navigate through its functionalities.