ghostwriter/plex
Composer 安装命令:
composer require ghostwriter/plex
包简介
Provides the fastest lexer for PHP, tokenizing text with named regex patterns for efficient processing
README 文档
README
Provides the fastest lexer for PHP, tokenizing text with named regex patterns for efficient processing.
Installation
You can install the package via composer:
composer require ghostwriter/plex
Star ⭐️ this repo if you find it useful
You can also star (🌟) this repo to find it easier later.
Usage
<?php declare(strict_types=1); use Ghostwriter\Plex\Grammar; use Ghostwriter\Plex\Token; use Ghostwriter\Plex\Lexer; $grammar = Grammar::new([ 'T_NUMBER' => '\d+', 'T_DOT' => '\.' ]); $lexer = Lexer::new($grammar); $expected = [ Token::new('T_NUMBER', '1', 1, 1, []), Token::new('T_DOT', '.', 1, 2, []), Token::new('T_NUMBER', '2', 1, 3, []), Token::new('T_DOT', '.', 1, 4, []), Token::new('T_NUMBER', '3', 1, 5, []), ]; $content = '1.2.3'; assert($expected == iterator_to_array($lexer->lex($content)));
Named Patterns
When defining a grammar, you can reference other grammar rules by name using the (?&NAME) syntax, where NAME is the name of the grammar rule.
This allows you to create complex patterns that are easier to read and maintain.
<?php declare(strict_types=1); use Ghostwriter\Plex\Grammar; use Ghostwriter\Plex\Token; use Ghostwriter\Plex\Lexer; $grammar = Grammar::new([ // References both 'T_NUM' and 'ref-str' (which references T_STR) 'T_ID' => '(?:(?&T_NUM)|(?&ref-str))*', // Matches numbers 'T_NUM' => '\d+', // Matches word characters 'T_STR' => '\w+', // References T_STR 'ref-str' => '(?&T_STR)', ]); $lexer = Lexer::new($grammar); $expected = [ Token::new('T_ID', '456def', 1, 6, []) ]; $content = '456def'; assert($expected == iterator_to_array($lexer->lex($content)));
Credits
Changelog
Please see CHANGELOG.md for more information on what has changed recently.
License
Please see LICENSE for more information on the license that applies to this project.
Security
Please see SECURITY.md for more information on security disclosure process.
ghostwriter/plex 适用场景与选型建议
ghostwriter/plex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 194.74k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ghostwriter/plex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ghostwriter/plex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 194.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: 未知许可证
- 更新时间: 2024-08-30