cageis/lexer
Composer 安装命令:
composer require cageis/lexer
包简介
Used to separate the characters of a string into tokens.
README 文档
README
Lexer is a minimal string parser that can be used to convert text into a list of tokens.
Example Usage
<?php $lexer = CageIs\Lexer\LexerFactory::create(); $tokens = $lexer->addTokenPattern(new CageIs\Lexer\TokenPattern('\d+', 'num')) ->addTokenPattern(new CageIs\Lexer\TokenPattern('[a-zA-Z]+', 'alpha')) ->setWhitespaceIgnore(true) ->parse("hello\n123\n^&111111") ->toArray(); // The results will be [ [ 'name' => "alpha", 'match' => "hello", ], [ 'name' => "num", 'match' => "123", ], [ 'name' => "Unknown", 'match' => "^", ], [ 'name' => "Unknown", 'match' => "&", ], [ 'name' => "num", 'match' => "111111", ] ];
Note: not calling $tokens->toArray() will return a collection object (CageIs\Lexer\TokenizedCollection) with a couple of helpful collection methods.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-18