parser: remove unneccessary FunctionKind enum

This commit is contained in:
Ryan Chandler 2022-07-28 15:55:13 +01:00
parent 151e0d90c3
commit 08e7c99f25
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
2 changed files with 5 additions and 20 deletions

View File

@ -27,12 +27,6 @@ mod block;
mod punc;
mod ident;
#[derive(PartialEq)]
enum FunctionKind {
Named,
Closure,
}
pub struct Parser {
pub current: Token,
pub peek: Token,
@ -447,7 +441,7 @@ impl Parser {
ret
}
},
TokenKind::Function if matches!(self.peek.kind, TokenKind::Identifier(_)) => self.function(FunctionKind::Named)?,
TokenKind::Function if matches!(self.peek.kind, TokenKind::Identifier(_)) => self.function()?,
TokenKind::SemiColon => {
self.next();
@ -463,14 +457,10 @@ impl Parser {
})
}
fn function(&mut self, kind: FunctionKind) -> ParseResult<Statement> {
fn function(&mut self) -> ParseResult<Statement> {
self.next();
let name = if kind == FunctionKind::Named {
self.ident()?
} else {
String::new()
};
let name = self.ident()?;
self.lparen()?;
@ -649,7 +639,7 @@ impl Parser {
Ok(Statement::Method { name: name.into(), params, body: vec![], return_type, flags: flags.iter().map(|t| t.clone().into()).collect() })
} else {
match self.function(FunctionKind::Named)? {
match self.function()? {
Statement::Function { name, params, body, return_type } => {
Ok(Statement::Method { name, params, body, flags: flags.iter().map(|t| t.clone().into()).collect(), return_type })
},
@ -691,7 +681,7 @@ impl Parser {
}
},
TokenKind::Function => {
match self.function(FunctionKind::Named)? {
match self.function()? {
Statement::Function { name, params, body, return_type } => {
Ok(Statement::Method { name, params, body, flags: vec![], return_type })
},

View File

@ -30,11 +30,6 @@ impl Parser {
Ok(())
}
pub(crate) fn lbracket(&mut self) -> ParseResult<()> {
expect!(self, TokenKind::LeftBracket, (), "expected [");
Ok(())
}
pub(crate) fn rbracket(&mut self) -> ParseResult<()> {
expect!(self, TokenKind::RightBracket, (), "expected ]");
Ok(())