Trait pest::Parser
[−]
[src]
pub trait Parser { type Rule; type Token; fn match_string(&mut self, string: &str) -> bool; fn match_range(&mut self, left: char, right: char) -> bool; fn try<F>(&mut self, revert: bool, rule: F) -> bool where F: FnOnce(&mut Self) -> bool; fn prec_climb<F, G>(&mut self, pos: usize, left: usize, min_prec: u8, last_op: Option<(Option<Self::Rule>, u8, bool)>, primary: &mut F, climb: &mut G) -> (Option<(Option<Self::Rule>, u8, bool)>, Option<usize>) where F: FnMut(&mut Self) -> bool, G: FnMut(&mut Self) -> Option<(Option<Self::Rule>, u8, bool)>; fn pos(&self) -> usize; fn set_pos(&mut self, pos: usize); fn end(&self) -> bool; fn eoi_matched(&self) -> bool; fn reset(&mut self); fn slice_input(&self, start: usize, end: usize) -> &str; fn queue(&self) -> &Vec<Self::Token>; fn queue_mut(&mut self) -> &mut Vec<Self::Token>; fn skip_ws(&mut self); fn skip_com(&mut self); fn is_atomic(&self) -> bool; fn set_atomic(&mut self, value: bool); fn track(&mut self, failed: Self::Rule, pos: usize); fn expected(&mut self) -> (Vec<Self::Rule>, usize); }
A trait
that defines a parser.
Associated Types
Required Methods
fn match_string(&mut self, string: &str) -> bool
Matches string
, returns whether it matched, and advances a parser with string.len()
in
case it did.
fn match_range(&mut self, left: char, right: char) -> bool
Matches char
between left
and right
, and advances a parser with one char
in case
it did.
fn try<F>(&mut self, revert: bool, rule: F) -> bool where F: FnOnce(&mut Self) -> bool
Tries to match rule
, returns whether it matched, and advances a parser with in case it
did. If revert
is true
, the parser will not advance.
fn prec_climb<F, G>(&mut self, pos: usize, left: usize, min_prec: u8, last_op: Option<(Option<Self::Rule>, u8, bool)>, primary: &mut F, climb: &mut G) -> (Option<(Option<Self::Rule>, u8, bool)>, Option<usize>) where F: FnMut(&mut Self) -> bool, G: FnMut(&mut Self) -> Option<(Option<Self::Rule>, u8, bool)>
Uses the precendence climbing algorithm to match rules. pos
is the current position
of the queue. left
is the left-most starting position of the current rule. min_prec
is
the currently processed precedence. last_op
is the last greedily parsed infix operator.
primary
is a closure defined in grammar!
that parses a primary expression. climb
is a
closure defined in grammar!
that returns the first Rule
that was parsed (provided it
was not silented) along with its precedence and right-associativity, or None
if no
operator passes. This operator triplet is also returned by the function when it greedily
parses an operator useful for a higher precedence.
fn pos(&self) -> usize
Returns the current position of a Parser
.
fn set_pos(&mut self, pos: usize)
Sets the position of a Parser
.
fn end(&self) -> bool
Returns whether a Parser
has reached its end.
fn eoi_matched(&self) -> bool
Returns whether a Parser
has matched end-of-input.
fn reset(&mut self)
Reset a Parser
.
fn slice_input(&self, start: usize, end: usize) -> &str
Slices a Parser
's Input
.
fn queue(&self) -> &Vec<Self::Token>
Returns the queue of all matched Token
s.
fn queue_mut(&mut self) -> &mut Vec<Self::Token>
Returns the mutable queue of all matched Token
s.
fn skip_ws(&mut self)
Skips white-space.
fn skip_com(&mut self)
Skips comments.
fn is_atomic(&self) -> bool
Returns whether a Parser
is currently inside an atomic rule.
fn set_atomic(&mut self, value: bool)
Sets a Parser
to atomic rule mode, barring comment & white-space skipping.
fn track(&mut self, failed: Self::Rule, pos: usize)
Keeps track of rule failures. It gets called when a rule fails at pos
.
fn expected(&mut self) -> (Vec<Self::Rule>, usize)
Retuns a Vec
of all expected Rule
s at the deepest position where the parsing last
stopped. Used for error reporting.