mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-30 15:18:02 +00:00
New Arguments and Arg/ArgWithDefault AST representation (#59)
This commit is contained in:
parent
3fbf4f6804
commit
fdec727f80
51 changed files with 22648 additions and 21711 deletions
|
@ -808,7 +808,7 @@ impl<R> PyNode for ast::ExcepthandlerExceptHandler<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> PyNode for ast::Arguments<R> {
|
||||
impl<R> PyNode for ast::PythonArguments<R> {
|
||||
#[inline]
|
||||
fn py_type_cache() -> &'static OnceCell<(Py<PyAny>, Py<PyAny>)> {
|
||||
static PY_TYPE: OnceCell<(Py<PyAny>, Py<PyAny>)> = OnceCell::new();
|
||||
|
@ -2288,7 +2288,7 @@ impl ToPyAst for ast::ExcepthandlerExceptHandler<TextRange> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyAst for ast::Arguments<TextRange> {
|
||||
impl ToPyAst for ast::PythonArguments<TextRange> {
|
||||
#[inline]
|
||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
||||
let cache = Self::py_type_cache().get().unwrap();
|
||||
|
@ -4312,7 +4312,7 @@ impl ToPyAst for ast::ExcepthandlerExceptHandler<SourceRange> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyAst for ast::Arguments<SourceRange> {
|
||||
impl ToPyAst for ast::PythonArguments<SourceRange> {
|
||||
#[inline]
|
||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
||||
let cache = Self::py_type_cache().get().unwrap();
|
||||
|
@ -4820,7 +4820,7 @@ fn init_types(py: Python) -> PyResult<()> {
|
|||
cache_py_type::<ast::Comprehension>(ast_module)?;
|
||||
cache_py_type::<ast::Excepthandler>(ast_module)?;
|
||||
cache_py_type::<ast::ExcepthandlerExceptHandler>(ast_module)?;
|
||||
cache_py_type::<ast::Arguments>(ast_module)?;
|
||||
cache_py_type::<ast::PythonArguments>(ast_module)?;
|
||||
cache_py_type::<ast::Arg>(ast_module)?;
|
||||
cache_py_type::<ast::Keyword>(ast_module)?;
|
||||
cache_py_type::<ast::Alias>(ast_module)?;
|
||||
|
|
|
@ -3289,10 +3289,10 @@ impl ExcepthandlerExceptHandler {
|
|||
|
||||
#[pyclass(module="rustpython_ast.located", name="_arguments", extends=super::Ast, frozen)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Arguments(pub &'static ast::Arguments<SourceRange>);
|
||||
pub struct Arguments(pub &'static ast::PythonArguments<SourceRange>);
|
||||
|
||||
impl From<&'static ast::Arguments<SourceRange>> for Arguments {
|
||||
fn from(node: &'static ast::Arguments<SourceRange>) -> Self {
|
||||
impl From<&'static ast::PythonArguments<SourceRange>> for Arguments {
|
||||
fn from(node: &'static ast::PythonArguments<SourceRange>) -> Self {
|
||||
Arguments(node)
|
||||
}
|
||||
}
|
||||
|
@ -3304,7 +3304,7 @@ impl ToPyObject for Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyWrapper for ast::Arguments<SourceRange> {
|
||||
impl ToPyWrapper for ast::PythonArguments<SourceRange> {
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
|
||||
Ok(Arguments(self).to_object(py))
|
||||
|
@ -4392,7 +4392,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
|
|||
super::init_type::<Comprehension, ast::Comprehension>(py, m)?;
|
||||
super::init_type::<Excepthandler, ast::Excepthandler>(py, m)?;
|
||||
super::init_type::<ExcepthandlerExceptHandler, ast::ExcepthandlerExceptHandler>(py, m)?;
|
||||
super::init_type::<Arguments, ast::Arguments>(py, m)?;
|
||||
super::init_type::<Arguments, ast::PythonArguments>(py, m)?;
|
||||
super::init_type::<Arg, ast::Arg>(py, m)?;
|
||||
super::init_type::<Keyword, ast::Keyword>(py, m)?;
|
||||
super::init_type::<Alias, ast::Alias>(py, m)?;
|
||||
|
|
|
@ -3289,10 +3289,10 @@ impl ExcepthandlerExceptHandler {
|
|||
|
||||
#[pyclass(module="rustpython_ast.ranged", name="_arguments", extends=super::Ast, frozen)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Arguments(pub &'static ast::Arguments<TextRange>);
|
||||
pub struct Arguments(pub &'static ast::PythonArguments<TextRange>);
|
||||
|
||||
impl From<&'static ast::Arguments<TextRange>> for Arguments {
|
||||
fn from(node: &'static ast::Arguments<TextRange>) -> Self {
|
||||
impl From<&'static ast::PythonArguments<TextRange>> for Arguments {
|
||||
fn from(node: &'static ast::PythonArguments<TextRange>) -> Self {
|
||||
Arguments(node)
|
||||
}
|
||||
}
|
||||
|
@ -3304,7 +3304,7 @@ impl ToPyObject for Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToPyWrapper for ast::Arguments<TextRange> {
|
||||
impl ToPyWrapper for ast::PythonArguments<TextRange> {
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, py: Python) -> PyResult<Py<PyAny>> {
|
||||
Ok(Arguments(self).to_object(py))
|
||||
|
@ -4096,7 +4096,7 @@ pub fn add_to_module(py: Python, m: &PyModule) -> PyResult<()> {
|
|||
super::init_type::<Comprehension, ast::Comprehension>(py, m)?;
|
||||
super::init_type::<Excepthandler, ast::Excepthandler>(py, m)?;
|
||||
super::init_type::<ExcepthandlerExceptHandler, ast::ExcepthandlerExceptHandler>(py, m)?;
|
||||
super::init_type::<Arguments, ast::Arguments>(py, m)?;
|
||||
super::init_type::<Arguments, ast::PythonArguments>(py, m)?;
|
||||
super::init_type::<Arg, ast::Arg>(py, m)?;
|
||||
super::init_type::<Keyword, ast::Keyword>(py, m)?;
|
||||
super::init_type::<Alias, ast::Alias>(py, m)?;
|
||||
|
|
|
@ -78,6 +78,18 @@ impl ToPyAst for ConversionFlag {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> ToPyAst for ast::Arguments<R>
|
||||
where
|
||||
R: Clone,
|
||||
ast::PythonArguments<R>: ToPyAst,
|
||||
{
|
||||
#[inline]
|
||||
fn to_py_ast<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
|
||||
let arguments = self.to_python_arguments();
|
||||
arguments.to_py_ast(py)
|
||||
}
|
||||
}
|
||||
|
||||
fn constant_to_object(constant: &ast::Constant, py: Python) -> PyObject {
|
||||
let cache = ast_cache();
|
||||
match constant {
|
||||
|
|
|
@ -93,6 +93,18 @@ impl<T: ToPyWrapper> ToPyWrapper for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R> ToPyWrapper for ast::Arguments<R>
|
||||
where
|
||||
Self: Clone,
|
||||
ast::PythonArguments<R>: ToPyWrapper,
|
||||
{
|
||||
#[inline]
|
||||
fn to_py_wrapper(&'static self, _py: Python) -> PyResult<Py<PyAny>> {
|
||||
todo!()
|
||||
// Ok(FunctionArguments(self).to_object(py))
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(module = "rustpython_ast", name = "AST", subclass)]
|
||||
pub struct Ast;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue