Difference between revisions of "AST"
m |
|||
Line 17: | Line 17: | ||
{SVG}g - shorthand for an expanded name in the SVG namespace | {SVG}g - shorthand for an expanded name in the SVG namespace | ||
(XMLElement)-- -- ( "name", NULL ) -- "{SVG}g" | (XMLElement)--+-- ( "name", NULL ) -- "{SVG}g" | ||
| | | | ||
+-- ( "child", NULL ) -- [1] | |||
[2] | [2] | ||
[1](XMLElement)-- -- ( "name", NULL ) -- "{SVG}rect" | [1](XMLElement)--+-- ( "name", NULL ) -- "{SVG}rect" | ||
| | | | ||
+-- ( "attribute", "x" ) -- "0 | |||
| | | | ||
+-- ( "attribute", "y" ) -- "0" | |||
| | | | ||
+-- ( "attribute", "width" ) -- "100" | |||
| | | | ||
+-- ( "attribute", "height" ) -- "100" | |||
| | | | ||
+-- ( "attribute", "style" ) -- [3] | |||
[2](XMLElement)-- -- ( "name", NULL ) -- "{SVG}use" | [2](XMLElement)--+-- ( "name", NULL ) -- "{SVG}use" | ||
| | | | ||
+-- ( "attribute", "{XLINK}href" ) -- "#foo" | |||
[3](CSSDeclList)-- -- ( "child", NULL ) -- [4] | [3](CSSDeclList)--+-- ( "child", NULL ) -- [4] | ||
[5] | [5] | ||
[4](CSSProperty)-- -- ( "name", NULL ) -- "fill" | [4](CSSProperty)--+-- ( "name", NULL ) -- "fill" | ||
| | | | ||
+-- ( "value", NULL ) -- "red" | |||
[5](CSSProperty)-- -- ( "name", NULL ) -- "stroke" | [5](CSSProperty)--+-- ( "name", NULL ) -- "stroke" | ||
| | | | ||
+-- ( "value", NULL ) -- "black" | |||
Revision as of 15:46, 20 April 2007
Here's a concrete example of what I have in mind. Take the following SVG fragment:
<g> <rect x="0" y="0" width="100" height="100" style="fill:red;stroke:black"/> <use xlink:href="#foo" /> </g>
The AST would look something like this:
Key: [1] - numbered continuation points so the diagram won't wrap
(ClassName) - a mutable node of a given class "blah" - an immutable string node ( "axis", "name" ) - a branch name (a branch can hold one or more children) {SVG}g - shorthand for an expanded name in the SVG namespace
(XMLElement)--+-- ( "name", NULL ) -- "{SVG}g" | +-- ( "child", NULL ) -- [1] [2]
[1](XMLElement)--+-- ( "name", NULL ) -- "{SVG}rect" | +-- ( "attribute", "x" ) -- "0 | +-- ( "attribute", "y" ) -- "0" | +-- ( "attribute", "width" ) -- "100" | +-- ( "attribute", "height" ) -- "100" | +-- ( "attribute", "style" ) -- [3]
[2](XMLElement)--+-- ( "name", NULL ) -- "{SVG}use" | +-- ( "attribute", "{XLINK}href" ) -- "#foo"
[3](CSSDeclList)--+-- ( "child", NULL ) -- [4] [5]
[4](CSSProperty)--+-- ( "name", NULL ) -- "fill" | +-- ( "value", NULL ) -- "red"
[5](CSSProperty)--+-- ( "name", NULL ) -- "stroke" | +-- ( "value", NULL ) -- "black"
The leaf nodes are immutable strings, so all mutations of the tree are
accomplished by adding/reordering/exchanging/removing nodes on branches.
Depending on the class of a node (and on higher-level objects which have attached themselves to it), various constraints may be applied as to which mutations are valid and permitted. Every mutation also results in a notification to any interested listeners, on a per-node basis.
[ For example, XML elements have only one "name", which cannot be changed, "attribute"s, and "child"ren -- no other branches are valid. Their "child" axis will only accept other XMLElements, and branches on the "attribute" axis will only accept one child. This permits the actual representation for XMLElements to be very compact and specialized. ]
Every node is capable of serializing itself as a UTF-8 string, and every class has an associated parser (here generally implemented using libxml or libcroco) that can be used to build nodes of that class from such a string.
What is this? Please explain