Function rustpython_parser::parse_tokens
source · pub fn parse_tokens(
lxr: impl IntoIterator<Item = LexResult>,
mode: Mode,
source_path: &str,
) -> Result<Mod, ParseError>
Expand description
Parse an iterator of LexResult
s 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());