Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a utility and/or library to dump a compact representation of a node? #182

Open
TysonAndre opened this issue Sep 19, 2017 · 1 comment
Labels

Comments

@TysonAndre
Copy link
Contributor

TysonAndre commented Sep 19, 2017

E.g. to tools or bin

This will help people who are developing libraries using this parser, as well as trying to debug the behavior on a given file/snippet.

I didn't see any similar issues mentioned elsewhere in the issues, readme, or tools directory.

Currently, I'm using this snippet: https://gist.github.com/TysonAndre/3c0619efc9695ef9f2465f4a55e6e6ee
Previously, I was using var_export(), which was several times longer.

» php dump.php "const X = 2*3+1;"
Node\SourceFileNode
    statementList: Node\Statement\ConstDeclaration
        constKeyword: Token: ConstKeyword(111): "const"
        constElements: Node\DelimitedList\ConstElementList
            children: Node\ConstElement
                name: Token: Name(2): " X"
                equalsToken: Token: EqualsToken(238): " ="
                assignment: Node\Expression\BinaryExpression
                    leftOperand: Node\Expression\BinaryExpression
                        leftOperand: Node\NumericLiteral
                            children: Token: IntegerLiteralToken(416): " 2"
                        operator: Token: AsteriskToken(212): "*"
                        rightOperand: Node\NumericLiteral
                            children: Token: IntegerLiteralToken(416): "3"
                    operator: Token: PlusToken(213): "+"
                    rightOperand: Node\NumericLiteral
                        children: Token: IntegerLiteralToken(416): "1"
        semicolon: Token: SemicolonToken(237): ";"
    endOfFileToken: Token: EndOfFileToken(1): ""

EDIT: I've moved that snippet to https://github.com/phan/phan/blob/master/internal/dump_fallback_ast.php

@roblourens
Copy link
Member

Sort of related to what the syntax-visualizer does: https://github.com/Microsoft/tolerant-php-parser/tree/master/syntax-visualizer which is just running the parsed file through json_encode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants