pub trait Language: Sized {
type Node<'a>: AstNode;
Show 23 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;
fn align_padding<'a>(
&self,
node: &Self::Node<'a>,
range: &CodeRange,
skip_ranges: &[CodeRange],
new_padding: Option<usize>,
offset: usize,
substitutions: &mut [(EffectRange, String)],
) -> Cow<'a, str>;
fn pad_snippet<'a>(&self, snippet: &'a str, padding: &str) -> Cow<'a, str>;
fn get_skip_padding_ranges(&self, node: &Self::Node<'_>) -> Vec<CodeRange>;
// Provided methods
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 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§
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
Sourcefn align_padding<'a>(
&self,
node: &Self::Node<'a>,
range: &CodeRange,
skip_ranges: &[CodeRange],
new_padding: Option<usize>,
offset: usize,
substitutions: &mut [(EffectRange, String)],
) -> Cow<'a, str>
fn align_padding<'a>( &self, node: &Self::Node<'a>, range: &CodeRange, skip_ranges: &[CodeRange], new_padding: Option<usize>, offset: usize, substitutions: &mut [(EffectRange, String)], ) -> Cow<'a, str>
Removes the padding from every line in the snippet identified by the
given range, such that the first line of the snippet is left-aligned.
Sourcefn pad_snippet<'a>(&self, snippet: &'a str, padding: &str) -> Cow<'a, str>
fn pad_snippet<'a>(&self, snippet: &'a str, padding: &str) -> Cow<'a, str>
Pads snippet by applying the given padding to every line.
Takes padding rules for whitespace-significant languages into account.
fn get_skip_padding_ranges(&self, node: &Self::Node<'_>) -> Vec<CodeRange>
Provided Methods§
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 substitute_metavariable_prefix(&self, src: &str) -> String
fn snippet_metavariable_to_grit_metavariable( &self, src: &str, ) -> Option<GritMetaValue>
Sourcefn check_replacements(
&self,
node: Self::Node<'_>,
replacements: &mut Vec<Replacement>,
)
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.
fn take_padding(&self, current: char, next: Option<char>) -> Option<char>
Sourcefn should_pad_snippet(&self) -> bool
fn should_pad_snippet(&self) -> bool
Whether snippets should be padded.
This is generally true for languages with relevant whitespace.
fn make_single_line_comment(&self, text: &str) -> String
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.