Skip to content

Commit

Permalink
Fix interaction of luau and lua53 for TokenReference::symbol('//=') (
Browse files Browse the repository at this point in the history
…#327)

We incorrectly parse as just double slash, since we take the lua53
branch first
  • Loading branch information
JohnnyMorganz authored Nov 17, 2024
1 parent b996441 commit 0361d2c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fixed `TokenReference::symbol("//=")` returning DoubleSlash + UnexpectedToken when `luau` and `lua53` are enabled together

## [1.1.1] - 2024-11-16

### Fixed
Expand Down
47 changes: 23 additions & 24 deletions full-moon/src/tokenizer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,32 +577,31 @@ impl Lexer {

'/' => {
version_switch!(self.lua_version, {
lua53 => {
if self.source.current() == Some('/') {
self.source.next();
return self.create(
start_position,
TokenType::Symbol {
symbol: Symbol::DoubleSlash,
},
);
}
}
luau => {
lua53 | luau => {
if self.source.consume('/') {
if self.source.consume('=') {
return self.create(start_position, TokenType::Symbol { symbol: Symbol::DoubleSlashEqual })
} else {
return self.create(start_position, TokenType::Symbol { symbol: Symbol::DoubleSlash} )
}
} else if self.source.consume('=') {
return self.create(
start_position,
TokenType::Symbol {
symbol: Symbol::SlashEqual,
},
);
version_switch!(self.lua_version, {
luau => {
if self.source.consume('=') {
return self.create(start_position, TokenType::Symbol { symbol: Symbol::DoubleSlashEqual })
}
}
});

return self.create(start_position, TokenType::Symbol { symbol: Symbol::DoubleSlash} );
}

version_switch!(self.lua_version, {
luau => {
if self.source.consume('=') {
return self.create(
start_position,
TokenType::Symbol {
symbol: Symbol::SlashEqual,
},
);
}
}
});
}
});

Expand Down
17 changes: 17 additions & 0 deletions full-moon/src/tokenizer/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,3 +1195,20 @@ mod tests {
}
}
*/

mod tests {
#[cfg(all(feature = "luau", feature = "lua53"))]
#[test]
fn test_token_symbol_create_double_slash_equal() {
use crate::tokenizer::{Symbol, TokenType};

use super::TokenReference;

assert!(matches!(
TokenReference::symbol("//=").unwrap().token().token_type(),
TokenType::Symbol {
symbol: Symbol::DoubleSlashEqual
}
))
}
}

0 comments on commit 0361d2c

Please sign in to comment.