Abstract superclass of all AST nodes.

Note that nodes are not Identifiable: as they are immutable, the identity of a particular instance is meaningless.

Additional information

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.

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[]
Initializer
Node()
Attributes
childrenshared formal Node[] children

The child nodes of this node.

datashared 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 get(), put(), and remove() with keys, which offers the following advantages:

  • full type safety,
  • the ability to attach arbitrarily many pieces of information by using multiple keys, and
  • isolation of information attached by different modules.

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.

stringshared actual String string

A developer-friendly string representing the instance.

At the moment, this is a Ceylon expression (created by CeylonExpressionTransformer), but this may change in the future; for anything other than diagnostic information, use CeylonExpressionTransformer or one of the other attributes directly.

Refines Object.string
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
copyExtraInfoToshared void copyExtraInfoTo(Node other)

Copies this node’s additional information to the other node.

deleteshared void delete(Key<out Anything> key)

Removes the additional information attached to this node using the given key from this node.

Unlike remove(), this method discards the previously attached information; this makes it possible to accept keys of any type (out Anything), enabling users to abstract over keys of different types. Internally, this also eliminates one reified type test within the method (as well as one reified type parameter), so delete is usually faster than remove too.

See also remove()
getshared Type? get<out Type>(Key<out Type> key)
given Type satisfies Object

Returns the additional information attached to this node using the given key, if any.

If you don’t care about the return type, you might want to use getObject() instead, which might perform better.

See also getObject()
getObjectshared Object? getObject(Key<out Anything> key)

Returns the additional information attached to this node using the given key, if any.

Unlike get(), this method doesn’t return any particular type; this makes it possible to accept keys of any type (out Anything), enabling users to abstract over keys of different types. Internally, this also eliminates one reified type test within the method (as well as one reified type parameter), so getObject is usually faster than get too.

See also get()
putshared Type? put<Type>(Key<Type> key, Type item)
given Type satisfies Object

Attaches the given additional information to this node using the given key. If other information was attached with the same key previously, it is returned.

If you don’t care about the previously attached information, you might want to use set() instead, which has a more convenient signature and might perform better.

Parameters:
  • key
    • is Type? ret = extraInfo.put(key.id, item)
  • item
    • is Type? ret = extraInfo.put(key.id, item)
See also set()
removeshared Type? remove<Type>(Key<out Type> key)
given Type satisfies Object

Removes the additional information attached to this node using the given key from this node, returning it.

If you don’t care about the returned information, you might want to use delete() instead, which might perform better.

Parameters:
  • key
    • is Type? ret = extraInfo.remove(key.id)
See also delete()
setshared void set<in Type>(Key<in Type> key, Type item)
given Type satisfies Object

Attaches the given additional information to this node using the given key.

Unlike put(), this method discards any previously attached information; this makes it possible to declare the type parameter of key contravariant, enabling users to abstract over keys of different types. Internally, this also eliminates one reified type test within the method, so set is usually faster than put too.

See also set()
transformshared formal Result transform<out Result>(Transformer<Result> transformer)

Transform this node with the given transformer by calling the appropriate transformX method on the transformer.

If you have a Node node that’s actually an LIdentifier instance, then the runtime will call LIdentifier.transform; therefore, this method is by nature narrowing. This means that if transformer is a NarrowingTransformer, calling node.transform(transformer) is equivalent to calling transformer.transformNode(node). On the other hand, if transformer is a WideningTransformer, then the two operations are very different.

transformChildrenshared Result[] transformChildren<out Result>(Transformer<Result> transformer)

Transform all child nodes by calling their transform() methods.

visitshared formal void visit(Visitor visitor)

Visit this node with the given visitor. Calls the appropriate visitX method on the visitor.

visitChildrenshared void visitChildren(Visitor visitor)

Visit the children of this node with the given visitor. Calls visit() on each child node.

Inherited Methods
Methods inherited from: Object
equals