Abstract superclass of all AST nodes.
Note that nodes are not Identifiable
: as they are immutable,
the identity of a particular instance is meaningless.
You can attach additional information to individual AST nodes using typed keys.
Two sets of methods are available for this;
get()
, put()
and remove()
offer more type safety and information,
while getObject()
, set()
and delete()
can be slightly faster.
get()
and getObject()
retrieve a piece of attached information,put()
and set()
store a piece of attached information, andremove()
and delete()
discard a piece of attached information.Usage example:
// toplevel shared Key<Token[]> tokensKey = ScopedKey<Token[]>(`module my.parser`, "tokens"); // in the parser node.put(tokensKey, tokens); // somewhere else assert (exists tokens = node.get(tokensKey)); // tokens has type Token[]
Anything
Object
Node
Object
Anything
Initializer |
Node() |
Attributes | |
children | shared formal Node[] children The child nodes of this node. |
data | shared variable Anything data An additional field for any extra data that an application may want to attach to a node. Use of this field is strongly discouraged.
Instead, use
In other words, this field is not typesafe, only allows for a single object to be attached, and offers no protection against multiple modules each attempting to register information here, overwriting each other’s information. To mitigate the last point, it is extremely strongly recommended that this field only be used by applications, never by libraries. There should only be one application at runtime, so this application would be in a position to know that it is exclusively accessing this field on any given node. Libraries on the other hand have no such guarantee, since they might be used together with other libraries without knowing whether those use this field. It is emphasized again that you should not use this field unless you absolutely need the performance benefit it brings. |
string | shared actual String string A developer-friendly string representing the instance. At the moment, this is a Ceylon expression (created by Refines Object.string |
Inherited Attributes |
Attributes inherited from: Object hash , string |
Methods | |
copyExtraInfoTo | shared void copyExtraInfoTo(Node other) Copies this node’s additional information to the |
delete | shared void delete(Key<out Anything> key) Removes the additional information attached to
this node using the given Unlike See also remove() |
get | shared Type? get<out Type>(Key<out Type> key) Returns the additional information attached to this node
using the given If you don’t care about the return type,
you might want to use See also getObject() |
getObject | shared Object? getObject(Key<out Anything> key) Returns the additional information attached to this node
using the given Unlike See also get() |
put | shared Type? put<Type>(Key<Type> key, Type item) Attaches the given additional information
to this node using the given If you don’t care about the previously attached information,
you might want to use Parameters:
See also set() |
remove | shared Type? remove<Type>(Key<out Type> key) |
set | shared void set<in Type>(Key<in Type> key, Type item) Attaches the given additional information
to this node using the given Unlike See also set() |
transform | shared formal Result transform<out Result>(Transformer<Result> transformer) Transform this node with the given If you have a See also NarrowingTransformer , WideningTransformer |
transformChildren | shared Result[] transformChildren<out Result>(Transformer<Result> transformer) Transform all child nodes by calling their |
visit | shared formal void visit(Visitor visitor) Visit this node with the given |
visitChildren | shared void visitChildren(Visitor visitor) Visit the children of this node with the given |
Inherited Methods |
Methods inherited from: Object equals |