Skip to content

Commit

Permalink
Adding naming convention as methods for Identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
notdanilo committed Nov 4, 2023
1 parent 8f54d44 commit 49907ef
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 382 deletions.
3 changes: 1 addition & 2 deletions ecosystem/python/parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl Parser<&std::path::Path> for PythonParser {
type Output = Library;
fn parse(&self, input: &std::path::Path) -> Result<Self::Output> {
let name = self.identifier_parser.parse(input)?;
let name = name.name.as_str().try_into()?;
let root_module = self.parse(SubPath(input))?;
Ok(Library { name, root_module })
Ok(Library { identifier: name, root_module })
}
}
8 changes: 3 additions & 5 deletions ecosystem/rust/cargo/src/build_system.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::path::{PathBuf, Path};
use ligen_ir::{prelude::*, Library};
use ligen_traits::build::{BuildSystem, BuildProfile};
use ligen_ir::conventions::naming::SnakeCase;

/// Cargo builder.
#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -48,13 +47,12 @@ impl BuildSystem for CargoBuilder {
build_command = build_command.arg("--release");
}

let library_name = SnakeCase::try_from(library.name.clone())?.to_string();
let ligen_path = Self::target_dir()
.unwrap()
.join("ligen");
let library_path = ligen_path
.join("rust")
.join(&library_name);
.join(&library.identifier.name);
let manifest_path = library_path.join("Cargo.toml");
let target_dir = library_path.join("target");

Expand All @@ -73,11 +71,11 @@ impl BuildSystem for CargoBuilder {
.filter_map(|entry| entry.ok());
let libraries_dir = ligen_path
.join("libraries")
.join(&library_name);
.join(&library.identifier.name);
std::fs::create_dir_all(&libraries_dir)?;
for entry in directory {
if let Some(file_name) = entry.file_name().to_str() {
if entry.file_type()?.is_file() && file_name.contains(&library_name) {
if entry.file_type()?.is_file() && file_name.contains(&library.identifier.name) {
std::fs::copy(&entry.path(), libraries_dir.join(file_name))?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/rust/cargo/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl FileGenerator for CargoGenerator {
fn generate_files(&self, library: &Library, file_set: &mut FileSet) -> Result<()> {
let file = file_set.entry(&PathBuf::from_str("Cargo.toml").unwrap());
let version = "0.1.0";
let name = &library.name;
let name = &library.identifier;
// FIXME: This is a placeholder and it will fail.
let path = PathBuf::default();
let path = path.display().to_string().replace('\\', "/");
Expand Down
8 changes: 4 additions & 4 deletions ecosystem/rust/cargo/src/parser/library.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ligen_ir::conventions::naming::{SnakeCase, NamingConvention};
use ligen_ir::Identifier;
use ligen_ir::prelude::*;
use ligen_ir::Library;
use ligen_parsing::parser::Parser;
Expand All @@ -22,9 +22,9 @@ impl Parser<&std::path::Path> for LibraryParser {
let library = cargo_toml.lib.ok_or_else(|| Error::Message("Library not found in Cargo.toml.".into()))?;
let library_path = directory.join(library.path.unwrap_or("src/lib.rs".into()));

let name = NamingConvention::try_from(package.name.as_str())?;
let identifier = Identifier::from(package.name.as_str());
let mut root_module = ModuleParser.parse(library_path.as_path())?;
root_module.identifier = SnakeCase::try_from(name.clone())?.to_string().into();
Ok(Self::Output { name, root_module })
root_module.identifier = identifier.clone();
Ok(Self::Output { identifier, root_module })
}
}
3 changes: 0 additions & 3 deletions ligen/ir/src/conventions/mod.rs

This file was deleted.

58 changes: 0 additions & 58 deletions ligen/ir/src/conventions/naming/camel_case.rs

This file was deleted.

48 changes: 0 additions & 48 deletions ligen/ir/src/conventions/naming/kebab_case.rs

This file was deleted.

103 changes: 0 additions & 103 deletions ligen/ir/src/conventions/naming/mod.rs

This file was deleted.

77 changes: 0 additions & 77 deletions ligen/ir/src/conventions/naming/pascal_case.rs

This file was deleted.

Loading

0 comments on commit 49907ef

Please sign in to comment.