Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions crates/plotnik-lib/src/bytecode/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod cols {
#[derive(Clone, Copy, Debug)]
pub struct Symbol {
/// Left modifier (2 chars): mode indicator or spaces.
/// Examples: " ", " !", ""
/// Examples: " ", " !", "!!"
pub left: &'static str,
/// Center symbol (1 char): direction or status.
/// Examples: "ε", "▽", "▷", "△", "●", "○", "⬥", "▶", "◀"
Expand Down Expand Up @@ -86,29 +86,29 @@ impl Symbol {
/// | --------------- | ------- | ----------------------------------- |
/// | Stay | (blank) | No movement, 5 spaces |
/// | Stay (epsilon) | ε | Only when no type/field constraints |
/// | StayExact | ‼· | Stay at position, exact match only |
/// | StayExact | !!! | Stay at position, exact match only |
/// | Down | ▽ | First child, skip any |
/// | DownSkip | !▽ | First child, skip trivia |
/// | DownExact | ‼▽ | First child, exact |
/// | DownExact | !!▽ | First child, exact |
/// | Next | ▷ | Next sibling, skip any |
/// | NextSkip | !▷ | Next sibling, skip trivia |
/// | NextExact | ‼▷ | Next sibling, exact |
/// | NextExact | !!▷ | Next sibling, exact |
/// | Up(n) | △ⁿ | Ascend n levels, skip any |
/// | UpSkipTrivia(n) | !△ⁿ | Ascend n, must be last non-trivia |
/// | UpExact(n) | ‼△ⁿ | Ascend n, must be last child |
/// | UpExact(n) | !!△ⁿ | Ascend n, must be last child |
pub fn nav_symbol(nav: Nav) -> Symbol {
match nav {
Nav::Stay => Symbol::EMPTY,
Nav::StayExact => Symbol::new(" ", "·", " "),
Nav::StayExact => Symbol::new(" ", "!!!", " "),
Nav::Down => Symbol::new(" ", "▽", " "),
Nav::DownSkip => Symbol::new(" !", "▽", " "),
Nav::DownExact => Symbol::new("", "▽", " "),
Nav::DownExact => Symbol::new("!!", "▽", " "),
Nav::Next => Symbol::new(" ", "▷", " "),
Nav::NextSkip => Symbol::new(" !", "▷", " "),
Nav::NextExact => Symbol::new("", "▷", " "),
Nav::NextExact => Symbol::new("!!", "▷", " "),
Nav::Up(n) => Symbol::new(" ", "△", superscript_suffix(n)),
Nav::UpSkipTrivia(n) => Symbol::new(" !", "△", superscript_suffix(n)),
Nav::UpExact(n) => Symbol::new("", "△", superscript_suffix(n)),
Nav::UpExact(n) => Symbol::new("!!", "△", superscript_suffix(n)),
}
}

Expand Down Expand Up @@ -316,14 +316,17 @@ mod tests {
fn test_symbol_format() {
assert_eq!(Symbol::EMPTY.format(), " ");
assert_eq!(Symbol::EPSILON.format(), " ε ");
assert_eq!(nav_symbol(Nav::StayExact).format(), " !!! ");
assert_eq!(nav_symbol(Nav::Down).format(), " ▽ ");
assert_eq!(nav_symbol(Nav::DownSkip).format(), " !▽ ");
assert_eq!(nav_symbol(Nav::DownExact).format(), "▽ ");
assert_eq!(nav_symbol(Nav::DownExact).format(), "!!▽ ");
assert_eq!(nav_symbol(Nav::Next).format(), " ▷ ");
assert_eq!(nav_symbol(Nav::NextSkip).format(), " !▷ ");
assert_eq!(nav_symbol(Nav::NextExact).format(), "!!▷ ");
assert_eq!(nav_symbol(Nav::Up(1)).format(), " △ ");
assert_eq!(nav_symbol(Nav::Up(2)).format(), " △² ");
assert_eq!(nav_symbol(Nav::UpSkipTrivia(1)).format(), " !△ ");
assert_eq!(nav_symbol(Nav::UpExact(1)).format(), "△ ");
assert_eq!(nav_symbol(Nav::UpExact(1)).format(), "!!△ ");
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Test:
04 ε 09, 11
06 ▶
07 ε [EndObj] 06
09 ‼· (identifier) [Node Set(M0)] 07
11 ‼· (number) [Node Set(M0)] 07
09 !!! (identifier) [Node Set(M0)] 07
11 !!! (number) [Node Set(M0)] 07
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Test:
06 ▶
07 ε [EndObj] 06
09 ε [EndEnum Set(M4)] 07
11 ‼· (identifier) [Node Set(M0)] 09
11 !!! (identifier) [Node Set(M0)] 09
13 ε [Enum(M2)] 11
15 ε [EndEnum Set(M4)] 07
17 ‼· (number) [Node Set(M1)] 15
17 !!! (number) [Node Set(M1)] 15
19 ε [Enum(M3)] 17
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Test = 01 :: T6
Test:
01 ε 02
02 ε [Obj] 04
04 ‼· (object) 05
04 !!! (object) 05
05 ε [Arr] 07
07 ε 42, 19
09 ε [EndArr Set(M5)] 11
Expand All @@ -59,10 +59,10 @@ Test:
17 ε [EndObj] 16
19 ε [EndArr Set(M5)] 17
21 ε [EndEnum Set(M4)] 12
23 ‼· (pair) [Node Set(M0)] 21
23 !!! (pair) [Node Set(M0)] 21
25 ε [Enum(M2)] 23
27 ε [EndEnum Set(M4)] 12
29 ‼· (shorthand_property_identifier) [Node Set(M1)] 27
29 !!! (shorthand_property_identifier) [Node Set(M1)] 27
31 ε [Enum(M3)] 29
33 ε 25, 31
35 ε [Obj] 33
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Test:
02 ε 09, 15
04 ▶
05 ε [EndEnum] 04
07 ‼· (identifier) [Node Set(M0)] 05
07 !!! (identifier) [Node Set(M0)] 05
09 ε [Enum(M2)] 07
11 ε [EndEnum] 04
13 ‼· (number) [Node Set(M1)] 11
13 !!! (number) [Node Set(M1)] 11
15 ε [Enum(M3)] 13
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Test = 01 :: T1
Test:
01 ε 02
02 ε [Obj] 04
04 ‼· (program) 05
04 !!! (program) 05
05 ε 10, 12
07 ▶
08 ε [EndObj] 07
10 ▽ (identifier) [Node Set(M0)] 14
12 ▽ (number) [Node Set(M0)] 14
10 !!▽ (identifier) [Node Set(M0)] 14
12 !!▽ (number) [Node Set(M0)] 14
14 △ 08
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Test:
04 ε 11, 15
06 ▶
07 ε [EndObj] 06
09 ‼· (identifier) [Node Set(M0)] 07
09 !!! (identifier) [Node Set(M0)] 07
11 ε [Null Set(M1)] 09
13 ‼· (number) [Node Set(M1)] 07
13 !!! (number) [Node Set(M1)] 07
15 ε [Null Set(M0)] 13
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Test = 09 :: T4
Inner:
01 ε 02
02 ε [Obj] 04
04 ‼· (identifier) [Node Set(M0)] 06
04 !!! (identifier) [Node Set(M0)] 06
06 ε [EndObj] 08
08 ▶

Expand All @@ -58,8 +58,8 @@ Test:
14 ▶
15 ε [EndObj] 14
17 ε [EndEnum Set(M4)] 15
19 ‼· (Inner) 17 ⯇
19 !!! (Inner) 17 ⯇
20 ε [Enum(M2)] 19
22 ε [EndEnum Set(M4)] 15
24 ‼· (number) [Node Set(M1)] 22
24 !!! (number) [Node Set(M1)] 22
26 ε [Enum(M3)] 24
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Test:
04 ε 11, 15
06 ▶
07 ε [EndObj] 06
09 ‼· (identifier) [Node Set(M0)] 07
09 !!! (identifier) [Node Set(M0)] 07
11 ε [Null Set(M1)] 09
13 ‼· (string) [Node Set(M1)] 07
13 !!! (string) [Node Set(M1)] 07
15 ε [Null Set(M0)] 13
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Test = 1 :: T0

Test:
1 ε 2
2 ‼· (parent) 3
2 !!! (parent) 3
3 ▽ (a) 4
4 !▷ (b) 5
5 △ 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Test = 1 :: T0

Test:
1 ε 2
2 ‼· (parent) 3
2 !!! (parent) 3
3 !▽ (first) 4
4 △ 5
5 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Test = 1 :: T0

Test:
1 ε 2
2 ‼· (parent) 3
2 !!! (parent) 3
3 ▽ (last) 4
4 !△ 5
5 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Test = 1 :: T0

Test:
1 ε 2
2 ‼· (parent) 3
2 !!! (parent) 3
3 ▽ (a) 4
4 ▷ (b) 5
5 △ 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Test = 1 :: T0

Test:
1 ε 2
2 ‼· (parent) 3
2 !!! (parent) 3
3 ▽ (+) 4
4 ▷ (next) 5
4 !!▷ (next) 5
5 △ 6
6 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Test = 1 :: T1
Test:
1 ε 2
2 ε [Obj] 4
4 ‼· (identifier) [Node Set(M0)] 6
4 !!! (identifier) [Node Set(M0)] 6
6 ε [EndObj] 8
8 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Test = 01 :: T1
Test:
01 ε 02
02 ε [Obj] 04
04 ‼· (a) [Node Set(M0)] 06
04 !!! (a) [Node Set(M0)] 06
06 ▽ (b) [Node Set(M1)] 08
08 ▽ (c) [Node Set(M2)] 10
10 ▽ (d) [Node Set(M3)] 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Test = 01 :: T1
Test:
01 ε 02
02 ε [Obj] 04
04 ‼· (binary_expression) 05
04 !!! (binary_expression) 05
05 ▽ (identifier) [Node Set(M0)] 07
07 ▷ (number) [Node Set(M1)] 09
09 △ 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Test = 01 :: T1
Test:
01 ε 02
02 ε [Obj] 04
04 ‼· (a) [Node Set(M0)] 06
04 !!! (a) [Node Set(M0)] 06
06 ▽ (b) [Node Set(M1)] 08
08 ▽ (c) [Node Set(M2)] 10
10 △ 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ Test:
09 ε [EndObj] 08
11 ε [EndObj Set(M2)] 09
13 ε [EndObj Set(M1)] 11
15 ‼· (identifier) [Node Set(M0)] 13
15 !!! (identifier) [Node Set(M0)] 13
17 ε [Obj] 15
19 ε [Null Set(M1)] 11
21 ▷ 24
22 ε 21, 19
24 ε 17, 22
26 ‼· 24
26 !!! 24
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Test:
01 ε 02
02 ε [Obj] 04
04 ε [Obj] 06
06 ‼· (a) [Node Set(M0)] 08
06 !!! (a) [Node Set(M0)] 08
08 ▷ (b) [Node Set(M1)] 10
10 ε [EndObj Set(M2)] 12
12 ε [EndObj] 14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ Test = 1 :: T2
Test:
1 ε 2
2 ε [Obj] 4
4 ‼· (identifier) [Node Set(M0)] 6
4 !!! (identifier) [Node Set(M0)] 6
6 ε [EndObj] 8
8 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Test = 1 :: T1
Test:
1 ε 2
2 ε [Obj] 4
4 ‼· (identifier) [Text Set(M0)] 6
4 !!! (identifier) [Text Set(M0)] 6
6 ε [EndObj] 8
8 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ Test:
15 ε [EndArr Set(M3)] 13
17 ε [EndObj Set(M2)] 08
19 ▷ (number) [Node Set(M1)] 17
21 ‼· (identifier) [Node Set(M0)] 19
21 !!! (identifier) [Node Set(M0)] 19
23 ε [Obj] 21
25 ε [Obj] 23
27 ▷ 30
28 ε 27, 15
30 ε 25, 28
32 ‼· 30
32 !!! 30
33 ▷ 36
34 ε 33, 15
36 ε 25, 34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Ident = 01 :: T02
Ident:
01 ε 02
02 ε [Obj] 04
04 ‼· (identifier) [Text Set(M0)] 06
04 !!! (identifier) [Text Set(M0)] 06
06 ε [EndObj] 08
08 ▶

Expand All @@ -78,7 +78,7 @@ Expression:
Assignment:
12 ε 13
13 ε [Obj] 15
15 ‼· (assignment_expression) 16
15 !!! (assignment_expression) 16
16 ▽ left: (identifier) [Node Set(M6)] 18
18 ▷ right: (Expression) 19 ⯇
19 ε [Set(M5)] 21
Expand All @@ -87,8 +87,8 @@ Assignment:
24 ▶
25 ▶
26 ε [EndEnum] 25
28 ‼· (number) [Node Set(M1)] 26
28 !!! (number) [Node Set(M1)] 26
30 ε [Enum(M3)] 28
32 ε [EndEnum] 25
34 ‼· (identifier) [Node Set(M2)] 32
34 !!! (identifier) [Node Set(M2)] 32
36 ε [Enum(M4)] 34
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ Foo = 01 :: T1
Foo:
01 ε 02
02 ε [Obj] 04
04 ‼· (identifier) [Node Set(M0)] 06
04 !!! (identifier) [Node Set(M0)] 06
06 ε [EndObj] 08
08 ▶

Bar:
09 ε 10
10 ε [Obj] 12
12 ‼· (string) [Node Set(M1)] 14
12 !!! (string) [Node Set(M1)] 14
14 ε [EndObj] 16
16 ▶
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Outer = 11 :: T4
Inner:
01 ε 02
02 ε [Obj] 04
04 ‼· (call) 05
04 !!! (call) 05
05 ▽ (identifier) [Node Set(M0)] 07
07 △ 08
08 ε [EndObj] 10
Expand All @@ -54,7 +54,7 @@ Inner:
Outer:
11 ε 12
12 ε [Obj] 14
14 ‼· (parent) 15
14 !!! (parent) 15
15 ε [Arr] 17
17 ε 41, 29
19 ε [EndArr Set(M3)] 21
Expand All @@ -65,7 +65,7 @@ Outer:
27 ε [EndObj] 26
29 ε [EndArr Set(M3)] 27
31 ε [Set(M2)] 22
33 ‼· (Inner) 31 ⯇
33 !!! (Inner) 31 ⯇
34 ε [Obj] 33
36 ▷ 39
37 ε 36, 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ Expression:
Root:
06 ε 07
07 ε [Obj] 09
09 ‼· (function_declaration) 10
09 !!! (function_declaration) 10
10 ▽ name: (identifier) [Node Set(M2)] 12
12 △ 13
13 ε [EndObj] 15
15 ▶
16 ▶
17 ε [EndObj] 16
19 ‼· (identifier) [Node Set(M0)] 17
19 !!! (identifier) [Node Set(M0)] 17
21 ε [Null Set(M1)] 19
23 ‼· (number) [Node Set(M1)] 17
23 !!! (number) [Node Set(M1)] 17
25 ε [Null Set(M0)] 23
Loading