Crate python_parser[−][src]
A Python parser based on nom, plus some utilities.
Panics
Never (except stack overflows).
Numbers
Python's integer literals may be arbitrary large. This is supported
thanks to the num_bigint crate.
Disable the bigint feature to fall back to u64.
String encoding
ast::PyStrings are WTF8-encoded if the wtf8 feature is enabled
(the default) allowing full support for Python's string litteral.
If that feature is disabled, they default to regular Rust string
Note that without the wtf8 feature, some valid string
literals will be badly parsed (missing characters).
Example
extern crate python_parser; use python_parser::ast::*; let code = "print(2 + 3, fd=sys.stderr)"; let ast = python_parser::file_input(python_parser::make_strspan(code)) .unwrap() .1; assert_eq!(ast, vec![ Statement::Assignment( vec![ Expression::Call( Box::new(Expression::Name("print".to_string())), vec![ Argument::Positional( Expression::Bop( Bop::Add, Box::new(Expression::Int(2u32.into())), Box::new(Expression::Int(3u32.into())), ) ), Argument::Keyword( "fd".to_string(), Expression::Attribute( Box::new(Expression::Name("sys".to_string())), "stderr".to_string(), ) ), ] ), ], vec![], ) ] );
Modules
| ast |
enums and structures that store the syntax tree outputed by the parser. |
| visitors |
Utilities that work on the AST. |
Functions
| eval_input |
Parses the input of eval(). |
| file_input |
Parses a module or sequence of commands. |
| make_strspan |
Helper to make an instance of |
| parse_single_input |
Parses a single interactive statement, like in the REPL. |