Add a Parse impl for symbol Value

This commit is contained in:
David Tolnay 2023-10-25 11:15:18 -07:00
parent ba17934bc1
commit 95742ff23c
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -65,13 +65,19 @@ impl Parse for Symbol {
fn parse(input: ParseStream<'_>) -> Result<Self> { fn parse(input: ParseStream<'_>) -> Result<Self> {
let name = input.parse()?; let name = input.parse()?;
let colon_token: Option<Token![:]> = input.parse()?; let colon_token: Option<Token![:]> = input.parse()?;
let value = let value = if colon_token.is_some() { input.parse()? } else { Value::SameAsName };
if colon_token.is_some() { Value::String(input.parse()?) } else { Value::SameAsName };
Ok(Symbol { name, value }) Ok(Symbol { name, value })
} }
} }
impl Parse for Value {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let lit: LitStr = input.parse()?;
Ok(Value::String(lit))
}
}
struct Input { struct Input {
keywords: Punctuated<Keyword, Token![,]>, keywords: Punctuated<Keyword, Token![,]>,
symbols: Punctuated<Symbol, Token![,]>, symbols: Punctuated<Symbol, Token![,]>,