$type
$type : string
The type of the node, can be a string of any kind.
Represents a node in the AST the parser generates.
A node has children and always tries to reference its parents
It also has some utility methods to work with those nodes
$parent : \Tale\Jade\Parser\Node|null
The parent-node of this node.
$children : array<mixed,\Tale\Jade\Parser\Node>
The children of this node.
__construct(string $type, integer|null $line = null, integer|null $offset = null)
Creates a new, detached node without children or a parent.
It can be appended to any node after that
The type can be any kind of string
string | $type | the type of this node |
integer|null | $line | the line at which we found this node |
integer|null | $offset | the offset in a line we found this node at |
indexOf(\Tale\Jade\Parser\Node $node) : integer|false
Returns the position of the given node inside this node.
[element:a] (0)[element:b] (1)[element:c] (2)[element:d]
[element:a]->indexOf([element:d]) === 2
\Tale\Jade\Parser\Node | $node | the child-node to get the index of |
prev() : \Tale\Jade\Parser\Node|null
Returns the previous sibling of this element or null, if if there isn't any.
[element:a] (0)[element:b] (1)[element:c]
[element:c]->prev() === [element:b]
next() : \Tale\Jade\Parser\Node|null
Returns the next sibling of this element or null, if if there isn't any.
[element:a] (0)[element:b] (1)[element:c]
[element:b]->next() === [element:c]
append(\Tale\Jade\Parser\Node $node) : $this
Appends the given node to this node's children.
This also sets the parent of the given child to this node
[element:a] (0)[element:b] (1)[element:c]
[element:a]->append([element:d])
[element:a] (0)[element:b] (1)[element:c] (2)[element:d]
\Tale\Jade\Parser\Node | $node | the new child node to be appended |
prepend(\Tale\Jade\Parser\Node $node) : $this
Prepends the given node to this node's children.
This also sets the parent of the given child to this node
[element:a] (0)[element:b] (1)[element:c]
[element:a]->prepend([element:d])
[element:a] (0)[element:d] (1)[element:b] (2)[element:c]
\Tale\Jade\Parser\Node | $node | the new child node to be prepended |
remove(\Tale\Jade\Parser\Node $node) : $this
Removes the given child node from this node's children.
The parent of the given child node will be set to null
[element:a] (0)[element:b] (1)[element:c] (2)[element:d]
[element:a]->remove([element:c])
[element:a] (0)[element:b] (1)[element:d]
\Tale\Jade\Parser\Node | $node | the node to remove from this node's children |
insertAfter(\Tale\Jade\Parser\Node $node, \Tale\Jade\Parser\Node $newNode) : $this
Inserts the second given node after the first given node inside this node's children.
This allows fine control over the node's children
The new nodes parent will be set to this node
[element:a] (0)[element:b] (1)[element:c]
[element:a]->insertAfter([element:b], [element:d])
[element:a] (0)[element:b] (1)[element:d] (2)[element:c]
\Tale\Jade\Parser\Node | $node | the child node of this node's children the new node will be inserted after |
\Tale\Jade\Parser\Node | $newNode | the new node that will be inserted after the first node |
insertBefore(\Tale\Jade\Parser\Node $node, \Tale\Jade\Parser\Node $newNode) : $this
Inserts the second given node before the first given node inside this node's children.
This allows fine control over the node's children
The new nodes parent will be set to this node
[element:a] (0)[element:b] (1)[element:c]
[element:a]->insertBefore([element:c], [element:d])
[element:a] (0)[element:b] (1)[element:d] (2)[element:c]
\Tale\Jade\Parser\Node | $node | the child node of this node's children the new node will be inserted before |
\Tale\Jade\Parser\Node | $newNode | the new node that will be inserted before the first node |
find(string $type) : \Generator
Finds nodes with the given type inside this nodes children.
Plus all it's children-children recursively and returns a generator providing them
This is used to collect all blocks, imports and mixins and handle them in a special way
If you need a normal array, use ->findArray() instead instead
string | $type | the node type to search for |
a generator of the found children
findArray(string $type) : array
Finds nodes with the given type inside this nodes children.
Plus all it's children-children recursively and returns an array with all of them
I you want to do further searching on it, you should rather use the Generator-version ->find() to improve memory-usage
string | $type | the node type to search for |
an array containing all found children
text(string $indentStyle = ' ', string $newLine = "\n", integer $level) : string
Returns all text and child-texts in a single text.
You can control the text-style with the arguments
string | $indentStyle | the indentation to use (multiplies with level) |
string | $newLine | the new-line style to use |
integer | $level | the initial indentation level |
the compiled text-block
dump(integer $level) : string
Dumps the node as a string to ease up debugging.
This is also the default-action for __toString on every node
The result will look like this:
[element tag=a expands=[element tag=b]] [element tag=c attributes={[attribute name=d name=e]}]
integer | $level | the initial indentation level |
the string to debug the node-tree
__toString() : string
Gets called when this node instance is casted to a string in any way
(echo, (string), strval, string operations, ., etc.)
Calls ->dump() and dumps a debuggable text-representation of this node and all of its child-nodes
a debuggable text-representation of this node tree