Expand description
A parser with YAML grammar, support UTF-8 characters.
This loader will output YAML nodes with representation notation repr::Repr.
If you just want to use sub-parser, please see Parser.
A simple example for parsing YAML only:
use yaml_peg::{node, parser::Loader};
let n = Loader::new(b"true").parse().unwrap();
assert_eq!(n, vec![node!(true)]);For matching partial grammar, each methods are the sub-parser. The methods have some behaviors:
- They will move the current cursor if matched.
- Returned value:
Result<(), PError>represents the sub-parser can be matched and mismatched.PErrorrepresents the sub-parser can be totally breaked when mismatched.
- Use
?to match a condition. - Use
Result::unwrap_or_defaultto match an optional condition. - Method
Parser::forwardis used to move on. - Method
Parser::textis used to get the matched string. - Method
Parser::backwardis used to get back if mismatched.
Fields
parser: Parser<'a>Parser base.
Implementations
sourceimpl<R: Repr> Loader<'_, R>
impl<R: Repr> Loader<'_, R>
The basic implementation.
These sub-parser returns PError, and failed immediately for PError::Terminate.
Additionally, they should eat the string by themself.
Parameter nest
The nest parameter presents that the expression is in a map structure,
includes grand parents.
If nest is false, the expression might in the document root.
Parameter inner
The inner parameter presents that the expression is in a flow expression.
sourcepub fn keep_anchors(self, keep_anchors: bool) -> Self
pub fn keep_anchors(self, keep_anchors: bool) -> Self
Keep the anchor insertion.
This will make Yaml::Alias have a placeholder
and adding anchor information in the Node.
sourcepub fn get_anchors(self) -> Anchors<R>
pub fn get_anchors(self) -> Anchors<R>
Consume this loader and return the recorded anchors.
sourcepub fn scalar(
&mut self,
level: usize,
nest: bool,
inner: bool
) -> PResult<Node<R>>
pub fn scalar(
&mut self,
level: usize,
nest: bool,
inner: bool
) -> PResult<Node<R>>
Match scalar.
sourcepub fn scalar_flow(&mut self, level: usize, inner: bool) -> PResult<Node<R>>
pub fn scalar_flow(&mut self, level: usize, inner: bool) -> PResult<Node<R>>
Match flow scalar.
Methods from Deref<Target = Parser<'a>>
sourcepub fn bound(&mut self) -> PResult<()>
pub fn bound(&mut self) -> PResult<()>
Match invisible boundaries and keep the gaps. (must matched once)
sourcepub fn complex_mapping(&mut self) -> PResult<()>
pub fn complex_mapping(&mut self) -> PResult<()>
Match complex mapping indicator (?).
sourcepub fn string_quoted(&mut self, sym: u8, ignore: &[u8]) -> PResult<String>
pub fn string_quoted(&mut self, sym: u8, ignore: &[u8]) -> PResult<String>
Match quoted string.
sourcepub fn string_plain(&mut self, level: usize, inner: bool) -> PResult<String>
pub fn string_plain(&mut self, level: usize, inner: bool) -> PResult<String>
Match plain string.
sourcepub fn string_literal(&mut self, level: usize) -> PResult<String>
pub fn string_literal(&mut self, level: usize) -> PResult<String>
Match literal string.
sourcepub fn string_folded(&mut self, level: usize) -> PResult<String>
pub fn string_folded(&mut self, level: usize) -> PResult<String>
Match folded string.
sourcepub fn string_wrapped(
&mut self,
level: usize,
sep: u8,
leading: bool
) -> PResult<String>
pub fn string_wrapped(
&mut self,
level: usize,
sep: u8,
leading: bool
) -> PResult<String>
Match wrapped string.
sourcepub fn identifier(&mut self) -> PResult<()>
pub fn identifier(&mut self) -> PResult<()>
Match valid YAML identifier.
sourcepub fn anchor_use(&mut self) -> PResult<String>
pub fn anchor_use(&mut self) -> PResult<String>
Match anchor used.
sourcepub fn ws(&mut self, opt: TakeOpt) -> PResult<()>
pub fn ws(&mut self, opt: TakeOpt) -> PResult<()>
Match any invisible characters except newline.
sourcepub fn ind_define(&mut self, level: usize) -> PResult<()>
pub fn ind_define(&mut self, level: usize) -> PResult<()>
Match and define new indent size.
sourcepub fn unind(&mut self, level: usize) -> PResult<bool>
pub fn unind(&mut self, level: usize) -> PResult<bool>
Match indent with previous level.
This sub-parser returns true if downgrading indent is used.
The downgrading can only use a level as unit, not a whitespace.
sourcepub fn take_while<F>(&mut self, f: F, opt: TakeOpt) -> PResult<()> where
F: Fn(&u8) -> bool,
pub fn take_while<F>(&mut self, f: F, opt: TakeOpt) -> PResult<()> where
F: Fn(&u8) -> bool,
Match until the condition failed.
The argument opt matches different terminate requirement.
sourcepub fn count<F, R>(&mut self, f: F) -> PResult<usize> where
F: FnOnce(&mut Self) -> PResult<R>,
pub fn count<F, R>(&mut self, f: F) -> PResult<usize> where
F: FnOnce(&mut Self) -> PResult<R>,
Count the position that parser goes, expect error.
Trait Implementations
Auto Trait Implementations
impl<'a, R> RefUnwindSafe for Loader<'a, R> where
R: RefUnwindSafe,
<R as Repr>::Ty: RefUnwindSafe,
impl<'a, R> Send for Loader<'a, R> where
R: Send,
<R as Repr>::Ty: Send,
impl<'a, R> Sync for Loader<'a, R> where
R: Sync,
<R as Repr>::Ty: Sync,
impl<'a, R> Unpin for Loader<'a, R>
impl<'a, R> UnwindSafe for Loader<'a, R> where
R: RefUnwindSafe,
<R as Repr>::Ty: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more