pub struct PrattBuilder { /* private fields */ }Expand description
Builder for Pratt parsing operators
Implementations§
Source§impl PrattBuilder
impl PrattBuilder
Sourcepub fn prefix(
self,
pattern: impl Into<Combinator>,
precedence: u8,
mapping: TokenStream,
) -> Self
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, "...")
Sourcepub fn prefix_kw(
self,
keyword: &str,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn infix(
self,
pattern: impl Into<Combinator>,
precedence: u8,
assoc: Assoc,
mapping: TokenStream,
) -> Self
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, "...")
Sourcepub fn infix_kw(
self,
keyword: &str,
precedence: u8,
assoc: Assoc,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix(
self,
pattern: impl Into<Combinator>,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix_call(
self,
open: &str,
close: &str,
separator: &str,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix_call_with_arg_rule(
self,
open: &str,
close: &str,
separator: &str,
arg_rule: &str,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix_index(
self,
open: &str,
close: &str,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix_member(
self,
literal: &str,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix_member_pattern(
self,
pattern: Combinator,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")
Sourcepub fn postfix_rule(
self,
rule_name: &str,
precedence: u8,
mapping: TokenStream,
) -> Self
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)")