Skip to content

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

Merged
merged 6 commits into from
Jul 20, 2023
Merged

Add new compiler pass to move anchors #371

merged 6 commits into from
Jul 20, 2023

Conversation

jaapio
Copy link
Member

@jaapio jaapio commented May 14, 2023

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.

use phpDocumentor\Guides\Nodes\CompoundNode;
use phpDocumentor\Guides\Nodes\DocumentNode;

class MoveAnchorPass implements CompilerPass
Copy link
Contributor

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).

Copy link
Member Author

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?

Copy link
Contributor

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).

Copy link
Member Author

@jaapio jaapio May 14, 2023

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

@jaapio jaapio force-pushed the feature/references branch from d273fba to 2254c6e Compare June 28, 2023 19:37
@jaapio jaapio force-pushed the feature/references branch 3 times, most recently from e152806 to 9991600 Compare July 14, 2023 15:29
@jaapio jaapio marked this pull request as ready for review July 18, 2023 19:54
@jaapio jaapio force-pushed the feature/references branch from 3d365f9 to ef99ff5 Compare July 18, 2023 20:04
@@ -50,7 +50,7 @@ private function traverseForTransformer(
}

foreach ($shadowNode->getChildren() as $shadowChild) {
$this->traverseForTransformer($transformer, $shadowChild, $compilerContext);
$this->traverseForTransformer($transformer, $shadowChild, $compilerContext->withShadowTree($shadowChild));
Copy link
Member Author

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.

@jaapio jaapio force-pushed the feature/references branch from ef99ff5 to 9720a27 Compare July 18, 2023 20:10
@jaapio jaapio requested review from wouterj and linawolf and removed request for wouterj July 18, 2023 20:12
@jaapio jaapio force-pushed the feature/references branch from 941e15c to 4c61b31 Compare July 18, 2023 21:05
jaapio and others added 6 commits July 20, 2023 19:44
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>
@jaapio jaapio force-pushed the feature/references branch from 4c61b31 to ee89ac4 Compare July 20, 2023 17:44
@jaapio jaapio enabled auto-merge July 20, 2023 17:44
@jaapio jaapio merged commit 8d1db85 into main Jul 20, 2023
@jaapio jaapio deleted the feature/references branch July 20, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants