Difference between revisions of "AST"

From Inkscape Wiki
Jump to navigation Jump to search
m (link fix)
 
(Categorization)
Line 11: Line 11:


Key: [1] - numbered continuation points so the diagram won't wrap
Key: [1] - numbered continuation points so the diagram won't wrap
     ([[ClassName]]) - a mutable node of a given class
     (ClassName) - a mutable node of a given class
     "blah" - an immutable string node
     "blah" - an immutable string node
     ( "axis", "name" ) - a branch name (a branch can hold one or
     ( "axis", "name" ) - a branch name (a branch can hold one or
Line 39: Line 39:
                   +-- ( "attribute", "{XLINK}href" ) -- "#foo"
                   +-- ( "attribute", "{XLINK}href" ) -- "#foo"


  [3]([[CSSDeclList]])--+-- ( "child", NULL ) -- [4]
  [3](CSSDeclList)--+-- ( "child", NULL ) -- [4]
                                             [5]
                                             [5]


Line 58: Line 58:
which mutations are valid and permitted.  Every mutation also results in
which mutations are valid and permitted.  Every mutation also results in
a notification to any interested listeners, on a per-node basis.
a notification to any interested listeners, on a per-node basis.


[ For example, XML elements have only one "name", which cannot be
[ For example, XML elements have only one "name", which cannot be
Line 71: Line 70:
or libcroco) that can be used to build nodes of that class from such a
or libcroco) that can be used to build nodes of that class from such a
string.
string.
What is this? Please explain
[[Category:Needs Work]]

Revision as of 20:27, 21 June 2006

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