Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code type mappings #17

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ fn unicode_notation_to_char(unicode_notation: &str) -> Result<char, InvalidChara
parse(unicode_notation).ok_or_else(|| InvalidCharacterType(unicode_notation.to_owned()))
}

/// All types of code that can have special rules about what is allowed or denied.
///
/// All source code not falling into one of these categories will be evaluated
/// by the `default` rules directly.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum CodeType {
/// Code comments. This includes all types of comments. This includes line comments,
/// block comments, etc. Depending on the language.
Comment,

/// String and character literals. Such as "hello", 'c' and similar, depending on
/// the language.
StringLiteral,
Identifiers,
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, serde::Deserialize)]
Expand All @@ -76,31 +84,37 @@ pub enum Language {

static GO_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"comment" => CodeType::Comment,

"interpreted_string_literal" => CodeType::StringLiteral,
"raw_string_literal" => CodeType::StringLiteral,
};

static JAVASCRIPT_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"comment" => CodeType::Comment,
"block_comment" => CodeType::Comment,

"string_fragment" => CodeType::StringLiteral,
};

static PYTHON_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"string_content" => CodeType::StringLiteral,
"comment" => CodeType::Comment,

"string_content" => CodeType::StringLiteral,
};

static RUST_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"doc_comment" => CodeType::Comment,
"line_comment" => CodeType::Comment,
"block_comment" => CodeType::Comment,

"string_content" => CodeType::StringLiteral,
"char_literal" => CodeType::StringLiteral,
};

static SWIFT_CODE_TYPES: phf::Map<&'static str, CodeType> = phf::phf_map! {
"comment" => CodeType::Comment,
"multiline_comment" => CodeType::Comment,

"line_str_text" => CodeType::StringLiteral,
"multi_line_str_text" => CodeType::StringLiteral,
};
Expand Down
Loading