module Node
Library functions for nodes.
Usage
import Node;
The following library functions are defined for nodes:
- arbNode
- arity
- delAnnotation
- delAnnotations
- delAnnotationsRec
- getAnnotations
- getChildren
- getKeywordParameters
- getName
- itoString
- makeNode
- setAnnotations
- setKeywordParameters
- toString
- unset
- unsetRec
function arity
Determine the number of children of a node.
int arity(node T)
Examples
rascal>import Node;
ok
rascal>arity("f"(10, "abc"));
int: 2
rascal>arity("f"(10, "abc", false));
int: 3
function getChildren
Get the children of a node.
list[value] getChildren(node T)
Examples
rascal>import Node;
ok
rascal>getChildren("f"(10, "abc"));
list[value]: [10,"abc"]
function getKeywordParameters
Get the keyword parameters of a node.
map[str,value] getKeywordParameters(node T)
Examples
rascal>import Node;
ok
rascal>getKeywordParameters("f"(10, "abc", height=0));
map[str, value]: ("height":0)
function getAnnotations
map[str, value] getAnnotations(node T)
function setKeywordParameters
Set the keyword parameters of a node.
&T <: node setKeywordParameters(&T <: node x, map[str,value] keywordParameters)
Examples
rascal>import Node;
ok
rascal>setKeywordParameters("f"(10, "abc"), ("height":0));
node: "f"(10,"abc",
height=0)
function setAnnotations
&T <: node setAnnotations(&T <: node x, map[str,value] keywordParameters)
function getName
Determine the name of a node.
str getName(node T)
Examples
rascal>import Node;
ok
rascal>getName("f"(10, "abc"));
str: "f"
---
f
---
function makeNode
Create a node given its function name and arguments.
node makeNode(str N, value V..., map[str, value] keywordParameters = ())
Examples
rascal>import Node;
ok
rascal>makeNode("f", [10, "abc"]);
node: "f"(10,"abc")
function unset
Reset a specific keyword parameter back to their default on a node.
&T <: node unset(&T <: node x, str keywordParameter)
function delAnnotation
&T <: node delAnnotation(&T <: node x, str keywordParameter)
function unset
Reset a set of keyword parameters back to their default on a node.
&T <: node unset(&T <: node x, set[str] keywordParameters)
function unset
Reset all keyword parameters back to their default.
&T <: node unset(&T <: node x)
function delAnnotations
&T <: node delAnnotations(&T <: node x)
function unsetRec
Recursively reset all keyword parameters of the node and its children back to their default.
&T unsetRec(&T x)
function delAnnotationsRec
&T delAnnotationsRec(&T x)
function unsetRec
Recursively reset a specific keyword parameter of the node and its children back to its default.
&T unsetRec(&T x, str keywordParameter)
function unsetRec
Recursively reset a selected set of keyword parameters of the node and its children back to their default.
&T <: node unsetRec(&T <: node x, set[str] keywordParameters)
function arbNode
node arbNode()
function toString
Convert a node to a string.
str toString(node T)
Examples
rascal>import Node;
ok
rascal>F = "f"(10, "abc", color="red", size="large");
node: "f"(10,"abc",
size="large",
color="red")
rascal>toString(F);
str: "\"f\"(10,\"abc\",size=\"large\",color=\"red\")"
---
"f"(10,"abc",size="large",color="red")
---
function itoString
Convert a node to an indented string.
str itoString(node T)
Examples
rascal>import Node;
ok
rascal>F = "f"(10, "abc", color="red", size="large");
node: "f"(10,"abc",
size="large",
color="red")
rascal>itoString(F);
str: "\"f\"(10,\"abc\",\n size=\"large\",\n color=\"red\")"
---
"f"(10,"abc",
size="large",
color="red")
---