Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8e5e3b0

Browse files
committed
Visualize to_son (sea of nodes) using mermaid.js already added
1 parent da5f1f3 commit 8e5e3b0

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ <h1>Syntax Tree</h1>
2020
<option value="prettyPrint">AST</option>
2121
<option value="disasm">ISEQ</option>
2222
<option value="mermaid">GRAPH</option>
23+
<option value="seaOfNodes">SEA OF NODES</option>
2324
</select>
2425
</div>
2526
</nav>

src/createRuby.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ export default async function createRuby() {
2525

2626
return vm.eval(rubySource).toString();
2727
},
28-
mermaid(source) {
29-
const jsonSource = JSON.stringify(JSON.stringify(source));
30-
const rubySource = `SyntaxTree.parse(JSON.parse(${jsonSource})).to_mermaid`;
31-
32-
return vm.eval(rubySource).toString();
33-
},
3428
// A function that calls through to the SyntaxTree.format function to get
3529
// the pretty-printed version of the source.
3630
format(source) {
@@ -39,13 +33,30 @@ export default async function createRuby() {
3933

4034
return vm.eval(rubySource).toString();
4135
},
36+
mermaid(source) {
37+
const jsonSource = JSON.stringify(JSON.stringify(source));
38+
const rubySource = `SyntaxTree.parse(JSON.parse(${jsonSource})).to_mermaid`;
39+
40+
return vm.eval(rubySource).toString();
41+
},
4242
// A function that calls through to PP to get the pretty-printed version of
4343
// the syntax tree.
4444
prettyPrint(source) {
4545
const jsonSource = JSON.stringify(JSON.stringify(source));
4646
const rubySource = `PP.pp(SyntaxTree.parse(JSON.parse(${jsonSource})), +"", 80)`;
4747

4848
return vm.eval(rubySource).toString();
49-
}
49+
},
50+
// A function to print the current YARV execution
51+
seaOfNodes(source) {
52+
const jsonSource = JSON.stringify(JSON.stringify(source));
53+
const rubySource = `
54+
iseq = RubyVM::InstructionSequence.compile(JSON.parse(${jsonSource}))
55+
iseq = SyntaxTree::YARV::InstructionSequence.from(iseq.to_a)
56+
iseq.to_son.to_mermaid
57+
`;
58+
59+
return vm.eval(rubySource).toString();
60+
}
5061
};
5162
};

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Promise.all([
5050
try {
5151
let source = displayFunction(editor.getValue());
5252

53-
if (event.detail.kind === "mermaid") {
53+
if (event.detail.kind === "mermaid" || event.detail.kind === "seaOfNodes") {
5454
output.setAttribute("style", "display: none;");
5555
graph.setAttribute("style", "text-align: left;")
5656
graph.innerHTML = "Loading..."

0 commit comments

Comments
 (0)