microsoft / microsoft/tolerant-php-parser

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

Open
#182 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
PHP
Stars
894
Forks
85
Avg merge
2d 13h
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with internal/dump_fallback_ast.php and compare it with the issue's sample output. Check the tools and bin directories for an appropriate entry point. Done means providing a compact node representation for a PHP file or snippet, suitable for parser-library development and debugging.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.