php-extended / php-parser-lexer
这个库是基于词法分析器处理数据的php-extended/php-parser-interface的实现
7.0.6
2024-07-31 13:36 UTC
Requires
- php: >=8.0
- php-extended/php-lexer-object: ^7
- php-extended/php-parser-object: ^7
Requires (Dev)
This package is auto-updated.
Last update: 2024-08-31 11:48:55 UTC
README
这个库是基于词法分析器处理数据的php-extended/php-parser-interface的实现。
安装
通过composer安装此库,并且所有类的自动加载都通过它们的自动加载器完成。
- 从他们的网站下载
composer.phar
。 - 然后运行以下命令以将此库作为依赖项安装
php composer.phar require php-extended/php-parser-lexer ^7
基本用法
这个库提供了一个单类 AbstractParserLexer
,它被设计为可实现的。它的 parseLexer
方法必须返回整个字符串的单个对象,如果不可能这样做,则抛出 ParseException
。
建议在 parseLexer
方法中使用
public function parseLexer(LexerInterface $lexer)
{
$lexer->rewind(); // do not forget !
$token = $this->expectOneOf($lexer, [<tokenids>]);
$this->expectEof($lexer, $token);
return MyObject($token->getData());
}
由于 LexerInterface
是一个 \Iterable
,你也可以将它用于foreach循环。
许可证
MIT (见 许可证文件).