Trait grit_util::Language

source ·
pub trait Language: Sized {
    type Node<'a>: AstNode;

Show 24 methods // Required methods fn language_name(&self) -> &'static str; fn snippet_context_strings(&self) -> &[(&'static str, &'static str)]; fn is_comment(&self, node: &Self::Node<'_>) -> bool; fn is_metavariable(&self, node: &Self::Node<'_>) -> bool; // Provided methods fn alternate_metavariable_kinds(&self) -> &[&'static str] { ... } fn metavariable_prefix(&self) -> &'static str { ... } fn comment_prefix(&self) -> &'static str { ... } fn metavariable_prefix_substitute(&self) -> &'static str { ... } fn metavariable_regex(&self) -> &'static Regex { ... } fn replaced_metavariable_regex(&self) -> &'static Regex { ... } fn metavariable_bracket_regex(&self) -> &'static Regex { ... } fn exact_variable_regex(&self) -> &'static Regex { ... } fn exact_replaced_variable_regex(&self) -> &'static Regex { ... } fn is_statement(&self, node: &Self::Node<'_>) -> bool { ... } fn comment_text_range(&self, node: &Self::Node<'_>) -> Option<ByteRange> { ... } fn should_skip_padding(&self, node: &Self::Node<'_>) -> bool { ... } fn get_skip_padding_ranges_for_snippet( &self, snippet: &str ) -> Vec<CodeRange> { ... } fn get_skip_padding_ranges(&self, node: &Self::Node<'_>) -> Vec<CodeRange> { ... } fn substitute_metavariable_prefix(&self, src: &str) -> String { ... } fn snippet_metavariable_to_grit_metavariable( &self, src: &str ) -> Option<GritMetaValue> { ... } fn check_replacements( &self, node: Self::Node<'_>, replacements: &mut Vec<Replacement> ) { ... } fn take_padding(&self, current: char, next: Option<char>) -> Option<char> { ... } fn should_pad_snippet(&self) -> bool { ... } fn make_single_line_comment(&self, text: &str) -> String { ... }
}

Required Associated Types§

Required Methods§

source

fn language_name(&self) -> &'static str

source

fn snippet_context_strings(&self) -> &[(&'static str, &'static str)]

source

fn is_comment(&self, node: &Self::Node<'_>) -> bool

source

fn is_metavariable(&self, node: &Self::Node<'_>) -> bool

Provided Methods§

source

fn alternate_metavariable_kinds(&self) -> &[&'static str]

source

fn metavariable_prefix(&self) -> &'static str

source

fn comment_prefix(&self) -> &'static str

source

fn metavariable_prefix_substitute(&self) -> &'static str

source

fn metavariable_regex(&self) -> &'static Regex

source

fn replaced_metavariable_regex(&self) -> &'static Regex

source

fn metavariable_bracket_regex(&self) -> &'static Regex

source

fn exact_variable_regex(&self) -> &'static Regex

source

fn exact_replaced_variable_regex(&self) -> &'static Regex

source

fn is_statement(&self, node: &Self::Node<'_>) -> bool

source

fn comment_text_range(&self, node: &Self::Node<'_>) -> Option<ByteRange>

source

fn should_skip_padding(&self, node: &Self::Node<'_>) -> bool

source

fn get_skip_padding_ranges_for_snippet(&self, snippet: &str) -> Vec<CodeRange>

source

fn get_skip_padding_ranges(&self, node: &Self::Node<'_>) -> Vec<CodeRange>

source

fn substitute_metavariable_prefix(&self, src: &str) -> String

source

fn snippet_metavariable_to_grit_metavariable( &self, src: &str ) -> Option<GritMetaValue>

source

fn check_replacements( &self, node: Self::Node<'_>, replacements: &mut Vec<Replacement> )

Check for nodes that should be removed or replaced.

This is used to “repair” the program after rewriting, such as by deleting orphaned ranges (like a variable declaration without any variables). If the node should be removed, it adds a range with a None value. If the node should be replaced, it adds a range with the replacement value.

source

fn take_padding(&self, current: char, next: Option<char>) -> Option<char>

source

fn should_pad_snippet(&self) -> bool

Whether snippets should be padded.

This is generally true for languages with relevant whitespace.

source

fn make_single_line_comment(&self, text: &str) -> String

Object Safety§

This trait is not object safe.

Implementors§