Skip to main content

module vis::Text

rascal-0.34.0

This module provides functions that map values to strings using ASCII Art pretty printing.

The words ASCII Art refers to the technique of constructing images from text characters that are in the ASCII set. However, in this case we may use any Unicode character for visual representation purposes. Visualizing values using "ASCII art".

Usage

import vis::Text;

Dependencies

import Node;
import List;
import ListRelation;
import ParseTree;
import Type;

Examples

rascal>syntax E = "e" | E "+" E;
ok
rascal>import IO;
ok
rascal>import vis::Text;
ok
rascal>ex = prettyTree([E] "e+e+e");
str: " ❖\n ├─ E = E \"+\" E \n │ ├─ E = \"e\" \n │ └─ E = E \"+\" E \n │ ├─ E = \"e\" \n │ └─ E = \"e\" \n └─ E = E \"+\" E \n ├─ E = E \"+\" E \n │ ├─ E = \"e\" \n │ └─ E = \"e\" \n └─ E = \"e\" \n"
---

├─ E = E "+" E
│ ├─ E = "e"
│ └─ E = E "+" E
│ ├─ E = "e"
│ └─ E = "e"
└─ E = E "+" E
├─ E = E "+" E
│ ├─ E = "e"
│ └─ E = "e"
└─ E = "e"

---
rascal>println(ex);

├─ E = E "+" E
│ ├─ E = "e"
│ └─ E = E "+" E
│ ├─ E = "e"
│ └─ E = "e"
└─ E = E "+" E
├─ E = E "+" E
│ ├─ E = "e"
│ └─ E = "e"
└─ E = "e"
ok

function prettyTree

Pretty prints parse trees using ASCII art lines for edges.

str prettyTree(Tree t, bool src=false, bool characters=true, bool \layout=false, bool literals=\layout)

function prettyNode

Pretty prints nodes and ADTs using ASCII art for the edges.

str prettyNode(node n, bool keywords=true)

function ppvalue

str ppvalue(value e, str(value) nodeLabel, lrel[str,value](value) edges)

function ppvalue {#vis-Text-ppvalue}

str ppvalue_(value e, str(value) nodeLabel, lrel[str,value](value) edges, str indent = "")