Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address issue 6 #7

Merged
merged 1 commit into from
Jan 17, 2022
Merged
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
27 changes: 23 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ fn run() -> Result<()> {
let mut in_literal = false;
let mut indent_level = 0;
let mut did_visit_children = false;
// rule properties
let mut has_head = false;
// after position markers
let mut after_if = false;

loop {
let node = cursor.node();
let is_named = node.is_named();
Expand All @@ -93,9 +98,16 @@ fn run() -> Result<()> {
match node.kind() {
"statement" | "comment" => {
writeln!(&mut stdout)?;
//reset rule properties
has_head = false;
}
"head" => {
has_head = true;
needs_space = true;
}
"head" | "NOT" | "aggregatefunction" => needs_space = true,
"NOT" | "aggregatefunction" => needs_space = true,
"IF" => {
after_if = true;
needs_space = true;
}
"literal" => {
Expand Down Expand Up @@ -146,7 +158,7 @@ fn run() -> Result<()> {
in_condition = true;
}
"literal" => {
if in_body && !in_literal {
if in_body && !in_literal && (!after_if || has_head) {
write!(&mut stdout, "\n ")?;
}
if in_body_agg {
Expand All @@ -158,14 +170,19 @@ fn run() -> Result<()> {
in_literal = true;
}
"lubodyaggregate" => {
if in_body && !in_literal {
if in_body && !in_literal && (!after_if || has_head) {
write!(&mut stdout, "\n ")?;
}
in_body_agg = true;
}
"IF" => {
if !has_head {
write!(&mut stdout, " ")?;
}
}
"COLON" | "cmp" => write!(&mut stdout, " ")?,
"RBRACE" => {
if in_body {
if in_body && (!after_if || has_head) {
write!(&mut stdout, "\n ")?;
} else {
write!(&mut stdout, " ")?;
Expand All @@ -183,6 +200,8 @@ fn run() -> Result<()> {
if opt.debug {
debug!("{} ", text);
}
// reset after position markers
after_if = false
}

if opt.debug {
Expand Down