Skip to content

Commit dbfe93c

Browse files
committed
started working on UMPL support
1 parent e21e4e7 commit dbfe93c

File tree

5 files changed

+99
-7
lines changed

5 files changed

+99
-7
lines changed

git-function-history-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ cached = {version = "0.42.0", optional = true}
3131
gitoxide-core = "0.22.0"
3232
git-repository = { version = "0.33.0", default-features = false, features = ["max-performance-safe"] }
3333
git-features = { version = "0.26.1", features = ["zlib", "once_cell"] }
34+
umpl = "1.0.2"

git-function-history-lib/src/languages/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
fmt::{self},
66
};
77
// TODO: lisp/scheme js, java?(https://github.com/tanin47/javaparser.rs) php?(https://docs.rs/tagua-parser/0.1.0/tagua_parser/)
8-
use self::{python::PythonFunction, ruby::RubyFunction, rust::RustFunction};
8+
use self::{python::PythonFunction, ruby::RubyFunction, rust::RustFunction, umpl::UMPLFunction};
99

1010
// #[cfg(feature = "c_lang")]
1111
// use self::c::CFunction;
@@ -26,6 +26,8 @@ pub enum Language {
2626
Go,
2727
/// the Ruby language
2828
Ruby,
29+
/// UMPL
30+
UMPL,
2931
/// all available languages
3032
All,
3133
}
@@ -43,6 +45,8 @@ pub enum LanguageFilter {
4345
Go(go::GoFilter),
4446
/// ruby filter
4547
Ruby(ruby::RubyFilter),
48+
/// umpl filter
49+
UMPL(umpl::UMPLFilter),
4650
}
4751

4852
impl Language {
@@ -75,10 +79,11 @@ impl Language {
7579
#[cfg(feature = "unstable")]
7680
Self::Go => "go",
7781
Self::Ruby => "ruby",
82+
Self::UMPL => "umpl",
7883
#[cfg(feature = "unstable")]
79-
Self::All => "python, rust, go, or ruby",
84+
Self::All => "python, rust, go, ruby, or umpl",
8085
#[cfg(not(feature = "unstable"))]
81-
Self::All => "python, rust, or ruby",
86+
Self::All => "python, rust, ruby, or umpl",
8287
}
8388
}
8489

@@ -92,10 +97,11 @@ impl Language {
9297
#[cfg(feature = "unstable")]
9398
Self::Go => &["go"],
9499
Self::Ruby => &["rb"],
100+
Self::UMPL => &["umpl"],
95101
#[cfg(feature = "unstable")]
96-
Self::All => &["py", "pyw", "rs", "go", "rb"],
102+
Self::All => &["py", "pyw", "rs", "go", "rb", "umpl"],
97103
#[cfg(not(feature = "unstable"))]
98-
Self::All => &["py", "pyw", "rs", "rb"],
104+
Self::All => &["py", "pyw", "rs", "rb", "umpl"],
99105
}
100106
}
101107
}
@@ -110,6 +116,7 @@ impl fmt::Display for Language {
110116
#[cfg(feature = "unstable")]
111117
Self::Go => write!(f, "go"),
112118
Self::Ruby => write!(f, "ruby"),
119+
Self::UMPL => write!(f, "umpl"),
113120
Self::All => write!(f, "all"),
114121
}
115122
}
@@ -123,6 +130,7 @@ pub mod go;
123130
pub mod python;
124131
pub mod ruby;
125132
pub mod rust;
133+
pub mod umpl;
126134

