Skip to content

Commit

Permalink
Isolate parser module
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Jan 10, 2025
1 parent cbc4243 commit 91592e2
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lang/py/converter/src/module/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use genotype_lang_py_config::PYLangConfig;
use genotype_lang_py_tree::module::PYModule;
use genotype_lang_py_visitor::traverse::PYTraverse;
use genotype_parser::tree::module::GTModule;
use genotype_parser::GTModule;
use visitor::PYModuleVisitor;

use crate::{context::PYConvertContext, convert::PYConvert, resolve::PYConvertResolve};
Expand Down
74 changes: 49 additions & 25 deletions lang/rs/converter/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use genotype_lang_rs_config::RSLangConfig;
use genotype_lang_rs_tree::module::RSModule;
use genotype_parser::tree::module::GTModule;
use genotype_parser::module::GTModule;
use miette::Result;

use crate::{context::RSConvertContext, convert::RSConvert, resolve::RSConvertResolve};
Expand Down Expand Up @@ -76,12 +76,20 @@ mod tests {
imports: vec![
GTImport {
span: (0, 0).into(),
path: GTPath::new((0, 0).into(), GTPathModuleId::Resolved("module/path".into()), "./path/to/module".into()),
path: GTPath::new(
(0, 0).into(),
GTPathModuleId::Resolved("module/path".into()),
"./path/to/module".into()
),
reference: GTImportReference::Glob((0, 0).into())
},
GTImport {
span: (0, 0).into(),
path: GTPath::new((0, 0).into(), GTPathModuleId::Resolved("module/path".into()), "./path/to/module".into()),
path: GTPath::new(
(0, 0).into(),
GTPathModuleId::Resolved("module/path".into()),
"./path/to/module".into()
),
reference: GTImportReference::Names(
(0, 0).into(),
vec![
Expand Down Expand Up @@ -176,15 +184,23 @@ mod tests {
),
descriptor: GTReference {
span: (0, 0).into(),
id: GTReferenceId("module".into(), (0, 1).into()),
definition_id: GTReferenceDefinitionId::Resolved(
GTDefinitionId("module".into(), "Author".into())
id: GTReferenceId(
"module".into(),
(0, 1).into()
),
definition_id:
GTReferenceDefinitionId::Resolved(
GTDefinitionId(
"module".into(),
"Author".into()
)
),
identifier: GTIdentifier::new(
(0, 0).into(),
"Author".into()
)
}.into(),
}
.into(),
required: true,
}
]
Expand All @@ -206,31 +222,28 @@ mod tests {
},
&resolve,
&Default::default()
).unwrap(),
)
.unwrap(),
RSConvertModule(RSModule {
id: "module".into(),
doc: None,
imports: vec![
RSUse {
reference: RSUseReference::Module,
dependency: RSDependency::Local(
RSPath(
GTModuleId("module/path".into()),
"super::path::to::module".into()
)
)
dependency: RSDependency::Local(RSPath(
GTModuleId("module/path".into()),
"super::path::to::module".into()
))
},
RSUse {
reference: RSUseReference::Named(vec![
RSUseName::Name("Name".into()),
RSUseName::Alias("Name".into(), "Alias".into())
]),
dependency: RSDependency::Local(
RSPath(
GTModuleId("module/path".into()),
"super::path::to::module".into()
)
)
dependency: RSDependency::Local(RSPath(
GTModuleId("module/path".into()),
"super::path::to::module".into()
))
},
RSUse {
reference: RSUseReference::Named(vec![
Expand All @@ -244,7 +257,10 @@ mod tests {
RSDefinition::Struct(RSStruct {
id: GTDefinitionId("module".into(), "User".into()),
doc: None,
attributes: vec!["derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)".into()],
attributes: vec![
"derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)"
.into()
],
name: "User".into(),
fields: vec![
RSField {
Expand All @@ -265,7 +281,10 @@ mod tests {
RSDefinition::Struct(RSStruct {
id: GTDefinitionId("module".into(), "Order".into()),
doc: None,
attributes: vec!["derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)".into()],
attributes: vec![
"derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)"
.into()
],
name: "Order".into(),
fields: vec![RSField {
doc: None,
Expand All @@ -275,14 +294,18 @@ mod tests {
id: GTReferenceId("module".into(), (0, 0).into()),
identifier: "Book".into(),
definition_id: GTDefinitionId("module".into(), "Book".into())
}.into(),
}
.into(),
}]
.into(),
}),
RSDefinition::Struct(RSStruct {
id: GTDefinitionId("module".into(), "Book".into()),
doc: None,
attributes: vec!["derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)".into()],
attributes: vec![
"derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)"
.into()
],
name: "Book".into(),
fields: vec![
RSField {
Expand All @@ -299,7 +322,8 @@ mod tests {
id: GTReferenceId("module".into(), (0, 1).into()),
identifier: "Author".into(),
definition_id: GTDefinitionId("module".into(), "Author".into())
}.into(),
}
.into(),
}
]
.into(),
Expand Down
2 changes: 1 addition & 1 deletion lang/ts/converter/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use genotype_lang_ts_tree::module::TSModule;
use genotype_parser::tree::module::GTModule;
use genotype_parser::module::GTModule;

use crate::{context::TSConvertContext, convert::TSConvert, resolve::TSConvertResolve};

Expand Down
2 changes: 2 additions & 0 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pub mod diagnostic;
pub mod module;
pub mod parser;
pub mod tree;

pub use diagnostic::*;
pub use module::*;
pub use parser::*;
pub use tree::*;
2 changes: 1 addition & 1 deletion parser/src/tree/module/mod.rs → parser/src/module/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{alias::GTAlias, doc::GTDoc, import::GTImport, GTModuleId};
use crate::*;

mod parse;
use miette::NamedSource;
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions parser/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub mod import_reference;
pub mod inline_import;
pub mod key;
pub mod literal;
pub mod module;
pub mod module_id;
pub mod object;
pub mod object_name;
Expand Down Expand Up @@ -61,7 +60,6 @@ pub use import_reference::*;
pub use inline_import::*;
pub use key::*;
pub use literal::*;
pub use module::*;
pub use module_id::*;
pub use object::*;
pub use object_name::*;
Expand Down
2 changes: 1 addition & 1 deletion parser/src/tree/reference/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod tests {
use miette::NamedSource;
use pretty_assertions::assert_eq;

use crate::{tree::GTModule, GTIdentifier};
use crate::*;

#[test]
fn test_parse_references() {
Expand Down
2 changes: 1 addition & 1 deletion project/src/module/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use genotype_parser::tree::GTModule;
use genotype_parser::GTModule;
use genotype_visitor::traverse::GTTraverse;
use miette::Result;

Expand Down
2 changes: 1 addition & 1 deletion project/src/module/parse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fs::read_to_string;

use genotype_parser::tree::{GTModule, GTModuleParse};
use genotype_parser::{GTModule, GTModuleParse};
use miette::{NamedSource, Result};

use crate::error::GTProjectError;
Expand Down
2 changes: 1 addition & 1 deletion project/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {
use crate::{GTProjectModuleReference, GTProjectModuleResolve};

use super::*;
use genotype_parser::tree::*;
use genotype_parser::*;
use miette::NamedSource;
use pretty_assertions::assert_eq;

Expand Down
2 changes: 1 addition & 1 deletion visitor/src/traverse/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use genotype_parser::tree::module::GTModule;
use genotype_parser::module::GTModule;

use crate::visitor::GTVisitor;

Expand Down
2 changes: 1 addition & 1 deletion visitor/src/visitor/mock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use genotype_parser::tree::*;
use genotype_parser::*;

use crate::visitor::GTVisitor;

Expand Down
2 changes: 1 addition & 1 deletion visitor/src/visitor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use genotype_parser::tree::*;
use genotype_parser::*;

#[cfg(test)]
pub mod mock;
Expand Down

0 comments on commit 91592e2

Please sign in to comment.