Skip to main content

validate_literal

Function validate_literal 

Source
pub fn validate_literal(lit: &Literal) -> Result<()>
Expand description

Validates that lit is a literal cel_parser can represent as a value: a recognized numeric suffix, and (for a suffixed or unsuffixed integer/float) a value in range for its width. Reuses the same literal-compiling checks the grammar itself applies to a literal token, against a throwaway context, for a caller (e.g. adam-lang’s CST parser, which records a literal token without compiling it into a value) that needs to reject the same literals the runtime parser would, without needing a ParserContext of its own to push into.

§Errors

Returns Err for an unrecognized numeric suffix, or a numeric value out of range for its width.

  • Complexity: Includes literal-token cloning and value parsing for the token’s text.

§Examples

let literal: syn::Lit = syn::parse_str("42i32").unwrap();
cel_parser::validate_literal(&literal).unwrap();