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

fix: fixed a parsing error on new lines in delimited expressions #28

Merged
merged 3 commits into from
Jan 28, 2025
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
4 changes: 2 additions & 2 deletions antidotum/tergo/src/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "tergo"
version = "0.1.1"
version = "0.1.2"
edition = "2021"

[lib]
crate-type = ["staticlib"]
name = "tergo"

[dependencies]
tergo-lib = "0.2.7"
tergo-lib = "0.2.8"
toml = "0.8.19"
extendr-api = "*"

Expand Down
Binary file modified antidotum/tergo/src/rust/vendor.tar.xz
Binary file not shown.
Binary file added antidotum/tergo/tergo_0.1.5.9001.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions balnea/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tergo-lib"
version = "0.2.7"
version = "0.2.8"
edition = "2021"
description = "A tool to format R code"
license = "MIT"
Expand All @@ -13,7 +13,7 @@ path = "src/lib.rs"

[dependencies]
tokenizer = { package = "tergo-tokenizer", path = "../aqua", version = "0.2.2" }
parser = { package = "tergo-parser", path = "../spongia", version = "0.2.2" }
parser = { package = "tergo-parser", path = "../spongia", version = "0.2.3" }
formatter = { package = "tergo-formatter", path = "../unguentum", version = "0.2.6" }
log = "0.4.21"
env_logger = "0.11.3"
Expand Down
11 changes: 11 additions & 0 deletions balnea/tests/format_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ comparison_test!(
"092",
Config::default()
);
comparison_test!(regression_25, "093", Config::default());
comparison_test!(
function_call_with_one_unnamed_one_named_arg,
"094",
Config::default()
);
comparison_test!(
function_call_with_many_newlines_after_arg_names,
"095",
Config::default()
);

// Tidyverse styleguide examples
comparison_test!(tidyverse_commas, "tidyverse_style_guide_001");
Expand Down
2 changes: 2 additions & 0 deletions balnea/tests/test_cases/093.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list.files(".", ignore.case
= TRUE)
1 change: 1 addition & 0 deletions balnea/tests/test_cases/093.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list.files(".", ignore.case = TRUE)
1 change: 1 addition & 0 deletions balnea/tests/test_cases/094.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list.files(".", ignore.case = TRUE)
1 change: 1 addition & 0 deletions balnea/tests/test_cases/094.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list.files(".", ignore.case = TRUE)
8 changes: 8 additions & 0 deletions balnea/tests/test_cases/095.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
list.files(".", ignore.case

= TRUE,
test

=

1)
1 change: 1 addition & 0 deletions balnea/tests/test_cases/095.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list.files(".", ignore.case = TRUE, test = 1)
4 changes: 2 additions & 2 deletions scopa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scopa"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

[lib]
Expand All @@ -9,7 +9,7 @@ path = "./src/lib.rs"

[dependencies]
wit-bindgen = "0.32.0"
tergo-lib = { path = "../balnea", version = "0.2.0" }
tergo-lib = { path = "../balnea", version = "0.2.8" }

[dev-dependencies]
wasm-tools = "1.217.0"
2 changes: 1 addition & 1 deletion spongia/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tergo-parser"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "MIT"
description = "Parser for tergo"
Expand Down
6 changes: 3 additions & 3 deletions spongia/src/compound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
Arg, Args, Delimiter, ElseIfConditional, Expression, ForLoop, FunctionDefinition,
IfConditional, IfExpression, Lambda, RepeatExpression, TrailingElse, WhileExpression,
},
expressions::expr,
expressions::{expr, expr_with_newlines},
program::statement_or_expr,
token_parsers::*,
Input,
Expand Down Expand Up @@ -48,10 +48,10 @@ where
tuple((
left_delimiter,
many0(newline),
opt(expr),
opt(expr_with_newlines),
many0(tuple((
tuple((comma, many0(newline))),
tuple((opt(expr), many0(newline))),
tuple((opt(expr_with_newlines), many0(newline))),
))),
many0(newline),
right_delimiter,
Expand Down
16 changes: 16 additions & 0 deletions spongia/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,22 @@ pub(crate) fn expr<'a, 'b: 'a>(tokens: Input<'a, 'b>) -> IResult<Input<'a, 'b>,
}
}

pub(crate) fn expr_with_newlines<'a, 'b: 'a>(
tokens: Input<'a, 'b>,
) -> IResult<Input<'a, 'b>, Expression<'a>> {
trace!("expr: {}", TokensBuffer(tokens));
let (mut tokens, term) = unary_term(tokens)?;
while !tokens.is_empty() && tokens[0].token == Newline {
tokens = &tokens[1..];
}
if !tokens.is_empty() {
let parser = ExprParser(0);
parser.parse(term, tokens)
} else {
Ok((tokens, term))
}
}

#[cfg(test)]
mod tests {
use tokenizer::tokens::commented_tokens;
Expand Down
2 changes: 1 addition & 1 deletion tergo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ repository = "https://github.com/kpagacz/tergo/"
clap = { version = "4.5.17", features = ["derive"] }
env_logger = "0.11.5"
log = "0.4.22"
tergo-lib = { path = "../balnea", version = "0.2.7" }
tergo-lib = { path = "../balnea", version = "0.2.8" }
toml = "0.8.19"
4 changes: 2 additions & 2 deletions unguentum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tergo-formatter"
version = "0.2.6"
version = "0.2.7"
edition = "2021"
license = "MIT"
description = "Formatter for tergo"
Expand All @@ -10,7 +10,7 @@ repository = "https://github.com/kpagacz/tergo/tree/main/unguentum"

[dependencies]
tokenizer = { package = "tergo-tokenizer", path = "../aqua", version = "0.2.2" }
parser = { package = "tergo-parser", path = "../spongia", version = "0.2.2" }
parser = { package = "tergo-parser", path = "../spongia", version = "0.2.3" }
log = "0.4.21"
serde = { version = "1.0.210", features = ["derive"] }

Expand Down
Loading