-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Parsing validation fails with bareword containing #
in block
#10327
Comments
Can confirm. Also, still doesn't work if I try running via
(same with your example So it seems this is not just a problem with the REPL not allowing you to submit the command, the |
ooh i stumbled upon the same exact one when writing this, where i tried |
Could I be assigned to this issue? I also have a suggested solution, please review that. Patch of suggested solutionIndex: crates/nu-parser/src/lex.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/crates/nu-parser/src/lex.rs b/crates/nu-parser/src/lex.rs
--- a/crates/nu-parser/src/lex.rs (revision Staged)
+++ b/crates/nu-parser/src/lex.rs (date 1733255567176)
@@ -51,7 +51,7 @@
}
// A baseline token is terminated if it's not nested inside of a paired
-// delimiter and the next character is one of: `|`, `;`, `#` or any
+// delimiter and the next character is one of: `|`, `;` or any
// whitespace.
fn is_item_terminator(
block_level: &[BlockKind],
@@ -115,6 +115,7 @@
// character (whitespace, `|`, `;` or `#`) is encountered, the baseline
// token is done.
// - Otherwise, accumulate the character into the current baseline token.
+ let mut previous_char = None;
while let Some(c) = input.get(*curr_offset) {
let c = *c;
@@ -150,8 +151,11 @@
} else if c == b'#' {
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
break;
- }
- in_comment = true;
+ } else if previous_char.map(|c: char| c.is_alphabetic()).unwrap_or(false) {
+ in_comment = false;
+ } else {
+ in_comment = true;
+ }
} else if c == b'\n' || c == b'\r' {
in_comment = false;
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
@@ -254,6 +258,7 @@
}
*curr_offset += 1;
+ previous_char = Some(c as char);
}
let span = Span::new(span_offset + token_start, span_offset + *curr_offset); I did test it manually: All current tests passes but I have not run any other checks. I also need to test if the condition also catches all letters or just the ASCII ones. Slightly better versionPatch of suggested solutionIndex: crates/nu-parser/src/lex.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/crates/nu-parser/src/lex.rs b/crates/nu-parser/src/lex.rs
--- a/crates/nu-parser/src/lex.rs (revision Staged)
+++ b/crates/nu-parser/src/lex.rs (date 1733256555600)
@@ -51,7 +51,7 @@
}
// A baseline token is terminated if it's not nested inside of a paired
-// delimiter and the next character is one of: `|`, `;`, `#` or any
+// delimiter and the next character is one of: `|`, `;` or any
// whitespace.
fn is_item_terminator(
block_level: &[BlockKind],
@@ -115,6 +115,7 @@
// character (whitespace, `|`, `;` or `#`) is encountered, the baseline
// token is done.
// - Otherwise, accumulate the character into the current baseline token.
+ let mut previous_char = 0;
while let Some(c) = input.get(*curr_offset) {
let c = *c;
@@ -151,7 +152,7 @@
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
break;
}
- in_comment = true;
+ in_comment = previous_char == b' ';
} else if c == b'\n' || c == b'\r' {
in_comment = false;
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
@@ -254,6 +255,7 @@
}
*curr_offset += 1;
+ previous_char = c;
}
let span = Span::new(span_offset + token_start, span_offset + *curr_offset); |
In the case if you have some working idea please open a draft PR directly, so we can discuss the necessary new tests or get folks to review the idea. Patch comments on GitHub are harder to work with than a quick |
Here is a draft of the suggestion: #14523 |
…e the first character of the token or prefixed with ` ` (space). (nushell#10327)
…cter of the token or prefixed with ` ` (space). (nushell#10327) Draft solution for better comment handling. nushell#10327
#14548) This PR should close 1. #10327 1. #13667 1. #13810 1. #14129 # Description For `#` to start a comment, then it either need to be the first character of the token or prefixed with ` ` (space). So now you can do this: ``` ~/Projects/nushell> 1..10 | each {echo test#testing } 12/05/2024 05:37:19 PM ╭───┬──────────────╮ │ 0 │ test#testing │ │ 1 │ test#testing │ │ 2 │ test#testing │ │ 3 │ test#testing │ │ 4 │ test#testing │ │ 5 │ test#testing │ │ 6 │ test#testing │ │ 7 │ test#testing │ │ 8 │ test#testing │ │ 9 │ test#testing │ ╰───┴──────────────╯ ``` # User-Facing Changes It is a breaking change if anyone expected comments to start in the middle of a string without any prefixing ` ` (space). # Tests + Formatting Did all: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library # After Submitting I cant see that I need to update anything in [the documentation](https://github.com/nushell/nushell.github.io) but please point me in the direction if there is anything. --------- Co-authored-by: Wind <WindSoilder@outlook.com>
…cter of the token or prefixed with ` ` (space). (nushell#10327)
#14562) This PR should close 1. #10327 1. #13667 1. #13810 1. #14129 # Description For `#` to start a comment, then it either need to be the first character of the token or prefixed with ` ` (space). So now you can do this: ``` ~/Projects/nushell> 1..10 | each {echo test#testing } 12/05/2024 05:37:19 PM ╭───┬──────────────╮ │ 0 │ test#testing │ │ 1 │ test#testing │ │ 2 │ test#testing │ │ 3 │ test#testing │ │ 4 │ test#testing │ │ 5 │ test#testing │ │ 6 │ test#testing │ │ 7 │ test#testing │ │ 8 │ test#testing │ │ 9 │ test#testing │ ╰───┴──────────────╯ ``` # User-Facing Changes It is a breaking change if anyone expected comments to start in the middle of a string without any prefixing ` ` (space). # Tests + Formatting Did all: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library # After Submitting I cant see that I need to update anything in [the documentation](https://github.com/nushell/nushell.github.io) but please point me in the direction if there is anything.
… prefixed with any whitespace.
…of token (#14616) This PR should close 1. #10327 1. #13667 1. #13810 1. #14129 # Description This got reverted #14606 because the previous changes only considered space a whitespace and forgot about tabs. I now added a check for any whitespace, even if it is only those two that would be relevant. The added test failed before the changes. For `#` to start a comment, then it either need to be the first character of the token or prefixed with ` ` (space). So now you can do this: ``` ~/Projects/nushell> 1..10 | each {echo test#testing } 12/05/2024 05:37:19 PM ╭───┬──────────────╮ │ 0 │ test#testing │ │ 1 │ test#testing │ │ 2 │ test#testing │ │ 3 │ test#testing │ │ 4 │ test#testing │ │ 5 │ test#testing │ │ 6 │ test#testing │ │ 7 │ test#testing │ │ 8 │ test#testing │ │ 9 │ test#testing │ ╰───┴──────────────╯ ``` # User-Facing Changes It is a breaking change if anyone expected comments to start in the middle of a string without any prefixing ` ` (space). # Tests + Formatting Did all: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library # After Submitting I cant see that I need to update anything in [the documentation](https://github.com/nushell/nushell.github.io) but please point me in the direction if there is anything.
Closed by #14616 |
Describe the bug
On the REPL insert, and try to submit via enter.
This will continue to insert a new line as if the block was not closed.
The basic behavior that a string containing a
#
is not interpreted as a comment (commonly found in the nix context) still works outside the block:The original problem was described in: (#6957, #6335, #8137)
The parsing/lexing change to make it possible came with #8151
How to reproduce
Expected behavior
Should be a valid expression to submit
Screenshots
No response
Configuration
Additional context
No response
The text was updated successfully, but these errors were encountered: