fix(pi-ast): satisfied rustfmt and clippy const-fn lint in ops.rs
- Reflowed compile_pattern/wrapper_template comments and while-condition to rustfmt's preferred layout. - Made wrapper_template a const fn to satisfy clippy::missing_const_for_fn under -D warnings.
This commit is contained in:
@@ -102,7 +102,8 @@ pub fn compile_pattern(
|
|||||||
) -> Result<Pattern> {
|
) -> Result<Pattern> {
|
||||||
let selector = selector.map(str::trim).filter(|s| !s.is_empty());
|
let selector = selector.map(str::trim).filter(|s| !s.is_empty());
|
||||||
let mut compiled = if let Some(selector) = selector {
|
let mut compiled = if let Some(selector) = selector {
|
||||||
Pattern::contextual(pattern, selector, lang).map_err(|err| anyhow!("Invalid pattern: {err}"))?
|
Pattern::contextual(pattern, selector, lang)
|
||||||
|
.map_err(|err| anyhow!("Invalid pattern: {err}"))?
|
||||||
} else {
|
} else {
|
||||||
match Pattern::try_new(pattern, lang) {
|
match Pattern::try_new(pattern, lang) {
|
||||||
Ok(compiled) => compiled,
|
Ok(compiled) => compiled,
|
||||||
@@ -126,8 +127,9 @@ pub fn compile_pattern(
|
|||||||
/// Language-specific wrapper template used to turn a multi-node fragment into a
|
/// Language-specific wrapper template used to turn a multi-node fragment into a
|
||||||
/// single selectable node. `None` for languages without a template — those keep
|
/// single selectable node. `None` for languages without a template — those keep
|
||||||
/// the original `MultipleNode` error.
|
/// the original `MultipleNode` error.
|
||||||
fn wrapper_template(lang: SupportLang) -> Option<(&'static str, &'static str, &'static str)> {
|
const fn wrapper_template(lang: SupportLang) -> Option<(&'static str, &'static str, &'static str)> {
|
||||||
// (prefix, suffix, selector-kind); the fragment is spliced between prefix/suffix.
|
// (prefix, suffix, selector-kind); the fragment is spliced between
|
||||||
|
// prefix/suffix.
|
||||||
match lang {
|
match lang {
|
||||||
SupportLang::Json => Some(("{", "}", "pair")),
|
SupportLang::Json => Some(("{", "}", "pair")),
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -135,9 +137,9 @@ fn wrapper_template(lang: SupportLang) -> Option<(&'static str, &'static str, &'
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Retry a fragment that failed as `MultipleNode` by wrapping it in a minimal
|
/// Retry a fragment that failed as `MultipleNode` by wrapping it in a minimal
|
||||||
/// valid context and selecting the node kind that spans it. Returns the compiled
|
/// valid context and selecting the node kind that spans it. Returns the
|
||||||
/// pattern (with `strictness` applied) or `None` if this language has no template
|
/// compiled pattern (with `strictness` applied) or `None` if this language has
|
||||||
/// or the wrapped form still fails to compile.
|
/// no template or the wrapped form still fails to compile.
|
||||||
fn compile_wrapped_fallback(
|
fn compile_wrapped_fallback(
|
||||||
pattern: &str,
|
pattern: &str,
|
||||||
strictness: &MatchStrictness,
|
strictness: &MatchStrictness,
|
||||||
@@ -180,8 +182,7 @@ fn quote_bare_metavars(pattern: &str) -> String {
|
|||||||
if bytes[index..].starts_with(b"$$") {
|
if bytes[index..].starts_with(b"$$") {
|
||||||
index += 2;
|
index += 2;
|
||||||
}
|
}
|
||||||
while index < bytes.len()
|
while index < bytes.len() && (bytes[index].is_ascii_alphanumeric() || bytes[index] == b'_')
|
||||||
&& (bytes[index].is_ascii_alphanumeric() || bytes[index] == b'_')
|
|
||||||
{
|
{
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user