-
Notifications
You must be signed in to change notification settings - Fork 64
Allow attributes to make format preserving print piece of cake #11
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
Comments
Please join forces with @dantleech in #10 - he wrote in two hours ago 😊 |
I've read it, but Tokens (array, chars) and Nodes (rich objects) are different thing |
Quite funny, I was just looking at your packages @TomasVotruba :) My approach for format preserving was to leave the AST read-only, but instead export it to a mutable format, e.g. XML. In the XML document the nodes are represented as elements, and the tokens have node values, e.g. <PhpDocNode>
<PhpDocTextNode text="Short description"/>
<PhpDocTextNode text=""/>
<PhpDocTextNode text="This is a multi-line description"/>
<PhpDocTextNode text="of the docblock."/>
<PhpDocTextNode text=""/>
<PhpDocTagNode name="@param">
<ParamTagNode isVariadic="" parameterName="$bar" description="">
<IdentifierTypeNode name="Fobar"/>
</ParamTagNode>
</PhpDocTagNode>
<PhpDocTagNode name="@param">
<ParamTagNode isVariadic="" parameterName="$foo" description="">
<IdentifierTypeNode name="Bar\Foo"/>
</ParamTagNode>
</PhpDocTagNode>
<PhpDocTagNode name="@param">
<ParamTagNode isVariadic="" parameterName="$baz" description="">
<IdentifierTypeNode name="int"/>
</ParamTagNode>
</PhpDocTagNode>
<PhpDocTextNode text=""/>
<PhpDocTagNode name="@throws">
<ThrowsTagNode description="">
<IdentifierTypeNode name="Barbar"/>
</ThrowsTagNode>
</PhpDocTagNode>
<PhpDocTagNode name="@method">
<MethodTagNode isStatic="" methodName="foobar" description="">
<IdentifierTypeNode name="string"/>
</MethodTagNode>
</PhpDocTagNode>
<PhpDocTextNode text=""/>
<PhpDocTagNode name="@return">
<ReturnTagNode description="">
<IdentifierTypeNode name="Hello"/>
</ReturnTagNode>
</PhpDocTagNode>
</PhpDocNode> Tokens would could look like That's what I'm working on anyway -- the nice thing is that you can import that XML into an XML of the PHP AST, and modify the whole source tree in one place. If it's interesting the PHP AST looks like this curently, work-in-progress (based on the Tolerant Parser AST): <Ast>
<SourceFileNode>
<InlineHtml>
<Token kind="ScriptSectionStartTag" fullStart="0" start="0" length="6"><?php
</Token>
</InlineHtml>
<ClassDeclaration>
<Preamble>
/**
* @author Daniel
*/
</Preamble>
<Token kind="ClassKeyword" fullStart="6" start="33" length="32">class</Token>
<Preamble> </Preamble>
<Token kind="Name" fullStart="38" start="39" length="13">ExampleClass</Token>
<ClassMembersNode>
<Preamble>
</Preamble>
<Token kind="OpenBraceToken" fullStart="51" start="52" length="2">{</Token>
<Preamble>
</Preamble>
<Token kind="CloseBraceToken" fullStart="53" start="54" length="2">}</Token>
</ClassMembersNode>
</ClassDeclaration>
<Preamble>
</Preamble>
<Token kind="EndOfFileToken" fullStart="55" start="56" length="1"></Token>
</SourceFileNode>
</Ast> |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
It probably out of scope of PHPStan (for now), but as we talked, it would be great if this package allowed format preserving print.
I already asked nikic how to do it, he explained me the basics. Basically,
AbstractNode
class with set/get attributes is the first step towards it: nikic/PHP-Parser@4d2a4d0#diff-ee2208021c6e96ff1de44281aa029630R108After few weeks I managed to make working prototype, but it contains lot of boiler plate code and external storage of tokens positions etc., to make it work.
Having this would also make it easy to configure FQN namespaces, the same way php-parser does, without modifing the output. And other SOLID features :)
The text was updated successfully, but these errors were encountered: