face/parser
Composer 安装命令:
composer require face/parser
包简介
helper to write parser with php
关键字:
README 文档
README
Tool to help to create a parser with php. Originally built to parse FQL queries but might be used for anything else.
Usage
use Face\Parser\RegexpLexer as Lexer; use Face\Parser\TokenNavigation; $lexer = new Lexer(); $lexer->setTokens([ "function" => "T_FUNCTION", "class" => "T_CLASS", "[a-zA-Z_][a-zA-Z0-9_]*" => "T_IDENTIFIER", "\\{" => "T_L_BRACKET", "\\}" => "T_R_BRACKET", "\\(" => "T_L_PARENTHESIS", "\\)" => "T_R_PARENTHESIS", ";" => "T_SEMICOLON", "\\s+" => "T_WHITESPACE" ]); $string = 'class foo{ function bar(){} }'; $tokenArray = $lexer->tokenize($string); $tokens = new TokenNavigation($tokenArray); // Check if the first token is a "class" keyword or throws an exception $tokens->expectToBe("T_CLASS"); $tokens->next(); $tokens->expectToBe("T_IDENTIFIER"); $className = $tokens->current()->getTokenValue(); // while next token is a function keyword while($tokens->hasNext() && $tokens->look(1)->is("T_FUNCTION")){ // Parse the function body someFunctionThatParsesTheFunctionAndJumpsToTheNextToken($tokens); }
统计信息
- 总下载量: 63
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-01