diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6dfc691..9c219525 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,39 +14,39 @@ jobs: - name: Test (default features) run: | cd full-moon - cargo test + cargo insta test - name: Test (Luau feature) run: | cd full-moon - cargo test --features luau + cargo insta test --features luau - name: Test (Lua 5.2 feature) run: | cd full-moon - cargo test --features lua52 + cargo insta test --features lua52 - name: Test (Lua 5.3 feature) run: | cd full-moon - cargo test --features lua53 + cargo insta test --features lua53 - name: Test (Lua 5.4 feature) run: | cd full-moon - cargo test --features lua54 + cargo insta test --features lua54 - name: Test (LuaJIT feature) run: | cd full-moon - cargo test --features luajit + cargo insta test --features luajit - name: Test (CfxLua feature) run: | cd full-moon - cargo test --features cfxlua + cargo insta test --features cfxlua - name: Test (all features) run: | cd full-moon - cargo test --features luau,lua52,lua53,lua54,luajit,cfxlua + cargo insta test --features luau,lua52,lua53,lua54,luajit,cfxlua - name: Test (no default features) run: | cd full-moon - cargo test --no-default-features --features serde + cargo insta test --no-default-features --features serde - name: Rustfmt run: | cargo fmt -- --check diff --git a/full-moon/src/ast/compound.rs b/full-moon/src/ast/compound.rs index 69cabeb3..a52c5143 100644 --- a/full-moon/src/ast/compound.rs +++ b/full-moon/src/ast/compound.rs @@ -1,8 +1,8 @@ -use derive_more::Display; -use serde::{Deserialize, Serialize}; -use full_moon_derive::{Node, Visit}; use crate::ast::{Expression, Var}; use crate::tokenizer::{Symbol, TokenReference}; +use derive_more::Display; +use full_moon_derive::{Node, Visit}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Display, PartialEq, Eq, Node, Visit)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] @@ -50,42 +50,41 @@ impl CompoundOp { pub(crate) fn from_token(token: TokenReference) -> Self { if token.is_symbol(Symbol::PlusEqual) { - return Self::PlusEqual(token) + return Self::PlusEqual(token); } else if token.is_symbol(Symbol::MinusEqual) { - return Self::MinusEqual(token) + return Self::MinusEqual(token); } else if token.is_symbol(Symbol::StarEqual) { - return Self::StarEqual(token) + return Self::StarEqual(token); } else if token.is_symbol(Symbol::SlashEqual) { - return Self::SlashEqual(token) + return Self::SlashEqual(token); } else if token.is_symbol(Symbol::CaretEqual) { - return Self::CaretEqual(token) + return Self::CaretEqual(token); } #[cfg(feature = "luau")] if token.is_symbol(Symbol::DoubleSlashEqual) { - return Self::DoubleSlashEqual(token) + return Self::DoubleSlashEqual(token); } else if token.is_symbol(Symbol::PercentEqual) { - return Self::PercentEqual(token) + return Self::PercentEqual(token); } else if token.is_symbol(Symbol::TwoDotsEqual) { - return Self::TwoDotsEqual(token) + return Self::TwoDotsEqual(token); } #[cfg(feature = "cfxlua")] if token.is_symbol(Symbol::LeftShift) { - return Self::LeftShift(token) + return Self::LeftShift(token); } else if token.is_symbol(Symbol::RightShift) { - return Self::RightShift(token) + return Self::RightShift(token); } else if token.is_symbol(Symbol::BitwiseAndAssignment) { - return Self::BitwiseAndAssignment(token) + return Self::BitwiseAndAssignment(token); } else if token.is_symbol(Symbol::BitwiseOrAssignment) { - return Self::BitwiseOrAssignment(token) + return Self::BitwiseOrAssignment(token); } unreachable!("converting an unknown token into a compound operator") } } - /// A Compound Assignment statement, such as `x += 1` or `x -= 1` #[derive(Clone, Debug, Display, PartialEq, Node, Visit)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] @@ -138,4 +137,4 @@ impl CompoundAssignment { pub fn with_rhs(self, rhs: Expression) -> Self { Self { rhs, ..self } } -} \ No newline at end of file +} diff --git a/full-moon/src/ast/lua54.rs b/full-moon/src/ast/lua54.rs index b9ee2b08..2512015f 100644 --- a/full-moon/src/ast/lua54.rs +++ b/full-moon/src/ast/lua54.rs @@ -50,4 +50,4 @@ impl Attribute { pub fn with_brackets(self, brackets: ContainedSpan) -> Self { Self { brackets, ..self } } -} \ No newline at end of file +} diff --git a/full-moon/src/ast/parsers.rs b/full-moon/src/ast/parsers.rs index 4bb02f3e..67bdb525 100644 --- a/full-moon/src/ast/parsers.rs +++ b/full-moon/src/ast/parsers.rs @@ -10,9 +10,7 @@ use super::{ }; #[cfg(any(feature = "cfxlua", feature = "luau"))] -use super::{ - Var -}; +use super::Var; use crate::{ ast, @@ -138,7 +136,6 @@ fn parse_compound_assignment(state: &mut ParserState, var: Var) -> ParserResult< ))) } - fn parse_stmt(state: &mut ParserState) -> ParserResult { let Ok(current_token) = state.current() else { return ParserResult::NotFound; @@ -334,19 +331,19 @@ fn parse_stmt(state: &mut ParserState) -> ParserResult { #[cfg(feature = "cfxlua")] Ok(token) - if state.lua_version().has_cfxlua() - && (token.is_symbol(Symbol::PlusEqual) - || token.is_symbol(Symbol::MinusEqual) - || token.is_symbol(Symbol::StarEqual) - || token.is_symbol(Symbol::SlashEqual) - || token.is_symbol(Symbol::CaretEqual) - || token.is_symbol(Symbol::LeftShift) - || token.is_symbol(Symbol::RightShift) - || token.is_symbol(Symbol::BitwiseAndAssignment) - || token.is_symbol(Symbol::BitwiseOrAssignment)) => - { - return parse_compound_assignment(state, var); - } + if state.lua_version().has_cfxlua() + && (token.is_symbol(Symbol::PlusEqual) + || token.is_symbol(Symbol::MinusEqual) + || token.is_symbol(Symbol::StarEqual) + || token.is_symbol(Symbol::SlashEqual) + || token.is_symbol(Symbol::CaretEqual) + || token.is_symbol(Symbol::LeftShift) + || token.is_symbol(Symbol::RightShift) + || token.is_symbol(Symbol::BitwiseAndAssignment) + || token.is_symbol(Symbol::BitwiseOrAssignment)) => + { + return parse_compound_assignment(state, var); + } Ok(token) if token.is_symbol(Symbol::Comma) || token.is_symbol(Symbol::Equal) => {} @@ -1075,13 +1072,11 @@ fn expect_local_assignment( #[cfg(feature = "cfxlua")] let symbols = [Symbol::Equal, Symbol::In]; - local_assignment.equal_token = match state.consume_if_symbols(&symbols) { Some(equal_token) => Some(equal_token), None => return Ok(local_assignment), }; - match parse_expression_list(state) { ParserResult::Value(expr_list) => local_assignment.expr_list = expr_list, @@ -1237,7 +1232,9 @@ fn force_table_constructor( let dot = state.consume().unwrap(); let key = match state.current() { - Ok(token) if token.token_kind() == TokenKind::Identifier => state.consume().unwrap(), + Ok(token) if token.token_kind() == TokenKind::Identifier => { + state.consume().unwrap() + } Ok(token) => { state.token_error(token.clone(), "expected identifier after `.`"); return unfinished_table(left_brace, fields); @@ -1580,7 +1577,10 @@ fn parse_suffix(state: &mut ParserState) -> ParserResult { Err(()) => return ParserResult::LexerMoved, }; - ParserResult::Value(ast::Suffix::Index(ast::Index::Dot { dot: safe_navigation, name })) + ParserResult::Value(ast::Suffix::Index(ast::Index::Dot { + dot: safe_navigation, + name, + })) } TokenType::Symbol { diff --git a/full-moon/src/ast/visitors.rs b/full-moon/src/ast/visitors.rs index 0a113b04..6e87f997 100644 --- a/full-moon/src/ast/visitors.rs +++ b/full-moon/src/ast/visitors.rs @@ -27,10 +27,7 @@ impl Visit for Field { } #[cfg(feature = "cfxlua")] - Field::SetConstructorField { - dot, - name - } => { + Field::SetConstructorField { dot, name } => { dot.visit(visitor); name.visit(visitor); } @@ -74,10 +71,7 @@ impl VisitMut for Field { } #[cfg(feature = "cfxlua")] - Field::SetConstructorField { - dot, - name - } => Field::SetConstructorField { + Field::SetConstructorField { dot, name } => Field::SetConstructorField { dot: dot.visit_mut(visitor), name: name.visit_mut(visitor), }, diff --git a/full-moon/src/tokenizer/lexer.rs b/full-moon/src/tokenizer/lexer.rs index 089f088a..c8e76c81 100644 --- a/full-moon/src/tokenizer/lexer.rs +++ b/full-moon/src/tokenizer/lexer.rs @@ -358,7 +358,7 @@ impl Lexer { start_position, InterpolatedStringKind::Begin, InterpolatedStringKind::Simple, - )) + )); } let (string, recovered) = self.read_string(quote); @@ -376,8 +376,6 @@ impl Lexer { ) } - - '=' => { if self.source.consume('=') { self.create( diff --git a/full-moon/src/tokenizer/structs.rs b/full-moon/src/tokenizer/structs.rs index c3bcd5f7..50133050 100644 --- a/full-moon/src/tokenizer/structs.rs +++ b/full-moon/src/tokenizer/structs.rs @@ -4,13 +4,13 @@ use crate::{ ShortString, }; +use super::{Lexer, LexerResult}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt::{self, Display}, }; -use super::{Lexer, LexerResult}; macro_rules! symbol { { diff --git a/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap b/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap index 2fe2a4cb..cdb5493c 100644 --- a/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap +++ b/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap @@ -639,4 +639,7 @@ stmts: token_type: type: Whitespace characters: "\r\n" + type_specifiers: + - ~ + - ~ - ~ diff --git a/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap.new b/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap.new deleted file mode 100644 index 61bd34f9..00000000 --- a/full-moon/tests/cfxlua_cases/pass/each_iteration/ast.snap.new +++ /dev/null @@ -1,646 +0,0 @@ ---- -source: full-moon/tests/pass_cases.rs -assertion_line: 47 -expression: ast.nodes() -input_file: full-moon/tests/cfxlua_cases/pass/each_iteration ---- -stmts: - - - LocalAssignment: - local_token: - leading_trivia: [] - token: - start_position: - bytes: 0 - line: 1 - character: 1 - end_position: - bytes: 5 - line: 1 - character: 6 - token_type: - type: Symbol - symbol: local - trailing_trivia: - - start_position: - bytes: 5 - line: 1 - character: 6 - end_position: - bytes: 6 - line: 1 - character: 7 - token_type: - type: Whitespace - characters: " " - name_list: - pairs: - - End: - leading_trivia: [] - token: - start_position: - bytes: 6 - line: 1 - character: 7 - end_position: - bytes: 7 - line: 1 - character: 8 - token_type: - type: Identifier - identifier: t - trailing_trivia: - - start_position: - bytes: 7 - line: 1 - character: 8 - end_position: - bytes: 8 - line: 1 - character: 9 - token_type: - type: Whitespace - characters: " " - equal_token: - leading_trivia: [] - token: - start_position: - bytes: 8 - line: 1 - character: 9 - end_position: - bytes: 9 - line: 1 - character: 10 - token_type: - type: Symbol - symbol: "=" - trailing_trivia: - - start_position: - bytes: 9 - line: 1 - character: 10 - end_position: - bytes: 10 - line: 1 - character: 11 - token_type: - type: Whitespace - characters: " " - expr_list: - pairs: - - End: - TableConstructor: - braces: - tokens: - - leading_trivia: [] - token: - start_position: - bytes: 10 - line: 1 - character: 11 - end_position: - bytes: 11 - line: 1 - character: 12 - token_type: - type: Symbol - symbol: "{" - trailing_trivia: - - start_position: - bytes: 11 - line: 1 - character: 12 - end_position: - bytes: 12 - line: 1 - character: 13 - token_type: - type: Whitespace - characters: " " - - leading_trivia: [] - token: - start_position: - bytes: 20 - line: 1 - character: 21 - end_position: - bytes: 21 - line: 1 - character: 22 - token_type: - type: Symbol - symbol: "}" - trailing_trivia: - - start_position: - bytes: 21 - line: 1 - character: 22 - end_position: - bytes: 23 - line: 1 - character: 23 - token_type: - type: Whitespace - characters: "\r\n" - fields: - pairs: - - Punctuated: - - NoKey: - Number: - leading_trivia: [] - token: - start_position: - bytes: 12 - line: 1 - character: 13 - end_position: - bytes: 13 - line: 1 - character: 14 - token_type: - type: Number - text: "1" - trailing_trivia: [] - - leading_trivia: [] - token: - start_position: - bytes: 13 - line: 1 - character: 14 - end_position: - bytes: 14 - line: 1 - character: 15 - token_type: - type: Symbol - symbol: "," - trailing_trivia: - - start_position: - bytes: 14 - line: 1 - character: 15 - end_position: - bytes: 15 - line: 1 - character: 16 - token_type: - type: Whitespace - characters: " " - - Punctuated: - - NoKey: - Number: - leading_trivia: [] - token: - start_position: - bytes: 15 - line: 1 - character: 16 - end_position: - bytes: 16 - line: 1 - character: 17 - token_type: - type: Number - text: "2" - trailing_trivia: [] - - leading_trivia: [] - token: - start_position: - bytes: 16 - line: 1 - character: 17 - end_position: - bytes: 17 - line: 1 - character: 18 - token_type: - type: Symbol - symbol: "," - trailing_trivia: - - start_position: - bytes: 17 - line: 1 - character: 18 - end_position: - bytes: 18 - line: 1 - character: 19 - token_type: - type: Whitespace - characters: " " - - End: - NoKey: - Number: - leading_trivia: [] - token: - start_position: - bytes: 18 - line: 1 - character: 19 - end_position: - bytes: 19 - line: 1 - character: 20 - token_type: - type: Number - text: "3" - trailing_trivia: - - start_position: - bytes: 19 - line: 1 - character: 20 - end_position: - bytes: 20 - line: 1 - character: 21 - token_type: - type: Whitespace - characters: " " - - ~ - - - GenericFor: - for_token: - leading_trivia: [] - token: - start_position: - bytes: 23 - line: 2 - character: 1 - end_position: - bytes: 26 - line: 2 - character: 4 - token_type: - type: Symbol - symbol: for - trailing_trivia: - - start_position: - bytes: 26 - line: 2 - character: 4 - end_position: - bytes: 27 - line: 2 - character: 5 - token_type: - type: Whitespace - characters: " " - names: - pairs: - - Punctuated: - - leading_trivia: [] - token: - start_position: - bytes: 27 - line: 2 - character: 5 - end_position: - bytes: 28 - line: 2 - character: 6 - token_type: - type: Identifier - identifier: k - trailing_trivia: [] - - leading_trivia: [] - token: - start_position: - bytes: 28 - line: 2 - character: 6 - end_position: - bytes: 29 - line: 2 - character: 7 - token_type: - type: Symbol - symbol: "," - trailing_trivia: - - start_position: - bytes: 29 - line: 2 - character: 7 - end_position: - bytes: 30 - line: 2 - character: 8 - token_type: - type: Whitespace - characters: " " - - End: - leading_trivia: [] - token: - start_position: - bytes: 30 - line: 2 - character: 8 - end_position: - bytes: 31 - line: 2 - character: 9 - token_type: - type: Identifier - identifier: v - trailing_trivia: - - start_position: - bytes: 31 - line: 2 - character: 9 - end_position: - bytes: 32 - line: 2 - character: 10 - token_type: - type: Whitespace - characters: " " - in_token: - leading_trivia: [] - token: - start_position: - bytes: 32 - line: 2 - character: 10 - end_position: - bytes: 34 - line: 2 - character: 12 - token_type: - type: Symbol - symbol: in - trailing_trivia: - - start_position: - bytes: 34 - line: 2 - character: 12 - end_position: - bytes: 35 - line: 2 - character: 13 - token_type: - type: Whitespace - characters: " " - expr_list: - pairs: - - End: - FunctionCall: - prefix: - Name: - leading_trivia: [] - token: - start_position: - bytes: 35 - line: 2 - character: 13 - end_position: - bytes: 39 - line: 2 - character: 17 - token_type: - type: Identifier - identifier: each - trailing_trivia: [] - suffixes: - - Call: - AnonymousCall: - Parentheses: - parentheses: - tokens: - - leading_trivia: [] - token: - start_position: - bytes: 39 - line: 2 - character: 17 - end_position: - bytes: 40 - line: 2 - character: 18 - token_type: - type: Symbol - symbol: ( - trailing_trivia: [] - - leading_trivia: [] - token: - start_position: - bytes: 41 - line: 2 - character: 19 - end_position: - bytes: 42 - line: 2 - character: 20 - token_type: - type: Symbol - symbol: ) - trailing_trivia: - - start_position: - bytes: 42 - line: 2 - character: 20 - end_position: - bytes: 43 - line: 2 - character: 21 - token_type: - type: Whitespace - characters: " " - arguments: - pairs: - - End: - Var: - Name: - leading_trivia: [] - token: - start_position: - bytes: 40 - line: 2 - character: 18 - end_position: - bytes: 41 - line: 2 - character: 19 - token_type: - type: Identifier - identifier: t - trailing_trivia: [] - do_token: - leading_trivia: [] - token: - start_position: - bytes: 43 - line: 2 - character: 21 - end_position: - bytes: 45 - line: 2 - character: 23 - token_type: - type: Symbol - symbol: do - trailing_trivia: - - start_position: - bytes: 45 - line: 2 - character: 23 - end_position: - bytes: 46 - line: 2 - character: 24 - token_type: - type: Whitespace - characters: " " - block: - stmts: - - - FunctionCall: - prefix: - Name: - leading_trivia: [] - token: - start_position: - bytes: 46 - line: 2 - character: 24 - end_position: - bytes: 51 - line: 2 - character: 29 - token_type: - type: Identifier - identifier: print - trailing_trivia: [] - suffixes: - - Call: - AnonymousCall: - Parentheses: - parentheses: - tokens: - - leading_trivia: [] - token: - start_position: - bytes: 51 - line: 2 - character: 29 - end_position: - bytes: 52 - line: 2 - character: 30 - token_type: - type: Symbol - symbol: ( - trailing_trivia: [] - - leading_trivia: [] - token: - start_position: - bytes: 56 - line: 2 - character: 34 - end_position: - bytes: 57 - line: 2 - character: 35 - token_type: - type: Symbol - symbol: ) - trailing_trivia: - - start_position: - bytes: 57 - line: 2 - character: 35 - end_position: - bytes: 58 - line: 2 - character: 36 - token_type: - type: Whitespace - characters: " " - arguments: - pairs: - - Punctuated: - - Var: - Name: - leading_trivia: [] - token: - start_position: - bytes: 52 - line: 2 - character: 30 - end_position: - bytes: 53 - line: 2 - character: 31 - token_type: - type: Identifier - identifier: k - trailing_trivia: [] - - leading_trivia: [] - token: - start_position: - bytes: 53 - line: 2 - character: 31 - end_position: - bytes: 54 - line: 2 - character: 32 - token_type: - type: Symbol - symbol: "," - trailing_trivia: - - start_position: - bytes: 54 - line: 2 - character: 32 - end_position: - bytes: 55 - line: 2 - character: 33 - token_type: - type: Whitespace - characters: " " - - End: - Var: - Name: - leading_trivia: [] - token: - start_position: - bytes: 55 - line: 2 - character: 33 - end_position: - bytes: 56 - line: 2 - character: 34 - token_type: - type: Identifier - identifier: v - trailing_trivia: [] - - ~ - end_token: - leading_trivia: [] - token: - start_position: - bytes: 58 - line: 2 - character: 36 - end_position: - bytes: 61 - line: 2 - character: 39 - token_type: - type: Symbol - symbol: end - trailing_trivia: - - start_position: - bytes: 61 - line: 2 - character: 39 - end_position: - bytes: 63 - line: 2 - character: 40 - token_type: - type: Whitespace - characters: "\r\n" - type_specifiers: - - ~ - - ~ - - ~ diff --git a/full-moon/tests/fail_cases.rs b/full-moon/tests/fail_cases.rs index 19de6b50..797ef514 100644 --- a/full-moon/tests/fail_cases.rs +++ b/full-moon/tests/fail_cases.rs @@ -156,4 +156,4 @@ fn test_cfxlua_tokenizer_fail_cases() { process_fail_case(path, &source, LuaVersion::cfxlua()); }) -} \ No newline at end of file +}