Open J-Moravec opened 1 month ago
Maybe we could have an option for this, but there are also better ways to look at the AST, if you are a human. xmlparsedata output is mainly meant for computers. E.g. have you seen lobstr::ast()
?
My user-case is learning the AST->Xpath for writing linters.
Removing the node attributes makes it more readable and is a good teaching tool on how to write linters.
Since it just a single line fix, I am fine if it is not merged approved, just felt like a nice and obvious utility to have.
In the README.md
, there is an example of parsing the expression into XML, then translating the XML into Xpath, and finally using the Xpath string to search through larger expressions to find matches. I found this useful for my user-case and removing the nodes made it so much easier to see what is going on.
Issue:
Node attributes are adding a lot of text noise. This makes it harder to read the parsed tree itself.
Adding an option to remove them would make it easier to see what is going on with R parser.
This can be as simple as using regex at the end of the
xml_parse_data
(for a bit of overhead):User story:
I am trying to understand how R is parsing different expressions to learn XPath for linting purpose.
The node attributes (
line
,col
,start
, andend
) are adding quite lot of text noise and mental overhead to this.Compare the following two snippets of the same
{x + 1}
expression:This makes comparing two parsed expressions much easier.