Skip to main content

ScanSyntax

Enum ScanSyntax 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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 #{} problem read_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' Char literal 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_run across 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.0 read 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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ScanSyntax

Source§

impl Debug for ScanSyntax

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ScanSyntax

Source§

impl PartialEq for ScanSyntax

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ScanSyntax

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more