pub fn parse(src: &str) -> Result<Pairs<'_, Rule>, Error<Rule>>Expand description
Parses the given source string using the PklParser and returns a Pairs iterator over the parsed tokens.
§Arguments
src- A string slice that holds the source code to be parsed.
§Returns
Ok(Pairs<Rule>)- A successful result containing aPairsiterator over the parsed tokens.Err(pest::error::Error<Rule>)- An error that occurred during parsing, encapsulated in apesterror.
§Example
let source = "your source code here";
let parsed = parse(source);
match parsed {
Ok(pairs) => {
for pair in pairs {
// handle parsed tokens
}
}
Err(error) => {
eprintln!("Parsing error: {:?}", error);
}
}