generated from tweag/project
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphViz visualisation support (#326)
* Basic GraphViz visualisation support * Different shapes for node types * Updated README (also included changes identified by review of the upcoming release announcement blog post: tweag/www#1550 (comment))
- Loading branch information
1 parent
a721772
commit c4fe76c
Showing
5 changed files
with
106 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// GraphViz visualisation for our SyntaxTree representation | ||
/// Named syntax nodes are elliptical; anonymous are rectangular | ||
use std::{fmt, io}; | ||
|
||
use crate::{tree_sitter::SyntaxNode, FormatterResult}; | ||
|
||
impl fmt::Display for SyntaxNode { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let shape = match self.is_named { | ||
true => "ellipse", | ||
false => "box", | ||
}; | ||
|
||
writeln!( | ||
f, | ||
" {} [label=\"{}\", shape={shape}];", | ||
self.id, | ||
self.kind.escape_default() | ||
)?; | ||
|
||
for child in &self.children { | ||
writeln!(f, " {} -- {};", self.id, child.id)?; | ||
write!(f, "{child}")?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn write(output: &mut dyn io::Write, root: &SyntaxNode) -> FormatterResult<()> { | ||
writeln!(output, "graph {{")?; | ||
write!(output, "{root}")?; | ||
writeln!(output, "}}")?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters