pub struct PrefixExpr<Operator, Operand, const MAX: usize = unsynn::::expressions::PrefixExpr::{constant#0}> {
pub operators: DelimitedVec<Operator, Nothing, Mandatory, 0, MAX>,
pub operand: Operand,
}Expand description
Prefix unary operator expression.
Parses: Op* Operand (0 to MAX operators, then operand)
Allows zero or more prefix operators before an operand. Multiple prefix operators
are applied right-to-left (innermost first). For example, --x is parsed as
-(-x) (two negations).
§Type Parameters
Operator: The prefix operator type (typically an enum of different unary operators)Operand: The type of expression that the operators apply toMAX: Maximum number of prefix operators (defaults tousize::MAXfor unlimited)
§Examples
unsynn! {
type Number = LiteralInteger;
}
// Parse "- - 5"
let mut tokens = "--5".to_token_iter();
let expr: PrefixExpr<Minus, Number> = tokens.parse().unwrap();
assert_eq!(expr.operators.len(), 2); // 2 Minus operators
// Limit prefix depth
type LimitedPrefix = PrefixExpr<Minus, Number, 3>; // Max 3 prefix operatorsFields§
§operators: DelimitedVec<Operator, Nothing, Mandatory, 0, MAX>The prefix operators (0 to MAX, applied right-to-left)
operand: OperandThe operand that the operators apply to
Implementations§
Source§impl<Operator, Operand, const MAX: usize> PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> PrefixExpr<Operator, Operand, MAX>
Sourcepub const fn new(
operators: DelimitedVec<Operator, Nothing, Mandatory, 0, MAX>,
operand: Operand,
) -> PrefixExpr<Operator, Operand, MAX>
pub const fn new( operators: DelimitedVec<Operator, Nothing, Mandatory, 0, MAX>, operand: Operand, ) -> PrefixExpr<Operator, Operand, MAX>
Create a new PrefixExpr with the given operators and operand.
Trait Implementations§
Source§impl<Operator, Operand, const MAX: usize> Clone for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> Clone for PrefixExpr<Operator, Operand, MAX>
Source§fn clone(&self) -> PrefixExpr<Operator, Operand, MAX>
fn clone(&self) -> PrefixExpr<Operator, Operand, MAX>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Operator, Operand, const MAX: usize> Debug for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> Debug for PrefixExpr<Operator, Operand, MAX>
Source§impl<Operator, Operand, const MAX: usize> Parser for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> Parser for PrefixExpr<Operator, Operand, MAX>
Source§fn parser(
tokens: &mut TokenIter,
) -> Result<PrefixExpr<Operator, Operand, MAX>, Error>
fn parser( tokens: &mut TokenIter, ) -> Result<PrefixExpr<Operator, Operand, MAX>, Error>
The actual parsing function that must be implemented. This mutates the
tokens
iterator directly. It should not be called from user code except for implementing
parsers itself and then only when the rules below are followed. Read moreSource§impl<Operator, Operand, const MAX: usize> ToTokens for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> ToTokens for PrefixExpr<Operator, Operand, MAX>
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn into_token_iter(self) -> TokenIter ⓘwhere
Self: Sized,
fn into_token_iter(self) -> TokenIter ⓘwhere
Self: Sized,
Convert
self into a TokenIter object.Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Convert
&self into a TokenStream object.Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Convert
self into a TokenStream object.Auto Trait Implementations§
impl<Operator, Operand, const MAX: usize> Freeze for PrefixExpr<Operator, Operand, MAX>where
Operand: Freeze,
impl<Operator, Operand, const MAX: usize> RefUnwindSafe for PrefixExpr<Operator, Operand, MAX>where
Operand: RefUnwindSafe,
Operator: RefUnwindSafe,
impl<Operator, Operand, const MAX: usize> Send for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> Sync for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> Unpin for PrefixExpr<Operator, Operand, MAX>
impl<Operator, Operand, const MAX: usize> UnwindSafe for PrefixExpr<Operator, Operand, MAX>where
Operand: UnwindSafe,
Operator: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynamicTokens for T
impl<T> DynamicTokens for T
Source§impl<T> Parse for Twhere
T: Parser,
impl<T> Parse for Twhere
T: Parser,
Source§fn parse(tokens: &mut TokenIter) -> Result<Self, Error>
fn parse(tokens: &mut TokenIter) -> Result<Self, Error>
This is the user facing API to parse grammatical entities. Calls a
parser() within a
transaction. Commits changes on success and returns the parsed value. Read more