summaryrefslogtreecommitdiff
path: root/src/syntax/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-11 17:33:13 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-11 17:33:13 +0100
commit1711b67877ce5c290e049775c340c9324f15341e (patch)
tree92d6ff7285cdc2d694ccfdf733ce8757866636ec /src/syntax/mod.rs
parentf9197dcfef11c4c054a460c80ff6023dae6f1f2a (diff)
Move all pretty printing into one module and pretty print values 🦋
Diffstat (limited to 'src/syntax/mod.rs')
-rw-r--r--src/syntax/mod.rs128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs
index a8ed2457..09c445b0 100644
--- a/src/syntax/mod.rs
+++ b/src/syntax/mod.rs
@@ -13,133 +13,5 @@ pub use node::*;
pub use span::*;
pub use token::*;
-use crate::pretty::{Pretty, Printer};
-
/// The abstract syntax tree.
pub type Tree = Vec<Node>;
-
-impl Pretty for Tree {
- fn pretty(&self, p: &mut Printer) {
- for node in self {
- node.pretty(p);
- }
- }
-}
-
-#[cfg(test)]
-mod tests {
- use crate::parse::parse;
- use crate::pretty::pretty;
-
- #[track_caller]
- fn test(src: &str, exp: &str) {
- let tree = parse(src).output;
- let found = pretty(&tree);
- if exp != found {
- println!("tree: {:#?}", tree);
- println!("expected: {}", exp);
- println!("found: {}", found);
- panic!("test failed");
- }
- }
-
- #[track_caller]
- fn roundtrip(src: &str) {
- test(src, src);
- }
-
- #[test]
- fn test_pretty_print_node() {
- // Basic text and markup.
- roundtrip("*");
- roundtrip("_");
- roundtrip(" ");
- roundtrip("\\ ");
- roundtrip("\n\n");
- roundtrip("hi");
-
- // Heading.
- roundtrip("= *Ok*");
-
- // Raw.
- roundtrip("``");
- roundtrip("`nolang 1`");
- roundtrip("```lang 1```");
- roundtrip("```lang 1 ```");
- roundtrip("```hi line ```");
- roundtrip("```py\ndef\n```");
- roundtrip("```\n line \n```");
- roundtrip("```\n`\n```");
- roundtrip("``` ` ```");
- roundtrip("````\n```\n```\n````");
- test("```lang```", "```lang ```");
- test("```1 ```", "``");
- test("``` 1```", "`1`");
- test("``` 1 ```", "`1 `");
- test("```` ` ````", "``` ` ```");
- }
-
- #[test]
- fn test_pretty_print_expr() {
- // Basic expressions.
- roundtrip("{none}");
- roundtrip("{hi}");
- roundtrip("{true}");
- roundtrip("{10}");
- roundtrip("{3.14}");
- roundtrip("{10.0pt}");
- roundtrip("{14.1deg}");
- roundtrip("{20.0%}");
- roundtrip("{#abcdef}");
- roundtrip(r#"{"hi"}"#);
- test(r#"{"let's \" go"}"#, r#"{"let's \" go"}"#);
-
- // Arrays.
- roundtrip("{()}");
- roundtrip("{(1)}");
- roundtrip("{(1, 2, 3)}");
-
- // Dictionaries.
- roundtrip("{(:)}");
- roundtrip("{(key: value)}");
- roundtrip("{(a: 1, b: 2)}");
-
- // Templates.
- roundtrip("[]");
- roundtrip("[*Ok*]");
- roundtrip("{[f]}");
-
- // Groups.
- roundtrip("{(1)}");
-
- // Blocks.
- roundtrip("{}");
- roundtrip("{1}");
- roundtrip("{ #let x = 1; x += 2; x + 1 }");
- roundtrip("[{}]");
-
- // Operators.
- roundtrip("{-x}");
- roundtrip("{not true}");
- roundtrip("{1 + 3}");
-
- // Parenthesized calls.
- roundtrip("{v()}");
- roundtrip("{v(1)}");
- roundtrip("{v(a: 1, b)}");
-
- // Function templates.
- roundtrip("#[v]");
- roundtrip("#[v 1]");
- roundtrip("#[v 1, 2][*Ok*]");
- roundtrip("#[v 1 | f 2]");
- test("{#[v]}", "{v()}");
- test("#[v 1, #[f 2]]", "#[v 1 | f 2]");
-
- // Keywords.
- roundtrip("#let x = 1 + 2");
- roundtrip("#if x [y] #else [z]");
- roundtrip("#for x #in y {z}");
- roundtrip("#for k, x #in y {z}");
- }
-}