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

Commit fab9cc5

Browse files
authored
Remove parser ast re-export (#41)
1 parent ff7bab5 commit fab9cc5

File tree

8 files changed

+30
-24
lines changed

8 files changed

+30
-24
lines changed

ruff_python_parser/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ast::{self, Expr, ExprContext};
1+
use ruff_python_ast::{self as ast, Expr, ExprContext};
22

33
pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr {
44
match expr {
@@ -49,7 +49,8 @@ pub(crate) fn set_context(expr: Expr, ctx: ExprContext) -> Expr {
4949

5050
#[cfg(test)]
5151
mod tests {
52-
use crate::{ast, Parse};
52+
use crate::Parse;
53+
use ruff_python_ast as ast;
5354

5455
#[test]
5556
fn test_assign_name() {

ruff_python_parser/src/function.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Contains functions that perform validation and parsing of arguments and parameters.
22
// Checks apply both to functions and to lambdas.
3-
use crate::{
4-
ast,
5-
lexer::{LexicalError, LexicalErrorType},
6-
};
7-
use ruff_python_ast::Ranged;
3+
use crate::lexer::{LexicalError, LexicalErrorType};
4+
use ruff_python_ast::{self as ast, Ranged};
85
use ruff_text_size::{TextRange, TextSize};
96
use rustc_hash::FxHashSet;
107

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

143141
macro_rules! function_and_lambda {
144142
($($name:ident: $code:expr,)*) => {

ruff_python_parser/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
//! mode or tokenizing the source beforehand:
9595
//!
9696
//! ```
97-
//! use ruff_python_parser::{Parse, ast};
97+
//! use ruff_python_parser::{Parse};
98+
//! use ruff_python_ast as ast;
9899
//!
99100
//! let python_source = r#"
100101
//! def is_odd(i):
@@ -112,7 +113,6 @@
112113
pub use parser::{parse, parse_starts_at, parse_tokens, Parse, ParseError, ParseErrorType};
113114
#[allow(deprecated)]
114115
pub use parser::{parse_expression, parse_expression_starts_at, parse_program};
115-
pub use ruff_python_ast as ast;
116116
pub use string::FStringErrorType;
117117
pub use token::{StringKind, Tok};
118118

ruff_python_parser/src/parser.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use ruff_text_size::TextSize;
2020

2121
use crate::lexer::{lex, lex_starts_at};
2222
use crate::{
23-
ast::{self, Ranged},
2423
lexer::{self, LexResult, LexicalError, LexicalErrorType},
2524
python,
2625
token::Tok,
2726
Mode,
2827
};
28+
use ruff_python_ast::{self as ast, Ranged};
2929

3030
/// Parse Python code string to implementor's type.
3131
///
@@ -34,7 +34,8 @@ use crate::{
3434
/// For example, parsing a simple function definition and a call to that function:
3535
///
3636
/// ```
37-
/// use ruff_python_parser::{self as parser, ast, Parse};
37+
/// use ruff_python_parser::{self as parser, Parse};
38+
/// use ruff_python_ast as ast;
3839
/// let source = r#"
3940
/// def foo():
4041
/// return 42
@@ -50,7 +51,8 @@ use crate::{
5051
///
5152
/// ```
5253
/// # use ruff_text_size::TextSize;
53-
/// # use ruff_python_parser::{self as parser, ast, Parse};
54+
/// # use ruff_python_ast as ast;
55+
/// # use ruff_python_parser::{self as parser, Parse};
5456
///
5557
/// let expr = ast::Expr::parse_starts_at("1 + 2", "<embedded>", TextSize::from(400));
5658
/// assert!(expr.is_ok());
@@ -582,8 +584,9 @@ include!("gen/parse.rs");
582584

583585
#[cfg(test)]
584586
mod tests {
585-
use crate::{ast, Parse};
587+
use crate::Parse;
586588
use insta::assert_debug_snapshot;
589+
use ruff_python_ast as ast;
587590

588591
use super::*;
589592

ruff_python_parser/src/python.lalrpop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
use num_bigint::BigInt;
77
use ruff_text_size::TextSize;
8+
use ruff_python_ast::{self as ast, Ranged, MagicKind};
89
use crate::{
9-
ast::{self as ast, Ranged, MagicKind},
1010
Mode,
1111
lexer::{LexicalError, LexicalErrorType},
1212
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},

ruff_python_parser/src/python.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// auto-generated: "lalrpop 0.20.0"
2-
// sha3: 44f1432ea449af8f70398fcbc3e641e2fd720734693a493e635795dd681954e0
2+
// sha3: bfe8038efa3e290b9841ea2f84a2278ded65476a00892aa448e9708655ccb86d
33
use num_bigint::BigInt;
44
use ruff_text_size::TextSize;
5+
use ruff_python_ast::{self as ast, Ranged, MagicKind};
56
use crate::{
6-
ast::{self as ast, Ranged, MagicKind},
77
Mode,
88
lexer::{LexicalError, LexicalErrorType},
99
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
@@ -24,8 +24,8 @@ mod __parse__Top {
2424

2525
use num_bigint::BigInt;
2626
use ruff_text_size::TextSize;
27+
use ruff_python_ast::{self as ast, Ranged, MagicKind};
2728
use crate::{
28-
ast::{self as ast, Ranged, MagicKind},
2929
Mode,
3030
lexer::{LexicalError, LexicalErrorType},
3131
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},

ruff_python_parser/src/string.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
use itertools::Itertools;
2+
3+
use ruff_python_ast::{self as ast, Constant, Expr};
4+
use ruff_python_ast::{ConversionFlag, Ranged};
5+
use ruff_text_size::{TextLen, TextRange, TextSize};
6+
17
// Contains the logic for parsing string literals (mostly concerned with f-strings.)
28
//
39
// The lexer doesn't do any special handling of f-strings, it just treats them as
410
// regular strings. Since the ruff_python_parser has no definition of f-string formats (Pending PEP 701)
511
// we have to do the parsing here, manually.
612
use crate::{
7-
ast::{self, Constant, Expr},
813
lexer::{LexicalError, LexicalErrorType},
914
parser::{LalrpopError, Parse, ParseError, ParseErrorType},
1015
token::{StringKind, Tok},
1116
};
12-
use itertools::Itertools;
13-
use ruff_python_ast::{ConversionFlag, Ranged};
14-
use ruff_text_size::{TextLen, TextRange, TextSize};
1517

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

832834
#[cfg(test)]
833835
mod tests {
836+
use crate::Parse;
837+
use ruff_python_ast as ast;
838+
834839
use super::*;
835-
use crate::{ast, Parse};
836840

837841
fn parse_fstring(source: &str) -> Result<Vec<Expr>, LexicalError> {
838842
StringParser::new(source, StringKind::FString, false, TextSize::default()).parse()

ruff_python_parser/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
//! loosely based on the token definitions found in the [CPython source].
55
//!
66
//! [CPython source]: https://github.com/python/cpython/blob/dfc2e065a2e71011017077e549cd2f9bf4944c54/Include/internal/pycore_token.h;
7-
use crate::ast::MagicKind;
87
use crate::Mode;
98
use num_bigint::BigInt;
9+
use ruff_python_ast::MagicKind;
1010
use ruff_text_size::TextSize;
1111
use std::fmt;
1212

0 commit comments

Comments
 (0)