-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Error on lack of module attr for implementation of interface
- Loading branch information
1 parent
3c1bf9a
commit 8994b5f
Showing
4 changed files
with
45 additions
and
35 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
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 |
---|---|---|
@@ -1,38 +1,35 @@ | ||
use proc_macro_error::abort; | ||
use syn::{ | ||
parse::{Error, Nothing, Parse, ParseStream}, | ||
Ident, Path, Result, Token, | ||
parse::{Nothing, Parse, ParseStream}, | ||
Error, Ident, Path, Result, Token, | ||
}; | ||
|
||
/// Parsed arguments for `contract` macro | ||
pub struct ContractArgs { | ||
/// Module in which contract impl block is defined. | ||
/// Used only while implementing `Interface` on `Contract`. | ||
pub module: Option<Path>, | ||
pub module: Path, | ||
} | ||
|
||
impl Parse for ContractArgs { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let mut module = None; | ||
|
||
while !input.is_empty() { | ||
let attr: Ident = input.parse()?; | ||
let maybe_module = input.parse().and_then(|attr: Ident| -> Result<Path> { | ||
let _: Token![=] = input.parse()?; | ||
|
||
if attr == "module" { | ||
module = Some(input.parse()?); | ||
input.parse() | ||
} else { | ||
return Err(Error::new(attr.span(), "expected `module`")); | ||
} | ||
|
||
if input.peek(Token![,]) { | ||
let _: Token![,] = input.parse()?; | ||
} else if !input.is_empty() { | ||
return Err(input.error("Unexpected token, comma expected")); | ||
Err(Error::new(attr.span(), "Missing `module` attribute")) | ||
} | ||
} | ||
|
||
}); | ||
let module: Path = match maybe_module { | ||
Ok(module) => module, | ||
Err(e) => abort!( | ||
e.span(), "The module path needs to be provided `#[contract(module=path::to::contract)`."; | ||
note = "Implementing interface on a contract requires to point the path to the contract structure."; | ||
note = "Parsing error: {}", e | ||
), | ||
}; | ||
let _: Nothing = input.parse()?; | ||
|
||
Ok(ContractArgs { module }) | ||
} | ||
} |