unify AST types
milahu opened this issue · 1 comments
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
- i hate checklists
Problem
xast-parse
produces a different AST than hast-parse
so i cannot use hast-util-select
on xast
part of rehypejs/rehype#112 (trying to use hast tools for xml)
Solution
unify ASTs across all parsers in the unifiedjs ecosystem
so that tools like select
"just work" on all ASTs
interface Node {
name: string,
type: string,
props: Record<string, any> | null,
children: Node[] | null, // node is a branch node
value: string?, // node is a leaf node
location: { start: number, end: number },
internal: Record<string, any> | null, // like props, but for unifiedjs internal data
// example: path to source file of a root node
isRoot: boolean, // shortcut to detect "context switch" between different ASTs
}
this would also allow to just "plug in" tools like graphQL, or interface with graph databases ...
benefit: ASTs are composable, for example, i can embed a python AST in a html code block.
or, i can parse <img src="image.svg">
, parse the svg file at src, transform the svg, inline the svg in html
maybe extend the Node
type of a parser-generator like tree-sitter
or lezer-parser
Alternatives
write N tools for M ASTs ...
which is the opposite of "unified"
"what would pandoc do?"
Please respect our time by filling out the template, following the support guidelines, and taking some time to think through your questions. I will block you otherwise.
You can use unist-util-select
in any unist language.
unified is specifically not pandoc, it specifically has different ASTs, being like Pandoc is not the goal. Pandoc is already a very good version of Pandoc.