Skip to content

Commit

Permalink
full-moon 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampfkarren committed Jul 6, 2024
1 parent 6e02c2f commit b29118b
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 119 deletions.
34 changes: 2 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MPL-2.0"
repository = "https://github.com/Kampfkarren/selene"

[workspace.dependencies]
full_moon = "0.19.0"
full_moon = "1.0.0-rc.5"
toml = "0.7.2"

# Do not update this without confirming profiling uses the same version of tracy-client as selene
Expand Down
7 changes: 6 additions & 1 deletion selene-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pretty_assertions = "1.3"
termcolor = "1.2"

[features]
default = ["roblox"]
default = ["lua52", "lua53", "lua54", "luajit", "roblox"]
force_exhaustive_checks = []

lua52 = ["full_moon/lua52"]
lua53 = ["full_moon/lua53"]
lua54 = ["full_moon/lua54"]
luajit = ["full_moon/luajit"]
roblox = ["full_moon/roblox"]
2 changes: 2 additions & 0 deletions selene-lib/default_std/lua52.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
base: lua51
lua_versions:
- lua52
globals:
bit32.arshift:
args:
Expand Down
2 changes: 2 additions & 0 deletions selene-lib/default_std/lua53.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
base: lua52
lua_versions:
- lua53
globals:
math.tointeger:
args:
Expand Down
2 changes: 2 additions & 0 deletions selene-lib/default_std/luau.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Invalid (put in selene-lib/default_std/roblox_base.yml instead): CFrame.new(), Instance.new(), task.spawn()
---
base: lua51
lua_versions:
- luau
globals:
bit32.arshift:
args:
Expand Down
2 changes: 1 addition & 1 deletion selene-lib/src/ast_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn is_vararg(expression: &ast::Expression) -> bool {
if_chain::if_chain! {
if let ast::Expression::Symbol(token) = expression;
if let tokenizer::TokenType::Symbol {
symbol: tokenizer::Symbol::Ellipse,
symbol: tokenizer::Symbol::Ellipsis,
} = token.token().token_type();

then {
Expand Down
16 changes: 8 additions & 8 deletions selene-lib/src/ast_util/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ impl ScopeVisitor {
self.read_expression(rhs);
}

ast::Expression::Function((name, _)) => {
self.read_name(name);
ast::Expression::Function(function_box) => {
self.read_name(&function_box.0);
}

ast::Expression::FunctionCall(call) => {
Expand All @@ -357,7 +357,7 @@ impl ScopeVisitor {
ast::Expression::Symbol(symbol) => {
if *symbol.token_type()
== (TokenType::Symbol {
symbol: Symbol::Ellipse,
symbol: Symbol::Ellipsis,
})
{
self.read_name(symbol);
Expand Down Expand Up @@ -433,7 +433,7 @@ impl ScopeVisitor {
if token.token_kind() == TokenKind::Identifier
|| *token.token_type()
== (TokenType::Symbol {
symbol: Symbol::Ellipse,
symbol: Symbol::Ellipsis,
})
{
self.captured_references.insert(identifier);
Expand Down Expand Up @@ -878,7 +878,7 @@ impl Visitor for ScopeVisitor {
}

#[cfg(feature = "roblox")]
fn visit_compound_assignment(&mut self, compound_assignment: &ast::types::CompoundAssignment) {
fn visit_compound_assignment(&mut self, compound_assignment: &ast::luau::CompoundAssignment) {
self.read_var(compound_assignment.lhs());
self.read_expression(compound_assignment.rhs());
}
Expand Down Expand Up @@ -911,7 +911,7 @@ impl Visitor for ScopeVisitor {
self.current_scope().blocked.push(Cow::Borrowed("..."));

for parameter in body.parameters() {
if let ast::Parameter::Ellipse(token) | ast::Parameter::Name(token) = parameter {
if let ast::Parameter::Ellipsis(token) | ast::Parameter::Name(token) = parameter {
self.define_name(token, range(token));
}
}
Expand Down Expand Up @@ -1092,8 +1092,8 @@ impl Visitor for ScopeVisitor {
}

#[cfg(feature = "roblox")]
fn visit_type_info(&mut self, type_info: &ast::types::TypeInfo) {
if let ast::types::TypeInfo::Module { module, .. } = type_info {
fn visit_type_info(&mut self, type_info: &ast::luau::TypeInfo) {
if let ast::luau::TypeInfo::Module { module, .. } = type_info {
self.read_name(module);
}
}
Expand Down
2 changes: 1 addition & 1 deletion selene-lib/src/ast_util/visit_nodes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use full_moon::{ast::*, node::Node, tokenizer::TokenReference, visitors::Visitor};

#[cfg(feature = "roblox")]
use full_moon::ast::types::*;
use full_moon::ast::luau::*;

pub(crate) trait NodeVisitor {
fn visit_node(&mut self, node: &dyn Node, visitor_type: VisitorType);
Expand Down
4 changes: 2 additions & 2 deletions selene-lib/src/lints/bad_string_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl Visitor for BadStringEscapeVisitor {
fn visit_expression(&mut self, node: &ast::Expression) {
if_chain::if_chain! {
if let ast::Expression::String(token) = node;
if let tokenizer::TokenType::StringLiteral { literal, multi_line, quote_type } = token.token_type();
if multi_line.is_none();
if let tokenizer::TokenType::StringLiteral { literal, quote_type, .. } = token.token_type();
if *quote_type != tokenizer::StringLiteralQuoteType::Brackets;
then {
let quote_type = *quote_type;
let value_start = node.range().unwrap().0.bytes();
Expand Down
3 changes: 2 additions & 1 deletion selene-lib/src/lints/high_cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ impl Visitor for HighCyclomaticComplexityVisitor {
}

fn visit_expression(&mut self, expression: &ast::Expression) {
if let ast::Expression::Function((_, function_body)) = expression {
if let ast::Expression::Function(function_box) = expression {
let function_body = &function_box.1;
let complexity = count_block_complexity(function_body.block(), 1);
if complexity > self.config.maximum_complexity {
self.positions.push((
Expand Down
8 changes: 5 additions & 3 deletions selene-lib/src/lints/mismatched_arg_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl ParameterCount {
)]
match parameter {
ast::Parameter::Name(_) => necessary_params += 1,
ast::Parameter::Ellipse(_) => {
ast::Parameter::Ellipsis(_) => {
if necessary_params == 0 {
return Self::Variable;
} else {
Expand Down Expand Up @@ -331,7 +331,8 @@ impl Visitor for MapFunctionDefinitionVisitor<'_> {
.zip(local_assignment.expressions());

for (name_token, expression) in assignment_expressions {
if let ast::Expression::Function((_, function_body)) = expression {
if let ast::Expression::Function(function_box) = expression {
let function_body = &function_box.1;
let identifier = range(name_token);

if let Some(id) = self.find_variable(identifier) {
Expand All @@ -346,7 +347,8 @@ impl Visitor for MapFunctionDefinitionVisitor<'_> {
let assignment_expressions = assignment.variables().iter().zip(assignment.expressions());

for (var, expression) in assignment_expressions {
if let ast::Expression::Function((_, function_body)) = expression {
if let ast::Expression::Function(function_box) = expression {
let function_body = &function_box.1;
let identifier = range(var);

if let Some(reference) = self.find_reference(identifier) {
Expand Down
4 changes: 2 additions & 2 deletions selene-lib/src/lints/standard_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn get_argument_type(expression: &ast::Expression) -> Option<PassedArgumentType>
Symbol::False => Some(ArgumentType::Bool.into()),
Symbol::True => Some(ArgumentType::Bool.into()),
Symbol::Nil => Some(ArgumentType::Nil.into()),
Symbol::Ellipse => Some(ArgumentType::Vararg.into()),
Symbol::Ellipsis => Some(ArgumentType::Vararg.into()),
ref other => {
unreachable!("TokenType::Symbol was not expected ({:?})", other)
}
Expand Down Expand Up @@ -532,7 +532,7 @@ impl Visitor for StandardLibraryVisitor<'_> {

ast::Expression::Symbol(token_ref) => {
if let TokenType::Symbol { symbol } = token_ref.token().token_type() {
if symbol == &full_moon::tokenizer::Symbol::Ellipse {
if symbol == &full_moon::tokenizer::Symbol::Ellipsis {
maybe_more_arguments = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion selene-lib/src/lints/unbalanced_assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn expression_is_ellipsis(expression: &ast::Expression) -> bool {
if let ast::Expression::Symbol(symbol) = expression {
return *symbol.token_type()
== TokenType::Symbol {
symbol: Symbol::Ellipse,
symbol: Symbol::Ellipsis,
};
}

Expand Down
89 changes: 89 additions & 0 deletions selene-lib/src/standard_library/lua_versions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LuaVersion {
Lua51,
Lua52,
Lua53,
Lua54,
Luau,
LuaJIT,

Unknown(String),
}

impl LuaVersion {
pub fn from_str(value: &str) -> Self {
match value {
"lua51" => Self::Lua51,
"lua52" => Self::Lua52,
"lua53" => Self::Lua53,
"lua54" => Self::Lua54,
"luau" => Self::Luau,
"luajit" => Self::LuaJIT,
_ => Self::Unknown(value.to_string()),
}
}

pub fn to_str(&self) -> &str {
match self {
Self::Lua51 => "lua51",
Self::Lua52 => "lua52",
Self::Lua53 => "lua53",
Self::Lua54 => "lua54",
Self::Luau => "luau",
Self::LuaJIT => "luajit",
Self::Unknown(value) => value,
}
}

pub fn to_lua_version(&self) -> Result<full_moon::ast::LuaVersion, LuaVersionError> {
match self {
Self::Lua51 => Ok(full_moon::ast::LuaVersion::lua51()),

#[cfg(feature = "lua52")]
Self::Lua52 => Ok(full_moon::ast::LuaVersion::lua52()),

#[cfg(feature = "lua53")]
Self::Lua53 => Ok(full_moon::ast::LuaVersion::lua53()),

#[cfg(feature = "lua54")]
Self::Lua54 => Ok(full_moon::ast::LuaVersion::lua54()),

#[cfg(feature = "roblox")]
Self::Luau => Ok(full_moon::ast::LuaVersion::luau()),

#[cfg(feature = "luajit")]
Self::LuaJIT => Ok(full_moon::ast::LuaVersion::luajit()),

Self::Unknown(value) => Err(LuaVersionError::Unknown(value)),

#[allow(unreachable_patterns)]
_ => Err(LuaVersionError::FeatureNotEnabled(self.to_str())),
}
}
}

pub enum LuaVersionError<'a> {
FeatureNotEnabled(&'a str),
Unknown(&'a str),
}

impl Serialize for LuaVersion {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.to_str())
}
}

impl<'de> Deserialize<'de> for LuaVersion {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
Ok(Self::from_str(&value))
}
}
Loading

0 comments on commit b29118b

Please sign in to comment.