Skip to content

Commit 212df5d

Browse files
committed
feat: pretty-print attempt 2
1 parent f61d5a1 commit 212df5d

File tree

444 files changed

+126113
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

444 files changed

+126113
-0
lines changed

Cargo.lock

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ slotmap = "1.0.7"
4343
smallvec = { version = "1.13.2", features = ["union", "const_new", "serde"] }
4444
strum = { version = "0.27.1", features = ["derive"] }
4545
# this will use tokio if available, otherwise async-std
46+
camino = "1.1.9"
4647
convert_case = "0.6.0"
48+
dir-test = "0.4.1"
4749
prost = "0.13.5"
4850
prost-reflect = "0.15.3"
4951
protox = "0.8.0"
@@ -77,6 +79,8 @@ pgt_lexer_codegen = { path = "./crates/pgt_lexer_codegen", version = "0
7779
pgt_lsp = { path = "./crates/pgt_lsp", version = "0.0.0" }
7880
pgt_markup = { path = "./crates/pgt_markup", version = "0.0.0" }
7981
pgt_plpgsql_check = { path = "./crates/pgt_plpgsql_check", version = "0.0.0" }
82+
pgt_pretty_print = { path = "./crates/pgt_pretty_print", version = "0.0.0" }
83+
pgt_pretty_print_codegen = { path = "./crates/pgt_pretty_print_codegen", version = "0.0.0" }
8084
pgt_query = { path = "./crates/pgt_query", version = "0.0.0" }
8185
pgt_query_ext = { path = "./crates/pgt_query_ext", version = "0.0.0" }
8286
pgt_query_macros = { path = "./crates/pgt_query_macros", version = "0.0.0" }

crates/pgt_pretty_print/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
authors.workspace = true
3+
categories.workspace = true
4+
description = "<DESCRIPTION>"
5+
edition.workspace = true
6+
homepage.workspace = true
7+
keywords.workspace = true
8+
license.workspace = true
9+
name = "pgt_pretty_print"
10+
repository.workspace = true
11+
version = "0.0.0"
12+
13+
14+
[dependencies]
15+
pgt_pretty_print_codegen.workspace = true
16+
pgt_query.workspace = true
17+
18+
[dev-dependencies]
19+
camino.workspace = true
20+
dir-test.workspace = true
21+
insta.workspace = true
22+
pgt_statement_splitter.workspace = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pgt_pretty_print_codegen::group_kind_codegen!();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod group_kind;
2+
pub mod token_kind;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pgt_pretty_print_codegen::token_kind_codegen!();
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
pub use crate::codegen::group_kind::GroupKind;
2+
pub use crate::codegen::token_kind::TokenKind;
3+
4+
#[derive(Debug, Clone, PartialEq)]
5+
pub enum LineType {
6+
/// Must break (semicolon, etc.)
7+
Hard,
8+
/// Break if group doesn't fit
9+
Soft,
10+
/// Break if group doesn't fit, but collapse to space if it does
11+
SoftOrSpace,
12+
}
13+
14+
#[derive(Debug, Clone, PartialEq)]
15+
pub enum LayoutEvent {
16+
Token(TokenKind),
17+
Space,
18+
Line(LineType),
19+
GroupStart { kind: GroupKind },
20+
GroupEnd,
21+
IndentStart,
22+
IndentEnd,
23+
}
24+
25+
#[derive(Debug, Default)]
26+
pub struct EventEmitter {
27+
pub events: Vec<LayoutEvent>,
28+
}
29+
30+
impl EventEmitter {
31+
pub fn new() -> Self {
32+
Self::default()
33+
}
34+
35+
pub fn token(&mut self, token: TokenKind) {
36+
self.events.push(LayoutEvent::Token(token));
37+
}
38+
39+
pub fn space(&mut self) {
40+
self.events.push(LayoutEvent::Space);
41+
}
42+
43+
pub fn line(&mut self, line_type: LineType) {
44+
self.events.push(LayoutEvent::Line(line_type));
45+
}
46+
47+
pub fn group_start(&mut self, kind: GroupKind) {
48+
self.events.push(LayoutEvent::GroupStart { kind });
49+
}
50+
51+
pub fn group_end(&mut self) {
52+
self.events.push(LayoutEvent::GroupEnd);
53+
}
54+
55+
pub fn indent_start(&mut self) {
56+
self.events.push(LayoutEvent::IndentStart);
57+
}
58+
59+
pub fn indent_end(&mut self) {
60+
self.events.push(LayoutEvent::IndentEnd);
61+
}
62+
}

crates/pgt_pretty_print/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mod codegen;
2+
pub mod emitter;
3+
pub mod nodes;
4+
pub mod renderer;
5+
6+
pub use crate::codegen::token_kind::TokenKind;

0 commit comments

Comments
 (0)