Skip to content

Commit b29118b

Browse files
committed
full-moon 1.0.0
1 parent 6e02c2f commit b29118b

17 files changed

+251
-119
lines changed

Cargo.lock

+2-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license = "MPL-2.0"
1111
repository = "https://github.com/Kampfkarren/selene"
1212

1313
[workspace.dependencies]
14-
full_moon = "0.19.0"
14+
full_moon = "1.0.0-rc.5"
1515
toml = "0.7.2"
1616

1717
# Do not update this without confirming profiling uses the same version of tracy-client as selene

selene-lib/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ pretty_assertions = "1.3"
3030
termcolor = "1.2"
3131

3232
[features]
33-
default = ["roblox"]
33+
default = ["lua52", "lua53", "lua54", "luajit", "roblox"]
3434
force_exhaustive_checks = []
35+
36+
lua52 = ["full_moon/lua52"]
37+
lua53 = ["full_moon/lua53"]
38+
lua54 = ["full_moon/lua54"]
39+
luajit = ["full_moon/luajit"]
3540
roblox = ["full_moon/roblox"]

selene-lib/default_std/lua52.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
base: lua51
3+
lua_versions:
4+
- lua52
35
globals:
46
bit32.arshift:
57
args:

selene-lib/default_std/lua53.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
base: lua52
3+
lua_versions:
4+
- lua53
35
globals:
46
math.tointeger:
57
args:

selene-lib/default_std/luau.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Invalid (put in selene-lib/default_std/roblox_base.yml instead): CFrame.new(), Instance.new(), task.spawn()
44
---
55
base: lua51
6+
lua_versions:
7+
- luau
68
globals:
79
bit32.arshift:
810
args:

