mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-27 22:04:50 +00:00
rustpython_ast python package (#79)
This commit is contained in:
parent
edcfcb4a74
commit
5270020423
5 changed files with 13 additions and 4 deletions
|
@ -33,7 +33,7 @@ log = "0.4.16"
|
||||||
num-complex = "0.4.0"
|
num-complex = "0.4.0"
|
||||||
num-bigint = "0.4.3"
|
num-bigint = "0.4.3"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
pyo3 = { version = "0.18.3" }
|
pyo3 = { version = "0.19.0" }
|
||||||
malachite-bigint = { version = "0.1.0" }
|
malachite-bigint = { version = "0.1.0" }
|
||||||
memchr = "2.5.0"
|
memchr = "2.5.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rustpython-ast-pyo3"
|
name = "rustpython-ast-pyo3"
|
||||||
version = "0.1.0"
|
version = "0.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
# abi3 = ["pyo3/abi3-py37"] # will be supported from next pyo3 version
|
||||||
# This feature is experimental
|
# This feature is experimental
|
||||||
# It reimplements AST types, but currently both slower than python AST types and limited to use in other API
|
# It reimplements AST types, but currently both slower than python AST types and limited to use in other API
|
||||||
wrapper = []
|
wrapper = []
|
||||||
|
@ -16,6 +17,7 @@ crate-type = ["cdylib"]
|
||||||
rustpython-ast = { workspace = true, features = ["location"] }
|
rustpython-ast = { workspace = true, features = ["location"] }
|
||||||
rustpython-parser = { workspace = true, features = ["num-bigint"] }
|
rustpython-parser = { workspace = true, features = ["num-bigint"] }
|
||||||
num-complex = { workspace = true }
|
num-complex = { workspace = true }
|
||||||
|
num-traits = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
once_cell = { workspace = true }
|
||||||
|
|
||||||
pyo3 = { workspace = true, features = ["num-bigint", "num-complex"] }
|
pyo3 = { workspace = true, features = ["num-bigint", "num-complex"] }
|
||||||
|
|
|
@ -10,6 +10,6 @@ classifiers = [
|
||||||
"Programming Language :: Python :: Implementation :: CPython",
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
[tool.maturin]
|
[tool.maturin]
|
||||||
|
# module-name = "_rustpython_ast"
|
||||||
features = ["pyo3/extension-module"]
|
features = ["pyo3/extension-module"]
|
||||||
|
|
3
ast-pyo3/rustpython_ast/__init__.py
Normal file
3
ast-pyo3/rustpython_ast/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from rustpython_ast.rustpython_ast import parse
|
||||||
|
|
||||||
|
__all__ = ["parse"]
|
|
@ -1,4 +1,5 @@
|
||||||
use num_complex::Complex64;
|
use num_complex::Complex64;
|
||||||
|
use num_traits::cast::ToPrimitive;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use pyo3::{
|
use pyo3::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
@ -97,7 +98,10 @@ fn constant_to_object(constant: &ast::Constant, py: Python) -> PyObject {
|
||||||
ast::Constant::Bool(bool) => cache.bool(py, *bool).into(),
|
ast::Constant::Bool(bool) => cache.bool(py, *bool).into(),
|
||||||
ast::Constant::Str(string) => string.to_object(py),
|
ast::Constant::Str(string) => string.to_object(py),
|
||||||
ast::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(),
|
ast::Constant::Bytes(bytes) => PyBytes::new(py, bytes).into(),
|
||||||
ast::Constant::Int(int) => int.to_object(py),
|
ast::Constant::Int(int) => match int.to_i64() {
|
||||||
|
Some(small_int) => small_int.to_object(py),
|
||||||
|
None => int.to_object(py),
|
||||||
|
},
|
||||||
ast::Constant::Tuple(elts) => {
|
ast::Constant::Tuple(elts) => {
|
||||||
let elts: Vec<_> = elts.iter().map(|c| constant_to_object(c, py)).collect();
|
let elts: Vec<_> = elts.iter().map(|c| constant_to_object(c, py)).collect();
|
||||||
PyTuple::new(py, elts).into()
|
PyTuple::new(py, elts).into()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue