ethan-leba / tree-edit

🌲 Structural editing in Emacs for any™ language!
GNU General Public License v3.0
395 stars 16 forks source link

Parsing fragments that are only valid in specific contexts #38

Open ethan-leba opened 2 years ago

ethan-leba commented 2 years ago

There are many node types that are only valid in a specific context. For example, a dictionary pair (key : value) is only valid within a dictionary node. Sometimes the error recovery can handle these cases, but in other cases it can't.

Possible solutions

Use the outer node when parsing

We can try to somehow use the syntax snippets in order to create the proper context, i.e. put the pair in a {} if the outer node is a dictionary.

Custom parser

We can define a parser where all node types are valid at the top level. This would require a custom parser, which is not viable currently, but may be down the line.

Temporary solution: store the type of a fragment on copy

This would only work for nodes copied with a tree-edit function, but would be an easier temporary fix. Would be a good optimization as well