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

Support \z escape in Luau strings #287

Merged
merged 4 commits into from
Oct 8, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expression>`: `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
Expand Down
6 changes: 3 additions & 3 deletions full-moon/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ fn test_bracket_head(slice: &str) -> Option<usize> {

fn read_string(lex: &mut Lexer<Atom>, 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
Expand All @@ -50,7 +50,7 @@ fn read_string(lex: &mut Lexer<Atom>, 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 => {
Expand Down
77 changes: 77 additions & 0 deletions full-moon/tests/roblox_cases/pass/z-escape-string/ast.snap
Original file line number Diff line number Diff line change
@@ -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: []
- ~

2 changes: 2 additions & 0 deletions full-moon/tests/roblox_cases/pass/z-escape-string/source.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print("testing \z
twelve")
60 changes: 60 additions & 0 deletions full-moon/tests/roblox_cases/pass/z-escape-string/tokens.snap
Original file line number Diff line number Diff line change
@@ -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