| 1 | //! Parsing of R DESCRIPTION relations strings. |
| 2 | use craterust-analyzer cargo r-description 0.4.1 crate/::versionrust-analyzer cargo r-description 0.4.1 version/::Versionrust-analyzer cargo r-description 0.4.1 version/Version#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::Charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Chars#; |
| 6 | |
| 7 | /// Constraint on a package version. |
| 8 | /// |
| 9 | /// The operators are those documented in Writing R Extensions: `<`, `<=`, |
| 10 | /// `==`, `!=`, `>=`, `>`. |
| 11 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 12 | pub enum VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint# { |
| 13 | /// < |
| 14 | LessThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThan#, |
| 15 | /// <= |
| 16 | LessThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThanEqual#, |
| 17 | /// == |
| 18 | Equalrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#Equal#, |
| 19 | /// != |
| 20 | NotEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#NotEqual#, |
| 21 | /// > |
| 22 | GreaterThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThan#, |
| 23 | /// >= |
| 24 | GreaterThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThanEqual#, |
| 25 | } |
| 26 | |
| 27 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint# { |
| 28 | type Errrust-analyzer cargo r-description 0.4.1 relations/impl#[VersionConstraint][FromStr]Err# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#; |
| 29 | |
| 30 | fn from_strrust-analyzer cargo r-description 0.4.1 relations/impl#[VersionConstraint][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[VersionConstraint][FromStr], Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[VersionConstraint][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> { |
| 31 | match s { |
| 32 | ">=" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThanEqual#), |
| 33 | "<=" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThanEqual#), |
| 34 | "==" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::Equalrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#Equal#), |
| 35 | "!=" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::NotEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#NotEqual#), |
| 36 | ">" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThan#), |
| 37 | "<" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThan#), |
| 38 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Invalid version constraint: {s}")), |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint# { |
| 44 | fn fmtrust-analyzer cargo r-description 0.4.1 relations/impl#[VersionConstraint][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 45 | match self { |
| 46 | VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThanEqual# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(">="), |
| 47 | VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThanEqual# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("<="), |
| 48 | VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::Equalrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#Equal# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("=="), |
| 49 | VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::NotEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#NotEqual# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("!="), |
| 50 | VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThan# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(">"), |
| 51 | VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThan# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("<"), |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /// Let's start with defining all kinds of tokens and |
| 57 | /// composite nodes. |
| 58 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 59 | #[allow(non_camel_case_types, clippy::upper_case_acronyms)] |
| 60 | #[repr(u16)] |
| 61 | #[allow(missing_docs)] |
| 62 | pub(craterust-analyzer cargo r-description 0.4.1 crate/) enum SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind# { |
| 63 | IDENTrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#IDENT# = 0, // package name |
| 64 | COMMArust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#COMMA#, // , |
| 65 | L_PARENSrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#L_PARENS#, // ( |
| 66 | R_PARENSrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#R_PARENS#, // ) |
| 67 | L_ANGLErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#L_ANGLE#, // < |
| 68 | R_ANGLErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#R_ANGLE#, // > |
| 69 | EQUALrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#EQUAL#, // = |
| 70 | NOTrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#NOT#, // ! |
| 71 | WHITESPACErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#WHITESPACE#, // whitespace |
| 72 | NEWLINErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#NEWLINE#, // newline |
| 73 | ERRORrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#ERROR#, // as well as errors |
| 74 | |
| 75 | // composite nodes |
| 76 | ROOTrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#ROOT#, // The entire file |
| 77 | RELATIONrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#RELATION#, // An alternative in a dependency |
| 78 | VERSIONrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#VERSION#, // A version constraint |
| 79 | CONSTRAINTrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#CONSTRAINT#, // (">=", "<=", "==", "!=", ">", "<") |
| 80 | } |
| 81 | |
| 82 | /// Convert our `SyntaxKind` into the rowan `SyntaxKind`. |
| 83 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#> for rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxKindrust-analyzer cargo rowan 0.16.1 green/SyntaxKind# { |
| 84 | fn fromrust-analyzer cargo r-description 0.4.1 relations/impl#[`rowan::SyntaxKind`][`From<SyntaxKind>`]from().(kind: SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#) -> Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`rowan::SyntaxKind`][`From<SyntaxKind>`] { |
| 85 | Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`rowan::SyntaxKind`][`From<SyntaxKind>`](kind as u16) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /// A lexer for relations strings. |
| 90 | pub(craterust-analyzer cargo r-description 0.4.1 crate/) struct Lexerrust-analyzer cargo r-description 0.4.1 relations/Lexer#<'a> { |
| 91 | inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input.: Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<Charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/Chars#<'a>>, |
| 92 | } |
| 93 | |
| 94 | impl<'a> Lexerrust-analyzer cargo r-description 0.4.1 relations/Lexer#<'a> { |
| 95 | /// Create a new lexer for the given input. |
| 96 | pub fn newrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]new().(input: &'a str) -> Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`] { |
| 97 | Lexerrust-analyzer cargo r-description 0.4.1 relations/Lexer# { |
| 98 | inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input.: input.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(), |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | fn is_whitespacerust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]is_whitespace().(c: char) -> bool { |
| 103 | c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\t' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\r' |
| 104 | } |
| 105 | |
| 106 | fn is_valid_ident_charrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]is_valid_ident_char().(c: char) -> bool { |
| 107 | c.is_ascii_alphanumericrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_alphanumeric().() || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'-' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'.' |
| 108 | } |
| 109 | |
| 110 | fn read_whilerust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]read_while().<F>(&mut self, predicate: F) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# |
| 111 | where |
| 112 | F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(char) -> bool, |
| 113 | { |
| 114 | let mut result = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 115 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&c) = self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() { |
| 116 | if predicate(c) { |
| 117 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c); |
| 118 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 119 | } else { |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | result |
| 124 | } |
| 125 | |
| 126 | fn next_tokenrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]next_token().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> { |
| 127 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&c) = self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() { |
| 128 | match c { |
| 129 | ',' => { |
| 130 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 131 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::COMMArust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#COMMA#, ",".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 132 | } |
| 133 | '(' => { |
| 134 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 135 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::L_PARENSrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#L_PARENS#, "(".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 136 | } |
| 137 | ')' => { |
| 138 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 139 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::R_PARENSrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#R_PARENS#, ")".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 140 | } |
| 141 | '<' => { |
| 142 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 143 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::L_ANGLErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#L_ANGLE#, "<".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 144 | } |
| 145 | '>' => { |
| 146 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 147 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::R_ANGLErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#R_ANGLE#, ">".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 148 | } |
| 149 | '=' => { |
| 150 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 151 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::EQUALrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#EQUAL#, "=".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 152 | } |
| 153 | '!' => { |
| 154 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 155 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::NOTrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#NOT#, "!".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 156 | } |
| 157 | '\n' => { |
| 158 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 159 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::NEWLINErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#NEWLINE#, "\n".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().())) |
| 160 | } |
| 161 | _ if Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]::is_whitespacerust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]is_whitespace().(c) => { |
| 162 | let whitespace = self.read_whilerust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]read_while().(Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]::is_whitespacerust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]is_whitespace().); |
| 163 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::WHITESPACErust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#WHITESPACE#, whitespace)) |
| 164 | } |
| 165 | // TODO: separate handling for package names and versions? |
| 166 | _ if Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]::is_valid_ident_charrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]is_valid_ident_char().(c) => { |
| 167 | let key = self.read_whilerust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]read_while().(Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]::is_valid_ident_charrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]is_valid_ident_char().); |
| 168 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::IDENTrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#IDENT#, key)) |
| 169 | } |
| 170 | _ => { |
| 171 | self.inputrust-analyzer cargo r-description 0.4.1 relations/Lexer#input..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 172 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#::ERRORrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#ERROR#, c.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 173 | } |
| 174 | } |
| 175 | } else { |
| 176 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for Lexerrust-analyzer cargo r-description 0.4.1 relations/Lexer#<'_> { |
| 182 | type Itemrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'_>`][Iterator]Item# = (SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#); |
| 183 | |
| 184 | fn nextrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'_>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'_>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 185 | self.next_tokenrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]next_token().() |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | pub(craterust-analyzer cargo r-description 0.4.1 crate/) fn lexrust-analyzer cargo r-description 0.4.1 relations/lex().(input: &str) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(SyntaxKindrust-analyzer cargo r-description 0.4.1 relations/SyntaxKind#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#)> { |
| 190 | let mut lexer = Lexerrust-analyzer cargo r-description 0.4.1 relations/Lexer#::newrust-analyzer cargo r-description 0.4.1 relations/impl#[`Lexer<'a>`]new().(input); |
| 191 | lexer.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>() |
| 192 | } |
| 193 | |
| 194 | /// A trait for looking up versions of packages. |
| 195 | pub trait VersionLookuprust-analyzer cargo r-description 0.4.1 relations/VersionLookup# { |
| 196 | /// Look up the version of a package. |
| 197 | fn lookup_versionrust-analyzer cargo r-description 0.4.1 relations/VersionLookup#lookup_version().<'a>(&'a self, package: &'_ str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, Versionrust-analyzer cargo r-description 0.4.1 version/Version#>>; |
| 198 | } |
| 199 | |
| 200 | impl VersionLookuprust-analyzer cargo r-description 0.4.1 relations/VersionLookup# for stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Versionrust-analyzer cargo r-description 0.4.1 version/Version#> { |
| 201 | fn lookup_versionrust-analyzer cargo r-description 0.4.1 relations/impl#[`std::collections::HashMap<String, Version>`][VersionLookup]lookup_version().<'a>(&'a self, package: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, Versionrust-analyzer cargo r-description 0.4.1 version/Version#>> { |
| 202 | self.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(package).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | impl<F> VersionLookuprust-analyzer cargo r-description 0.4.1 relations/VersionLookup# for F |
| 207 | where |
| 208 | F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Versionrust-analyzer cargo r-description 0.4.1 version/Version#>, |
| 209 | { |
| 210 | fn lookup_versionrust-analyzer cargo r-description 0.4.1 relations/impl#[F][VersionLookup]lookup_version().<'a>(&'a self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, Versionrust-analyzer cargo r-description 0.4.1 version/Version#>> { |
| 211 | self(name).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | impl VersionLookuprust-analyzer cargo r-description 0.4.1 relations/VersionLookup# for (Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Versionrust-analyzer cargo r-description 0.4.1 version/Version#) { |
| 216 | fn lookup_versionrust-analyzer cargo r-description 0.4.1 relations/impl#[`(String, Version)`][VersionLookup]lookup_version().<'a>(&'a self, name: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, Versionrust-analyzer cargo r-description 0.4.1 version/Version#>> { |
| 217 | if name rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[`&str`][`PartialEq<String>`]eq().self.0 { |
| 218 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(&self.1)) |
| 219 | } else { |
| 220 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | #[cfg(test)] |
| 226 | mod testsrust-analyzer cargo r-description 0.4.1 relations/tests/ { |
| 227 | use superrust-analyzer cargo r-description 0.4.1 relations/::VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#; |
| 228 | |
| 229 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 230 | fn parse_r_operatorsrust-analyzer cargo r-description 0.4.1 relations/tests/parse_r_operators().() { |
| 231 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("<".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThan#)); |
| 232 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("<=".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThanEqual#)); |
| 233 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("==".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::Equalrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#Equal#)); |
| 234 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("!=".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::NotEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#NotEqual#)); |
| 235 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(">".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThan#)); |
| 236 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(">=".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().(), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThanEqual#)); |
| 237 | } |
| 238 | |
| 239 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 240 | fn debian_operators_are_rejectedrust-analyzer cargo r-description 0.4.1 relations/tests/debian_operators_are_rejected().() { |
| 241 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!("<<".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#>().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 242 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(">>".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#>().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 243 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!("=".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#>().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 244 | } |
| 245 | |
| 246 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 247 | fn display_uses_r_operatorsrust-analyzer cargo r-description 0.4.1 relations/tests/display_uses_r_operators().() { |
| 248 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThan#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "<"); |
| 249 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::LessThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#LessThanEqual#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "<="); |
| 250 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::Equalrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#Equal#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "=="); |
| 251 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::NotEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#NotEqual#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "!="); |
| 252 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThan#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), ">"); |
| 253 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#::GreaterThanEqualrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#GreaterThanEqual#.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), ">="); |
| 254 | } |
| 255 | |
| 256 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 257 | fn invalid_operatorrust-analyzer cargo r-description 0.4.1 relations/tests/invalid_operator().() { |
| 258 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!("~=".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<VersionConstraintrust-analyzer cargo r-description 0.4.1 relations/VersionConstraint#>().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 259 | } |
| 260 | } |