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

1016 leading whitespaces after indentation are not parsed correctly #1023

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 11 additions & 14 deletions compiler/frontend/src/string_to_rcst/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ mod test {
closing_double_quote: DoubleQuote
closing_single_quotes:
"###);
// issue: https://github.com/candy-lang/candy/issues/1016
assert_rich_ir_snapshot!(text("\"\n text\n\"", 0), @r###"
// https://github.com/candy-lang/candy/issues/1016
assert_rich_ir_snapshot!(text("\"\n foo\n bar\n\"", 0), @r###"
Remaining input: ""
Parsed: Text:
opening: TrailingWhitespace:
Expand All @@ -305,18 +305,22 @@ mod test {
whitespace:
Newline "\n"
Whitespace " "
Whitespace " "
parts:
TextPart "foo"
TrailingWhitespace:
child: TextPart "text"
child: TextNewline "\n"
whitespace:
Whitespace " "
TrailingWhitespace:
child: TextPart " bar"
whitespace:
Newline "\n"
closing: ClosingText:
closing_double_quote: DoubleQuote
closing_single_quotes:
"###);
// https://github.com/candy-lang/candy/issues/1016
assert_rich_ir_snapshot!(text("\"\n foo\n bar\n\"", 0), @r###"
// issue: https://github.com/candy-lang/candy/issues/1016
assert_rich_ir_snapshot!(text("\"\n text\n\"", 0), @r###"
Remaining input: ""
Parsed: Text:
opening: TrailingWhitespace:
Expand All @@ -327,21 +331,14 @@ mod test {
Newline "\n"
Whitespace " "
parts:
TextPart "foo"
TrailingWhitespace:
child: TextNewline "\n"
whitespace:
Whitespace " "
Whitespace " "
TrailingWhitespace:
child: TextPart "bar"
child: TextPart " text"
whitespace:
Newline "\n"
closing: ClosingText:
closing_double_quote: DoubleQuote
closing_single_quotes:
"###);

assert_rich_ir_snapshot!(text("\" foobar \"", 0), @r###"
Remaining input: ""
Parsed: Text:
Expand Down
10 changes: 6 additions & 4 deletions compiler/frontend/src/string_to_rcst/whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ pub fn whitespaces_and_newlines(
new_parts.push(newline);
is_sufficiently_indented = false;
}

if let Some((new_new_input, whitespace)) = leading_indentation(new_input, indentation) {
new_input = new_new_input;
new_parts.push(whitespace);

input = new_input;
parts.append(&mut new_parts);
is_sufficiently_indented = true;
} else if let Some((new_new_input, whitespace)) = single_line_whitespace(new_input) {
}
if let Some((new_new_input, whitespace)) = single_line_whitespace(new_input) {
new_input = new_new_input;
new_parts.push(whitespace);
}
Expand Down Expand Up @@ -231,16 +231,18 @@ mod test {
assert_rich_ir_snapshot!(
whitespaces_and_newlines("\n foo", 0, true),
@r###"
Remaining input: " foo"
Remaining input: "foo"
Parsed: Newline "\n"
Whitespace " "
"###
);
assert_rich_ir_snapshot!(
whitespaces_and_newlines(" \n foo", 0, true),
@r###"
Remaining input: " foo"
Remaining input: "foo"
Parsed: Whitespace " "
Newline "\n"
Whitespace " "
"###
);
Comment on lines 231 to 247
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the Whitespace here be wrapped in CstError::TooMuchWhitespace in the general case? (For parsed text, the output looks fine)

assert_rich_ir_snapshot!(
Expand Down
Loading