-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add new compiler pass to move anchors #371
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
Conversation
use phpDocumentor\Guides\Nodes\CompoundNode; | ||
use phpDocumentor\Guides\Nodes\DocumentNode; | ||
|
||
class MoveAnchorPass implements CompilerPass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a node transformer instead? That already has all code to traverse the tree of nodes.
The way I differentiate between them is:
- Node transformers operate within a single document (and therefor can even be cached)
- Compiler passes operate in the project, managing cross document logic (like toctrees).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current node tranformer cannot handle this, as I need to move elements. But I could be wrong...
I have to make sure that I move elements at the right level, and in the node transformer, I don't know that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe I have a wrong idea about the AST that we are dealing with here. But if it looks like this:
COMPOUND
...
ANCHOR
ANCHOR
COMPOUND
...
I think a transformer that supports compound and anchor nodes should work. It'll then store the anchors in a property when it discovers them, and push them in the compound node when it reaches one (clearing the property).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check if it is possible to do this in a transformer, I think the main issue I will have is that the transformer will first handle the child nodes an then go to the next node. And its state is shared between the nodes.
ANCHOR1
COMPOUND
ANCHOR2
ANCHOR3
COMPOUND
ANCHOR4
COMPOUND
Should be come
COMPOUND
ANCHOR1
COMPOUND
ANCHOR2
ANCHOR3
COMPOUND
ANCHOR4
d273fba
to
2254c6e
Compare
e152806
to
9991600
Compare
3d365f9
to
ef99ff5
Compare
@@ -50,7 +50,7 @@ private function traverseForTransformer( | |||
} | |||
|
|||
foreach ($shadowNode->getChildren() as $shadowChild) { | |||
$this->traverseForTransformer($transformer, $shadowChild, $compilerContext); | |||
$this->traverseForTransformer($transformer, $shadowChild, $compilerContext->withShadowTree($shadowChild)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug, we should pass the current node in the shadow tree. So we can move around at the correct level.
ef99ff5
to
9720a27
Compare
packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php
Outdated
Show resolved
Hide resolved
packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php
Outdated
Show resolved
Hide resolved
packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php
Outdated
Show resolved
Hide resolved
packages/guides/tests/unit/Compiler/NodeTransformers/MoveAnchorTransformerTest.php
Outdated
Show resolved
Hide resolved
941e15c
to
4c61b31
Compare
Anchors should be part of the first compound node after their definition. Anchors at the end of a compound node are positioned wrong by the parser So they are moved to the next compoundnode.
Co-authored-by: Grégoire Paris <postmaster@greg0ire.fr>
4c61b31
to
ee89ac4
Compare
Anchors should be part of the first compound node after their definition. Anchors at the end of a compound node are positioned wrong by the parser So they are moved to the next compoundnode.