Node
rascal-0.40.17
Synopsis
Node values.
Syntax
Exp₀ ( Exp₁, Exp₂, ..., FieldName₁ = Expr₁, FieldName₂ = Expr₂, ... )
Types
Exp₀ | Exp₁ | Exp₂ | ... | Exp₀ ( Exp₁, Exp₂, ... ) |
---|---|---|---|---|
str | value | value | ... | 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:
- Equal
- FieldAssignment
- FieldSelection
- GreaterThan
- GreaterThanOrEqual
- LessThan
- LessThanOrEqual
- NotEqual
- Slice
- Subscription
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)