Created
June 28, 2025 21:17
-
-
Save freedomtowin/631e5d347f55d44eb1543cf7d7730ec4 to your computer and use it in GitHub Desktop.
Example of creating a Gist using Python
This file contains hidden or 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
struct ForIfClause { | |
pattern: Pat, | |
sequence: Expr, | |
conditions: Vec<Condition>, | |
} | |
impl Parse for ForIfClause { | |
fn parse(input: ParseStream) -> syn::Result<Self> { | |
_ = input.parse::<Token![for]>()?; | |
let pattern = Pat::parse_single(input)?; | |
_ = input.parse::<Token![in]>()?; | |
let sequence = input.parse()?; | |
let conditions = parse_zero_or_more(input); | |
Ok(Self { | |
pattern, | |
sequence, | |
conditions, | |
}) | |
} | |
} | |
fn parse_zero_or_more<T: Parse>(input: ParseStream) -> Vec<T> { | |
let mut result = Vec::new(); | |
while let Ok(item) = input.parse() { | |
result.push(item); | |
} | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment