Skip to content

Commit

Permalink
Merge pull request #2 from fmccl/revert-1-main
Browse files Browse the repository at this point in the history
Revert "fmt & clippy"
  • Loading branch information
fmccl authored Aug 10, 2024
2 parents 3ed030c + 10f7446 commit 0f3bfbd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
7 changes: 5 additions & 2 deletions molang_proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ 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 @@ -62,4 +65,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: 9 additions & 7 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ 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 {
return Err(MolangError::VariableNotFound(
name.to_string(),
));
if constants.contains_key(name) {
return Err(MolangError::NotAssignable(format!(
"Constant {name}"
)));
} else {
return Err(MolangError::VariableNotFound(
format!("{name}"),
));
}
}
}
} 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..];

Ok(Expr::Derived(Box::new(match op {
return 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)] => Ok(Expr::Literal(Value::Number(*n))),
[Token::Number(n)] => return 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(tokens: &[Token]) -> Vec<&[Token]> {
fn comma_split<'a>(tokens: &'a Vec<Token>) -> Vec<&'a [Token]> {
let mut result = Vec::new();
let mut start = 0;

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

if let Some(last) = result.pop() {
if !last.is_empty() {
if last.len() != 0 {
result.push(last);
}
}
Expand Down
11 changes: 2 additions & 9 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ 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: 8 additions & 4 deletions src/tokeniser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,16 @@ impl State<char, Token, TokeniseError> for AccessTokenState {
> {
let (access, new_state, action) = self.state.handle(c)?;

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

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

match action {
Expand Down

0 comments on commit 0f3bfbd

Please sign in to comment.