Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdotink authored Oct 10, 2024
2 parents 510ec9c + 7ed9d15 commit 75f6a11
Show file tree
Hide file tree
Showing 126 changed files with 171 additions and 171 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [1.0.0] - 2024-10-08

### Added
- Added structs `TypeUnion` and `TypeIntersection` which both contain a field for a leading `TokenReference` (`|` or `&`), and a field which contains a `Punctuated<TypeInfo>`.
- Added support for parsing leading `|` and `&` in types.

### Changed
- **[BREAKING CHANGE]** Changed `TypeInfo::Union` and `TypeInfo::Intersection` to hold structs `TypeUnion` and `TypeIntersection` respectively.

- **[BREAKING CHANGE]** The `print()` function has been removed, use `ast.to_string()` instead.

## [1.0.0-rc.5] - 2024-07-06
### Changed
Expand Down
10 changes: 5 additions & 5 deletions full-moon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "full_moon"
version = "1.0.0-rc.5"
version = "1.0.0"
authors = ["Kampfkarren <[email protected]>"]
description = "A lossless Lua parser"
license = "MPL-2.0"
Expand Down Expand Up @@ -32,15 +32,15 @@ derive_more = { version = "1.0", features = ["display"] }
full_moon_derive = { path = "../full-moon-derive", version = "=0.11.0" }
paste = "1.0"
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
smol_str = { version = "0.1.23", features = ["serde"] }
smol_str = { version = "0.3.1", features = ["serde"] }

[dev-dependencies]
codespan = "0.11.1"
codespan-reporting = "0.11.1"
criterion = "0.5.1"
insta = { version = "1.26.0", features = ["glob", "yaml"] }
pretty_assertions = "1.3.0"
termcolor = "1.2.0"
insta = { version = "1.40.0", features = ["glob", "yaml"] }
pretty_assertions = "1.4.1"
termcolor = "1.4.1"

[[bench]]
name = "date"
Expand Down
69 changes: 37 additions & 32 deletions full-moon/src/ast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
mod parser_structs;
#[macro_use]
mod parser_util;
mod parsers;
pub mod punctuated;
pub mod span;
mod update_positions;
mod visitors;
use std::fmt::Formatter;
use std::{borrow::Cow, fmt};

use crate::{
tokenizer::{Position, Symbol, Token, TokenReference, TokenType},
util::*,
};
use derive_more::Display;
use full_moon_derive::{Node, Visit};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, fmt};

use full_moon_derive::{Node, Visit};
#[cfg(any(feature = "lua52", feature = "luajit"))]
use lua52::*;
#[cfg(feature = "lua54")]
use lua54::*;
#[cfg(feature = "luau")]
use luau::*;
pub use parser_structs::AstResult;
use punctuated::{Pair, Punctuated};
use span::ContainedSpan;
pub use versions::*;

pub use parser_structs::AstResult;
use crate::{
tokenizer::{Position, Symbol, Token, TokenReference, TokenType},
util::*,
};

mod versions;
pub use versions::*;
mod parser_structs;
#[macro_use]
mod parser_util;
mod parsers;
pub mod punctuated;
pub mod span;
mod update_positions;
mod visitors;

#[cfg(feature = "luau")]
pub mod luau;
#[cfg(feature = "luau")]
use luau::*;

#[cfg(feature = "luau")]
mod luau_visitors;
mod versions;

#[cfg(any(feature = "lua52", feature = "luajit"))]
pub mod lua52;
#[cfg(any(feature = "lua52", feature = "luajit"))]
use lua52::*;

#[cfg(feature = "lua54")]
pub mod lua54;
#[cfg(feature = "lua54")]
use lua54::*;

/// A block of statements, such as in if/do/etc block
#[derive(Clone, Debug, Default, Display, PartialEq, Node, Visit)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
Expand Down Expand Up @@ -2294,10 +2291,18 @@ impl Ast {
}
}

impl fmt::Display for Ast {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.nodes())?;
write!(f, "{}", self.eof())
}
}

#[cfg(test)]
mod tests {
use crate::{parse, visitors::VisitorMut};

use super::*;
use crate::{parse, print, visitors::VisitorMut};

#[test]
fn test_with_eof_safety() {
Expand All @@ -2307,7 +2312,7 @@ mod tests {
ast.with_eof(eof)
};

print(&new_ast);
assert_eq!("local foo = 1", new_ast.to_string());
}

#[test]
Expand All @@ -2318,7 +2323,7 @@ mod tests {
ast.with_nodes(nodes)
};

print(&new_ast);
assert_eq!(new_ast.to_string(), "local foo = 1");
}

#[test]
Expand All @@ -2336,7 +2341,7 @@ mod tests {
SyntaxRewriter.visit_ast(ast)
};

print(&new_ast);
assert_eq!(new_ast.to_string(), "local foo = 1");
}

// Tests AST nodes with new methods that call unwrap
Expand Down Expand Up @@ -2404,6 +2409,6 @@ mod tests {
)]);

let ast = parse("").unwrap().with_nodes(block);
assert_eq!(print(&ast), "local variable = 1");
assert_eq!(ast.to_string(), "local variable = 1");
}
}
5 changes: 0 additions & 5 deletions full-moon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,3 @@ pub fn parse(code: &str) -> Result<ast::Ast, Vec<Error>> {
pub fn parse_fallible(code: &str, lua_version: LuaVersion) -> ast::AstResult {
ast::AstResult::parse_fallible(code, lua_version)
}

/// Prints back Lua code from an [`Ast`](ast::Ast)
pub fn print(ast: &ast::Ast) -> String {
format!("{}{}", ast.nodes(), ast.eof())
}
4 changes: 2 additions & 2 deletions full-moon/src/short_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ShortString(SmolStr);
impl ShortString {
/// Creates a new ShortString from the given text.
pub fn new<T: Into<String> + AsRef<str>>(text: T) -> Self {
ShortString(SmolStr::from(text))
ShortString(SmolStr::new(text))
}

/// Returns a `&str` representation of the ShortString.
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Deref for ShortString {

impl<T: Into<String> + AsRef<str>> From<T> for ShortString {
fn from(value: T) -> Self {
ShortString(SmolStr::from(value))
ShortString(SmolStr::new(value))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/assignment-1
---
x =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/assignment-2
---
"x = "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/assignment-3
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/bin-op-1
---
"return 1 "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/bin-op-2
---
"return 1 "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/call-1
---
call()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/call-2
---
"call(\"hello\")"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/call-3
---
"call(\"hello\", \"world\")"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/call-4
---
call()
Expand Down
2 changes: 1 addition & 1 deletion full-moon/tests/cases/fail/parser/do-1/ast_to_string.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/do-1
---
"do\n\tcall()end"
Expand Down
2 changes: 1 addition & 1 deletion full-moon/tests/cases/fail/parser/do-2/ast_to_string.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/do-2
---
do end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-1
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-2
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-3
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-4
---
function x()end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-5
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-6
---
function x()end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-7
---
function x(...)end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/function-8
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/generic-for-1
---
""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/generic-for-2
---
for x in pairs(y)doend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: full-moon/tests/fail_cases.rs
assertion_line: 30
expression: "full_moon::print(&ast)"
expression: "ast.to_string()"
input_file: full-moon/tests/cases/fail/parser/generic-for-3
---
for x in pairs(y) doend
Expand Down
Loading

0 comments on commit 75f6a11

Please sign in to comment.