127135
/// trait that all languages functions must implement
128136
pub trait FunctionTrait: fmt::Debug + fmt::Display {
@@ -324,6 +332,7 @@ make_file!(RustFile, RustFunction, Rust);
324332
#[cfg(feature = "unstable")]
325333
make_file!(GoFile, GoFunction, Go);
326334
make_file!(RubyFile, RubyFunction, Ruby);
335+
make_file!(UMPLFile, UMPLFunction, UMPL);
327336

328337
#[cfg(test)]
329338
mod lang_tests {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use umpl;
2+
3+
use std::{error::Error, fmt};
4+
5+
use crate::impl_function_trait;
6+
7+
use super::FunctionTrait;
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
pub struct UMPLFunction {
10+
pub (crate) lines: (usize, usize),
11+
pub (crate) name: String,
12+
pub (crate) body: String,
13+
}
14+
15+
impl fmt::Display for UMPLFunction {
16+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17+
todo!()
18+
}
19+
}
20+
21+
impl FunctionTrait for UMPLFunction {
22+
impl_function_trait!(UMPLFunction);
23+
24+
fn get_total_lines(&self) -> (usize, usize) {
25+
todo!()
26+
}
27+
28+
fn get_tops(&self) -> Vec<(String, usize)> {
29+
todo!()
30+
}
31+
32+
fn get_bottoms(&self) -> Vec<(String, usize)> {
33+
todo!()
34+
}
35+
}
36+
37+
pub(crate) fn find_function_in_file(
38+
file_contents: &str,
39+
name: &str,
40+
) -> Result<Vec<UMPLFunction>, Box<dyn Error>> {
41+
// parse the file contents
42+
let lexed = umpl::lexer::Lexer::new(file_contents.to_string());
43+
let tokens = lexed.scan_tokens();
44+
let mut parsed = umpl::parser::Parser::new(tokens);
45+
let ast = parsed.parse();
46+
for node in ast {
47+
48+
}
49+
Err("")?
50+
}
51+
52+
#[derive(Debug, Clone, PartialEq, Eq)]
53+
pub enum UMPLFilter {
54+
55+
56+
}
57+
58+
impl UMPLFilter {
59+
pub fn matches(&self, function: &UMPLFunction) -> bool {
60+
false
61+
}
62+
}

git-function-history-lib/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ macro_rules! get_item_from_oid_option {
3838
#[cfg(feature = "cache")]
3939
use cached::proc_macro::cached;
4040
use chrono::{DateTime, NaiveDateTime, Utc};
41-
use languages::{rust, LanguageFilter, PythonFile, RubyFile, RustFile};
41+
use languages::{rust, LanguageFilter, PythonFile, RubyFile, RustFile, UMPLFile};
4242
#[cfg(feature = "parallel")]
4343
use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
4444

@@ -381,6 +381,11 @@ fn traverse_tree(
381381
continue;
382382
}
383383
}
384+
Language::UMPL=> {
385+
if !ends_with_cmp_no_case(&file, "ump") {
386+
continue;
387+
}
388+
}
384389
Language::All => {
385390
cfg_if::cfg_if! {
386391
// if #[cfg(feature = "c_lang")] {
@@ -550,6 +555,10 @@ fn find_function_in_file_with_commit(
550555
let functions = languages::ruby::find_function_in_file(fc, name)?;
551556
FileType::Ruby(RubyFile::new(file_path.to_string(), functions))
552557
}
558+
Language::UMPL => {
559+
let functions = languages::umpl::find_function_in_file(fc, name)?;
560+
FileType::UMPL(UMPLFile::new(file_path.to_string(), functions))
561+
}
553562
Language::All => match file_path.split('.').last() {
554563
Some("rs") => {
555564
let functions = rust::find_function_in_file(fc, name)?;

git-function-history-lib/src/types.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
};
99

1010
use crate::{
11-
languages::{FileTrait, FunctionTrait, PythonFile, RubyFile, RustFile},
11+
languages::{FileTrait, FunctionTrait, PythonFile, RubyFile, RustFile, UMPLFile},
1212
Filter,
1313
};
1414

@@ -27,6 +27,7 @@ pub enum FileType {
2727
#[cfg(feature = "unstable")]
2828
Go(GoFile),
2929
Ruby(RubyFile),
30+
UMPL(UMPLFile),
3031
}
3132

3233
impl FileTrait for FileType {
@@ -39,6 +40,7 @@ impl FileTrait for FileType {
3940
#[cfg(feature = "unstable")]
4041
Self::Go(file) => file.get_file_name(),
4142
Self::Ruby(file) => file.get_file_name(),
43+
Self::UMPL(file) => file.get_file_name(),
4244
}
4345
}
4446
fn get_functions(&self) -> Vec<Box<dyn FunctionTrait>> {
@@ -50,6 +52,7 @@ impl FileTrait for FileType {
5052
#[cfg(feature = "unstable")]
5153
Self::Go(file) => file.get_functions(),
5254
Self::Ruby(file) => file.get_functions(),
55+
Self::UMPL(file) => file.get_functions(),
5356
}
5457
}
5558

@@ -63,6 +66,7 @@ impl FileTrait for FileType {
6366
let filtered = file.filter_by(filter)?;
6467
Ok(Self::Python(filtered))
6568
}
69+
6670
// #[cfg(feature = "c_lang")]
6771
// Self::C(file) => {
6872
// let filtered = file.filter_by(filter)?;
@@ -77,6 +81,10 @@ impl FileTrait for FileType {
7781
let filtered = file.filter_by(filter)?;
7882
Ok(Self::Ruby(filtered))
7983
}
84+
Self::UMPL(file) => {
85+
let filtered = file.filter_by(filter)?;
86+
Ok(Self::UMPL(filtered))
87+
}
8088
}
8189
}
8290

@@ -89,6 +97,7 @@ impl FileTrait for FileType {
8997
#[cfg(feature = "unstable")]
9098
Self::Go(file) => file.get_current(),
9199
Self::Ruby(file) => file.get_current(),
100+
Self::UMPL(file) => file.get_current(),
92101
}
93102
}
94103

@@ -101,6 +110,7 @@ impl FileTrait for FileType {
101110
#[cfg(feature = "unstable")]
102111
Self::Go(file) => file.get_language(),
103112
Self::Ruby(file) => file.get_language(),
113+
Self::UMPL(file) => file.get_language(),
104114
}
105115
}
106116
}
@@ -115,6 +125,7 @@ impl fmt::Display for FileType {
115125
#[cfg(feature = "unstable")]
116126
Self::Go(file) => write!(f, "{file}"),
117127
Self::Ruby(file) => write!(f, "{file}"),
128+
Self::UMPL(file) => write!(f, "{file}"),
118129
}
119130
}
120131
}

0 commit comments

Comments
 (0)