mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-24 21:44:45 +00:00
Flatten rustpython_parser interface
This commit is contained in:
parent
8580e4ebb5
commit
cb8c6fb78d
7 changed files with 168 additions and 177 deletions
|
@ -54,20 +54,18 @@
|
|||
//!
|
||||
//! The functionality of this crate is split into several modules:
|
||||
//!
|
||||
//! - [token]: This module contains the definition of the tokens that are generated by the lexer.
|
||||
//! - token: This module contains the definition of the tokens that are generated by the lexer.
|
||||
//! - [lexer]: This module contains the lexer and is responsible for generating the tokens.
|
||||
//! - [parser]: This module contains an interface to the parser and is responsible for generating the AST.
|
||||
//! - parser: This module contains an interface to the parser and is responsible for generating the AST.
|
||||
//! - Functions and strings have special parsing requirements that are handled in additional files.
|
||||
//! - [mode]: This module contains the definition of the different modes that the parser can be in.
|
||||
//! - [error]: This module contains the definition of the errors that can be returned by the parser.
|
||||
//! - mode: This module contains the definition of the different modes that the parser can be in.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! For example, to get a stream of tokens from a given string, one could do this:
|
||||
//!
|
||||
//! ```
|
||||
//! use rustpython_parser::mode::Mode;
|
||||
//! use rustpython_parser::lexer::lex;
|
||||
//! use rustpython_parser::{lexer::lex, Mode};
|
||||
//!
|
||||
//! let python_source = r#"
|
||||
//! def is_odd(i):
|
||||
|
@ -80,9 +78,7 @@
|
|||
//! These tokens can be directly fed into the parser to generate an AST:
|
||||
//!
|
||||
//! ```
|
||||
//! use rustpython_parser::lexer::lex;
|
||||
//! use rustpython_parser::mode::Mode;
|
||||
//! use rustpython_parser::parser::parse_tokens;
|
||||
//! use rustpython_parser::{lexer::lex, Mode, parse_tokens};
|
||||
//!
|
||||
//! let python_source = r#"
|
||||
//! def is_odd(i):
|
||||
|
@ -98,7 +94,7 @@
|
|||
//! mode or tokenizing the source beforehand:
|
||||
//!
|
||||
//! ```
|
||||
//! use rustpython_parser::parser::parse_program;
|
||||
//! use rustpython_parser::parse_program;
|
||||
//!
|
||||
//! let python_source = r#"
|
||||
//! def is_odd(i):
|
||||
|
@ -111,11 +107,7 @@
|
|||
//!
|
||||
//! [lexical analysis]: https://en.wikipedia.org/wiki/Lexical_analysis
|
||||
//! [parsing]: https://en.wikipedia.org/wiki/Parsing
|
||||
//! [token]: crate::token
|
||||
//! [lexer]: crate::lexer
|
||||
//! [parser]: crate::parser
|
||||
//! [mode]: crate::mode
|
||||
//! [error]: crate::error
|
||||
|
||||
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
|
||||
#![doc(html_root_url = "https://docs.rs/rustpython-parser/")]
|
||||
|
@ -125,12 +117,21 @@ extern crate log;
|
|||
pub use rustpython_ast as ast;
|
||||
|
||||
mod function;
|
||||
// Skip flattening lexer to distinguish from full parser
|
||||
pub mod lexer;
|
||||
pub mod mode;
|
||||
pub mod parser;
|
||||
mod mode;
|
||||
mod parser;
|
||||
mod string;
|
||||
#[rustfmt::skip]
|
||||
mod python;
|
||||
mod context;
|
||||
mod soft_keywords;
|
||||
pub mod token;
|
||||
mod token;
|
||||
|
||||
pub use mode::Mode;
|
||||
pub use parser::{
|
||||
parse, parse_expression, parse_expression_located, parse_located, parse_program, parse_tokens,
|
||||
ParseError, ParseErrorType,
|
||||
};
|
||||
pub use string::FStringErrorType;
|
||||
pub use token::{StringKind, Tok};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue