2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2023-01-14 23:18:58 -05:00
|
|
|
use syn::parse::Parse;
|
|
|
|
use syn::parse::ParseStream;
|
|
|
|
use syn::Error;
|
|
|
|
use syn::Ident;
|
|
|
|
use syn::Result;
|
|
|
|
use syn::Token;
|
2022-11-10 06:53:31 -05:00
|
|
|
|
2023-03-05 03:00:22 -05:00
|
|
|
#[derive(Clone, Debug, Default)]
|
2022-11-10 06:53:31 -05:00
|
|
|
pub struct Attributes {
|
|
|
|
pub is_unstable: bool,
|
|
|
|
pub is_v8: bool,
|
|
|
|
pub must_be_fast: bool,
|
|
|
|
pub deferred: bool,
|
2022-11-27 08:54:28 -05:00
|
|
|
pub is_wasm: bool,
|
2023-03-05 03:00:22 -05:00
|
|
|
pub relation: Option<Ident>,
|
2022-11-10 06:53:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Parse for Attributes {
|
|
|
|
fn parse(input: ParseStream) -> Result<Self> {
|
2023-03-05 03:00:22 -05:00
|
|
|
let mut self_ = Self::default();
|
|
|
|
let mut fast = false;
|
|
|
|
while let Ok(v) = input.parse::<Ident>() {
|
|
|
|
match v.to_string().as_str() {
|
|
|
|
"unstable" => self_.is_unstable = true,
|
|
|
|
"v8" => self_.is_v8 = true,
|
|
|
|
"fast" => fast = true,
|
|
|
|
"deferred" => self_.deferred = true,
|
|
|
|
"wasm" => self_.is_wasm = true,
|
|
|
|
"slow" => {
|
|
|
|
if !fast {
|
|
|
|
return Err(Error::new(
|
|
|
|
input.span(),
|
|
|
|
"relational attributes can only be used with fast attribute",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
input.parse::<Token![=]>()?;
|
|
|
|
self_.relation = Some(input.parse()?);
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
return Err(Error::new(
|
|
|
|
input.span(),
|
|
|
|
"invalid attribute, expected one of: unstable, v8, fast, deferred, wasm",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let _ = input.parse::<Token![,]>();
|
2022-11-10 06:53:31 -05:00
|
|
|
}
|
2022-11-27 08:54:28 -05:00
|
|
|
|
2023-03-05 03:00:22 -05:00
|
|
|
self_.must_be_fast = self_.is_wasm || fast;
|
2022-11-27 08:54:28 -05:00
|
|
|
|
2023-03-05 03:00:22 -05:00
|
|
|
Ok(self_)
|
2022-11-10 06:53:31 -05:00
|
|
|
}
|
|
|
|
}
|