| 1 | //! Accessors for `vpath` directives. |
| 2 | |
| 3 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath#; |
| 4 | use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::*; |
| 5 | use rowanrust-analyzer cargo rowan 0.16.1 crate/::astrust-analyzer cargo rowan 0.16.1 ast/::AstNoderust-analyzer cargo rowan 0.16.1 ast/AstNode#; |
| 6 | |
| 7 | impl Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath# { |
| 8 | /// Returns the pattern argument of the `vpath` directive, if any. |
| 9 | /// |
| 10 | /// `vpath` (no args) returns `None`. |
| 11 | /// `vpath PATTERN` returns `Some("PATTERN")`. |
| 12 | /// `vpath PATTERN DIRS` returns `Some("PATTERN")`. |
| 13 | pub fn patternrust-analyzer cargo makefile-lossless 0.3.40 ast/vpath/impl#[Vpath]pattern().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 14 | // Walk tokens: skip the leading `vpath` keyword and whitespace, |
| 15 | // then collect tokens up to the next whitespace or to the EXPR |
| 16 | // (directories) node. |
| 17 | let mut after_keyword = false; |
| 18 | let mut out = 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().(); |
| 19 | for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Vpath][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() { |
| 20 | match child { |
| 21 | rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Tokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Token#(t) => { |
| 22 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().after_keyword { |
| 23 | if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# && t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."vpath" { |
| 24 | after_keyword = true; |
| 25 | } |
| 26 | continue; |
| 27 | } |
| 28 | if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# { |
| 29 | if out.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 30 | continue; |
| 31 | } else { |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# { |
| 36 | break; |
| 37 | } |
| 38 | out.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().()); |
| 39 | } |
| 40 | rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#::Noderust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#Node#(_) => { |
| 41 | // The EXPR (directories) node marks the end of the |
| 42 | // pattern. |
| 43 | break; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | if out.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() { |
| 48 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 49 | } else { |
| 50 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(out) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /// Returns the raw directory-list text (everything after the pattern), |
| 55 | /// or `None` if the directive has no directories. |
| 56 | pub fn directories_textrust-analyzer cargo makefile-lossless 0.3.40 ast/vpath/impl#[Vpath]directories_text().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 57 | self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Vpath][AstNode]syntax().() |
| 58 | .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() |
| 59 | .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|c| c.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#) |
| 60 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|n| n.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 61 | } |
| 62 | } |