Skip to content

Commit

Permalink
Merge pull request #1 from Adrian8115/main
Browse files Browse the repository at this point in the history
fmt & clippy
  • Loading branch information
fmccl authored Aug 6, 2024
2 parents 8212184 + 9fba929 commit 3ed030c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
7 changes: 2 additions & 5 deletions molang_proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ fn molang_struct(input: TokenStream) -> TokenStream {
.map(|field| field.ident.clone().unwrap())
.collect();

let field_types: Vec<Type> = fields
.iter()
.map(|field| field.ty.clone())
.collect();
let field_types: Vec<Type> = fields.iter().map(|field| field.ty.clone()).collect();

quote! {
impl molang::ToMolangValue for #name {
Expand Down Expand Up @@ -65,4 +62,4 @@ fn my_test() {
})
);
panic!("abc");
}
}
2 changes: 1 addition & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ impl Operator {
Self::Equality => 8,
}
}
}
}
16 changes: 7 additions & 9 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,14 @@ pub fn run(
if let Some(some_current) = variables.get_mut(name) {
current = some_current;
break;
} else if constants.contains_key(name) {
return Err(MolangError::NotAssignable(format!(
"Constant {name}"
)));
} else {
if constants.contains_key(name) {
return Err(MolangError::NotAssignable(format!(
"Constant {name}"
)));
} else {
return Err(MolangError::VariableNotFound(
format!("{name}"),
));
}
return Err(MolangError::VariableNotFound(
name.to_string(),
));
}
}
} else if let Value::Struct(struc) =
Expand Down
10 changes: 5 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn treeify(mut tokens: &[Token]) -> Result<Expr, CompileError> {
let left = &tokens[..i];
let right = &tokens[i + 1..];

return Ok(Expr::Derived(Box::new(match op {
Ok(Expr::Derived(Box::new(match op {
Operator::Not => {
if !left.is_empty() {
return Err(CompileError::TokensBeforePrefixOperator);
Expand All @@ -80,10 +80,10 @@ pub fn treeify(mut tokens: &[Token]) -> Result<Expr, CompileError> {
Operator::NullishCoalescing => {
Instruction::NullishCoalescing(treeify(left)?, treeify(right)?)
}
})));
})))
} else {
match tokens {
[Token::Number(n)] => return Ok(Expr::Literal(Value::Number(*n))),
[Token::Number(n)] => Ok(Expr::Literal(Value::Number(*n))),
[Token::Access(accesses)] => {
let mut access_exprs = Vec::new();
for access in accesses {
Expand All @@ -109,7 +109,7 @@ pub fn treeify(mut tokens: &[Token]) -> Result<Expr, CompileError> {
}
}

fn comma_split<'a>(tokens: &'a Vec<Token>) -> Vec<&'a [Token]> {
fn comma_split(tokens: &[Token]) -> Vec<&[Token]> {
let mut result = Vec::new();
let mut start = 0;

Expand All @@ -123,7 +123,7 @@ fn comma_split<'a>(tokens: &'a Vec<Token>) -> Vec<&'a [Token]> {
result.push(&tokens[start..]);

if let Some(last) = result.pop() {
if last.len() != 0 {
if !last.is_empty() {
result.push(last);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ pub trait State<In, Out, Error> {
fn handle(
&mut self,
c: Option<In>,
) -> Result<(Option<Out>, Option<Box<dyn State<In, Out, Error>>>, SequenceAction), Error>;
) -> Result<
(
Option<Out>,
Option<Box<dyn State<In, Out, Error>>>,
SequenceAction,
),
Error,
>;
}

pub enum SequenceAction {
Advance,
Done,
Hold,
}
}
12 changes: 4 additions & 8 deletions src/tokeniser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,12 @@ impl State<char, Token, TokeniseError> for AccessTokenState {
> {
let (access, new_state, action) = self.state.handle(c)?;

match access {
Some(access) => self.accesses.push(access),
None => {}
if let Some(access) = access {
self.accesses.push(access)
}

match new_state {
Some(new_state) => {
self.state = new_state;
}
None => {}
if let Some(new_state) = new_state {
self.state = new_state;
}

match action {
Expand Down

0 comments on commit 3ed030c

Please sign in to comment.