-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
100 additions
and
76 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
6 changes: 4 additions & 2 deletions
6
crates/sol-macro/src/ast/error.rs → crates/sol-macro/src/ast/item/error.rs
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
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
6 changes: 4 additions & 2 deletions
6
crates/sol-macro/src/ast/struct.rs → crates/sol-macro/src/ast/item/struct.rs
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
2 changes: 1 addition & 1 deletion
2
crates/sol-macro/src/ast/udt.rs → crates/sol-macro/src/ast/item/udt.rs
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
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,62 @@ | ||
use crate::ast::{kw, Parameters}; | ||
use proc_macro2::Span; | ||
use std::fmt; | ||
use syn::{ | ||
parenthesized, | ||
parse::{Parse, ParseStream}, | ||
token::Paren, | ||
Error, Result, Token, | ||
}; | ||
|
||
#[derive(Clone, PartialEq, Eq)] | ||
pub struct Returns { | ||
returns_token: kw::returns, | ||
paren_token: Paren, | ||
pub returns: Parameters<Token![,]>, | ||
} | ||
|
||
impl fmt::Debug for Returns { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_tuple("Returns").field(&self.returns).finish() | ||
} | ||
} | ||
|
||
impl fmt::Display for Returns { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str("returns (")?; | ||
for (i, r) in self.returns.iter().enumerate() { | ||
if i > 0 { | ||
f.write_str(", ")?; | ||
} | ||
write!(f, "{r}")?; | ||
} | ||
f.write_str(")") | ||
} | ||
} | ||
|
||
impl Parse for Returns { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let content; | ||
let this = Self { | ||
returns_token: input.parse()?, | ||
paren_token: parenthesized!(content in input), | ||
returns: content.parse()?, | ||
}; | ||
if this.returns.is_empty() { | ||
Err(Error::new( | ||
this.paren_token.span.join(), | ||
"expected at least one return type", | ||
)) | ||
} else { | ||
Ok(this) | ||
} | ||
} | ||
} | ||
|
||
impl Returns { | ||
#[allow(dead_code)] | ||
pub fn span(&self) -> Span { | ||
let span = self.returns_token.span; | ||
span.join(self.paren_token.span.join()).unwrap_or(span) | ||
} | ||
} |
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