-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parse module in macro crate (#374)
- Loading branch information
Showing
4 changed files
with
108 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,7 @@ | ||
use proc_macro2::Ident; | ||
use syn::{ | ||
bracketed, | ||
parse::{Parse, ParseStream}, | ||
punctuated::Punctuated, | ||
LitStr, Result, Token, | ||
}; | ||
mod dialect_operation_set; | ||
mod identifier_list; | ||
mod pass_set; | ||
|
||
pub struct IdentifierList { | ||
identifiers: Vec<Ident>, | ||
} | ||
|
||
impl IdentifierList { | ||
pub fn identifiers(&self) -> &[Ident] { | ||
&self.identifiers | ||
} | ||
} | ||
|
||
impl Parse for IdentifierList { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
Ok(Self { | ||
identifiers: Punctuated::<Ident, Token![,]>::parse_terminated(input)? | ||
.into_iter() | ||
.collect(), | ||
}) | ||
} | ||
} | ||
|
||
pub struct DialectOperationSet { | ||
dialect: Ident, | ||
identifiers: IdentifierList, | ||
} | ||
|
||
impl DialectOperationSet { | ||
pub const fn dialect(&self) -> &Ident { | ||
&self.dialect | ||
} | ||
|
||
pub fn identifiers(&self) -> &[Ident] { | ||
self.identifiers.identifiers() | ||
} | ||
} | ||
|
||
impl Parse for DialectOperationSet { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let dialect = Ident::parse(input)?; | ||
<Token![,]>::parse(input)?; | ||
|
||
Ok(Self { | ||
dialect, | ||
identifiers: { | ||
let content; | ||
bracketed!(content in input); | ||
content.parse::<IdentifierList>()? | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
pub struct PassSet { | ||
prefix: LitStr, | ||
identifiers: IdentifierList, | ||
} | ||
|
||
impl PassSet { | ||
pub const fn prefix(&self) -> &LitStr { | ||
&self.prefix | ||
} | ||
|
||
pub fn identifiers(&self) -> &[Ident] { | ||
self.identifiers.identifiers() | ||
} | ||
} | ||
|
||
impl Parse for PassSet { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let prefix = input.parse()?; | ||
<Token![,]>::parse(input)?; | ||
|
||
Ok(Self { | ||
prefix, | ||
identifiers: { | ||
let content; | ||
bracketed!(content in input); | ||
content.parse::<IdentifierList>()? | ||
}, | ||
}) | ||
} | ||
} | ||
pub use dialect_operation_set::DialectOperationSet; | ||
pub use identifier_list::IdentifierList; | ||
pub use pass_set::PassSet; |
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,38 @@ | ||
use super::IdentifierList; | ||
use proc_macro2::Ident; | ||
use syn::{ | ||
bracketed, | ||
parse::{Parse, ParseStream}, | ||
Result, Token, | ||
}; | ||
|
||
pub struct DialectOperationSet { | ||
dialect: Ident, | ||
identifiers: IdentifierList, | ||
} | ||
|
||
impl DialectOperationSet { | ||
pub const fn dialect(&self) -> &Ident { | ||
&self.dialect | ||
} | ||
|
||
pub fn identifiers(&self) -> &[Ident] { | ||
self.identifiers.identifiers() | ||
} | ||
} | ||
|
||
impl Parse for DialectOperationSet { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let dialect = Ident::parse(input)?; | ||
<Token![,]>::parse(input)?; | ||
|
||
Ok(Self { | ||
dialect, | ||
identifiers: { | ||
let content; | ||
bracketed!(content in input); | ||
content.parse::<IdentifierList>()? | ||
}, | ||
}) | ||
} | ||
} |
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,26 @@ | ||
use proc_macro2::Ident; | ||
use syn::{ | ||
parse::{Parse, ParseStream}, | ||
punctuated::Punctuated, | ||
Result, Token, | ||
}; | ||
|
||
pub struct IdentifierList { | ||
identifiers: Vec<Ident>, | ||
} | ||
|
||
impl IdentifierList { | ||
pub fn identifiers(&self) -> &[Ident] { | ||
&self.identifiers | ||
} | ||
} | ||
|
||
impl Parse for IdentifierList { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
Ok(Self { | ||
identifiers: Punctuated::<Ident, Token![,]>::parse_terminated(input)? | ||
.into_iter() | ||
.collect(), | ||
}) | ||
} | ||
} |
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,38 @@ | ||
use super::IdentifierList; | ||
use proc_macro2::Ident; | ||
use syn::{ | ||
bracketed, | ||
parse::{Parse, ParseStream}, | ||
LitStr, Result, Token, | ||
}; | ||
|
||
pub struct PassSet { | ||
prefix: LitStr, | ||
identifiers: IdentifierList, | ||
} | ||
|
||
impl PassSet { | ||
pub const fn prefix(&self) -> &LitStr { | ||
&self.prefix | ||
} | ||
|
||
pub fn identifiers(&self) -> &[Ident] { | ||
self.identifiers.identifiers() | ||
} | ||
} | ||
|
||
impl Parse for PassSet { | ||
fn parse(input: ParseStream) -> Result<Self> { | ||
let prefix = input.parse()?; | ||
<Token![,]>::parse(input)?; | ||
|
||
Ok(Self { | ||
prefix, | ||
identifiers: { | ||
let content; | ||
bracketed!(content in input); | ||
content.parse::<IdentifierList>()? | ||
}, | ||
}) | ||
} | ||
} |