-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract language configuration into individual toml file (#564
) * refactor: extract language configuration into individual toml file * feat: add golang language configuration (#565)
- Loading branch information
Showing
14 changed files
with
160 additions
and
146 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[[config]] | ||
languages = ["python"] | ||
line_comment = "#" | ||
top_level_keywords = ["def", "from", "class", "import"] | ||
|
||
[[config]] | ||
languages = ["rust"] | ||
line_comment = "//" | ||
top_level_keywords = [ | ||
"fn", | ||
"trait", | ||
"impl", | ||
"enum", | ||
"pub", | ||
"extern", | ||
"static", | ||
"trait", | ||
"unsafe", | ||
"use", | ||
] | ||
|
||
[[config]] | ||
languages = ["javascript", "typescript", "javascriptreact", "typescriptreact"] | ||
line_comment = "//" | ||
top_level_keywords = [ | ||
"abstract", | ||
"async", | ||
"class", | ||
"const", | ||
"export", | ||
"function", | ||
"interface", | ||
"module", | ||
"package", | ||
"type", | ||
"var", | ||
"enum", | ||
"let", | ||
] | ||
|
||
[[config]] | ||
languages = ["go"] | ||
line_comment = "//" | ||
top_level_keywords = [ | ||
"func", | ||
"interface", | ||
"struct", | ||
"package", | ||
"type", | ||
"import", | ||
"var", | ||
"const", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use lazy_static::lazy_static; | ||
use serde::Deserialize; | ||
|
||
lazy_static! { | ||
static ref DEFAULT: Vec<&'static str> = vec![ | ||
"\n\n", | ||
"\n\n ", | ||
"\n\n ", | ||
"\n\n ", | ||
"\n\n ", | ||
"\n\n ", | ||
"\n\n ", | ||
"\n\n ", | ||
"\n\n\t", | ||
"\n\n\t\t", | ||
"\n\n\t\t\t", | ||
"\n\n\t\t\t\t", | ||
"\n\n\t\t\t\t\t", | ||
"\n\n\t\t\t\t\t\t", | ||
"\n\n\t\t\t\t\t\t\t", | ||
]; | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct ConfigList { | ||
config: Vec<Language>, | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub struct Language { | ||
languages: Vec<String>, | ||
top_level_keywords: Vec<String>, | ||
|
||
pub line_comment: String, | ||
} | ||
|
||
impl Language { | ||
pub fn get_stop_words(&self) -> Vec<String> { | ||
let mut out = vec![]; | ||
out.push(format!("\n{}", self.line_comment)); | ||
for word in &self.top_level_keywords { | ||
out.push(format!("\n{}", word)); | ||
} | ||
|
||
for x in DEFAULT.iter() { | ||
out.push((*x).to_owned()); | ||
} | ||
|
||
out | ||
} | ||
|
||
pub fn get_hashkey(&self) -> String { | ||
self.languages[0].clone() | ||
} | ||
} | ||
|
||
lazy_static! { | ||
static ref CONFIG: ConfigList = | ||
serdeconv::from_toml_str(include_str!("../assets/languages.toml")).unwrap(); | ||
pub static ref UNKNOWN_LANGUAGE: Language = Language { | ||
languages: vec!["unknown".to_owned()], | ||
line_comment: "".to_owned(), | ||
top_level_keywords: vec![], | ||
}; | ||
} | ||
|
||
pub fn get_language(language: &str) -> &'static Language { | ||
CONFIG | ||
.config | ||
.iter() | ||
.find(|c| c.languages.iter().any(|x| x == language)) | ||
.unwrap_or(&UNKNOWN_LANGUAGE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod config; | ||
pub mod events; | ||
pub mod index; | ||
pub mod languages; | ||
pub mod path; | ||
pub mod usage; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.