Skip to content

Commit

Permalink
Merge branch 'Kampfkarren:main' into feat/update-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
DataM0del authored Oct 5, 2024
2 parents 99e963f + 81a9fc3 commit f7b5c9d
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 14 deletions.
4 changes: 2 additions & 2 deletions full-moon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ keywords = ["lua", "parser", "lua51", "lua52", "luau"]
edition = "2021"

[package.metadata.docs.rs]
# Build Locally: RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --features luau,lua52,lua53,lua54,luajit --no-deps --open
# Build Locally: RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --features luau,lua52,lua53,lua54,luajit --no-deps --open
features = ["luau", "lua52", "lua53", "lua54", "luajit"]
rustdoc-args = ["--cfg", "doc_cfg"]
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["serde"]
Expand Down
2 changes: 1 addition & 1 deletion full-moon/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use lua54::*;
#[display(
"{}{}",
display_optional_punctuated_vec(stmts),
display_option(&last_stmt.as_ref().map(display_optional_punctuated))
display_option(last_stmt.as_ref().map(display_optional_punctuated))
)]
pub struct Block {
stmts: Vec<(Stmt, Option<TokenReference>)>,
Expand Down
2 changes: 1 addition & 1 deletion full-moon/src/ast/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ fn parse_simple_type(
TokenType::Identifier { .. } => {
let name = state.consume().unwrap();

if name.to_string() == "typeof" {
if name.token.to_string() == "typeof" {
let left_parenthesis =
match state.require(Symbol::LeftParen, "expected `(` after `typeof`") {
Some(token) => token,
Expand Down
17 changes: 9 additions & 8 deletions full-moon/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![warn(missing_docs)]
#![allow(clippy::large_enum_variant)]
#![cfg_attr(doc_cfg, feature(doc_auto_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
//! # Full Moon
//!
//! `full_moon` is a lossless parser for Lua, supporting Lua 5.1, 5.2, 5.3, 5.4 and Luau
Expand Down Expand Up @@ -95,16 +95,17 @@ pub fn parse(code: &str) -> Result<ast::Ast, Vec<Error>> {

/// Given code and a pinned Lua version, will produce an [`ast::AstResult`].
/// This AstResult always produces some [`Ast`](ast::Ast), regardless of errors.
/// If a partial Ast is produced (i.e. if there are any errors), a few guarantees are lost.
/// If a partial Ast is produced (i.e. if there are any errors), a few guarantees are lost:
///
/// 1. Tokens may be produced that aren't in the code itself. For example, `if x == 2 code()`
/// will produce a phantom `then` token in order to produce a usable [`If`](ast::If) struct.
/// These phantom tokens will have a null position. If you need accurate positions from the
/// phantom tokens, you can call [`Ast::update_positions`](ast::Ast::update_positions).
/// will produce a phantom `then` token in order to produce a usable [`If`](ast::If) struct.
/// These phantom tokens will have a null position. If you need accurate positions from the
/// phantom tokens, you can call [`Ast::update_positions`](ast::Ast::update_positions).
/// 2. The code, when printed, is not guaranteed to be valid Lua.
/// This can happen in the case of something like `local x = if`, which will produce a
/// [`LocalAssignment`](ast::LocalAssignment) that would print to `local x =`.
/// This can happen in the case of something like `local x = if`, which will produce a
/// [`LocalAssignment`](ast::LocalAssignment) that would print to `local x =`.
/// 3. There are no stability guarantees for partial Ast results, but they are consistent
/// within the same exact version of full-moon.
/// within the same exact version of full-moon.
pub fn parse_fallible(code: &str, lua_version: LuaVersion) -> ast::AstResult {
ast::AstResult::parse_fallible(code, lua_version)
}
Expand Down
6 changes: 4 additions & 2 deletions full-moon/src/tokenizer/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,9 @@ impl fmt::Display for TokenizerError {

impl std::error::Error for TokenizerError {}

// #[cfg(test)]
#[cfg(feature = "rewrite todo: tokenizer tests")]
/*
// rewrite TODO: tokenizer tests
mod tests {
use crate::tokenizer::*;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -1193,3 +1194,4 @@ mod tests {
let _ = tokens("¹;");
}
}
*/
190 changes: 190 additions & 0 deletions full-moon/tests/roblox_cases/pass/multiline_typeof_regression/ast.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
source: full-moon/tests/pass_cases.rs
expression: ast.nodes()
input_file: full-moon/tests/roblox_cases/pass/multiline_typeof_regression
---
stmts:
- - TypeDeclaration:
type_token:
leading_trivia: []
token:
start_position:
bytes: 0
line: 1
character: 1
end_position:
bytes: 4
line: 1
character: 5
token_type:
type: Identifier
identifier: type
trailing_trivia:
- start_position:
bytes: 4
line: 1
character: 5
end_position:
bytes: 5
line: 1
character: 6
token_type:
type: Whitespace
characters: " "
base:
leading_trivia: []
token:
start_position:
bytes: 5
line: 1
character: 6
end_position:
bytes: 11
line: 1
character: 12
token_type:
type: Identifier
identifier: TypeOf
trailing_trivia:
- start_position:
bytes: 11
line: 1
character: 12
end_position:
bytes: 12
line: 1
character: 13
token_type:
type: Whitespace
characters: " "
generics: ~
equal_token:
leading_trivia: []
token:
start_position:
bytes: 12
line: 1
character: 13
end_position:
bytes: 13
line: 1
character: 14
token_type:
type: Symbol
symbol: "="
trailing_trivia:
- start_position:
bytes: 13
line: 1
character: 14
end_position:
bytes: 14
line: 1
character: 14
token_type:
type: Whitespace
characters: "\n"
declare_as:
Typeof:
typeof_token:
leading_trivia:
- start_position:
bytes: 14
line: 2
character: 1
end_position:
bytes: 18
line: 2
character: 5
token_type:
type: Whitespace
characters: " "
token:
start_position:
bytes: 18
line: 2
character: 5
end_position:
bytes: 24
line: 2
character: 11
token_type:
type: Identifier
identifier: typeof
trailing_trivia: []
parentheses:
tokens:
- leading_trivia: []
token:
start_position:
bytes: 24
line: 2
character: 11
end_position:
bytes: 25
line: 2
character: 12
token_type:
type: Symbol
symbol: (
trailing_trivia: []
- leading_trivia: []
token:
start_position:
bytes: 27
line: 2
character: 14
end_position:
bytes: 28
line: 2
character: 15
token_type:
type: Symbol
symbol: )
trailing_trivia:
- start_position:
bytes: 28
line: 2
character: 15
end_position:
bytes: 29
line: 2
character: 15
token_type:
type: Whitespace
characters: "\n"
inner:
TableConstructor:
braces:
tokens:
- leading_trivia: []
token:
start_position:
bytes: 25
line: 2
character: 12
end_position:
bytes: 26
line: 2
character: 13
token_type:
type: Symbol
symbol: "{"
trailing_trivia: []
- leading_trivia: []
token:
start_position:
bytes: 26
line: 2
character: 13
end_position:
bytes: 27
line: 2
character: 14
token_type:
type: Symbol
symbol: "}"
trailing_trivia: []
fields:
pairs: []
- ~
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type TypeOf =
typeof({})
Loading

0 comments on commit f7b5c9d

Please sign in to comment.