Represent symbol value as enum to prepare for supporting env vars

This commit is contained in:
David Tolnay 2023-10-25 11:12:32 -07:00
parent 173dcb211a
commit ba17934bc1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -53,14 +53,20 @@ impl Parse for Keyword {
struct Symbol { struct Symbol {
name: Ident, name: Ident,
value: Option<LitStr>, value: Value,
}
enum Value {
SameAsName,
String(LitStr),
} }
impl Parse for Symbol { 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 = if colon_token.is_some() { Some(input.parse()?) } else { None }; let value =
if colon_token.is_some() { Value::String(input.parse()?) } else { Value::SameAsName };
Ok(Symbol { name, value }) Ok(Symbol { name, value })
} }
@ -168,8 +174,8 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
for symbol in input.symbols.iter() { for symbol in input.symbols.iter() {
let name = &symbol.name; let name = &symbol.name;
let value = match &symbol.value { let value = match &symbol.value {
Some(value) => value.value(), Value::SameAsName => name.to_string(),
None => name.to_string(), Value::String(lit) => lit.value(),
}; };
check_dup(symbol.name.span(), &value, &mut errors); check_dup(symbol.name.span(), &value, &mut errors);
check_order(symbol.name.span(), &name.to_string(), &mut errors); check_order(symbol.name.span(), &name.to_string(), &mut errors);