Skip to content

Commit

Permalink
Remove parse_modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Oct 7, 2024
1 parent cb3d321 commit 279c8d2
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions compiler/noirc_frontend/src/parser/parser/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ pub(crate) struct Modifiers {
impl<'a> Parser<'a> {
/// Modifiers = 'unconstrained'? ItemVisibility 'comptime'? 'mut'?
pub(crate) fn parse_modifiers(&mut self, allow_mutable: bool) -> Modifiers {
let unconstrained = self.parse_modifier(Keyword::Unconstrained);
let unconstrained = if self.eat_keyword(Keyword::Unconstrained) {
Some(self.previous_token_span)
} else {
None
};

let start_span = self.current_token_span;
let visibility = self.parse_item_visibility();
let visibility_span = self.span_since(start_span);

let comptime = self.parse_modifier(Keyword::Comptime);
let mutable = if allow_mutable { self.parse_modifier(Keyword::Mut) } else { None };

Modifiers { visibility, visibility_span, unconstrained, comptime, mutable }
}

fn parse_modifier(&mut self, keyword: Keyword) -> Option<Span> {
if self.eat_keyword(keyword) {
let comptime =
if self.eat_keyword(Keyword::Comptime) { Some(self.previous_token_span) } else { None };
let mutable = if allow_mutable && self.eat_keyword(Keyword::Mut) {
Some(self.previous_token_span)
} else {
None
}
};

Modifiers { visibility, visibility_span, unconstrained, comptime, mutable }
}
}

0 comments on commit 279c8d2

Please sign in to comment.