Skip to content

Commit

Permalink
Misc cleanups in the parser (FuelLabs#2480)
Browse files Browse the repository at this point in the history
* misc cleanups in the parser

* fix bug in peek_delimiter

Co-authored-by: Alex Hansen <[email protected]>
  • Loading branch information
Centril and sezna authored Aug 10, 2022
1 parent e7b315e commit c7113d3
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 750 deletions.
21 changes: 9 additions & 12 deletions sway-parse/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use sway_types::Ident;

impl<T: Parse> Parse for Annotated<T> {
fn parse(parser: &mut Parser) -> ParseResult<Self> {
// Parse the attribute list.
let mut attribute_list = Vec::new();
loop {
if parser.peek::<HashToken>().is_some() {
attribute_list.push(parser.parse()?);
} else {
break;
}
while let Some(attr) = parser.guarded_parse::<HashToken, _>()? {
attribute_list.push(attr);
}

// Parse the `T` value.
let value = parser.parse()?;

Ok(Annotated {
attribute_list,
value,
Expand All @@ -25,19 +25,16 @@ impl<T: Parse> Parse for Annotated<T> {

impl Parse for AttributeDecl {
fn parse(parser: &mut Parser) -> ParseResult<Self> {
let hash_token = parser.parse()?;
let attribute = parser.parse()?;
Ok(AttributeDecl {
hash_token,
attribute,
hash_token: parser.parse()?,
attribute: parser.parse()?,
})
}
}

impl Parse for Attribute {
fn parse(parser: &mut Parser) -> ParseResult<Self> {
let storage = parser.take::<StorageToken>();
let name = if let Some(storage) = storage {
let name = if let Some(storage) = parser.take::<StorageToken>() {
Ident::from(storage)
} else {
parser.parse()?
Expand Down
Loading

0 comments on commit c7113d3

Please sign in to comment.