Skip to content

Commit

Permalink
Merge branch 'improve-code-type-mappings'
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Sep 27, 2024
2 parents a5b7d6d + cad8083 commit 2756090
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit 2756090

Please sign in to comment.