KristopherGBaker / Maaku

The Maaku framework provides a Swift wrapper around cmark with the addition of a Swift friendly representation of the AST
MIT License
51 stars 12 forks source link

Would be nice to be able to manipulate the AST via CMNode rather than having to use underlying cmarkNode #45

Open NightFlyer opened 5 years ago

NightFlyer commented 5 years ago

If I want to manipulate the abstract syntax tree that the parser returns, I currently need to do that by getting the cmarkNode and manipulating that myself.

It would be nice if CMNode provided the functionality needed to change values in the nodes and to manipulate the tree structure.

This includes being able to change values in the individual node (such as the heading level), as well as to be able to change the structure of the tree (by changing the order of children or moving a subtree from one part of the tree to another by changing the parent). Note that changing the structure of the tree requires a bit of housekeeping to keep all the pointers correct (next, previous, parent, firstChild, and lastChild). By putting that housekeeping in CMNode, that will reduce the burden on the users so they don't have to make sure that they're doing the right thing all the time.

It is also necessary to be able to create new nodes so they can be added to the tree.

This will allow for creation of apps that want to provide an "org-mode" style of presenting the document to the user: allowing the user to move chunks of the document around as they work.

NightFlyer commented 5 years ago

I'll start to work on this and start with some pull requests. But, let me know if you want Maaku to be "read-only" rather than supporting manipulating the tree.

NightFlyer commented 5 years ago

It appears that in general, the underlying methods to manipulate the values in a node return a boolean as to whether or not the set worked (usually because the node is the wrong type to allow that operation)

I think that in Swift, this would be better captured by throwing an exception if the set doesn't work, because it generally means that the node was the wrong type of node.

NightFlyer commented 5 years ago

I just noticed that libcmark provides some tree manipulation methods, so it will just be a case of making those visible through the Maaku interface.