diff --git a/CHANGELOG.md b/CHANGELOG.md index 123f11d3..9dc1a1b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Flattened `Expression::Value` to all be variants of `Expression` directly, as this was not used anywhere else. The extra `type_assertion` field has been moved into a new variant `Expression::TypeAssertion`. None of these variants are boxed. - The following fields/variants have been changed from `Expression` to `Box`: `Prefix::Expression`, `Var::Expression`, `IfExpression::condition`, `IfExpression::if_expression`, `IfExpression::else_expression`. - When using serde, `Expression` will no longer act untagged. + +### Fixed - Fixed parsing of string interpolation double brace for Luau code +- Fixed failure to parse `\z` escapes in strings in Luau mode ## [0.18.1] - 2023-03-19 ### Fixed diff --git a/full-moon/src/atom.rs b/full-moon/src/atom.rs index fd3d035a..e2fff7b6 100644 --- a/full-moon/src/atom.rs +++ b/full-moon/src/atom.rs @@ -30,11 +30,11 @@ fn test_bracket_head(slice: &str) -> Option { fn read_string(lex: &mut Lexer, quote: char) -> bool { let mut escape = false; - #[cfg(feature = "lua52")] + #[cfg(any(feature = "lua52", feature = "roblox"))] let mut z_escaped = false; for char in lex.remainder().chars() { match (escape, char) { - #[cfg(feature = "lua52")] + #[cfg(any(feature = "lua52", feature = "roblox"))] (true, 'z') => { escape = false; z_escaped = true @@ -50,7 +50,7 @@ fn read_string(lex: &mut Lexer, quote: char) -> bool { } } (false, '\\') => escape = true, - #[cfg(feature = "lua52")] + #[cfg(any(feature = "lua52", feature = "roblox"))] (false, '\n' | '\r') if z_escaped => z_escaped = false, (false, '\n' | '\r') => break, (false, ..) if char == quote => { diff --git a/full-moon/tests/roblox_cases/pass/z-escape-string/ast.snap b/full-moon/tests/roblox_cases/pass/z-escape-string/ast.snap new file mode 100644 index 00000000..714faee2 --- /dev/null +++ b/full-moon/tests/roblox_cases/pass/z-escape-string/ast.snap @@ -0,0 +1,77 @@ +--- +source: full-moon/tests/pass_cases.rs +expression: ast.nodes() +--- +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: print + 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: [] + - leading_trivia: [] + token: + start_position: + bytes: 29 + line: 2 + character: 12 + end_position: + bytes: 30 + line: 2 + character: 13 + token_type: + type: Symbol + symbol: ) + trailing_trivia: [] + arguments: + pairs: + - End: + String: + leading_trivia: [] + token: + start_position: + bytes: 6 + line: 1 + character: 7 + end_position: + bytes: 29 + line: 2 + character: 12 + token_type: + type: StringLiteral + literal: "testing \\z\n\t twelve" + quote_type: Double + trailing_trivia: [] + - ~ + diff --git a/full-moon/tests/roblox_cases/pass/z-escape-string/source.lua b/full-moon/tests/roblox_cases/pass/z-escape-string/source.lua new file mode 100644 index 00000000..230a2b44 --- /dev/null +++ b/full-moon/tests/roblox_cases/pass/z-escape-string/source.lua @@ -0,0 +1,2 @@ +print("testing \z + twelve") \ No newline at end of file diff --git a/full-moon/tests/roblox_cases/pass/z-escape-string/tokens.snap b/full-moon/tests/roblox_cases/pass/z-escape-string/tokens.snap new file mode 100644 index 00000000..3193aac1 --- /dev/null +++ b/full-moon/tests/roblox_cases/pass/z-escape-string/tokens.snap @@ -0,0 +1,60 @@ +--- +source: full-moon/tests/pass_cases.rs +expression: tokens +--- +- start_position: + bytes: 0 + line: 1 + character: 1 + end_position: + bytes: 5 + line: 1 + character: 6 + token_type: + type: Identifier + identifier: print +- start_position: + bytes: 5 + line: 1 + character: 6 + end_position: + bytes: 6 + line: 1 + character: 7 + token_type: + type: Symbol + symbol: ( +- start_position: + bytes: 6 + line: 1 + character: 7 + end_position: + bytes: 29 + line: 2 + character: 12 + token_type: + type: StringLiteral + literal: "testing \\z\n\t twelve" + quote_type: Double +- start_position: + bytes: 29 + line: 2 + character: 12 + end_position: + bytes: 30 + line: 2 + character: 13 + token_type: + type: Symbol + symbol: ) +- start_position: + bytes: 30 + line: 2 + character: 13 + end_position: + bytes: 30 + line: 2 + character: 13 + token_type: + type: Eof +