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.
The low level grammar implementation.
These sub-parser returns Result<(), PError>
, and calling Parser::backward
if mismatched.
A short function to raise error.
Match until the condition failed.
The argument opt
matches different terminate requirement.
A wrapper for saving checkpoint locally.
The implementation of the 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 quoted string.
Match plain string.
Match flow string and return the content.
Match wrapped string.
Match valid YAML identifier.
Match anchor used.
Match any invisible characters except newline.
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.
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 scalar.
Match flow scalar.
Match flow scalar terminal.