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 string interpolation regression #305

Merged
merged 1 commit into from
Jul 6, 2024
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"rust-analyzer.cargo.features": ["luau", "lua52", "lua53", "lua54"]
"rust-analyzer.cargo.features": ["luau", "lua52", "lua53", "lua54", "luau"]
}
47 changes: 25 additions & 22 deletions full-moon/src/tokenizer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,33 +215,36 @@ impl Lexer {

loop {
let sent_eof = self.sent_eof;
let start_position = self.source.lexer_position;

match self.process_next() {
Some(LexerResult::Ok(token)) if token.token_type().is_trivia() => {
// Take all trivia up to and including the newline character. If we see a newline character
// we should break once we have taken it in.
let should_break =
if let TokenType::Whitespace { ref characters } = token.token_type() {
// Use contains in order to tolerate \r\n line endings and mixed whitespace tokens
characters.contains('\n')
} else {
false
};
let start_position: LexerPosition = self.source.lexer_position;

trailing_trivia.push(token);
// All things that can start trivia, so we can avoid when something definitely can't
if matches!(self.source.current(), Some('\n' | '\r' | '#' | '-' | ' ')) {
if let Some(LexerResult::Ok(token)) = self.process_next() {
if token.token_type().is_trivia() {
// Take all trivia up to and including the newline character. If we see a newline character
// we should break once we have taken it in.
let should_break =
if let TokenType::Whitespace { ref characters } = token.token_type() {
// Use contains in order to tolerate \r\n line endings and mixed whitespace tokens
characters.contains('\n')
} else {
false
};

if should_break {
break;
}
}
trailing_trivia.push(token);

_ => {
self.source.lexer_position = start_position;
self.sent_eof = sent_eof;
break;
if should_break {
break;
}

continue;
}
}
}

self.source.lexer_position = start_position;
self.sent_eof = sent_eof;
break;
}

trailing_trivia
Expand Down
89 changes: 0 additions & 89 deletions full-moon/src/tokenizer_luau.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
source: full-moon/tests/pass_cases.rs
assertion_line: 48
expression: ast.nodes()
input_file: full-moon/tests/roblox_cases/pass/string_interpolation_regression
---
stmts:
- - FunctionCall:
prefix:
Name:
leading_trivia: []
token:
start_position:
bytes: 0
line: 1
character: 1
end_position:
bytes: 5
line: 1
character: 6
token_type:
type: Identifier
identifier: error
trailing_trivia: []
suffixes:
- Call:
AnonymousCall:
Parentheses:
parentheses:
tokens:
- leading_trivia: []
token:
start_position:
bytes: 5
line: 1
character: 6
end_position:
bytes: 6
line: 1
character: 7
token_type:
type: Symbol
symbol: (
trailing_trivia:
- start_position:
bytes: 6
line: 1
character: 7
end_position:
bytes: 7
line: 1
character: 7
token_type:
type: Whitespace
characters: "\n"
- leading_trivia: []
token:
start_position:
bytes: 18
line: 3
character: 1
end_position:
bytes: 19
line: 3
character: 2
token_type:
type: Symbol
symbol: )
trailing_trivia:
- start_position:
bytes: 19
line: 3
character: 2
end_position:
bytes: 20
line: 3
character: 2
token_type:
type: Whitespace
characters: "\n"
arguments:
pairs:
- End:
InterpolatedString:
segments:
- literal:
leading_trivia:
- start_position:
bytes: 7
line: 2
character: 1
end_position:
bytes: 8
line: 2
character: 2
token_type:
type: Whitespace
characters: "\t"
token:
start_position:
bytes: 8
line: 2
character: 2
end_position:
bytes: 12
line: 2
character: 6
token_type:
type: InterpolatedString
literal: "a "
kind: Begin
trailing_trivia: []
expression:
Var:
Name:
leading_trivia: []
token:
start_position:
bytes: 12
line: 2
character: 6
end_position:
bytes: 13
line: 2
character: 7
token_type:
type: Identifier
identifier: b
trailing_trivia: []
last_string:
leading_trivia: []
token:
start_position:
bytes: 13
line: 2
character: 7
end_position:
bytes: 17
line: 2
character: 11
token_type:
type: InterpolatedString
literal: " c"
kind: End
trailing_trivia:
- start_position:
bytes: 17
line: 2
character: 11
end_position:
bytes: 18
line: 2
character: 11
token_type:
type: Whitespace
characters: "\n"
- ~

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error(
`a {b} c`
)
Loading
Loading