From a4d7c193f8aadc5114730edef239eec72516312a Mon Sep 17 00:00:00 2001 From: Danilo Guanabara Date: Sun, 29 Oct 2023 23:26:09 -0300 Subject: [PATCH] Making sure full_parser is parsing only valid full IR --- ecosystem/python/parser/src/identifier.rs | 10 ++++++++- .../python/parser/src/object/full_parser.rs | 22 ++++++------------- .../python/parser/src/object/symbol_parser.rs | 16 ++------------ .../src/types/type_definition/full_parser.rs | 8 +++++-- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/ecosystem/python/parser/src/identifier.rs b/ecosystem/python/parser/src/identifier.rs index 69daa4e0..77199114 100644 --- a/ecosystem/python/parser/src/identifier.rs +++ b/ecosystem/python/parser/src/identifier.rs @@ -1,4 +1,4 @@ -use ligen::ir::Identifier; +use ligen::ir::{Identifier, Mutability}; use ligen::parsing::parser::Parser; use ligen::parsing::parser::universal::identifier::IdentifierParser as InternalParser; use crate::prelude::*; @@ -24,4 +24,12 @@ impl IdentifierParser { pub fn is_private(&self, identifier: &Identifier) -> bool { identifier.name.starts_with('_') && !identifier.name.starts_with("__") } + + pub fn get_mutability(&self, identifier: &Identifier) -> Mutability { + if identifier.name.to_uppercase() == identifier.name { + Mutability::Constant + } else { + Mutability::Mutable + } + } } \ No newline at end of file diff --git a/ecosystem/python/parser/src/object/full_parser.rs b/ecosystem/python/parser/src/object/full_parser.rs index 532e13d0..9d9696f7 100644 --- a/ecosystem/python/parser/src/object/full_parser.rs +++ b/ecosystem/python/parser/src/object/full_parser.rs @@ -1,7 +1,5 @@ -// FIXME: Duplicated from symbol_parser. - use rustpython_parser::ast::{Expr, StmtAnnAssign, StmtAssign, StmtAugAssign}; -use ligen::ir::{Object, Identifier, Mutability}; +use ligen::ir::Object; use crate::identifier::IdentifierParser; use crate::prelude::*; @@ -34,9 +32,12 @@ impl Parser<&Expr> for FullParser { .ok_or(Error::Message("Expected identifier".into()))? .id .as_str(); - let identifier = IdentifierParser::new().parse(identifier)?; - let mutability = self.get_mutability(&identifier); - Ok(Object { identifier, mutability, ..Default::default() }) + let identifier_parser = IdentifierParser::new(); + let identifier = identifier_parser.parse(identifier)?; + let mutability = identifier_parser.get_mutability(&identifier); + let literal = Err(Error::Message("Not implemented".into()))?; + let type_ = Err(Error::Message("Not implemented".into()))?; + Ok(Object { identifier, mutability, literal, type_ }) } } @@ -53,12 +54,3 @@ impl Parser<&StmtAssign> for FullParser { } } -impl FullParser { - fn get_mutability(&self, identifier: &Identifier) -> Mutability { - if identifier.name.to_uppercase() == identifier.name { - Mutability::Constant - } else { - Mutability::Mutable - } - } -} \ No newline at end of file diff --git a/ecosystem/python/parser/src/object/symbol_parser.rs b/ecosystem/python/parser/src/object/symbol_parser.rs index 4b50358f..befa6189 100644 --- a/ecosystem/python/parser/src/object/symbol_parser.rs +++ b/ecosystem/python/parser/src/object/symbol_parser.rs @@ -1,6 +1,5 @@ -use ligen::ir::Mutability; use rustpython_parser::ast::{Expr, StmtAnnAssign, StmtAssign, StmtAugAssign}; -use ligen::ir::{Object, Identifier}; +use ligen::ir::Object; use crate::identifier::IdentifierParser; use crate::prelude::*; @@ -34,8 +33,7 @@ impl Parser<&Expr> for SymbolParser { .id .as_str(); let identifier = IdentifierParser::new().parse(identifier)?; - let mutability = self.get_mutability(&identifier); - Ok(Object { identifier, mutability, ..Default::default() }) + Ok(Object { identifier, ..Default::default() }) } } @@ -51,13 +49,3 @@ impl Parser<&StmtAssign> for SymbolParser { Ok(objects) } } - -impl SymbolParser { - fn get_mutability(&self, identifier: &Identifier) -> Mutability { - if identifier.name.to_uppercase() == identifier.name { - Mutability::Constant - } else { - Mutability::Mutable - } - } -} \ No newline at end of file diff --git a/ecosystem/python/parser/src/types/type_definition/full_parser.rs b/ecosystem/python/parser/src/types/type_definition/full_parser.rs index aee4f113..4ad2ecbe 100644 --- a/ecosystem/python/parser/src/types/type_definition/full_parser.rs +++ b/ecosystem/python/parser/src/types/type_definition/full_parser.rs @@ -1,5 +1,5 @@ use crate::{prelude::*, identifier::IdentifierParser}; -use ligen::ir::TypeDefinition; +use ligen::ir::{TypeDefinition, Visibility}; use rustpython_parser::ast::StmtClassDef; use super::DynamicParser; @@ -12,7 +12,11 @@ impl<'a> DynamicParser<'a> for FullParser {} impl Parser> for FullParser { type Output = TypeDefinition; fn parse(&self, input: WithSource) -> Result { + let attributes = Err(Error::Message("Not implemented".into()))?; let identifier = IdentifierParser::new().parse(input.ast.name.as_str())?; - Ok(TypeDefinition { identifier, ..Default::default() }) + let visibility = Visibility::Public; + let definition = Err(Error::Message("Not implemented".into()))?; + let interfaces = Err(Error::Message("Not implemented".into()))?; + Ok(TypeDefinition { attributes, visibility, identifier, definition, interfaces }) } } \ No newline at end of file