Skip to content

Commit

Permalink
chore: make generic_group() returns an Option (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco committed Jan 25, 2023
1 parent 53e2890 commit 7c39608
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
10 changes: 7 additions & 3 deletions src/parser/internal/expression/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ use crate::parser::state::State;
use crate::tree::expression::generic::GenericGroupExpression;
use crate::tree::utils::CommaSeparated;

pub fn generic_group(state: &mut State) -> ParseResult<GenericGroupExpression> {
Ok(GenericGroupExpression {
pub fn generic_group(state: &mut State) -> ParseResult<Option<GenericGroupExpression>> {
if state.iterator.current().kind != TokenKind::Generic {
return Ok(None);
}

Ok(Some(GenericGroupExpression {
double_colon_less_than: utils::skip(state, TokenKind::Generic)?,
types: {
let mut inner = vec![];
Expand Down Expand Up @@ -45,5 +49,5 @@ pub fn generic_group(state: &mut State) -> ParseResult<GenericGroupExpression> {
utils::skip(state, TokenKind::GreaterThan)?
}
},
})
}))
}
12 changes: 2 additions & 10 deletions src/parser/internal/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ expressions! {
Ok(Expression::FunctionalOperation(FunctionalOperationExpression::Expression {
comments: state.iterator.comments(),
dollar,
generics: if state.iterator.current().kind == TokenKind::Generic {
Some(generic::generic_group(state)?)
} else {
None
},
generics: generic::generic_group(state)?,
left_parenthesis: utils::skip_left_parenthesis(state)?,
expression: Box::new(create(state)?),
right_parenthesis: utils::skip_right_parenthesis(state)?,
Expand Down Expand Up @@ -306,11 +302,7 @@ expressions! {
identifier::fully_qualified_type_identifier_including_self(state)?
)
},
generics: if state.iterator.current().kind == TokenKind::Generic {
Some(generic::generic_group(state)?)
} else {
None
},
generics: generic::generic_group(state)?,
arguments: argument::argument_list_expression(state)?
}
))
Expand Down
18 changes: 3 additions & 15 deletions src/parser/internal/expression/postfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ pub fn postfix(state: &mut State, left: Expression, kind: &TokenKind) -> ParseRe
})
}
TokenKind::Generic | TokenKind::LeftParen => {
let generics = if kind == &TokenKind::Generic {
Some(generic::generic_group(state)?)
} else {
None
};
let generics = generic::generic_group(state)?;

let comments = state.iterator.comments();
// `(...)` closure creation
Expand Down Expand Up @@ -115,11 +111,7 @@ pub fn postfix(state: &mut State, left: Expression, kind: &TokenKind) -> ParseRe

let current = state.iterator.current();
if current.kind == TokenKind::LeftParen || current.kind == TokenKind::Generic {
let generics = if current.kind == TokenKind::Generic {
Some(generic::generic_group(state)?)
} else {
None
};
let generics = generic::generic_group(state)?;

if state.iterator.lookahead(1).kind == TokenKind::Ellipsis
&& state.iterator.lookahead(2).kind == TokenKind::RightParen
Expand Down Expand Up @@ -191,11 +183,7 @@ pub fn postfix(state: &mut State, left: Expression, kind: &TokenKind) -> ParseRe

let current = state.iterator.current();
if current.kind == TokenKind::LeftParen || current.kind == TokenKind::Generic {
let generics = if current.kind == TokenKind::Generic {
Some(generic::generic_group(state)?)
} else {
None
};
let generics = generic::generic_group(state)?;

if kind == &TokenKind::QuestionArrow {
let arguments = argument::argument_list_expression(state)?;
Expand Down

0 comments on commit 7c39608

Please sign in to comment.