-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move attributes to a new file
- Loading branch information
1 parent
2b5df09
commit 7774b50
Showing
4 changed files
with
54 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use chumsky::Parser; | ||
use noirc_errors::Span; | ||
|
||
use crate::{ | ||
parser::{NoirParser, ParserError, ParserErrorReason}, | ||
token::{Attribute, Attributes, Token, TokenKind}, | ||
}; | ||
|
||
use super::primitives::token_kind; | ||
|
||
fn attribute() -> impl NoirParser<Attribute> { | ||
token_kind(TokenKind::Attribute).map(|token| match token { | ||
Token::Attribute(attribute) => attribute, | ||
_ => unreachable!("Parser should have already errored due to token not being an attribute"), | ||
}) | ||
} | ||
|
||
pub(super) fn attributes() -> impl NoirParser<Vec<Attribute>> { | ||
attribute().repeated() | ||
} | ||
|
||
pub(super) fn validate_attributes( | ||
attributes: Vec<Attribute>, | ||
span: Span, | ||
emit: &mut dyn FnMut(ParserError), | ||
) -> Attributes { | ||
let mut primary = None; | ||
let mut secondary = Vec::new(); | ||
|
||
for attribute in attributes { | ||
match attribute { | ||
Attribute::Function(attr) => { | ||
if primary.is_some() { | ||
emit(ParserError::with_reason( | ||
ParserErrorReason::MultipleFunctionAttributesFound, | ||
span, | ||
)); | ||
} | ||
primary = Some(attr); | ||
} | ||
Attribute::Secondary(attr) => secondary.push(attr), | ||
} | ||
} | ||
|
||
Attributes { function: primary, secondary } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters