pub struct Loader<'a, R: Repr> {
    pub parser: Parser<'a>,
    /* private fields */
}
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.
    • PError represents the sub-parser can be totally breaked when mismatched.
  • Use ? to match a condition.
  • Use Result::unwrap_or_default to match an optional condition.
  • Method Parser::forward is used to move on.
  • Method Parser::text is used to get the matched string.
  • Method Parser::backward is used to get back if mismatched.

Fields

parser: Parser<'a>

Parser base.

Implementations

Create YAML loader includes a parser.

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.

Keep the anchor insertion.

This will make Yaml::Alias have a placeholder and adding anchor information in the Node.

Consume this loader and return the recorded anchors.

YAML entry point, return entire doc if exist.

Match one doc block.

Match doc end.

Match scalar.

Match flow scalar.

Match flow scalar terminal.

Match flow sequence.

Match flow map.

Match sequence.

Match map.

Methods from Deref<Target = Parser<'a>>

Match directives.

Match invisible boundaries and keep the gaps. (must matched once)

Match complex mapping indicator (?).

Match integer.

Match float.

Match float with scientific notation.

Match quoted string.

Match plain string.

Match literal string.

Match folded string.

Match chomping option.

Match wrapped string.

Match valid YAML identifier.

Match tags.

Match anchor definition.

Match anchor used.

Match any invisible characters except newline.

Match newline characters.

Match any invisible characters.

Match and define new indent size.

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.

Match any optional invisible characters between two lines.

Set cmt to true to ignore comments at the line end.

Match comment.

Show the right hand side string after the current cursor.

Get the text from the eaten cursor to the current position.

Get the indicator.

A short function to raise error.

Consume and move the pointer.

Consume the eaten part.

Move the current position back.

Move back current cursor.

Match symbol.

Match symbol set.

Match symbol sequence.

Match until the condition failed.

The argument opt matches different terminate requirement.

Count the position that parser goes, expect error.

A wrapper for saving checkpoint locally.

Match indent.

Trait Implementations

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.