Skip to main content

PrattBuilder

Struct PrattBuilder 

Source
pub struct PrattBuilder { /* private fields */ }
Expand description

Builder for Pratt parsing operators

Implementations§

Source§

impl PrattBuilder

Source

pub fn prefix( self, pattern: impl Into<Combinator>, precedence: u8, mapping: TokenStream, ) -> Self

Define a prefix operator with a pattern Example: ops.prefix("-", 16, "|e| unary(e, Neg)") Example: ops.prefix(r.sequence((r.lit("-"), r.not_followed_by(r.lit("-")))), 16, "...")

Source

pub fn prefix_kw( self, keyword: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define a prefix operator for a keyword (ensures not followed by identifier char) Example: ops.prefix_kw("typeof", 16, "|e| unary(e, Typeof)")

Source

pub fn infix( self, pattern: impl Into<Combinator>, precedence: u8, assoc: Assoc, mapping: TokenStream, ) -> Self

Define an infix operator with a pattern Example: ops.infix("+", 13, Assoc::Left, "|l, r| binary(l, r, Add)") Example: ops.infix(r.sequence((r.lit("-"), r.not_followed_by(r.lit("-")))), 9, Left, "...")

Source

pub fn infix_kw( self, keyword: &str, precedence: u8, assoc: Assoc, mapping: TokenStream, ) -> Self

Define an infix operator for a keyword (ensures not followed by identifier char) Example: ops.infix_kw("in", 11, Assoc::Left, "|l, r| binary(l, r, In)")

Source

pub fn postfix( self, pattern: impl Into<Combinator>, precedence: u8, mapping: TokenStream, ) -> Self

Define a simple postfix operator with a pattern (++, –) Example: ops.postfix("++", 17, "|e| update(e, Increment, false)")

Source

pub fn postfix_call( self, open: &str, close: &str, separator: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define a call expression postfix: callee(args) Example: ops.postfix_call("(", ")", ",", 18, "|callee, args| call(callee, args)")

Source

pub fn postfix_call_with_arg_rule( self, open: &str, close: &str, separator: &str, arg_rule: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define a call expression postfix with a custom argument rule: callee(args) The arg_rule is used to parse each argument (e.g., to support spread) Example: ops.postfix_call_with_arg_rule("(", ")", ",", "call_argument", 18, "|callee, args| call(callee, args)")

Source

pub fn postfix_index( self, open: &str, close: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define an index expression postfix: obj[index] Example: ops.postfix_index("[", "]", 18, "|obj, prop| member_computed(obj, prop)")

Source

pub fn postfix_member( self, literal: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define a member access postfix: obj.prop Example: ops.postfix_member(".", 18, "|obj, prop| member(obj, prop)")

Source

pub fn postfix_member_pattern( self, pattern: Combinator, precedence: u8, mapping: TokenStream, ) -> Self

Define a member access postfix with a custom pattern Use this when you need not_followed_by constraints Example: ops.postfix_member_pattern(r.sequence((r.lit("."), r.not_followed_by(r.char('.')))), 18, "|obj, prop| member(obj, prop)")

Source

pub fn postfix_rule( self, rule_name: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define a rule-based postfix: parses another rule as the suffix Used for tagged template literals: tagtemplate Example: ops.postfix_rule("template_literal", 18, "|tag, template| tagged_template(tag, template)")

Source

pub fn ternary( self, first: &str, second: &str, precedence: u8, mapping: TokenStream, ) -> Self

Define a ternary operator: cond ? then : else Example: ops.ternary("?", ":", 3, "|c, t, f| conditional(c, t, f)")

Trait Implementations§

Source§

impl Debug for PrattBuilder

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, 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.