Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make generic_group() returns an Option #47

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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