#[non_exhaustive]pub enum ScanSyntax {
Ruby,
Swift,
Toml,
Groovy,
}Expand description
Which manifest syntax family a scan should follow: which characters open a string literal, whether that literal’s contents are backslash-escaped, and which characters start a comment.
One variant per syntax family, not per quote-style/comment-style combination — a
ScanSyntax value fully determines both, so a new manifest family adds one variant
here (and an exhaustive match on it forces every scan function to handle it) instead
of a cross product of independent style flags.
#[non_exhaustive]: this enum gains a variant every time deps-lsp adds support for a
manifest family with its own quoting/comment syntax — it already grew Groovy once
(#1186), as an undocumented break against a matching downstream match. Ecosystem support
is expected to keep expanding, and exhaustiveness on this type buys callers nothing (no
scan function is meant to special-case “any other syntax”), so a future addition should
ship as a non-breaking patch instead of forcing a major version bump.
§Examples
use deps_core::quote_scan::{ScanSyntax, strip_line_comment};
assert_eq!(
strip_line_comment(r#"gem "x", source: "https://h" # comment"#, ScanSyntax::Ruby),
r#"gem "x", source: "https://h" "#,
);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Ruby
Ruby (Gemfile) syntax: " and ' string literals, both backslash-escaped; # starts
a line comment. Only "..." literals interpolate (#{...}, tracked by
read_string_literal via a dedicated helper) — Ruby’s '...' literals never
interpolate, so #{ inside one is just literal text, scanned like any other
backslash-escaped content.
Swift
Swift (Package.swift) syntax: " string literals, backslash-escaped; // starts
a line comment and /* ... */ a block comment.
Toml
TOML syntax: " string literals are backslash-escaped; ' literal strings are
not escaped at all (a \ inside one is just a literal backslash). # starts a
line comment.
Groovy
Groovy/Kotlin DSL syntax (Gradle build scripts): " and ' string literals, both
backslash-escaped (ScanSyntax::Ruby’s quote handling); // starts a line comment
and /* ... */ a block comment (ScanSyntax::Swift’s comment handling). Unlike
Ruby, ?"/?' is not a distinct token, so the ?-predecessor char-literal check is
never consulted for this variant.
Known, documented approximations (all pre-existing in this crate’s Gradle-specific scanners this variant replaces, not new regressions):
- Groovy GString interpolation (
"${...}") nesting a same-type quote ("${p.get("x")}") is not tracked — the Groovy analogue of the Ruby#{}problemread_string_literal’s interpolation-aware path solves; a literal reads as closing at the inner"instead. - Triple-quoted strings (
'''...''',"""...""") are not tokenized; each'/"inside one is read as an ordinary delimiter. - A Kotlin
'a'Charliteral is scanned as a one-character string literal, which is harmless for skip-scanning (the content is opaque either way). - Known, intentional divergence from the crate-local scanner this variant replaces
(#1174 impl-critic C2): the old scanner tracked one
backslash_runacross the entire input, so a stray\in code position (outside any string) suppressed the very next quote as a delimiter (e.g.impl \"a:b:1.0read as no open string at all); this scanner’s escape tracking is scoped to inside a literal, so the same input opens a"literal there instead. Unreachable from valid Groovy/Kotlin syntax (a bare\is not valid outside a string literal), and the new answer is arguably the more correct one, so this is not treated as a regression.
Trait Implementations§
Source§impl Clone for ScanSyntax
impl Clone for ScanSyntax
impl Copy for ScanSyntax
Source§impl Debug for ScanSyntax
impl Debug for ScanSyntax
impl Eq for ScanSyntax
Source§impl PartialEq for ScanSyntax
impl PartialEq for ScanSyntax
impl StructuralPartialEq for ScanSyntax
Auto Trait Implementations§
impl Freeze for ScanSyntax
impl RefUnwindSafe for ScanSyntax
impl Send for ScanSyntax
impl Sync for ScanSyntax
impl Unpin for ScanSyntax
impl UnsafeUnpin for ScanSyntax
impl UnwindSafe for ScanSyntax
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.