Struct yaml_peg::parser::Parser[][src]

pub struct Parser<'a, R: Repr> {
    pub pos: usize,
    pub eaten: usize,
    pub anchors: AnchorBase<R>,
    // some fields omitted
}
Expand description

A PEG parser with YAML grammar, support UTF-8 characters.

A simple example for parsing YAML only:

use yaml_peg::{node, parser::Parser};

let n = Parser::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

pos: usize

Current position.

eaten: usize

Read position.

anchors: AnchorBase<R>

A visitor of anchors.

Implementations

The implementation of string pointer.

Create a PEG parser with the string.

Show the right hand side string after the current cursor.

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

The low level grammar implementation.

These sub-parser returns Result<(), PError>, and calling Parser::backward if mismatched.

Builder method for setting indent.

Set the starting point if character boundary is valid.

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 from a set.

Match sequence.

Match until the condition failed.

The argument opt matches different terminate requirement.

A wrapper for saving checkpoint locally.

A SET detector.

A NOT detector.

Match indent.

The implementation of the directives.

Match directives.

The low level grammar implementation for YAML.

These sub-parser returns Result<R, PError>, and calling Parser::backward if mismatched.

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

Match complex mapping indicator (?).

Match integer.

Match float.

Match float with scientific notation.

Match NaN.

Match inf, return true if the value is positive.

Match quoted string.

Match plain string.

Match flow string and return the content.

Match literal string.

Match folded string.

Match chomping option.

Match wrapped string.

String escaping, return a new 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 indent with previous level.

Return true if downgrading indent is allowed.

Match any optional invisible characters between two lines.

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

Match comment.

The basic implementation.

These sub-parser returns PError, and failed immediately for PError::Terminate. Additionally, they should eat the string by themself.

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

Match flow map.

Match array.

Match map.

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

Performs the conversion.

Performs the conversion.

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.