Prepare for moving the parser into the Ruff monorepo (#40)

This commit is contained in:
Micha Reiser
2023-07-26 12:28:43 +02:00
committed by GitHub
parent 593b46be5e
commit ff7bab589e
154 changed files with 2399 additions and 3803 deletions

View File

@@ -0,0 +1,15 @@
[package]
name = "ruff_python_ast"
version = "0.2.0"
description = "AST definitions for Ruff"
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
edition = "2021"
repository = "https://github.com/astral-sh/ruff"
license = "MIT"
[dependencies]
ruff_text_size = { workspace = true }
is-macro = { workspace = true }
num-bigint = { workspace = true }
static_assertions = { workspace = true }

View File

@@ -0,0 +1,48 @@
//! Python AST node definitions and utilities.
//!
//! AST nodes are very similary defined like [Python AST](https://docs.python.org/3/library/ast.html).
//! But a few exceptions exist due to ruff_python_parser optimization.
//! They can be transformed to matching Python-styled AST in reasonable cost.
//!
//! [PythonArguments] is replaced by [Arguments]. The new [Arguments] type representation uses a new type
//! [ArgWithDefault] to represent arguments with default values. See each type documentation for more details.
//!
//! A few top-level sum types are renamed to human friendly names.
//! [CmpOp] refers `cmpop`
//! [UnaryOp] refers `unaryop`
//! [BoolOp] refers `boolop`
//! [WithItem] refers `withitem`
//! [ExceptHandler] refers `excepthandler`
//!
mod nodes;
pub use nodes::*;
use ruff_text_size::{TextRange, TextSize};
pub trait Ranged {
fn range(&self) -> TextRange;
fn start(&self) -> TextSize {
self.range().start()
}
fn end(&self) -> TextSize {
self.range().end()
}
}
impl Ranged for TextRange {
fn range(&self) -> TextRange {
*self
}
}
impl<T> Ranged for &T
where
T: Ranged,
{
fn range(&self) -> TextRange {
T::range(self)
}
}

3036
ruff_python_ast/src/nodes.rs Normal file

File diff suppressed because it is too large Load Diff