A way to reach the parent node(s) or root node from a given Prism::Node

Offen
#4,379 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Muss geklärt werden
Aktivitätsstatus
Aktiv
Tech-Stack
c, ruby
Bereich
compilers

Rechercherichtung

Start by reading the linked Ruby issue note and the discussion here to understand the proposed Prism::Node#root or Prism::Node#parse_result API and the concern about keeping the whole tree alive. Then inspect how nodes retain Prism::Source and how Prism.parse constructs its result. Done means the API choice and memory tradeoff are resolved; the issue does not specify an implementation or tests.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

This is from https://bugs.ruby-lang.org/issues/22520#note-5, for #syntax_tree.
It can be necessary to get the parent node(s) or even the root node, from a given Prism::Node.

One idea would be to have Prism::Node#root or Prism::Node#parse_result, which would work through the existing @source ivar of every node holding a Prism::Source.
So then we'd store the root node or the ParseResult inside the Source, and we could then provide Prism::Node#root or Prism::Node#parse_result.

There is one downside, this means holding on to any node (even leaves) would keep the whole tree alive.
(Currently every node holds the source, so the entire source code, but does not hold on parent nodes)
If that's a concern, this could be controlled via a keyword argument of Prism.parse (opt-in or opt-out).

I'm happy to make a PR for this but I wanted to first see what others think of this idea, and whether they prefer Prism::Node#root or Prism::Node#parse_result, or some other solution.
(Feel free to convert this to a GitHub discussion if you prefer)

Vorherrschende Sprache
C
Sterne
1k
Forks
206
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
71

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ruby/prism

Alle Issues in ruby/prism

Ähnliche Issues

Weitere Issues zu C

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.