selene-lib/src/ast_util/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn is_vararg(expression: &ast::Expression) -> bool {
5151
if_chain::if_chain! {
5252
if let ast::Expression::Symbol(token) = expression;
5353
if let tokenizer::TokenType::Symbol {
54-
symbol: tokenizer::Symbol::Ellipse,
54+
symbol: tokenizer::Symbol::Ellipsis,
5555
} = token.token().token_type();
5656

5757
then {

selene-lib/src/ast_util/scopes.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ impl ScopeVisitor {
339339
self.read_expression(rhs);
340340
}
341341

342-
ast::Expression::Function((name, _)) => {
343-
self.read_name(name);
342+
ast::Expression::Function(function_box) => {
343+
self.read_name(&function_box.0);
344344
}
345345

346346
ast::Expression::FunctionCall(call) => {
@@ -357,7 +357,7 @@ impl ScopeVisitor {
357357
ast::Expression::Symbol(symbol) => {
358358
if *symbol.token_type()
359359
== (TokenType::Symbol {
360-
symbol: Symbol::Ellipse,
360+
symbol: Symbol::Ellipsis,
361361
})
362362
{
363363
self.read_name(symbol);
@@ -433,7 +433,7 @@ impl ScopeVisitor {
433433
if token.token_kind() == TokenKind::Identifier
434434
|| *token.token_type()
435435
== (TokenType::Symbol {
436-
symbol: Symbol::Ellipse,
436+
symbol: Symbol::Ellipsis,
437437
})
438438
{
439439
self.captured_references.insert(identifier);
@@ -878,7 +878,7 @@ impl Visitor for ScopeVisitor {
878878
}
879879

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

913913
for parameter in body.parameters() {
914-
if let ast::Parameter::Ellipse(token) | ast::Parameter::Name(token) = parameter {
914+
if let ast::Parameter::Ellipsis(token) | ast::Parameter::Name(token) = parameter {
915915
self.define_name(token, range(token));
916916
}
917917
}
@@ -1092,8 +1092,8 @@ impl Visitor for ScopeVisitor {
10921092
}
10931093

10941094
#[cfg(feature = "roblox")]
1095-
fn visit_type_info(&mut self, type_info: &ast::types::TypeInfo) {
1096-
if let ast::types::TypeInfo::Module { module, .. } = type_info {
1095+
fn visit_type_info(&mut self, type_info: &ast::luau::TypeInfo) {
1096+
if let ast::luau::TypeInfo::Module { module, .. } = type_info {
10971097
self.read_name(module);
10981098
}
10991099
}

selene-lib/src/ast_util/visit_nodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use full_moon::{ast::*, node::Node, tokenizer::TokenReference, visitors::Visitor};
22

33
#[cfg(feature = "roblox")]
4-
use full_moon::ast::types::*;
4+
use full_moon::ast::luau::*;
55

66
pub(crate) trait NodeVisitor {
77
fn visit_node(&mut self, node: &dyn Node, visitor_type: VisitorType);

selene-lib/src/lints/bad_string_escape.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl Visitor for BadStringEscapeVisitor {
107107
fn visit_expression(&mut self, node: &ast::Expression) {
108108
if_chain::if_chain! {
109109
if let ast::Expression::String(token) = node;
110-
if let tokenizer::TokenType::StringLiteral { literal, multi_line, quote_type } = token.token_type();
111-
if multi_line.is_none();
110+
if let tokenizer::TokenType::StringLiteral { literal, quote_type, .. } = token.token_type();
111+
if *quote_type != tokenizer::StringLiteralQuoteType::Brackets;
112112
then {
113113
let quote_type = *quote_type;
114114
let value_start = node.range().unwrap().0.bytes();

selene-lib/src/lints/high_cyclomatic_complexity.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ impl Visitor for HighCyclomaticComplexityVisitor {
400400
}
401401

402402
fn visit_expression(&mut self, expression: &ast::Expression) {
403-
if let ast::Expression::Function((_, function_body)) = expression {
403+
if let ast::Expression::Function(function_box) = expression {
404+
let function_body = &function_box.1;
404405
let complexity = count_block_complexity(function_body.block(), 1);
405406
if complexity > self.config.maximum_complexity {
406407
self.positions.push((

selene-lib/src/lints/mismatched_arg_count.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl ParameterCount {
107107
)]
108108
match parameter {
109109
ast::Parameter::Name(_) => necessary_params += 1,
110-
ast::Parameter::Ellipse(_) => {
110+
ast::Parameter::Ellipsis(_) => {
111111
if necessary_params == 0 {
112112
return Self::Variable;
113113
} else {
@@ -331,7 +331,8 @@ impl Visitor for MapFunctionDefinitionVisitor<'_> {
331331
.zip(local_assignment.expressions());
332332

333333
for (name_token, expression) in assignment_expressions {
334-
if let ast::Expression::Function((_, function_body)) = expression {
334+
if let ast::Expression::Function(function_box) = expression {
335+
let function_body = &function_box.1;
335336
let identifier = range(name_token);
336337

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

348349
for (var, expression) in assignment_expressions {
349-
if let ast::Expression::Function((_, function_body)) = expression {
350+
if let ast::Expression::Function(function_box) = expression {
351+
let function_body = &function_box.1;
350352
let identifier = range(var);
351353

352354
if let Some(reference) = self.find_reference(identifier) {

selene-lib/src/lints/standard_library.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn get_argument_type(expression: &ast::Expression) -> Option<PassedArgumentType>
7676
Symbol::False => Some(ArgumentType::Bool.into()),
7777
Symbol::True => Some(ArgumentType::Bool.into()),
7878
Symbol::Nil => Some(ArgumentType::Nil.into()),
79-
Symbol::Ellipse => Some(ArgumentType::Vararg.into()),
79+
Symbol::Ellipsis => Some(ArgumentType::Vararg.into()),
8080
ref other => {
8181
unreachable!("TokenType::Symbol was not expected ({:?})", other)
8282
}
@@ -532,7 +532,7 @@ impl Visitor for StandardLibraryVisitor<'_> {
532532

533533
ast::Expression::Symbol(token_ref) => {
534534
if let TokenType::Symbol { symbol } = token_ref.token().token_type() {
535-
if symbol == &full_moon::tokenizer::Symbol::Ellipse {
535+
if symbol == &full_moon::tokenizer::Symbol::Ellipsis {
536536
maybe_more_arguments = true;
537537
}
538538
}

selene-lib/src/lints/unbalanced_assignments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn expression_is_ellipsis(expression: &ast::Expression) -> bool {
9494
if let ast::Expression::Symbol(symbol) = expression {
9595
return *symbol.token_type()
9696
== TokenType::Symbol {
97-
symbol: Symbol::Ellipse,
97+
symbol: Symbol::Ellipsis,
9898
};
9999
}
100100

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Clone, Debug, PartialEq, Eq)]
4+
pub enum LuaVersion {
5+
Lua51,
6+
Lua52,
7+
Lua53,
8+
Lua54,
9+
Luau,
10+
LuaJIT,
11+
12+
Unknown(String),
13+
}
14+
15+
impl LuaVersion {
16+
pub fn from_str(value: &str) -> Self {
17+
match value {
18+
"lua51" => Self::Lua51,
19+
"lua52" => Self::Lua52,
20+
"lua53" => Self::Lua53,
21+
"lua54" => Self::Lua54,
22+
"luau" => Self::Luau,
23+
"luajit" => Self::LuaJIT,
24+
_ => Self::Unknown(value.to_string()),
25+
}
26+
}
27+
28+
pub fn to_str(&self) -> &str {
29+
match self {
30+
Self::Lua51 => "lua51",
31+
Self::Lua52 => "lua52",
32+
Self::Lua53 => "lua53",
33+
Self::Lua54 => "lua54",
34+
Self::Luau => "luau",
35+
Self::LuaJIT => "luajit",
36+
Self::Unknown(value) => value,
37+
}
38+
}
39+
40+
pub fn to_lua_version(&self) -> Result<full_moon::ast::LuaVersion, LuaVersionError> {
41+
match self {
42+
Self::Lua51 => Ok(full_moon::ast::LuaVersion::lua51()),
43+
44+
#[cfg(feature = "lua52")]
45+
Self::Lua52 => Ok(full_moon::ast::LuaVersion::lua52()),
46+
47+
#[cfg(feature = "lua53")]
48+
Self::Lua53 => Ok(full_moon::ast::LuaVersion::lua53()),
49+
50+
#[cfg(feature = "lua54")]
51+
Self::Lua54 => Ok(full_moon::ast::LuaVersion::lua54()),
52+
53+
#[cfg(feature = "roblox")]
54+
Self::Luau => Ok(full_moon::ast::LuaVersion::luau()),
55+
56+
#[cfg(feature = "luajit")]
57+
Self::LuaJIT => Ok(full_moon::ast::LuaVersion::luajit()),
58+
59+
Self::Unknown(value) => Err(LuaVersionError::Unknown(value)),
60+
61+
#[allow(unreachable_patterns)]
62+
_ => Err(LuaVersionError::FeatureNotEnabled(self.to_str())),
63+
}
64+
}
65+
}
66+
67+
pub enum LuaVersionError<'a> {
68+
FeatureNotEnabled(&'a str),
69+
Unknown(&'a str),
70+
}
71+
72+
impl Serialize for LuaVersion {
73+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
74+
where
75+
S: serde::Serializer,
76+
{
77+
serializer.serialize_str(self.to_str())
78+
}
79+
}
80+
81+
impl<'de> Deserialize<'de> for LuaVersion {
82+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
83+
where
84+
D: serde::Deserializer<'de>,
85+
{
86+
let value = String::deserialize(deserializer)?;
87+
Ok(Self::from_str(&value))
88+
}
89+
}

0 commit comments

Comments
 (0)