A custom keyword is a DSL-specific syntax token declared with syn::custom_keyword!. Rust does not otherwise treat words such as bucket or lambda as special, so the macro gives syn explicit parsing knowledge for them. section 9.3.2
Listing 9.6 Our four keywords: bucket, lambda, memory, and timeout
pub(crate) mod kw {
syn::custom_keyword!(bucket);
syn::custom_keyword!(lambda);
syn::custom_keyword!(mem);
syn::custom_keyword!(time);
}
Declare related tokens together in a conventional kw module. Each declaration creates a type that can be parsed and inspected with lookahead. section 9.3.2
Use the generated types with ParseStream::peek to choose a grammar branch, then consume the token with input.parse(). A parser can therefore distinguish resource declarations and optional properties while producing targeted errors for unsupported input. section 9.3.2
Parsing infrastructure declarations
A parser can recognize bucket and lambda declarations, then parse each declaration's details: input.peek(kw::bucket) selects Bucket, input.peek(kw::lambda) selects Lambda, and Bucket parses kw::bucket before its identifier. Lambda similarly checks kw::mem and kw::time for optional numeric properties. Invalid forms such as a missing lambda name or nonnumeric memory value receive errors tied to the relevant token.
Custom keywords also work as generic Parse implementations: a shared numeric-property helper can parse kw::time or kw::mem through a type parameter constrained by Parse.
