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

Abierto
#4,379 9 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Activo
Stack tecnológico
c, ruby
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)

Lenguaje dominante
C
Estrellas
1k
Forks
206
Merge medio
1 d 1 h
PR fusionados (30 d)
71

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ruby/prism

Todos los issues de ruby/prism

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.