PHP 解析器 Tolerant PHP Parser

码农软件 · 软件分类 · 语法解析工具 · 2019-12-12 10:59:15

软件介绍

这是一个早期的 PHP 解析器,相当于实现了 PHP 对 PHP 脚本的解析。

示例代码:

<?php
// Autoload required classes
require "vendor/autoload.php";

// Instantiate new parser instance
$parser = new PhpParser\Parser();

// Return and print an AST from string contents
$astNode = $parser->parseSourceFile('<?php /* comment */ echo "hi!"');
var_dump($astNode);

// Gets and prints errors from AST Node. The parser handles errors gracefully,
// so it can be used in IDE usage scenarios (where code is often incomplete).
$errors = PhpParser\Utilities::getDiagnostics($astNode);
var_dump(iterator_to_array($errors));

// Traverse all Node descendants of $astNode
foreach ($astNode->getDescendantNodes() as $descendant) {
    if ($descendant instanceof \PhpParser\Node\StringLiteral) {
        // Print the Node text (without whitespace or comments)
        var_dump($descendant->getText());

        // All Nodes link back to their parents, so it's easy to navigate the tree.
        $grandParent = $descendant->getParent()->getParent();
        var_dump($grandParent->getNodeKindName());

        // The AST is fully-representative, and round-trippable to the original source.
        // This enables consumers to build reliable formatting and refactoring tools.
        var_dump($grandParent->getLeadingCommentAndWhitespaceText());
    }

    // In addition to retrieving all children or descendants of a Node,
    // Nodes expose properties specific to the Node type.
    if ($descendant instanceof \PhpParser\Node\Expression\EchoExpression) {
        $echoKeywordStartPosition = $descendant->echoKeyword->getStartPosition();
        // To cut down on memory consumption, positions are represented as a single integer 
        // index into the document, but their line and character positions are easily retrieved.
        $lineCharacterPosition = \PhpParser\Utilities::getLineCharacterPositionFromPosition(
            $echoKeywordStartPosition
        );
        echo "line: $lineCharacterPosition->line, character: $lineCharacterPosition->character";
    }
}

本文地址:https://codercto.com/soft/d/20976.html

游戏改变世界

游戏改变世界

[美] 简•麦戈尼格尔(Jane McGonigal) / 闾佳 / 浙江人民出版社 / 2012-9 / 59.90元

◆《游戏改变世界》是著名未来学家、TED大会新锐演讲者简•麦戈尼格尔探索互联时代重要趋势的最新力作。在书中,作者指出:游戏可以弥补现实世界的不足和缺陷,游戏化可以让现实变得更美好。 ◆作者在书中用大量事例告诉我们,游戏击中了人类幸福的核心,提供了令人愉悦的奖励、刺激性的挑战和宏大的胜利,而这些都是现实世界十分匮乏的。她的研究表明,我们可以借助游戏的力量,让生活变得像游戏一样精彩。 ◆作......一起来看看 《游戏改变世界》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具