cedar_policy_core::parser::err

Struct ExpectedTokenConfig

Source
pub struct ExpectedTokenConfig {
    pub friendly_token_names: HashMap<&'static str, &'static str>,
    pub impossible_tokens: HashSet<&'static str>,
    pub special_identifier_tokens: HashSet<&'static str>,
    pub identifier_sentinel: &'static str,
    pub first_set_identifier_tokens: HashSet<&'static str>,
    pub first_set_sentinel: &'static str,
}
Expand description

Defines configurable rules for how tokens in an UnrecognizedToken or UnrecognizedEof error should be displayed to users.

Fields§

§friendly_token_names: HashMap<&'static str, &'static str>

Defines user-friendly names for tokens used by our parser. Keys are the names of tokens as defined in the .lalrpop grammar file. A token may be omitted from this map if the name is already friendly enough.

§impossible_tokens: HashSet<&'static str>

Some tokens defined in our grammar always cause later processing to fail. Our policy grammar defines a token for the mod operator %, but we reject any CST that uses the operator. To reduce confusion we filter these from the list of expected tokens in an error message.

§special_identifier_tokens: HashSet<&'static str>

Both our policy and schema grammar have a generic identifier token and some more specific identifier tokens that we use to parse specific constructs. It is very often not useful to explicitly list out all of these special identifier because the parser really just wants any generic identifier. That it would accept these does not give any useful information.

§identifier_sentinel: &'static str

If this token is expected, then the parser expected a generic identifier, so we omit the specific identifiers favor of saying we expect an “identifier”.

§first_set_identifier_tokens: HashSet<&'static str>

Special identifiers that may be worth displaying even if the parser wants a generic identifier. These can tokens will be parsed as something other than an identifier when they occur as the first token in an expression (or a type, in the case of the schema grammar).

§first_set_sentinel: &'static str

If this token is expected, then the parser was looking to start parsing an expression (or type, in the schema). We know that we should report the tokens that aren’t parsed as identifiers at the start of an expression.

Trait Implementations§

Source§

impl Debug for ExpectedTokenConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.