pub fn parse_tokens(
lxr: impl IntoIterator<Item = LexResult>,
mode: Mode,
source_path: &str,
) -> Result<Mod, ParseError>Expand description
Parse an iterator of LexResults using the specified Mode.
This could allow you to perform some preprocessing on the tokens before parsing them.
ยงExample
As an example, instead of parsing a string, we can parse a list of tokens after we generate
them using the lexer::lex function:
use rustpython_parser::{lexer::lex, Mode, parse_tokens};
let expr = parse_tokens(lex("1 + 2", Mode::Expression), Mode::Expression, "<embedded>");
assert!(expr.is_ok());