Skip to main content

Node

rascal-0.34.0

Synopsis

Node values.

Syntax

Exp₀ ( Exp₁, Exp₂, ..., FieldName₁ = Expr₁, FieldName₂ = Expr₂, ... )

Types

Exp₀Exp₁Exp₂...Exp₀ ( Exp₁, Exp₂, ... )
strvaluevalue...node

Description

Values of type node represent untyped trees and are constructed as follows:

  • the string value of Exp₀ is the node name;
  • zero or more expressions of type value are the node\'s children.
  • optionally, unordered named fields can be added as well.

The following are provided for nodes:

Examples

A node with name "my_node" and three arguments:

rascal>"my_node"(1, true, "abc");
node: "my_node"(1,true,"abc")

A nested node structure:

rascal>"my_node1"(1, "my_node2"(3.5, ["a", "b", "c"]), true);
node: "my_node1"(
1,
"my_node2"(
3.5,
["a","b","c"]),
true)

A node with named fields:

rascal>"my_node2"(1,2,size=2,age=24);
node: "my_node2"(1,2,
size=2,
age=24)

Benefits

  • nodes are untyped and can be used to quickly import untyped data into Rascal
  • pattern matching on nodes is quite expressive

Pitfalls

  • the lack of types at run-time makes pattern matching on node possibly inaccurate (you might match more than you think)