Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Remove parser ast re-export #41

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ruff_python_parser/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::{self, Expr, ExprContext};
use ruff_python_ast::{self as ast, Expr, ExprContext};

pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr {
match expr {
Expand Down Expand Up @@ -49,7 +49,8 @@ pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr {

#[cfg(test)]
mod tests {
use crate::{ast, Parse};
use crate::Parse;
use ruff_python_ast as ast;

#[test]
fn test_assign_name() {
Expand Down
10 changes: 4 additions & 6 deletions ruff_python_parser/src/function.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// Contains functions that perform validation and parsing of arguments and parameters.
// Checks apply both to functions and to lambdas.
use crate::{
ast,
lexer::{LexicalError, LexicalErrorType},
};
use ruff_python_ast::Ranged;
use crate::lexer::{LexicalError, LexicalErrorType};
use ruff_python_ast::{self as ast, Ranged};
use ruff_text_size::{TextRange, TextSize};
use rustc_hash::FxHashSet;

Expand Down Expand Up @@ -138,7 +135,8 @@ const fn is_starred(exp: &ast::Expr) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::{ast, parser::ParseErrorType, Parse};
use crate::{Parse, ParseErrorType};
use ruff_python_ast::{self as ast};

macro_rules! function_and_lambda {
($($name:ident: $code:expr,)*) => {
Expand Down
4 changes: 2 additions & 2 deletions ruff_python_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
//! mode or tokenizing the source beforehand:
//!
//! ```
//! use ruff_python_parser::{Parse, ast};
//! use ruff_python_parser::{Parse};
//! use ruff_python_ast as ast;
//!
//! let python_source = r#"
//! def is_odd(i):
Expand All @@ -112,7 +113,6 @@
pub use parser::{parse, parse_starts_at, parse_tokens, Parse, ParseError, ParseErrorType};
#[allow(deprecated)]
pub use parser::{parse_expression, parse_expression_starts_at, parse_program};
pub use ruff_python_ast as ast;
pub use string::FStringErrorType;
pub use token::{StringKind, Tok};

Expand Down
11 changes: 7 additions & 4 deletions ruff_python_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use ruff_text_size::TextSize;

use crate::lexer::{lex, lex_starts_at};
use crate::{
ast::{self, Ranged},
lexer::{self, LexResult, LexicalError, LexicalErrorType},
python,
token::Tok,
Mode,
};
use ruff_python_ast::{self as ast, Ranged};

/// Parse Python code string to implementor's type.
///
Expand All @@ -34,7 +34,8 @@ use crate::{
/// For example, parsing a simple function definition and a call to that function:
///
/// ```
/// use ruff_python_parser::{self as parser, ast, Parse};
/// use ruff_python_parser::{self as parser, Parse};
/// use ruff_python_ast as ast;
/// let source = r#"
/// def foo():
/// return 42
Expand All @@ -50,7 +51,8 @@ use crate::{
///
/// ```
/// # use ruff_text_size::TextSize;
/// # use ruff_python_parser::{self as parser, ast, Parse};
/// # use ruff_python_ast as ast;
/// # use ruff_python_parser::{self as parser, Parse};
///
/// let expr = ast::Expr::parse_starts_at("1 + 2", "<embedded>", TextSize::from(400));
/// assert!(expr.is_ok());
Expand Down Expand Up @@ -582,8 +584,9 @@ include!("gen/parse.rs");

#[cfg(test)]
mod tests {
use crate::{ast, Parse};
use crate::Parse;
use insta::assert_debug_snapshot;
use ruff_python_ast as ast;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion ruff_python_parser/src/python.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

use num_bigint::BigInt;
use ruff_text_size::TextSize;
use ruff_python_ast::{self as ast, Ranged, MagicKind};
use crate::{
ast::{self as ast, Ranged, MagicKind},
Mode,
lexer::{LexicalError, LexicalErrorType},
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
Expand Down
6 changes: 3 additions & 3 deletions ruff_python_parser/src/python.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// auto-generated: "lalrpop 0.20.0"
// sha3: 44f1432ea449af8f70398fcbc3e641e2fd720734693a493e635795dd681954e0
// sha3: bfe8038efa3e290b9841ea2f84a2278ded65476a00892aa448e9708655ccb86d
use num_bigint::BigInt;
use ruff_text_size::TextSize;
use ruff_python_ast::{self as ast, Ranged, MagicKind};
use crate::{
ast::{self as ast, Ranged, MagicKind},
Mode,
lexer::{LexicalError, LexicalErrorType},
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
Expand All @@ -24,8 +24,8 @@ mod __parse__Top {

use num_bigint::BigInt;
use ruff_text_size::TextSize;
use ruff_python_ast::{self as ast, Ranged, MagicKind};
use crate::{
ast::{self as ast, Ranged, MagicKind},
Mode,
lexer::{LexicalError, LexicalErrorType},
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
Expand Down
14 changes: 9 additions & 5 deletions ruff_python_parser/src/string.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use itertools::Itertools;

use ruff_python_ast::{self as ast, Constant, Expr};
use ruff_python_ast::{ConversionFlag, Ranged};
use ruff_text_size::{TextLen, TextRange, TextSize};

// Contains the logic for parsing string literals (mostly concerned with f-strings.)
//
// The lexer doesn't do any special handling of f-strings, it just treats them as
// regular strings. Since the ruff_python_parser has no definition of f-string formats (Pending PEP 701)
// we have to do the parsing here, manually.
use crate::{
ast::{self, Constant, Expr},
lexer::{LexicalError, LexicalErrorType},
parser::{LalrpopError, Parse, ParseError, ParseErrorType},
token::{StringKind, Tok},
};
use itertools::Itertools;
use ruff_python_ast::{ConversionFlag, Ranged};
use ruff_text_size::{TextLen, TextRange, TextSize};

// unicode_name2 does not expose `MAX_NAME_LENGTH`, so we replicate that constant here, fix #3798
const MAX_UNICODE_NAME: usize = 88;
Expand Down Expand Up @@ -831,8 +833,10 @@ impl From<FStringError> for LalrpopError<TextSize, Tok, LexicalError> {

#[cfg(test)]
mod tests {
use crate::Parse;
use ruff_python_ast as ast;

use super::*;
use crate::{ast, Parse};

fn parse_fstring(source: &str) -> Result<Vec<Expr>, LexicalError> {
StringParser::new(source, StringKind::FString, false, TextSize::default()).parse()
Expand Down
2 changes: 1 addition & 1 deletion ruff_python_parser/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! loosely based on the token definitions found in the [CPython source].
//!
//! [CPython source]: https://github.com/python/cpython/blob/dfc2e065a2e71011017077e549cd2f9bf4944c54/Include/internal/pycore_token.h;
use crate::ast::MagicKind;
use crate::Mode;
use num_bigint::BigInt;
use ruff_python_ast::MagicKind;
use ruff_text_size::TextSize;
use std::fmt;

Expand Down