Debian Codegraph @

src/ast/makefile.rs

raw symbols SCIP
1 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::{
2 parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse()., Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#, ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#, Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#, Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#, Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#, SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#,
3 VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#, VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#, Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath#,
4 };
5 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/::matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().;
6 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::SyntaxKindrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#::*;
7 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#;
8 use rowanrust-analyzer cargo rowan 0.16.1 crate/::GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#;
9 use 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/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#;
10
11 /// Represents different types of items that can appear in a Makefile
12 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
13 pub enum MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem# {
14 /// A rule definition (e.g., "target: prerequisites")
15 Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#),
16 /// A variable definition (e.g., "VAR = value")
17 Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#),
18 /// An include directive (e.g., "include foo.mk")
19 Includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Include#(Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#),
20 /// A conditional block (e.g., "ifdef DEBUG ... endif")
21 Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#),
22 /// A `vpath` directive (e.g., `vpath %.c src`)
23 Vpathrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Vpath#(Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath#),
24 }
25
26 impl MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem# {
27 /// Try to cast a syntax node to a MakefileItem
28 pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) fn castrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]cast().(node: SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]> {
29 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rule) = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]cast().(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().()) {
30 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(rule))
31 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var) = VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]cast().(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().()) {
32 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(var))
33 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inc) = Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().()) {
34 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Include#(inc))
35 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(vp) = Vpathrust-analyzer cargo makefile-lossless 0.3.40 lossless/Vpath#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Vpath][AstNode]cast().(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().()) {
36 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Vpathrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Vpath#(vp))
37 } else {
38 Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional][AstNode]cast().(node).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#)
39 }
40 }
41
42 /// Get the underlying syntax node
43 pub fn syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().(&self) -> &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode# {
44 match self {
45 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(r) => r.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().(),
46 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => v.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]syntax().(),
47 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Include#(i) => i.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().(),
48 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(c) => c.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional][AstNode]syntax().(),
49 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Vpathrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Vpath#(v) => v.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Vpath][AstNode]syntax().(),
50 }
51 }
52
53 /// Helper to get parent node or return an appropriate error
54 fn get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().(&self, action: &str, method: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
55 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
56 Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
57 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
58 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Cannot {} item without parent", action),
59 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
60 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("MakefileItem::{}", method),
61 }],
62 })
63 })
64 }
65
66 /// Check if a token is a regular comment (not a shebang)
67 fn is_regular_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]is_regular_comment().(token: &rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>) -> bool {
68 token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("#!")
69 }
70
71 /// Extract comment text from a comment token, removing '#' prefix
72 fn extract_comment_textrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]extract_comment_text().(token: &rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
73 let text = token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().();
74 text.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("# ")
75 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| text.strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().('#'))
76 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(text)
77 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
78 }
79
80 /// Helper to find all preceding comment-related elements up to the first non-comment element
81 ///
82 /// Returns elements in reverse order (from closest to furthest from the item)
83 fn collect_preceding_comment_elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]collect_preceding_comment_elements().(
84 &self,
85 ) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#<SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>>> {
86 let mut elements = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
87 let mut current = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().prev_sibling_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]prev_sibling_or_token().();
88
89 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) = current {
90 match &element {
91 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#(token) if Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]::is_regular_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]is_regular_comment().(token) => {
92 elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().());
93 }
94 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#(token)
95 if token.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# || token.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# =>
96 {
97 elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().());
98 }
99 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#(n) if n.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().BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE# => {
100 elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().());
101 }
102 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#(token) if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# => {
103 // Hit a shebang, stop here
104 break;
105 }
106 _ => break,
107 }
108 current = element.prev_sibling_or_tokenrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]prev_sibling_or_token().();
109 }
110
111 elements
112 }
113
114 /// Helper to parse comment text and extract properly formatted comment tokens
115 fn parse_comment_tokensrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]parse_comment_tokens().(
116 comment_text: &str,
117 ) -> (
118 rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>,
119 Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>>,
120 ) {
121 let comment_line = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("# {}\n", comment_text);
122 let temp_makefile = craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(&comment_line, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
123 let root = temp_makefile.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().();
124
125 let mut comment_token = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
126 let mut newline_token = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
127 let mut found_comment = false;
128
129 for element in root.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
130 if let 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#(token) = element {
131 if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# {
132 comment_token = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token);
133 found_comment = true;
134 } else if token.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# && found_comment && newline_token.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
135 newline_token = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token);
136 break;
137 }
138 }
139 }
140
141 (
142 comment_token.expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Failed to extract comment token"),
143 newline_token,
144 )
145 }
146
147 /// Replace this MakefileItem with another MakefileItem
148 ///
149 /// This preserves the position of the original item but replaces its content
150 /// with the new item. Preceding comments are preserved.
151 ///
152 /// # Example
153 /// ```
154 /// use makefile_lossless::{Makefile, MakefileItem};
155 /// let mut makefile: Makefile = "VAR1 = old\nrule:\n\tcommand\n".parse().unwrap();
156 /// let temp: Makefile = "VAR2 = new\n".parse().unwrap();
157 /// let new_var = temp.variable_definitions().next().unwrap();
158 /// let mut first_item = makefile.items().next().unwrap();
159 /// first_item.replace(MakefileItem::Variable(new_var)).unwrap();
160 /// assert!(makefile.to_string().contains("VAR2 = new"));
161 /// assert!(!makefile.to_string().contains("VAR1"));
162 /// ```
163 pub fn replacerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]replace().(&mut self, new_item: MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
164 let parent = self.get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().("replace", "replace")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
165 let current_index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
166
167 // Replace the current node with the new item's syntax
168 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
169 current_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#current_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1,
170 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
171 );
172
173 // Update self to point to the new item
174 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = new_item;
175
176 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
177 }
178
179 /// Add a comment before this MakefileItem
180 ///
181 /// The comment text should not include the leading '#' character.
182 /// Multiple comment lines can be added by calling this method multiple times.
183 ///
184 /// # Example
185 /// ```
186 /// use makefile_lossless::Makefile;
187 /// let mut makefile: Makefile = "VAR = value\n".parse().unwrap();
188 /// let mut item = makefile.items().next().unwrap();
189 /// item.add_comment("This is a variable").unwrap();
190 /// assert!(makefile.to_string().contains("# This is a variable"));
191 /// ```
192 pub fn add_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]add_comment().(&mut self, comment_text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
193 let parent = self.get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().("add comment to", "add_comment")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
194 let current_index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
195
196 // Get properly formatted comment tokens
197 let (comment_token, newline_token) = Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]::parse_comment_tokensrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]parse_comment_tokens().(comment_text);
198
199 let mut elements = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![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#(comment_token)];
200 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(newline) = newline_token {
201 elements.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(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#(newline));
202 }
203
204 // Insert comment and newline before the current item
205 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(current_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#current_index, elements);
206
207 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
208 }
209
210 /// Get all preceding comments for this MakefileItem
211 ///
212 /// Returns an iterator of comment strings (without the leading '#' and whitespace).
213 ///
214 /// # Example
215 /// ```
216 /// use makefile_lossless::Makefile;
217 /// let makefile: Makefile = "# Comment 1\n# Comment 2\nVAR = value\n".parse().unwrap();
218 /// let item = makefile.items().next().unwrap();
219 /// let comments: Vec<_> = item.preceding_comments().collect();
220 /// assert_eq!(comments.len(), 2);
221 /// assert_eq!(comments[0], "Comment 1");
222 /// assert_eq!(comments[1], "Comment 2");
223 /// ```
224 pub fn preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]preceding_comments().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
225 let elements = self.collect_preceding_comment_elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]collect_preceding_comment_elements().();
226 let mut comments = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
227
228 // Process elements in reverse order (furthest to closest)
229 for element in elements.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() {
230 if let 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#(token) = element {
231 if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# {
232 comments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]::extract_comment_textrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]extract_comment_text().(token));
233 }
234 }
235 }
236
237 comments.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
238 }
239
240 /// Remove all preceding comments for this MakefileItem
241 ///
242 /// Returns the number of comments removed.
243 ///
244 /// # Example
245 /// ```
246 /// use makefile_lossless::Makefile;
247 /// let mut makefile: Makefile = "# Comment 1\n# Comment 2\nVAR = value\n".parse().unwrap();
248 /// let mut item = makefile.items().next().unwrap();
249 /// let count = item.remove_comments().unwrap();
250 /// assert_eq!(count, 2);
251 /// assert!(!makefile.to_string().contains("# Comment"));
252 /// ```
253 pub fn remove_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]remove_comments().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
254 let parent = self.get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().("remove comments from", "remove_comments")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
255 let collected_elements = self.collect_preceding_comment_elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]collect_preceding_comment_elements().();
256
257 // Count the comments
258 let mut comment_count = 0;
259 for element in collected_elements.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
260 if let 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#(token) = element {
261 if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# {
262 comment_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
263 }
264 }
265 }
266
267 // Determine which elements to remove - similar to remove_with_preceding_comments
268 // We remove comments and up to 1 blank line worth of newlines
269 let mut elements_to_remove = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
270 let mut consecutive_newlines = 0;
271 for element in collected_elements.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().() {
272 let should_remove = match element {
273 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#(token) if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# => {
274 consecutive_newlines = 0;
275 true // Remove comments
276 }
277 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#(token) if token.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# => {
278 consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
279 comment_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().1
280 }
281 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#(token) if token.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# => comment_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0,
282 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#(n) if n.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().BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE# => {
283 consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
284 comment_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && consecutive_newlines rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().1
285 }
286 _ => false,
287 };
288
289 if should_remove {
290 elements_to_remove.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(element.clonerust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`][Clone]clone().());
291 }
292 }
293
294 // Remove elements in reverse order (from highest index to lowest)
295 elements_to_remove.sort_by_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by_key().(|el| stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Reverserust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Reverse#(el.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]index().()));
296 for element in elements_to_remove {
297 let idx = element.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]index().();
298 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
299 }
300
301 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(comment_count)
302 }
303
304 /// Modify the first preceding comment for this MakefileItem
305 ///
306 /// Returns `true` if a comment was found and modified, `false` if no comment exists.
307 /// The comment text should not include the leading '#' character.
308 ///
309 /// # Example
310 /// ```
311 /// use makefile_lossless::Makefile;
312 /// let mut makefile: Makefile = "# Old comment\nVAR = value\n".parse().unwrap();
313 /// let mut item = makefile.items().next().unwrap();
314 /// let modified = item.modify_comment("New comment").unwrap();
315 /// assert!(modified);
316 /// assert!(makefile.to_string().contains("# New comment"));
317 /// assert!(!makefile.to_string().contains("# Old comment"));
318 /// ```
319 pub fn modify_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]modify_comment().(&mut self, new_comment_text: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
320 let parent = self.get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().("modify comment for", "modify_comment")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
321
322 // Find the first preceding comment (closest to the item)
323 let collected_elements = self.collect_preceding_comment_elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]collect_preceding_comment_elements().();
324 let comment_element = collected_elements.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|element| {
325 if let 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#(token) = element {
326 token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT#
327 } else {
328 false
329 }
330 });
331
332 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element) = comment_element {
333 let idx = element.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<L>>`]index().();
334 let (new_comment_token, _) = Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]::parse_comment_tokensrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]parse_comment_tokens().(new_comment_text);
335 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
336 idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1,
337 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![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#(new_comment_token)],
338 );
339 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true)
340 } else {
341 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false)
342 }
343 }
344
345 /// Insert a new MakefileItem before this item
346 ///
347 /// This inserts the new item immediately before the current item in the makefile.
348 /// The new item is inserted at the same level as the current item.
349 ///
350 /// # Example
351 /// ```
352 /// use makefile_lossless::{Makefile, MakefileItem};
353 /// let mut makefile: Makefile = "VAR1 = first\nVAR2 = second\n".parse().unwrap();
354 /// let temp: Makefile = "VAR_NEW = inserted\n".parse().unwrap();
355 /// let new_var = temp.variable_definitions().next().unwrap();
356 /// let mut second_item = makefile.items().nth(1).unwrap();
357 /// second_item.insert_before(MakefileItem::Variable(new_var)).unwrap();
358 /// let result = makefile.to_string();
359 /// assert!(result.contains("VAR1 = first\nVAR_NEW = inserted\nVAR2 = second"));
360 /// ```
361 pub fn insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(&mut self, new_item: MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
362 let parent = self.get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().("insert before", "insert_before")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
363 let current_index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
364
365 // Insert the new item before the current item
366 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
367 current_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#current_index,
368 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
369 );
370
371 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
372 }
373
374 /// Insert a new MakefileItem after this item
375 ///
376 /// This inserts the new item immediately after the current item in the makefile.
377 /// The new item is inserted at the same level as the current item.
378 ///
379 /// # Example
380 /// ```
381 /// use makefile_lossless::{Makefile, MakefileItem};
382 /// let mut makefile: Makefile = "VAR1 = first\nVAR2 = second\n".parse().unwrap();
383 /// let temp: Makefile = "VAR_NEW = inserted\n".parse().unwrap();
384 /// let new_var = temp.variable_definitions().next().unwrap();
385 /// let mut first_item = makefile.items().next().unwrap();
386 /// first_item.insert_after(MakefileItem::Variable(new_var)).unwrap();
387 /// let result = makefile.to_string();
388 /// assert!(result.contains("VAR1 = first\nVAR_NEW = inserted\nVAR2 = second"));
389 /// ```
390 pub fn insert_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_after().(&mut self, new_item: MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
391 let parent = self.get_parent_or_errorrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]get_parent_or_error().("insert after", "insert_after")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
392 let current_index = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
393
394 // Insert the new item after the current item
395 parent.splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
396 current_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#current_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1,
397 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
398 );
399
400 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
401 }
402 }
403
404 // Internal trait for extracting specific item types from MakefileItem
405 trait ExtractFromItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/ExtractFromItem#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
406 fn extractrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/ExtractFromItem#extract().(item: MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self>;
407 }
408
409 impl ExtractFromItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/ExtractFromItem# for Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# {
410 fn extractrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Rule][ExtractFromItem]extract().(item: MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Rule][ExtractFromItem]> {
411 match item {
412 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(r) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r),
413 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
414 }
415 }
416 }
417
418 impl ExtractFromItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/ExtractFromItem# for VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition# {
419 fn extractrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[VariableDefinition][ExtractFromItem]extract().(item: MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[VariableDefinition][ExtractFromItem]> {
420 match item {
421 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v),
422 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
423 }
424 }
425 }
426
427 // Internal stack-based iterator for recursively collecting items from conditionals
428 struct RecursiveItemsIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#<T> {
429 stackrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#stack.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#>,
430 _phantomrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#_phantom.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>,
431 }
432
433 impl<T> RecursiveItemsIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#<T> {
434 fn newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`]new().(items: impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#>) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`] {
435 Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`] {
436 stackrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#stack.: items.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
437 _phantomrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#_phantom.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#,
438 }
439 }
440 }
441
442 impl<T: ExtractFromItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/ExtractFromItem#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for RecursiveItemsIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#<T> {
443 type Itemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]Item# = T;
444
445 fn nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
446 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = self.stackrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#stack..pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().() {
447 if let MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(ref cond) = item {
448 // Push in natural order since we pop from front
449 self.stackrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#stack..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][`Extend<T>`]extend().(cond.if_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]if_items().());
450 self.stackrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#stack..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][`Extend<T>`]extend().(cond.else_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/conditional/impl#[Conditional]else_items().());
451 }
452 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(extracted) = T::extractrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/ExtractFromItem#extract().(item) {
453 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(extracted);
454 }
455 }
456 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
457 }
458 }
459
460 /// Iterator over blocks of consecutive comment lines in a makefile.
461 struct CommentBlockIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter# {
462 elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<rowanrust-analyzer cargo rowan 0.16.1 crate/::NodeOrTokenrust-analyzer cargo rowan 0.16.1 utility_types/NodeOrToken#<SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#, rowanrust-analyzer cargo rowan 0.16.1 crate/::SyntaxTokenrust-analyzer cargo rowan 0.16.1 api/SyntaxToken#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::Langrust-analyzer cargo makefile-lossless 0.3.40 lossless/Lang#>>>,
463 posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos.: usize,
464 }
465
466 impl CommentBlockIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter# {
467 fn newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter]new().(root: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) -> Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter] {
468 Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter] {
469 elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements.: root.children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
470 posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos.: 0,
471 }
472 }
473 }
474
475 impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for CommentBlockIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter# {
476 type Itemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter][Iterator]Item# = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#;
477
478 fn nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
479 // Find the start of the next comment
480 while self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
481 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
482 if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# {
483 break;
484 }
485 }
486 self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
487 }
488
489 if self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
490 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
491 }
492
493 let block_start = self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().
494 .as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().()
495 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
496 .text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().()
497 .startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().();
498 let mut block_end = self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().
499 .as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().()
500 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
501 .text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().()
502 .endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().();
503 let mut comment_count = 1;
504 self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
505
506 // Extend the block through consecutive comments (with whitespace/newlines/blank lines between)
507 while self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
508 match &self.elementsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). {
509 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#(token)
510 if token.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# || token.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# =>
511 {
512 self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
513 }
514 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#(node) if node.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().BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE# => {
515 self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
516 }
517 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#(token) if token.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().COMMENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#COMMENT# => {
518 block_end = token.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text_range().().endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().();
519 comment_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
520 self.posrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#pos. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
521 }
522 _ => break,
523 }
524 }
525
526 // Only return blocks with 2+ comment lines
527 if comment_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().2 {
528 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(block_start, block_end))
529 } else {
530 // Single comment line — skip it and try next
531 self.nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter][Iterator]next().()
532 }
533 }
534 }
535
536 impl Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# {
537 /// Create a new empty makefile
538 pub fn newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]new().() -> Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# {
539 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
540
541 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(ROOTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ROOT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
542 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
543
544 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
545 Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]cast().(syntax).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
546 }
547
548 /// Parse makefile text, returning a Parse result
549 pub fn parserust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]parse().(text: &str) -> craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#> {
550 craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#::<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#>::parse_makefilerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<Makefile>`]parse_makefile().(text)
551 }
552
553 /// Get the text content of the makefile
554 pub fn coderust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]code().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
555 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().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().()
556 }
557
558 /// Check if this node is the root of a makefile
559 pub fn is_rootrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_root().(&self) -> bool {
560 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().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().ROOTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ROOT#
561 }
562
563 /// Read a makefile from a reader
564 pub fn readrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read().<R: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(mut r: R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
565 let mut buf = 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().();
566 r.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_to_string().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
567 buf.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
568 }
569
570 /// Read makefile from a reader, but allow syntax errors
571 pub fn read_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]read_relaxed().<R: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(mut r: R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
572 let mut buf = 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().();
573 r.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_to_string().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
574
575 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(&buf, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
576 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().())
577 }
578
579 /// Parse a makefile from a string, allowing syntax errors.
580 ///
581 /// Returns the parsed makefile and a list of errors. The makefile tree is
582 /// always returned, even if there are parse errors, enabling error-resilient
583 /// tooling that can work with partial or invalid input.
584 pub fn from_str_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_str_relaxed().(s: &str) -> (Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile], Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#>) {
585 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(s, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
586 (parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().(), parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.)
587 }
588
589 /// Read a makefile from a file path, allowing syntax errors.
590 ///
591 /// Returns the parsed makefile and a list of errors.
592 pub fn from_file_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_file_relaxed().(
593 path: impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>,
594 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile], Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#>), stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> {
595 let text = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
596 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]::from_str_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_str_relaxed().(&text))
597 }
598
599 /// Retrieve the rules in the makefile
600 ///
601 /// # Example
602 /// ```
603 /// use makefile_lossless::Makefile;
604 /// let makefile: Makefile = "rule: dependency\n\tcommand\n".parse().unwrap();
605 /// assert_eq!(makefile.rules().count(), 1);
606 /// ```
607 pub fn rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> + '_ {
608 RecursiveItemsIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`]new().(self.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().())
609 }
610
611 /// Get all rules that have a specific target
612 pub fn rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_by_target().<'a>(&'a self, target: &'a str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> + 'a {
613 self.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().()
614 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(move |rule| rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().target))
615 }
616
617 /// Get all variable definitions in the makefile
618 pub fn variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#> + '_ {
619 RecursiveItemsIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/RecursiveItemsIter#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`]new().(self.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().())
620 }
621
622 /// Get all conditionals in the makefile (top-level only)
623 pub fn conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]conditionals().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#> + '_ {
624 self.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|item| match item {
625 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Conditional#(c) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c),
626 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
627 })
628 }
629
630 /// Get all top-level items (rules, variables, includes, conditionals) in the makefile
631 ///
632 /// # Example
633 /// ```
634 /// use makefile_lossless::{Makefile, MakefileItem};
635 /// let makefile: Makefile = r#"VAR = value
636 /// ifdef DEBUG
637 /// CFLAGS = -g
638 /// endif
639 /// rule:
640 /// command
641 /// "#.parse().unwrap();
642 /// let items: Vec<_> = makefile.items().collect();
643 /// assert_eq!(items.len(), 3); // VAR, conditional, rule
644 /// ```
645 pub fn itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#> + '_ {
646 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::castrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]cast().)
647 }
648
649 /// Find all variables by name
650 ///
651 /// Returns an iterator over all variable definitions with the given name.
652 /// Makefiles can have multiple definitions of the same variable.
653 ///
654 /// # Example
655 /// ```
656 /// use makefile_lossless::Makefile;
657 /// let makefile: Makefile = "VAR1 = value1\nVAR2 = value2\nVAR1 = value3\n".parse().unwrap();
658 /// let vars: Vec<_> = makefile.find_variable("VAR1").collect();
659 /// assert_eq!(vars.len(), 2);
660 /// assert_eq!(vars[0].raw_value(), Some("value1".to_string()));
661 /// assert_eq!(vars[1].raw_value(), Some("value3".to_string()));
662 /// ```
663 pub fn find_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_variable().<'a>(
664 &'a self,
665 name: &'a str,
666 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#> + 'a {
667 self.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().()
668 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(move |var| var.namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().().as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name))
669 }
670
671 /// Get all variable references in the makefile.
672 ///
673 /// Walks the entire syntax tree to find all `$(VAR)` and `${VAR}` references
674 /// in variable values, prerequisites, and targets.
675 ///
676 /// Note: Variable references inside recipes are not included, since recipes
677 /// are stored as raw text in the syntax tree.
678 ///
679 /// # Example
680 /// ```
681 /// use makefile_lossless::Makefile;
682 /// let makefile: Makefile = "CFLAGS = $(BASE_FLAGS) -Wall\nall: $(TARGETS)\n".parse().unwrap();
683 /// let refs: Vec<_> = makefile.variable_references().collect();
684 /// let names: Vec<_> = refs.iter().filter_map(|r| r.name()).collect();
685 /// assert!(names.contains(&"BASE_FLAGS".to_string()));
686 /// assert!(names.contains(&"TARGETS".to_string()));
687 /// ```
688 pub fn variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#> + '_ {
689 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
690 .descendantsrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]descendants().()
691 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]cast().)
692 }
693
694 /// Get all top-level items that overlap with the given text range.
695 ///
696 /// Since items are stored in document order, this skips items entirely
697 /// before the range and stops once past it.
698 ///
699 /// # Example
700 /// ```
701 /// use makefile_lossless::{Makefile, TextRange};
702 /// let makefile: Makefile = "CC = gcc\nall: build\n\techo done\n".parse().unwrap();
703 /// let range = TextRange::new(0.into(), 8.into());
704 /// let items: Vec<_> = makefile.items_in_range(range).collect();
705 /// assert_eq!(items.len(), 1);
706 /// ```
707 pub fn items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(
708 &self,
709 range: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#,
710 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#> + '_ {
711 self.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().()
712 .skip_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip_while().(move |item| item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().range.startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().())
713 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(move |item| item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().startrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]start().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().range.endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().())
714 }
715
716 /// Get all variable references that overlap with the given text range.
717 ///
718 /// Only walks descendants of top-level items that overlap the range,
719 /// rather than scanning the entire tree.
720 pub fn variable_references_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references_in_range().(
721 &self,
722 range: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#,
723 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#> + '_ {
724 self.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|item| {
725 item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().()
726 .descendantsrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]descendants().()
727 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(VariableReferencerust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableReference#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]cast().)
728 .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#<_>>()
729 })
730 }
731
732 /// Get all rules that overlap with the given text range.
733 pub fn rules_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_in_range().(&self, range: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> + '_ {
734 self.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|item| match item {
735 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(r) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r),
736 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
737 })
738 }
739
740 /// Get all variable definitions that overlap with the given text range.
741 pub fn variable_definitions_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions_in_range().(
742 &self,
743 range: rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#,
744 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#> + '_ {
745 self.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|item| match item {
746 MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(v) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v),
747 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
748 })
749 }
750
751 /// Get all blocks of consecutive comment lines in the makefile.
752 ///
753 /// Returns the text range of each block. A comment block is two or more
754 /// consecutive comment lines (separated only by whitespace or blank lines).
755 ///
756 /// # Example
757 /// ```
758 /// use makefile_lossless::Makefile;
759 /// let makefile: Makefile = "# line 1\n# line 2\n# line 3\nall:\n\techo done\n".parse().unwrap();
760 /// let blocks: Vec<_> = makefile.comment_blocks().collect();
761 /// assert_eq!(blocks.len(), 1);
762 /// ```
763 pub fn comment_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]comment_blocks().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#> + '_ {
764 CommentBlockIterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/CommentBlockIter#::newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[CommentBlockIter]new().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().())
765 }
766
767 /// Add a new rule to the makefile
768 ///
769 /// # Example
770 /// ```
771 /// use makefile_lossless::Makefile;
772 /// let mut makefile = Makefile::new();
773 /// makefile.add_rule("rule");
774 /// assert_eq!(makefile.to_string(), "rule:\n");
775 /// ```
776 pub fn add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().(&mut self, target: &str) -> Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# {
777 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
778 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
779 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), target);
780 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), ":");
781 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
782 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
783
784 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
785 let pos = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().();
786
787 // Add a blank line before the new rule if there are existing rules
788 // This maintains standard makefile formatting
789 let needs_blank_line = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|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().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#);
790
791 if needs_blank_line {
792 // Create a BLANK_LINE node
793 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
794 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
795 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
796 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
797 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
798
799 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
800 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
801 } else {
802 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
803 }
804
805 // Use children().count() - 1 to get the last added child node
806 // (not children_with_tokens().count() which includes tokens)
807 Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
808 }
809
810 /// Add a new conditional to the makefile
811 ///
812 /// # Arguments
813 /// * `conditional_type` - The type of conditional: "ifdef", "ifndef", "ifeq", or "ifneq"
814 /// * `condition` - The condition expression (e.g., "DEBUG" for ifdef/ifndef, or "(a,b)" for ifeq/ifneq)
815 /// * `if_body` - The content of the if branch
816 /// * `else_body` - Optional content for the else branch
817 ///
818 /// # Example
819 /// ```
820 /// use makefile_lossless::Makefile;
821 /// let mut makefile = Makefile::new();
822 /// makefile.add_conditional("ifdef", "DEBUG", "VAR = debug\n", None);
823 /// assert!(makefile.to_string().contains("ifdef DEBUG"));
824 /// ```
825 pub fn add_conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional().(
826 &mut self,
827 conditional_type: &str,
828 condition: &str,
829 if_body: &str,
830 else_body: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
831 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
832 // Validate conditional type
833 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().["ifdef", "ifndef", "ifeq", "ifneq"].containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&conditional_type) {
834 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
835 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
836 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
837 "Invalid conditional type: {}. Must be one of: ifdef, ifndef, ifeq, ifneq",
838 conditional_type
839 ),
840 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
841 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "add_conditional".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
842 }],
843 }));
844 }
845
846 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
847 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
848
849 // Build CONDITIONAL_IF
850 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_IFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_IF#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
851 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), conditional_type);
852 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), " ");
853
854 // Wrap condition in EXPR node
855 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
856 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), condition);
857 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
858
859 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
860 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
861
862 // Add if body content
863 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().if_body.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
864 for line in if_body.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
865 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().line.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
866 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), line);
867 }
868 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
869 }
870 // Add final newline if if_body doesn't end with one
871 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().if_body.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\n') && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().if_body.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
872 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
873 }
874 }
875
876 // Add else clause if provided
877 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(else_content) = else_body {
878 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_ELSErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ELSE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
879 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "else");
880 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
881 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
882
883 // Add else body content
884 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().else_content.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
885 for line in else_content.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().() {
886 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().line.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
887 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), line);
888 }
889 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
890 }
891 // Add final newline if else_content doesn't end with one
892 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().else_content.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\n') && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().else_content.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
893 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
894 }
895 }
896 }
897
898 // Build CONDITIONAL_ENDIF
899 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_ENDIFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ENDIF#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
900 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "endif");
901 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
902 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
903
904 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
905
906 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
907 let pos = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().();
908
909 // Add a blank line before the new conditional if there are existing elements
910 let needs_blank_line = self
911 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
912 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
913 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|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().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE# || 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().VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE# || 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().CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#);
914
915 if needs_blank_line {
916 // Create a BLANK_LINE node
917 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
918 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
919 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
920 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
921 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
922
923 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
924 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
925 } else {
926 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
927 }
928
929 // Return the newly added conditional
930 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
931 }
932
933 /// Add a new conditional to the makefile with typed items
934 ///
935 /// This is a more type-safe alternative to `add_conditional` that accepts iterators of
936 /// `MakefileItem` instead of raw strings.
937 ///
938 /// # Arguments
939 /// * `conditional_type` - The type of conditional: "ifdef", "ifndef", "ifeq", or "ifneq"
940 /// * `condition` - The condition expression (e.g., "DEBUG" for ifdef/ifndef, or "(a,b)" for ifeq/ifneq)
941 /// * `if_items` - Items for the if branch
942 /// * `else_items` - Optional items for the else branch
943 ///
944 /// # Example
945 /// ```
946 /// use makefile_lossless::{Makefile, MakefileItem};
947 /// let mut makefile = Makefile::new();
948 /// let temp1: Makefile = "CFLAGS = -g\n".parse().unwrap();
949 /// let var1 = temp1.variable_definitions().next().unwrap();
950 /// let temp2: Makefile = "CFLAGS = -O2\n".parse().unwrap();
951 /// let var2 = temp2.variable_definitions().next().unwrap();
952 /// makefile.add_conditional_with_items(
953 /// "ifdef",
954 /// "DEBUG",
955 /// vec![MakefileItem::Variable(var1)],
956 /// Some(vec![MakefileItem::Variable(var2)])
957 /// ).unwrap();
958 /// assert!(makefile.to_string().contains("ifdef DEBUG"));
959 /// assert!(makefile.to_string().contains("CFLAGS = -g"));
960 /// assert!(makefile.to_string().contains("CFLAGS = -O2"));
961 /// ```
962 pub fn add_conditional_with_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_conditional_with_items().<I1, I2>(
963 &mut self,
964 conditional_type: &str,
965 condition: &str,
966 if_items: I1,
967 else_items: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I2>,
968 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#>
969 where
970 I1: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#>,
971 I2: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#>,
972 {
973 // Validate conditional type
974 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().["ifdef", "ifndef", "ifeq", "ifneq"].containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&conditional_type) {
975 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
976 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
977 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
978 "Invalid conditional type: {}. Must be one of: ifdef, ifndef, ifeq, ifneq",
979 conditional_type
980 ),
981 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
982 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "add_conditional_with_items".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
983 }],
984 }));
985 }
986
987 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
988 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
989
990 // Build CONDITIONAL_IF
991 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_IFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_IF#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
992 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), conditional_type);
993 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), " ");
994
995 // Wrap condition in EXPR node
996 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
997 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), condition);
998 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
999
1000 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1001 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1002
1003 // Add if branch items
1004 for item in if_items {
1005 // Clone the item's syntax tree into our builder
1006 let item_text = item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1007 // Parse it again to get green nodes
1008 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), item_text.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().());
1009 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1010 }
1011
1012 // Add else clause if provided
1013 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(else_iter) = else_items {
1014 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_ELSErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ELSE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1015 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "else");
1016 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1017 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1018
1019 // Add else branch items
1020 for item in else_iter {
1021 let item_text = item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1022 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), item_text.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().());
1023 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1024 }
1025 }
1026
1027 // Build CONDITIONAL_ENDIF
1028 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(CONDITIONAL_ENDIFrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL_ENDIF#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1029 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "endif");
1030 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1031 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1032
1033 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1034
1035 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1036 let pos = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().();
1037
1038 // Add a blank line before the new conditional if there are existing elements
1039 let needs_blank_line = self
1040 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1041 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1042 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|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().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE# || 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().VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE# || 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().CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#);
1043
1044 if needs_blank_line {
1045 // Create a BLANK_LINE node
1046 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1047 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1048 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1049 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1050 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1051
1052 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1053 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
1054 } else {
1055 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
1056 }
1057
1058 // Return the newly added conditional
1059 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Conditional][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
1060 }
1061
1062 /// Read the makefile
1063 pub fn from_readerrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_reader().<R: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(mut r: R) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1064 let mut buf = 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().();
1065 r.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_to_string().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1066
1067 let parsed = parserust-analyzer cargo makefile-lossless 0.3.40 lossless/parse().(&buf, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
1068 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1069 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1070 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: parsed.errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/Parse#errors.,
1071 }))
1072 } else {
1073 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(parsed.rootrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Parse]root().())
1074 }
1075 }
1076
1077 /// Replace rule at given index with a new rule
1078 ///
1079 /// # Example
1080 /// ```
1081 /// use makefile_lossless::Makefile;
1082 /// let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
1083 /// let new_rule: makefile_lossless::Rule = "new_rule:\n\tnew_command\n".parse().unwrap();
1084 /// makefile.replace_rule(0, new_rule).unwrap();
1085 /// assert!(makefile.rules().any(|r| r.targets().any(|t| t == "new_rule")));
1086 /// ```
1087 pub fn replace_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]replace_rule().(&mut self, index: usize, new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1088 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
1089 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1090 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1091 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|n| n.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().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#)
1092 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1093
1094 if rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1095 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1096 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1097 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "Cannot replace rule in empty makefile".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1098 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1099 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "replace_rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1100 }],
1101 }));
1102 }
1103
1104 if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1105 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1106 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1107 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1108 "Rule index {} out of bounds (max {})",
1109 index,
1110 rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1
1111 ),
1112 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1113 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "replace_rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1114 }],
1115 }));
1116 }
1117
1118 let target_node = &rules[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
1119 let target_index = target_node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
1120
1121 // Replace the rule at the target index
1122 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
1123 target_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#target_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1,
1124 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_rule.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
1125 );
1126 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1127 }
1128
1129 /// Remove rule at given index
1130 ///
1131 /// # Example
1132 /// ```
1133 /// use makefile_lossless::Makefile;
1134 /// let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
1135 /// let removed = makefile.remove_rule(0).unwrap();
1136 /// assert_eq!(removed.targets().collect::<Vec<_>>(), vec!["rule1"]);
1137 /// assert_eq!(makefile.rules().count(), 1);
1138 /// ```
1139 pub fn remove_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_rule().(&mut self, index: usize) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1140 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
1141 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1142 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1143 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|n| n.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().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#)
1144 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1145
1146 if rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1147 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1148 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1149 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "Cannot remove rule from empty makefile".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1150 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1151 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "remove_rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1152 }],
1153 }));
1154 }
1155
1156 if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1157 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1158 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1159 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
1160 "Rule index {} out of bounds (max {})",
1161 index,
1162 rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1
1163 ),
1164 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1165 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "remove_rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1166 }],
1167 }));
1168 }
1169
1170 let target_node = rules[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().();
1171 let target_index = target_node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
1172
1173 // Remove the rule at the target index
1174 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1175 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(target_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#target_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
1176 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]cast().(target_node).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
1177 }
1178
1179 /// Insert rule at given position
1180 ///
1181 /// # Example
1182 /// ```
1183 /// use makefile_lossless::Makefile;
1184 /// let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
1185 /// let new_rule: makefile_lossless::Rule = "inserted_rule:\n\tinserted_command\n".parse().unwrap();
1186 /// makefile.insert_rule(1, new_rule).unwrap();
1187 /// let targets: Vec<_> = makefile.rules().flat_map(|r| r.targets().collect::<Vec<_>>()).collect();
1188 /// assert_eq!(targets, vec!["rule1", "inserted_rule", "rule2"]);
1189 /// ```
1190 pub fn insert_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_rule().(&mut self, index: usize, new_rule: Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1191 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
1192 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1193 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1194 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|n| n.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().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#)
1195 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1196
1197 if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1198 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1199 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1200 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Rule index {} out of bounds (max {})", index, rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()),
1201 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1202 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "insert_rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1203 }],
1204 }));
1205 }
1206
1207 let target_index = if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1208 // Insert at the end
1209 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
1210 } else {
1211 // Insert before the rule at the given index
1212 rules[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().()
1213 };
1214
1215 // Build the nodes to insert
1216 let mut nodes_to_insert = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1217
1218 // Determine if we need to add blank lines to maintain formatting consistency
1219 if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().rules.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1220 // Inserting before the first rule - check if first rule has a blank line before it
1221 // If so, we should add one after our new rule instead
1222 // For now, just add the rule without a blank line before it
1223 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(new_rule.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1224
1225 // Add a blank line after the new rule
1226 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1227 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1228 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1229 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1230 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1231 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1232 } else if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1233 // Inserting in the middle (before an existing rule)
1234 // The syntax tree structure is: ... [maybe BLANK_LINE] RULE(target) ...
1235 // We're inserting right before RULE(target)
1236
1237 // If there's a BLANK_LINE immediately before the target rule,
1238 // it will stay there and separate the previous rule from our new rule.
1239 // We don't need to add a BLANK_LINE before our new rule in that case.
1240
1241 // But we DO need to add a BLANK_LINE after our new rule to separate it
1242 // from the target rule (which we're inserting before).
1243
1244 // Check if there's a blank line immediately before target_index
1245 let has_blank_before = if target_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
1246 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1247 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
1248 .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(target_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1)
1249 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|n| n.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|node| node.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().BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#))
1250 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false)
1251 } else {
1252 false
1253 };
1254
1255 // Only add a blank before if there isn't one already and we're not at the start
1256 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_blank_before && index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
1257 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1258 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1259 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1260 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1261 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1262 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1263 }
1264
1265 // Add the new rule
1266 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(new_rule.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1267
1268 // Always add a blank line after the new rule to separate it from the next rule
1269 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1270 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1271 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1272 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1273 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1274 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1275 } else {
1276 // Inserting at the end when there are existing rules
1277 // Add a blank line before the new rule
1278 let mut bl_builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1279 bl_builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(BLANK_LINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BLANK_LINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1280 bl_builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1281 bl_builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1282 let blank_line = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(bl_builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1283 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(blank_line.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1284
1285 // Add the new rule
1286 nodes_to_insert.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(new_rule.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1287 }
1288
1289 // Insert all nodes at the target index
1290 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1291 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(target_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#target_index, nodes_to_insert);
1292 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1293 }
1294
1295 /// Get all include directives in the makefile
1296 ///
1297 /// # Example
1298 /// ```
1299 /// use makefile_lossless::Makefile;
1300 /// let makefile: Makefile = "include config.mk\n-include .env\n".parse().unwrap();
1301 /// let includes = makefile.includes().collect::<Vec<_>>();
1302 /// assert_eq!(includes.len(), 2);
1303 /// ```
1304 pub fn includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#> {
1305 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().)
1306 }
1307
1308 /// Get all included file paths
1309 ///
1310 /// # Example
1311 /// ```
1312 /// use makefile_lossless::Makefile;
1313 /// let makefile: Makefile = "include config.mk\n-include .env\n".parse().unwrap();
1314 /// let paths = makefile.included_files().collect::<Vec<_>>();
1315 /// assert_eq!(paths, vec!["config.mk", ".env"]);
1316 /// ```
1317 pub fn included_filesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]included_files().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> + '_ {
1318 // We need to collect all Include nodes from anywhere in the syntax tree,
1319 // not just direct children of the root, to handle includes in conditionals
1320 fn collect_includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/collect_includes().(node: &SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#> {
1321 let mut includes = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
1322
1323 // First check if this node itself is an Include
1324 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(include) = Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().()) {
1325 includes.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(include);
1326 }
1327
1328 // Then recurse into all children
1329 for child in node.childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().() {
1330 includes.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(collect_includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/collect_includes().(&child));
1331 }
1332
1333 includes
1334 }
1335
1336 // Start collection from the root node
1337 let includes = collect_includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/collect_includes().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().());
1338
1339 // Convert to an iterator of paths
1340 includes.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|include| {
1341 include
1342 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]syntax().()
1343 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1344 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|node| node.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#)
1345 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|expr| expr.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().().trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
1346 .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().()
1347 })
1348 }
1349
1350 /// Find the first rule with a specific target name
1351 ///
1352 /// # Example
1353 /// ```
1354 /// use makefile_lossless::Makefile;
1355 /// let makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
1356 /// let rule = makefile.find_rule_by_target("rule2");
1357 /// assert!(rule.is_some());
1358 /// assert_eq!(rule.unwrap().targets().collect::<Vec<_>>(), vec!["rule2"]);
1359 /// ```
1360 pub fn find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().(&self, target: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> {
1361 self.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().()
1362 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|rule| rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().target))
1363 }
1364
1365 /// Find all rules with a specific target name
1366 ///
1367 /// # Example
1368 /// ```
1369 /// use makefile_lossless::Makefile;
1370 /// let makefile: Makefile = "rule1:\n\tcommand1\nrule1:\n\tcommand2\nrule2:\n\tcommand3\n".parse().unwrap();
1371 /// let rules: Vec<_> = makefile.find_rules_by_target("rule1").collect();
1372 /// assert_eq!(rules.len(), 2);
1373 /// ```
1374 pub fn find_rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target().<'a>(&'a self, target: &'a str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> + 'a {
1375 self.rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_by_target().(target)
1376 }
1377
1378 /// Find the first rule whose target matches the given pattern
1379 ///
1380 /// Supports make-style pattern matching where `%` in a rule's target acts as a wildcard.
1381 /// For example, a rule with target `%.o` will match `foo.o`, `bar.o`, etc.
1382 ///
1383 /// # Example
1384 /// ```
1385 /// use makefile_lossless::Makefile;
1386 /// let makefile: Makefile = "%.o: %.c\n\t$(CC) -c $<\n".parse().unwrap();
1387 /// let rule = makefile.find_rule_by_target_pattern("foo.o");
1388 /// assert!(rule.is_some());
1389 /// ```
1390 pub fn find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().(&self, target: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> {
1391 self.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().()
1392 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|rule| rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().(&t, target)))
1393 }
1394
1395 /// Find all rules whose targets match the given pattern
1396 ///
1397 /// Supports make-style pattern matching where `%` in a rule's target acts as a wildcard.
1398 /// For example, a rule with target `%.o` will match `foo.o`, `bar.o`, etc.
1399 ///
1400 /// # Example
1401 /// ```
1402 /// use makefile_lossless::Makefile;
1403 /// let makefile: Makefile = "%.o: %.c\n\t$(CC) -c $<\n%.o: %.s\n\t$(AS) -o $@ $<\n".parse().unwrap();
1404 /// let rules: Vec<_> = makefile.find_rules_by_target_pattern("foo.o").collect();
1405 /// assert_eq!(rules.len(), 2);
1406 /// ```
1407 pub fn find_rules_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rules_by_target_pattern().<'a>(
1408 &'a self,
1409 target: &'a str,
1410 ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> + 'a {
1411 self.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().()
1412 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(move |rule| rule.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| matches_patternrust-analyzer cargo makefile-lossless 0.3.40 pattern/matches_pattern().(&t, target)))
1413 }
1414
1415 /// Add a target to .PHONY (creates .PHONY rule if it doesn't exist)
1416 ///
1417 /// # Example
1418 /// ```
1419 /// use makefile_lossless::Makefile;
1420 /// let mut makefile = Makefile::new();
1421 /// makefile.add_phony_target("clean").unwrap();
1422 /// assert!(makefile.is_phony("clean"));
1423 /// ```
1424 pub fn add_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_phony_target().(&mut self, target: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1425 // Find existing .PHONY rule
1426 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut phony_rule) = self.find_rule_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target().(".PHONY") {
1427 // Check if target is already in prerequisites
1428 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().phony_rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|p| p rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().target) {
1429 phony_rule.add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_prerequisite().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1430 }
1431 } else {
1432 // Create new .PHONY rule
1433 let mut phony_rule = self.add_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_rule().(".PHONY");
1434 phony_rule.add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_prerequisite().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1435 }
1436 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1437 }
1438
1439 /// Remove a target from .PHONY (removes .PHONY rule if it becomes empty)
1440 ///
1441 /// Returns `true` if the target was found and removed, `false` if it wasn't in .PHONY.
1442 /// If there are multiple .PHONY rules, it removes the target from the first rule that contains it.
1443 ///
1444 /// # Example
1445 /// ```
1446 /// use makefile_lossless::Makefile;
1447 /// let mut makefile: Makefile = ".PHONY: clean test\n".parse().unwrap();
1448 /// assert!(makefile.remove_phony_target("clean").unwrap());
1449 /// assert!(!makefile.is_phony("clean"));
1450 /// assert!(makefile.is_phony("test"));
1451 /// ```
1452 pub fn remove_phony_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]remove_phony_target().(&mut self, target: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1453 // Find the first .PHONY rule that contains the target
1454 let mut phony_rule = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1455 for rule in self.rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_by_target().(".PHONY") {
1456 if rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|p| p rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().target) {
1457 phony_rule = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rule);
1458 break;
1459 }
1460 }
1461
1462 let mut phony_rule = match phony_rule {
1463 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(rule) => rule,
1464 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false),
1465 };
1466
1467 // Count prerequisites before removal
1468 let prereq_count = phony_rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().countrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/into_iter/impl#[`IntoIter<T, A>`][Iterator]count().();
1469
1470 // Remove the prerequisite
1471 phony_rule.remove_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_prerequisite().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1472
1473 // Check if .PHONY has no more prerequisites, if so remove the rule
1474 if prereq_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 {
1475 // We just removed the last prerequisite, so remove the entire rule
1476 phony_rule.removerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1477 }
1478
1479 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true)
1480 }
1481
1482 /// Check if a target is marked as phony
1483 ///
1484 /// # Example
1485 /// ```
1486 /// use makefile_lossless::Makefile;
1487 /// let makefile: Makefile = ".PHONY: clean test\n".parse().unwrap();
1488 /// assert!(makefile.is_phony("clean"));
1489 /// assert!(makefile.is_phony("test"));
1490 /// assert!(!makefile.is_phony("build"));
1491 /// ```
1492 pub fn is_phonyrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]is_phony().(&self, target: &str) -> bool {
1493 // Check all .PHONY rules since there can be multiple
1494 self.rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_by_target().(".PHONY")
1495 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|rule| rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|p| p rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().target))
1496 }
1497
1498 /// Get all phony targets
1499 ///
1500 /// # Example
1501 /// ```
1502 /// use makefile_lossless::Makefile;
1503 /// let makefile: Makefile = ".PHONY: clean test build\n".parse().unwrap();
1504 /// let phony_targets: Vec<_> = makefile.phony_targets().collect();
1505 /// assert_eq!(phony_targets, vec!["clean", "test", "build"]);
1506 /// ```
1507 pub fn phony_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]phony_targets().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> + '_ {
1508 // Collect from all .PHONY rules since there can be multiple
1509 self.rules_by_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_by_target().(".PHONY")
1510 .flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(|rule| rule.prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().().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#<_>>())
1511 }
1512
1513 /// Add a new include directive at the beginning of the makefile
1514 ///
1515 /// # Arguments
1516 /// * `path` - The file path to include (e.g., "config.mk")
1517 ///
1518 /// # Example
1519 /// ```
1520 /// use makefile_lossless::Makefile;
1521 /// let mut makefile = Makefile::new();
1522 /// makefile.add_include("config.mk");
1523 /// assert_eq!(makefile.included_files().collect::<Vec<_>>(), vec!["config.mk"]);
1524 /// ```
1525 pub fn add_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]add_include().(&mut self, path: &str) -> Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include# {
1526 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1527 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1528 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "include");
1529 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), " ");
1530
1531 // Wrap path in EXPR node
1532 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1533 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), path);
1534 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1535
1536 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1537 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1538
1539 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1540
1541 // Insert at the beginning (position 0)
1542 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
1543
1544 // Return the newly added include (first child)
1545 Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().nextrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNodeChildren<L>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
1546 }
1547
1548 /// Insert an include directive at a specific position
1549 ///
1550 /// The position is relative to other top-level items (rules, variables, includes, conditionals).
1551 ///
1552 /// # Arguments
1553 /// * `index` - The position to insert at (0 = beginning, items().count() = end)
1554 /// * `path` - The file path to include (e.g., "config.mk")
1555 ///
1556 /// # Example
1557 /// ```
1558 /// use makefile_lossless::Makefile;
1559 /// let mut makefile: Makefile = "VAR = value\nrule:\n\tcommand\n".parse().unwrap();
1560 /// makefile.insert_include(1, "config.mk").unwrap();
1561 /// let items: Vec<_> = makefile.items().collect();
1562 /// assert_eq!(items.len(), 3); // VAR, include, rule
1563 /// ```
1564 pub fn insert_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include().(&mut self, index: usize, path: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1565 let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1566
1567 if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1568 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1569 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1570 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Index {} out of bounds (max {})", index, items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()),
1571 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1572 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "insert_include".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1573 }],
1574 }));
1575 }
1576
1577 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1578 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1579 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "include");
1580 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), " ");
1581
1582 // Wrap path in EXPR node
1583 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1584 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), path);
1585 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1586
1587 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1588 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1589
1590 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1591
1592 let target_index = if index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
1593 // Insert at the end
1594 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#count().()
1595 } else {
1596 // Insert before the item at the given index
1597 items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().()
1598 };
1599
1600 // Insert the include node
1601 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1602 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(target_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#target_index, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
1603
1604 // Find and return the newly added include
1605 // It should be at the child index we inserted at
1606 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(index).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
1607 }
1608
1609 /// Insert an include directive after a specific MakefileItem
1610 ///
1611 /// This is useful when you want to insert an include relative to another item in the makefile.
1612 ///
1613 /// # Arguments
1614 /// * `after` - The MakefileItem to insert after
1615 /// * `path` - The file path to include (e.g., "config.mk")
1616 ///
1617 /// # Example
1618 /// ```
1619 /// use makefile_lossless::Makefile;
1620 /// let mut makefile: Makefile = "VAR1 = value1\nVAR2 = value2\n".parse().unwrap();
1621 /// let first_var = makefile.items().next().unwrap();
1622 /// makefile.insert_include_after(&first_var, "config.mk").unwrap();
1623 /// let paths: Vec<_> = makefile.included_files().collect();
1624 /// assert_eq!(paths, vec!["config.mk"]);
1625 /// ```
1626 pub fn insert_include_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]insert_include_after().(
1627 &mut self,
1628 after: &MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#,
1629 path: &str,
1630 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#, Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1631 let mut builder = GreenNodeBuilderrust-analyzer cargo rowan 0.16.1 green/builder/GreenNodeBuilder#::newrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]new().();
1632 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(INCLUDErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INCLUDE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1633 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "include");
1634 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), " ");
1635
1636 // Wrap path in EXPR node
1637 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
1638 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), path);
1639 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1640
1641 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\n");
1642 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
1643
1644 let syntax = SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#::new_root_mutrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]new_root_mut().(builder.finishrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish().());
1645
1646 // Find the position of the item to insert after
1647 let after_syntax = after.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().();
1648 let target_index = after_syntax.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
1649
1650 // Insert the include node after the target item
1651 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1652 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(target_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#target_index, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
1653
1654 // Find and return the newly added include
1655 // It should be the child immediately after the 'after' item
1656 let after_child_index = self
1657 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().()
1658 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1659 .positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#position().(|child| child.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().() rust-analyzer cargo text-size 1.1.1 range/impl#[TextRange][`PartialEq<Self>`]eq().==rust-analyzer cargo text-size 1.1.1 range/impl#[TextRange][`PartialEq<Self>`]eq(). rust-analyzer cargo text-size 1.1.1 range/impl#[TextRange][`PartialEq<Self>`]eq().after_syntax.text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().())
1660 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
1661 Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#::Parserust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#Parse#(ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError# {
1662 errorsrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#errors.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ErrorInforust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo# {
1663 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "Could not find the reference item".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1664 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1665 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "insert_include_after".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1666 }],
1667 })
1668 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1669
1670 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Includerust-analyzer cargo makefile-lossless 0.3.40 lossless/Include#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Include][AstNode]cast().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Makefile][AstNode]syntax().().childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(after_child_index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
1671 }
1672 }
1673
1674 #[cfg(test)]
1675 mod testsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/ {
1676 use superrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/::*;
1677
1678 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1679 fn test_makefile_item_replace_variable_with_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_replace_variable_with_variable().() {
1680 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = old\nrule:\n\tcommand\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1681 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR2 = new\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1682 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1683 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1684 first_item.replacerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]replace().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1685
1686 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1687 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR2 = new\nrule:\n\tcommand\n");
1688 }
1689
1690 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1691 fn test_makefile_item_replace_variable_with_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_replace_variable_with_rule().() {
1692 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = value\nrule1:\n\tcommand1\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1693 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "new_rule:\n\tnew_command\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1694 let new_rule = temp.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1695 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1696 first_item.replacerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]replace().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(new_rule)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1697
1698 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1699 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "new_rule:\n\tnew_command\nrule1:\n\tcommand1\n");
1700 }
1701
1702 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1703 fn test_makefile_item_replace_preserves_positionrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_replace_preserves_position().() {
1704 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = second\nVAR3 = third\n"
1705 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
1706 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1707 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "NEW = replacement\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1708 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1709
1710 // Replace the second item
1711 let mut second_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1712 second_item
1713 .replacerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]replace().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
1714 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1715
1716 let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1717 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3);
1718 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("VAR1".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
1719 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("NEW".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
1720 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 ast/variable/impl#[VariableDefinition]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("VAR3".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
1721 }
1722
1723 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1724 fn test_makefile_item_add_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_add_comment().() {
1725 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1726 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1727 item.add_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]add_comment().("This is a variable").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1728
1729 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1730 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "# This is a variable\nVAR = value\n");
1731 }
1732
1733 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1734 fn test_makefile_item_add_multiple_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_add_multiple_comments().() {
1735 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1736 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1737 item.add_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]add_comment().("Comment 1").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1738 // Note: After modifying the tree, we need to get a fresh reference
1739 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1740 item.add_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]add_comment().("Comment 2").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1741
1742 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1743 // Comments are added before the item, so adding Comment 2 after Comment 1
1744 // results in Comment 1 appearing first (furthest from item), then Comment 2
1745 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "# Comment 1\n# Comment 2\nVAR = value\n");
1746 }
1747
1748 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1749 fn test_makefile_item_preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_preceding_comments().() {
1750 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment 1\n# Comment 2\nVAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1751 let item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1752 let comments: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = item.preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]preceding_comments().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1753 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
1754 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "Comment 1");
1755 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "Comment 2");
1756 }
1757
1758 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1759 fn test_makefile_item_preceding_comments_no_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_preceding_comments_no_comments().() {
1760 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1761 let item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1762 let comments: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = item.preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]preceding_comments().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1763 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
1764 }
1765
1766 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1767 fn test_makefile_item_preceding_comments_ignores_shebangrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_preceding_comments_ignores_shebang().() {
1768 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "#!/usr/bin/make\n# Real comment\nVAR = value\n"
1769 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
1770 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1771 let item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1772 let comments: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = item.preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]preceding_comments().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1773 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
1774 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "Real comment");
1775 }
1776
1777 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1778 fn test_makefile_item_remove_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_remove_comments().() {
1779 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment 1\n# Comment 2\nVAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1780 // Get a fresh reference to the item to ensure we have the current tree state
1781 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1782 let count = item.remove_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]remove_comments().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1783
1784 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 2);
1785 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1786 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR = value\n");
1787 }
1788
1789 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1790 fn test_makefile_item_remove_comments_no_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_remove_comments_no_comments().() {
1791 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1792 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1793 let count = item.remove_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]remove_comments().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1794
1795 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 0);
1796 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "VAR = value\n");
1797 }
1798
1799 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1800 fn test_makefile_item_modify_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_modify_comment().() {
1801 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Old comment\nVAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1802 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1803 let modified = item.modify_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]modify_comment().("New comment").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1804
1805 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(modified);
1806 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1807 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "# New comment\nVAR = value\n");
1808 }
1809
1810 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1811 fn test_makefile_item_modify_comment_no_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_modify_comment_no_comment().() {
1812 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1813 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1814 let modified = item.modify_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]modify_comment().("New comment").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1815
1816 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().modified);
1817 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "VAR = value\n");
1818 }
1819
1820 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1821 fn test_makefile_item_modify_comment_modifies_closestrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_modify_comment_modifies_closest().() {
1822 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment 1\n# Comment 2\n# Comment 3\nVAR = value\n"
1823 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
1824 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1825 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1826 let modified = item.modify_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]modify_comment().("Modified").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1827
1828 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(modified);
1829 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1830 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1831 result,
1832 "# Comment 1\n# Comment 2\n# Modified\nVAR = value\n"
1833 );
1834 }
1835
1836 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1837 fn test_makefile_item_comment_workflowrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_comment_workflow().() {
1838 // Test adding, modifying, and removing comments in sequence
1839 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1840 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1841
1842 // Add a comment
1843 item.add_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]add_comment().("Initial comment").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1844 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "# Initial comment\nVAR = value\n");
1845
1846 // Get a fresh reference after modification
1847 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1848 // Modify it
1849 item.modify_commentrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]modify_comment().("Updated comment").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1850 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "# Updated comment\nVAR = value\n");
1851
1852 // Get a fresh reference after modification
1853 let mut item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1854 // Remove it
1855 let count = item.remove_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]remove_comments().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1856 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(count, 1);
1857 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "VAR = value\n");
1858 }
1859
1860 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1861 fn test_makefile_item_replace_with_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_replace_with_comments().() {
1862 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment for VAR1\nVAR1 = old\nrule:\n\tcommand\n"
1863 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
1864 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1865 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR2 = new\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1866 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1867 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1868
1869 // Verify comment exists before replace
1870 let comments: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = first_item.preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]preceding_comments().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1871 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
1872 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(comments[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., "Comment for VAR1");
1873
1874 // Replace the item
1875 first_item.replacerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]replace().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1876
1877 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1878 // The comment should still be there (replace preserves preceding comments)
1879 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "# Comment for VAR1\nVAR2 = new\nrule:\n\tcommand\n");
1880 }
1881
1882 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1883 fn test_makefile_item_insert_before_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_before_variable().() {
1884 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = second\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1885 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1886 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1887 let mut second_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1888 second_item
1889 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
1890 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1891
1892 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1893 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR1 = first\nVAR_NEW = inserted\nVAR2 = second\n");
1894 }
1895
1896 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1897 fn test_makefile_item_insert_after_variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_after_variable().() {
1898 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = second\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1899 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1900 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1901 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1902 first_item
1903 .insert_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_after().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
1904 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1905
1906 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1907 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR1 = first\nVAR_NEW = inserted\nVAR2 = second\n");
1908 }
1909
1910 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1911 fn test_makefile_item_insert_before_first_itemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_before_first_item().() {
1912 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = second\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1913 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1914 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1915 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1916 first_item
1917 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
1918 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1919
1920 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1921 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR_NEW = inserted\nVAR1 = first\nVAR2 = second\n");
1922 }
1923
1924 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1925 fn test_makefile_item_insert_after_last_itemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_after_last_item().() {
1926 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = second\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1927 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1928 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1929 let mut last_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1930 last_item
1931 .insert_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_after().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
1932 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1933
1934 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1935 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR1 = first\nVAR2 = second\nVAR_NEW = inserted\n");
1936 }
1937
1938 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1939 fn test_makefile_item_insert_before_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_before_include().() {
1940 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = value\nrule:\n\tcommand\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1941 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include test.mk\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1942 let new_include = temp.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1943 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1944 first_item
1945 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Include#(new_include))
1946 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1947
1948 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1949 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "include test.mk\nVAR1 = value\nrule:\n\tcommand\n");
1950 }
1951
1952 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1953 fn test_makefile_item_insert_after_includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_after_include().() {
1954 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = value\nrule:\n\tcommand\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1955 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "include test.mk\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1956 let new_include = temp.includesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]includes().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1957 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1958 first_item
1959 .insert_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_after().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Includerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Include#(new_include))
1960 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1961
1962 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1963 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR1 = value\ninclude test.mk\nrule:\n\tcommand\n");
1964 }
1965
1966 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1967 fn test_makefile_item_insert_before_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_before_rule().() {
1968 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1969 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "new_rule:\n\tnew_command\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1970 let new_rule = temp.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1971 let mut second_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1972 second_item
1973 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(new_rule))
1974 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1975
1976 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1977 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1978 result,
1979 "rule1:\n\tcommand1\nnew_rule:\n\tnew_command\nrule2:\n\tcommand2\n"
1980 );
1981 }
1982
1983 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1984 fn test_makefile_item_insert_after_rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_after_rule().() {
1985 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1986 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "new_rule:\n\tnew_command\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1987 let new_rule = temp.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1988 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
1989 first_item
1990 .insert_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_after().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Rulerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Rule#(new_rule))
1991 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1992
1993 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1994 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1995 result,
1996 "rule1:\n\tcommand1\nnew_rule:\n\tnew_command\nrule2:\n\tcommand2\n"
1997 );
1998 }
1999
2000 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2001 fn test_makefile_item_insert_before_with_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_before_with_comments().() {
2002 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment 1\nVAR1 = first\n# Comment 2\nVAR2 = second\n"
2003 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
2004 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2005 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2006 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2007 let mut second_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2008 second_item
2009 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
2010 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2011
2012 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
2013 // The new variable should be inserted before Comment 2 (which precedes VAR2)
2014 // This is correct because insert_before inserts before the item and its preceding comments
2015 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
2016 result,
2017 "# Comment 1\nVAR1 = first\n# Comment 2\nVAR_NEW = inserted\nVAR2 = second\n"
2018 );
2019 }
2020
2021 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2022 fn test_makefile_item_insert_after_with_commentsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_after_with_comments().() {
2023 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# Comment 1\nVAR1 = first\n# Comment 2\nVAR2 = second\n"
2024 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
2025 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2026 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2027 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2028 let mut first_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2029 first_item
2030 .insert_afterrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_after().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
2031 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2032
2033 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
2034 // The new variable should be inserted between VAR1 and Comment 2/VAR2
2035 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
2036 result,
2037 "# Comment 1\nVAR1 = first\nVAR_NEW = inserted\n# Comment 2\nVAR2 = second\n"
2038 );
2039 }
2040
2041 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2042 fn test_makefile_item_insert_before_preserves_formattingrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_before_preserves_formatting().() {
2043 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = second\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2044 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_NEW = inserted\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2045 let new_var = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().nextrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[`RecursiveItemsIter<T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2046 let mut second_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2047 second_item
2048 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_var))
2049 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2050
2051 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
2052 // Formatting of the new item is preserved from its source
2053 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
2054 result,
2055 "VAR1 = first\nVAR_NEW = inserted\nVAR2 = second\n"
2056 );
2057 }
2058
2059 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2060 fn test_makefile_item_insert_multiple_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_makefile_item_insert_multiple_items().() {
2061 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR1 = first\nVAR2 = last\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2062 let temp: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR_A = a\nVAR_B = b\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2063 let mut new_vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = temp.variable_definitionsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2064
2065 let mut target_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2066 target_item
2067 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_vars.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()))
2068 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2069
2070 // Get fresh reference after first insertion
2071 let mut target_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2072 target_item
2073 .insert_beforerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]insert_before().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(new_vars.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()))
2074 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2075
2076 let result = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
2077 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(result, "VAR1 = first\nVAR_A = a\nVAR_B = b\nVAR2 = last\n");
2078 }
2079
2080 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2081 fn test_rules_after_nested_conditionalsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_rules_after_nested_conditionals().() {
2082 // Test for bug where .rules() returns no rules after nested conditionals
2083 // This was reported in https://bugs.debian.org/1126511
2084 let makefile_content = r#"#!/usr/bin/make -f
2085
2086 ifeq ($(filter nodoc, $(DEB_BUILD_OPTIONS)),)
2087 ifneq ($(shell which valadoc),)
2088 BUILD_DOC:=-Ddocs=true
2089 endif
2090 endif
2091
2092 %:
2093 dh $@
2094
2095 override_dh_auto_configure:
2096 echo test
2097 "#;
2098 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = makefile_content.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2099
2100 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rulesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2101 let targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>> = rules.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]targets().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2102 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
2103 rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
2104 2,
2105 "Expected 2 rules (% and override_dh_auto_configure), got {} rules with targets: {:?}",
2106 rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
2107 targets
2108 );
2109
2110 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["%"]);
2111 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(targets[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["override_dh_auto_configure"]);
2112
2113 // Also test that pattern matching works
2114 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile.find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("build-arch").is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
2115 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(makefile
2116 .find_rule_by_target_patternrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]find_rule_by_target_pattern().("build-indep")
2117 .is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().());
2118 }
2119
2120 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2121 fn test_items_in_range_single_itemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_items_in_range_single_item().() {
2122 let input = "CC = gcc\n\nall: build\n\techo done\n";
2123 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2124 // Range covering just the variable definition "CC = gcc\n"
2125 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), 8.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2126 let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2127 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
2128 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(items[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()., MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::Variablerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#Variable#(_)));
2129 }
2130
2131 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2132 fn test_items_in_range_multiple_itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_items_in_range_multiple_items().() {
2133 let input = "CC = gcc\n\nall: build\n\techo done\n";
2134 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2135 // Range covering the whole file
2136 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), (input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() as u32).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2137 let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2138 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
2139 }
2140
2141 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2142 fn test_items_in_range_no_overlaprust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_items_in_range_no_overlap().() {
2143 let input = "CC = gcc\n\nall: build\n\techo done\n";
2144 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2145 // Range in the blank line between items
2146 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(9.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), 10.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2147 let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2148 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
2149 }
2150
2151 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2152 fn test_items_in_range_partial_overlaprust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_items_in_range_partial_overlap().() {
2153 let input = "CC = gcc\nLD = ld\nall: build\n\techo done\n";
2154 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2155 // Range overlapping end of first var and start of second
2156 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(5.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), 12.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2157 let items: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.items_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2158 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(items.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
2159 }
2160
2161 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2162 fn test_rules_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_rules_in_range().() {
2163 let input = "CC = gcc\nall: build\n\techo done\nclean:\n\trm -rf build\n";
2164 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2165 // Range covering the whole file
2166 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), (input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() as u32).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2167 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rules_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2168 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
2169
2170 // Range covering only the variable
2171 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), 9.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2172 let rules: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.rules_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]rules_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2173 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
2174 }
2175
2176 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2177 fn test_variable_definitions_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_variable_definitions_in_range().() {
2178 let input = "CC = gcc\nLD = ld\nall: build\n\techo done\n";
2179 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2180 // Range covering the two variable definitions
2181 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), 17.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2182 let vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_definitions_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2183 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
2184
2185 // Range covering only the rule
2186 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(17.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), (input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() as u32).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2187 let vars: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_definitions_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_definitions_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2188 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vars.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
2189 }
2190
2191 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2192 fn test_variable_references_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_variable_references_in_range().() {
2193 let input = "CFLAGS = $(BASE) -Wall\nall: $(TARGETS)\n\techo done\n";
2194 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = input.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2195
2196 // Full range should find the same refs as variable_references()
2197 let all_refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_referencesrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2198 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), (input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() as u32).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2199 let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_references_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2200 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), all_refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
2201
2202 // Range covering only the variable definition should find $(BASE)
2203 // Find the actual end of the variable item
2204 let var_item = makefile.itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]items().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter_map/impl#[`FilterMap<I, F>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
2205 let var_end: u32 = var_item.syntaxrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]syntax().().text_rangerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]text_range().().endrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]end().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
2206 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), var_end.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2207 let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_references_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2208 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
2209 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("BASE".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
2210
2211 // Range covering only the rule should find $(TARGETS)
2212 let range = rowanrust-analyzer cargo rowan 0.16.1 crate/::TextRangerust-analyzer cargo text-size 1.1.1 range/TextRange#::newrust-analyzer cargo text-size 1.1.1 range/impl#[TextRange]new().(var_end.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), (input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() as u32).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
2213 let refs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.variable_references_in_rangerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]variable_references_in_range().(range).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2214 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
2215 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(refs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..namerust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableReference]name().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("TARGETS".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()));
2216 }
2217
2218 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2219 fn test_comment_blocks_single_blockrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_comment_blocks_single_block().() {
2220 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# line 1\n# line 2\n# line 3\nall:\n\techo done\n"
2221 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
2222 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2223 let blocks: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.comment_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]comment_blocks().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2224 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blocks.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
2225 let text = &makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#::fromrust-analyzer cargo text-size 1.1.1 range/impl#[`Range<T>`][`From<TextRange>`]from().(blocks[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().;
2226 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("# line 1"));
2227 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(text.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("# line 3"));
2228 }
2229
2230 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2231 fn test_comment_blocks_multiple_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_comment_blocks_multiple_blocks().() {
2232 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# =
2233 "# block 1a\n# block 1b\nVAR = value\n# block 2a\n# block 2b\nall:\n\techo done\n"
2234 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().()
2235 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2236 let blocks: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.comment_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]comment_blocks().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2237 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blocks.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 2);
2238 }
2239
2240 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2241 fn test_comment_blocks_no_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_comment_blocks_no_blocks().() {
2242 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "VAR = value\nall:\n\techo done\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2243 let blocks: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.comment_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]comment_blocks().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2244 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blocks.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
2245 }
2246
2247 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2248 fn test_comment_blocks_single_comment_not_a_blockrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_comment_blocks_single_comment_not_a_block().() {
2249 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# just one line\nVAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2250 let blocks: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.comment_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]comment_blocks().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2251 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blocks.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
2252 }
2253
2254 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
2255 fn test_comment_blocks_with_blank_line_betweenrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/tests/test_comment_blocks_with_blank_line_between().() {
2256 let makefile: Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# = "# line 1\n\n# line 2\nVAR = value\n".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
2257 let blocks: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = makefile.comment_blocksrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]comment_blocks().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
2258 // Blank lines between comments should still form a block
2259 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(blocks.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
2260 }
2261 }