Debian Codegraph @

src/ast/rule.rs

raw symbols SCIP
1 use superrust-analyzer cargo makefile-lossless 0.3.40 ast/::makefilerust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/::MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#;
2 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::{
3 remove_with_preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/remove_with_preceding_comments()., trim_trailing_newlinesrust-analyzer cargo makefile-lossless 0.3.40 lossless/trim_trailing_newlines()., 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#,
4 Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#, ParseErrorrust-analyzer cargo makefile-lossless 0.3.40 lossless/ParseError#, Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe#, Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#, SyntaxElementrust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxElement#, SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode#,
5 };
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
10 // Helper function to build a PREREQUISITES node containing PREREQUISITE nodes
11 fn build_prerequisites_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_prerequisites_node().(prereqs: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#], include_leading_space: bool) -> SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode# {
12 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().();
13 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
14
15 for (i, prereq) in prereqs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
16 // Add space: before first prerequisite if requested, and between all prerequisites
17 if (i 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 && include_leading_space) || i 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 {
18 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().(), " ");
19 }
20
21 // Build each PREREQUISITE node
22 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(PREREQUISITErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
23 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().(), prereq);
24 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
25 }
26
27 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
28 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().())
29 }
30
31 // Helper function to build targets section (TARGETS node)
32 fn build_targets_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_targets_node().(targets: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]) -> SyntaxNoderust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxNode# {
33 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().();
34 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
35
36 for (i, target) in targets.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
37 if i 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 {
38 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().(), " ");
39 }
40 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);
41 }
42
43 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
44 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().())
45 }
46
47 /// Represents different types of items that can appear in a Rule's body
48 #[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:)]
49 pub enum RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem# {
50 /// A recipe line (command to execute)
51 Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
52 /// A conditional block within the rule
53 Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#(Conditionalrust-analyzer cargo makefile-lossless 0.3.40 lossless/Conditional#),
54 }
55
56 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem# {
57 fn fmtrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[RuleItem][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
58 match self {
59 RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(text) => f.debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("Recipe").fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(text).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().(),
60 RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#(_) => f
61 .debug_tuplerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_tuple().("Conditional")
62 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]field().(&"<Conditional>")
63 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugTuple<'a, 'b>`]finish().(),
64 }
65 }
66 }
67
68 impl RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem# {
69 /// Try to cast a syntax node to a RuleItem
70 pub(craterust-analyzer cargo makefile-lossless 0.3.40 crate/) fn castrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[RuleItem]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/rule/impl#[RuleItem]> {
71 match node.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() {
72 RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE# => {
73 // Extract the recipe text from the RECIPE node
74 let text = node.children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|it| {
75 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
76 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().TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT# {
77 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
78 }
79 }
80 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
81 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
82 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Reciperust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Recipe#(text))
83 }
84 CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL# => 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().(RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::Conditionalrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#Conditional#),
85 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
86 }
87 }
88 }
89
90 impl Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# {
91 /// Parse rule text, returning a Parse result
92 pub fn parserust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]parse().(text: &str) -> craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#> {
93 craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Parserust-analyzer cargo makefile-lossless 0.3.40 parse/Parse#::<Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#>::parse_rulerust-analyzer cargo makefile-lossless 0.3.40 parse/impl#[`Parse<Rule>`]parse_rule().(text)
94 }
95
96 /// Create a new rule with the given targets, prerequisites, and recipes
97 ///
98 /// # Arguments
99 /// * `targets` - A slice of target names
100 /// * `prerequisites` - A slice of prerequisite names (can be empty)
101 /// * `recipes` - A slice of recipe lines (can be empty)
102 ///
103 /// # Example
104 /// ```
105 /// use makefile_lossless::Rule;
106 ///
107 /// let rule = Rule::new(&["all"], &["build", "test"], &["echo Done"]);
108 /// assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["all"]);
109 /// assert_eq!(rule.prerequisites().collect::<Vec<_>>(), vec!["build", "test"]);
110 /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo Done"]);
111 /// ```
112 pub fn newrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]new().(targets: &[&str], prerequisites: &[&str], recipes: &[&str]) -> Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule# {
113 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().();
114 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().());
115
116 // Build targets
117 for (i, target) in targets.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
118 if i 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 {
119 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().(), " ");
120 }
121 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);
122 }
123
124 // Add colon
125 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().(), ":");
126
127 // Build prerequisites
128 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().prerequisites.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
129 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().(), " ");
130 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
131
132 for (i, prereq) in prerequisites.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
133 if i 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 {
134 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().(), " ");
135 }
136 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(PREREQUISITErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
137 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().(), prereq);
138 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
139 }
140
141 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
142 }
143
144 // Add newline after rule declaration
145 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");
146
147 // Build recipes
148 for recipe in recipes {
149 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
150 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t");
151 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), recipe);
152 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");
153 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
154 }
155
156 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
157
158 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().());
159 Rulerust-analyzer cargo makefile-lossless 0.3.40 lossless/Rule#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]cast().(syntax).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
160 }
161
162 /// Get the parent item of this rule, if any
163 ///
164 /// Returns `Some(MakefileItem)` if this rule has a parent that is a MakefileItem
165 /// (e.g., a Conditional), or `None` if the parent is the root Makefile node.
166 ///
167 /// # Example
168 /// ```
169 /// use makefile_lossless::Makefile;
170 ///
171 /// let makefile: Makefile = r#"ifdef DEBUG
172 /// all:
173 /// echo "test"
174 /// endif
175 /// "#.parse().unwrap();
176 ///
177 /// let cond = makefile.conditionals().next().unwrap();
178 /// let rule = cond.if_items().next().unwrap();
179 /// // Rule's parent is the conditional
180 /// assert!(matches!(rule, makefile_lossless::MakefileItem::Rule(_)));
181 /// ```
182 pub fn parentrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]parent().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#> {
183 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().parentrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]parent().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(MakefileItemrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/MakefileItem#::castrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[MakefileItem]cast().)
184 }
185
186 /// Check if this is a double-colon rule (`target:: prereqs`).
187 ///
188 /// Double-colon rules allow multiple recipe blocks for the same target,
189 /// each executed independently when its prerequisites are newer.
190 ///
191 /// # Example
192 /// ```
193 /// use makefile_lossless::Makefile;
194 /// let makefile: Makefile = "all:: dep1\n\techo first\n".parse().unwrap();
195 /// let rule = makefile.rules().next().unwrap();
196 /// assert!(rule.is_double_colon());
197 /// ```
198 pub fn is_double_colonrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]is_double_colon().(&self) -> bool {
199 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
200 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
201 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|it| it.into_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]into_token().())
202 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# && t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."::")
203 }
204
205 // Helper method to collect variable references from tokens
206 fn collect_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]collect_variable_reference().(
207 &self,
208 tokens: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<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# = SyntaxElementrust-analyzer cargo makefile-lossless 0.3.40 lossless/SyntaxElement#>>,
209 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
210 let mut var_ref = 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().();
211
212 // Check if we're at a $ token
213 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() {
214 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = token.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
215 if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# {
216 var_ref.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
217
218 // Check if the next token is a (
219 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next) = tokens.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
220 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(nt) = next.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
221 if nt.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().LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# {
222 // Consume the opening parenthesis
223 var_ref.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(nt.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
224 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
225
226 // Track parenthesis nesting level
227 let mut paren_count = 1;
228
229 // Keep consuming tokens until we find the matching closing parenthesis
230 for next_token in tokens.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().() {
231 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(nt) = next_token.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
232 var_ref.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(nt.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
233
234 if nt.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().LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# {
235 paren_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;
236 } else if nt.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().RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN# {
237 paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1;
238 if paren_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 {
239 break;
240 }
241 }
242 }
243 }
244
245 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var_ref);
246 }
247 }
248 }
249
250 // Handle simpler variable references (though this branch may be less common)
251 for next_token in tokens.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().() {
252 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(nt) = next_token.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
253 var_ref.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(nt.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
254 if nt.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().RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN# {
255 break;
256 }
257 }
258 }
259 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var_ref);
260 }
261 }
262 }
263
264 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
265 }
266
267 // Helper method to extract targets from a TARGETS node
268 fn extract_targets_from_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]extract_targets_from_node().(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#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
269 let mut result = 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 current_target = 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().();
271 let mut in_parens = 0;
272
273 for child in node.children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
274 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = child.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
275 match token.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() {
276 IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# => {
277 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
278 }
279 WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE# | INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT# | BACKSLASHrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#BACKSLASH# | NEWLINErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#NEWLINE# => {
280 // Whitespace and line continuations (backslash-newline
281 // plus the continued line's indent) delimit targets,
282 // unless we're inside parentheses.
283 if in_parens rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().current_target.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
284 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(current_target.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().());
285 current_target.clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]clear().();
286 } else if in_parens rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 {
287 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
288 }
289 }
290 LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# => {
291 in_parens 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;
292 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
293 }
294 RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN# => {
295 in_parens rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1;
296 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
297 }
298 DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# => {
299 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
300 }
301 _ => {
302 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
303 }
304 }
305 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(child_node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
306 // Handle nested nodes like ARCHIVE_MEMBERS
307 current_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&child_node.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().());
308 }
309 }
310
311 // Push the last target if any
312 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().current_target.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
313 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(current_target);
314 }
315
316 result
317 }
318
319 /// Targets of this rule
320 ///
321 /// # Example
322 /// ```
323 /// use makefile_lossless::Rule;
324 ///
325 /// let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
326 /// assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["rule"]);
327 /// ```
328 pub fn targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]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#> + '_ {
329 // First check if there's a TARGETS node
330 for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
331 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
332 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().TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS# {
333 // Extract targets from the TARGETS node
334 return Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]::extract_targets_from_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]extract_targets_from_node().(node).into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().();
335 }
336 }
337 // Stop at the operator
338 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = child.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
339 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().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# {
340 break;
341 }
342 }
343 }
344
345 // Fallback to old parsing logic for backward compatibility
346 let mut result = 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().();
347 let mut tokens = self
348 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
349 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
350 .take_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take_while().(|it| it.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(true))
351 .peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
352
353 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = tokens.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().() {
354 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = token.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
355 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); // Consume the node
356 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().EXPRrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#EXPR# {
357 // Handle when the target is an expression node
358 let mut var_content = 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().();
359 for child in node.children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
360 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = child.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
361 var_content.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
362 }
363 }
364 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().var_content.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
365 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(var_content);
366 }
367 }
368 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = token.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
369 if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().DOLLARrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#DOLLAR# {
370 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(var_ref) = self.collect_variable_referencerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]collect_variable_reference().(&mut tokens) {
371 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(var_ref);
372 }
373 } else if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().IDENTIFIERrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#IDENTIFIER# {
374 // Check if this identifier is followed by archive members
375 let ident_text = t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
376 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); // Consume the identifier
377
378 // Peek ahead to see if we have archive member syntax
379 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next) = tokens.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
380 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next_token) = next.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
381 if next_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().LPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#LPAREN# {
382 // This is an archive member target, collect the whole thing
383 let mut archive_target = ident_text;
384 archive_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(next_token.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().()); // Add '('
385 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); // Consume LPAREN
386
387 // Collect everything until RPAREN
388 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = tokens.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() {
389 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = token.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
390 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().ARCHIVE_MEMBERSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#ARCHIVE_MEMBERS# {
391 archive_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&node.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().());
392 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
393 } else {
394 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
395 }
396 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = token.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
397 if t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().RPARENrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RPAREN# {
398 archive_target.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(t.textrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]text().());
399 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
400 break;
401 } else {
402 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
403 }
404 } else {
405 break;
406 }
407 }
408 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(archive_target);
409 } else {
410 // Regular identifier
411 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ident_text);
412 }
413 } else {
414 // Regular identifier
415 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ident_text);
416 }
417 } else {
418 // Regular identifier
419 result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ident_text);
420 }
421 } else {
422 tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); // Skip other token types
423 }
424 }
425 }
426 result.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
427 }
428
429 /// Get the prerequisites in the rule
430 ///
431 /// # Example
432 /// ```
433 /// use makefile_lossless::Rule;
434 /// let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
435 /// assert_eq!(rule.prerequisites().collect::<Vec<_>>(), vec!["dependency"]);
436 /// ```
437 pub fn prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]prerequisites().(&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#> + '_ {
438 // Find PREREQUISITES node after OPERATOR token
439 let mut found_operator = false;
440 let mut prerequisites_node = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
441
442 for element in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
443 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = element.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
444 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().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# {
445 found_operator = true;
446 }
447 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = element.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
448 if found_operator && 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().PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES# {
449 prerequisites_node = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().());
450 break;
451 }
452 }
453 }
454
455 let result: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prereqs) = prerequisites_node {
456 // Iterate over PREREQUISITE child nodes
457 prereqs
458 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
459 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|child| child.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().PREREQUISITErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITE#)
460 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|child| child.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().())
461 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
462 } else {
463 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().()
464 };
465
466 result.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
467 }
468
469 /// Get the commands in the rule
470 ///
471 /// # Example
472 /// ```
473 /// use makefile_lossless::Rule;
474 /// let rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
475 /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["command"]);
476 /// ```
477 pub fn recipesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipes().(&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#> {
478 self.recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.textrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe]text().())
479 }
480
481 /// If this rule is actually a target-specific variable assignment
482 /// (`target: VAR [op] value`), return the embedded [`VariableDefinition`].
483 ///
484 /// # Example
485 /// ```
486 /// use makefile_lossless::Rule;
487 /// let rule: Rule = "all: CFLAGS = -O2\n".parse().unwrap();
488 /// let var = rule.scoped_assignment().unwrap();
489 /// assert_eq!(var.name(), Some("CFLAGS".to_string()));
490 /// assert_eq!(var.assignment_operator(), Some("=".to_string()));
491 /// ```
492 pub fn scoped_assignmentrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]scoped_assignment().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#> {
493 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
494 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
495 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find().(|c| c.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().VARIABLErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#VARIABLE#)
496 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(craterust-analyzer cargo makefile-lossless 0.3.40 crate/::losslessrust-analyzer cargo makefile-lossless 0.3.40 lossless/::VariableDefinitionrust-analyzer cargo makefile-lossless 0.3.40 lossless/VariableDefinition#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[VariableDefinition][AstNode]cast().)
497 }
498
499 /// Get recipe nodes with line/column information
500 ///
501 /// Returns an iterator over `Recipe` AST nodes, which support the `line()`, `column()`,
502 /// and `line_col()` methods to get position information.
503 ///
504 /// # Example
505 /// ```
506 /// use makefile_lossless::Rule;
507 ///
508 /// let rule_text = "test:\n\techo line1\n\techo line2\n";
509 /// let rule: Rule = rule_text.parse().unwrap();
510 ///
511 /// let recipe_nodes: Vec<_> = rule.recipe_nodes().collect();
512 /// assert_eq!(recipe_nodes.len(), 2);
513 /// assert_eq!(recipe_nodes[0].text(), "echo line1");
514 /// assert_eq!(recipe_nodes[0].line(), 1); // 0-indexed
515 /// assert_eq!(recipe_nodes[1].text(), "echo line2");
516 /// assert_eq!(recipe_nodes[1].line(), 2);
517 /// ```
518 pub fn recipe_nodesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_nodes().(&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# = Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe#> {
519 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
520 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
521 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|it| it.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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
522 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(Reciperust-analyzer cargo makefile-lossless 0.3.40 lossless/Recipe#::castrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Recipe][AstNode]cast().)
523 }
524
525 /// Get all items (recipe lines and conditionals) in the rule's body
526 ///
527 /// This method iterates through the rule's body and yields both recipe lines
528 /// and any conditionals that appear within the rule.
529 ///
530 /// # Example
531 /// ```
532 /// use makefile_lossless::{Rule, RuleItem};
533 ///
534 /// let rule_text = r#"test:
535 /// echo "before"
536 /// ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
537 /// ./run-tests
538 /// endif
539 /// echo "after"
540 /// "#;
541 /// let rule: Rule = rule_text.parse().unwrap();
542 ///
543 /// let items: Vec<_> = rule.items().collect();
544 /// assert_eq!(items.len(), 3); // recipe, conditional, recipe
545 ///
546 /// match &items[0] {
547 /// RuleItem::Recipe(r) => assert_eq!(r, "echo \"before\""),
548 /// _ => panic!("Expected recipe"),
549 /// }
550 ///
551 /// match &items[1] {
552 /// RuleItem::Conditional(_) => {},
553 /// _ => panic!("Expected conditional"),
554 /// }
555 ///
556 /// match &items[2] {
557 /// RuleItem::Recipe(r) => assert_eq!(r, "echo \"after\""),
558 /// _ => panic!("Expected recipe"),
559 /// }
560 /// ```
561 pub fn itemsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]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# = RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#> + '_ {
562 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
563 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
564 .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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE# || 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().CONDITIONALrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#CONDITIONAL#)
565 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(RuleItemrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/RuleItem#::castrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[RuleItem]cast().)
566 }
567
568 /// Replace the command at index i with a new line
569 ///
570 /// # Example
571 /// ```
572 /// use makefile_lossless::Rule;
573 /// let mut rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
574 /// rule.replace_command(0, "new command");
575 /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["new command"]);
576 /// ```
577 pub fn replace_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]replace_command().(&mut self, i: usize, line: &str) -> bool {
578 // Collect all RECIPE nodes (matching the indexing used by recipe_nodes())
579 let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
580 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
581 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
582 .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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
583 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
584
585 if i 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().recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
586 return false;
587 }
588
589 // Get the target RECIPE node and its index among all siblings
590 let target_node = &recipes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
591 let target_index = target_node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
592
593 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().();
594 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
595 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t");
596 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), line);
597 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");
598 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
599
600 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().());
601
602 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
603 .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!![syntax.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
604
605 true
606 }
607
608 /// Add a new command to the rule
609 ///
610 /// # Example
611 /// ```
612 /// use makefile_lossless::Rule;
613 /// let mut rule: Rule = "rule: dependency\n\tcommand".parse().unwrap();
614 /// rule.push_command("command2");
615 /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["command", "command2"]);
616 /// ```
617 pub fn push_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]push_command().(&mut self, line: &str) {
618 // Find the latest RECIPE entry, then append the new line after it.
619 let index = self
620 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
621 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
622 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|it| it.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, 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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
623 .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().();
624
625 let index = index.map_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or_else().(
626 || self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][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().(),
627 |it| it.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`NodeOrToken<SyntaxNode<L>, SyntaxToken<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,
628 );
629
630 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().();
631 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
632 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t");
633 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), line);
634 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");
635 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
636 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().());
637
638 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
639 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#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().()]);
640 }
641
642 /// Remove command at given index
643 ///
644 /// # Example
645 /// ```
646 /// use makefile_lossless::Rule;
647 /// let mut rule: Rule = "rule:\n\tcommand1\n\tcommand2\n".parse().unwrap();
648 /// rule.remove_command(0);
649 /// assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["command2"]);
650 /// ```
651 pub fn remove_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_command().(&mut self, index: usize) -> bool {
652 let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
653 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
654 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
655 .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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
656 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
657
658 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().recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
659 return false;
660 }
661
662 let target_node = &recipes[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().;
663 let target_index = target_node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
664
665 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
666 .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!![]);
667 true
668 }
669
670 /// Insert command at given index
671 ///
672 /// # Example
673 /// ```
674 /// use makefile_lossless::Rule;
675 /// let mut rule: Rule = "rule:\n\tcommand1\n\tcommand2\n".parse().unwrap();
676 /// rule.insert_command(1, "inserted_command");
677 /// let recipes: Vec<_> = rule.recipes().collect();
678 /// assert_eq!(recipes, vec!["command1", "inserted_command", "command2"]);
679 /// ```
680 pub fn insert_commandrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]insert_command().(&mut self, index: usize, line: &str) -> bool {
681 let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
682 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
683 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
684 .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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
685 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
686
687 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().recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
688 return false;
689 }
690
691 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().recipes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
692 // Insert at the end - find position after last recipe
693 recipes.lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|n| n.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).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
694 // No recipes exist, insert after the rule header
695 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][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().()
696 })
697 } else {
698 // Insert before the recipe at the given index
699 recipes[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().()
700 };
701
702 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().();
703 builder.start_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]start_node().(RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
704 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(INDENTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#INDENT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), "\t");
705 builder.tokenrust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]token().(TEXTrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TEXT#.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), line);
706 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");
707 builder.finish_noderust-analyzer cargo rowan 0.16.1 green/builder/impl#[`GreenNodeBuilder<'_>`]finish_node().();
708 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().());
709
710 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
711 .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().()]);
712 true
713 }
714
715 /// Get the number of commands/recipes in this rule
716 ///
717 /// # Example
718 /// ```
719 /// use makefile_lossless::Rule;
720 /// let rule: Rule = "rule:\n\tcommand1\n\tcommand2\n".parse().unwrap();
721 /// assert_eq!(rule.recipe_count(), 2);
722 /// ```
723 pub fn recipe_countrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]recipe_count().(&self) -> usize {
724 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
725 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
726 .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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
727 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().()
728 }
729
730 /// Clear all commands from this rule
731 ///
732 /// # Example
733 /// ```
734 /// use makefile_lossless::Rule;
735 /// let mut rule: Rule = "rule:\n\tcommand1\n\tcommand2\n".parse().unwrap();
736 /// rule.clear_commands();
737 /// assert_eq!(rule.recipe_count(), 0);
738 /// ```
739 pub fn clear_commandsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]clear_commands().(&mut self) {
740 let recipes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = self
741 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
742 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
743 .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().RECIPErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RECIPE#)
744 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
745
746 if recipes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
747 return;
748 }
749
750 // Remove all recipes in reverse order to maintain correct indices
751 for recipe in recipes.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().() {
752 let index = recipe.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
753 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#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!![]);
754 }
755 }
756
757 /// Remove a prerequisite from this rule
758 ///
759 /// Returns `true` if the prerequisite was found and removed, `false` if it wasn't found.
760 ///
761 /// # Example
762 /// ```
763 /// use makefile_lossless::Rule;
764 /// let mut rule: Rule = "target: dep1 dep2 dep3\n".parse().unwrap();
765 /// assert!(rule.remove_prerequisite("dep2").unwrap());
766 /// assert_eq!(rule.prerequisites().collect::<Vec<_>>(), vec!["dep1", "dep3"]);
767 /// assert!(!rule.remove_prerequisite("nonexistent").unwrap());
768 /// ```
769 pub fn remove_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_prerequisite().(&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#> {
770 // Find the PREREQUISITES node after the OPERATOR
771 let mut found_operator = false;
772 let mut prereqs_node = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
773
774 for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
775 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = child.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
776 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().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# {
777 found_operator = true;
778 }
779 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
780 if found_operator && 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().PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES# {
781 prereqs_node = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node.clonerust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`][Clone]clone().());
782 break;
783 }
784 }
785 }
786
787 let prereqs_node = match prereqs_node {
788 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) => node,
789 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), // No prerequisites
790 };
791
792 // Collect current prerequisites
793 let current_prereqs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = self.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().();
794
795 // Check if target exists
796 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().current_prereqs.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|p| p rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().target) {
797 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
798 }
799
800 // Filter out the target
801 let new_prereqs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = current_prereqs
802 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
803 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| p rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().target)
804 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
805
806 // Check if the existing PREREQUISITES node starts with whitespace
807 let has_leading_whitespace = prereqs_node
808 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
809 .nextrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxElementChildren<L>`][Iterator]next().()
810 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|e| matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(e.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().()), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#)))
811 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false);
812
813 // Rebuild the PREREQUISITES node with the new prerequisites
814 let prereqs_index = prereqs_node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().();
815 let new_prereqs_node = build_prerequisites_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_prerequisites_node().(&new_prereqs, has_leading_whitespace);
816
817 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
818 prereqs_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#prereqs_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,
819 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_prereqs_node.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
820 );
821
822 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true)
823 }
824
825 /// Add a prerequisite to this rule
826 ///
827 /// # Example
828 /// ```
829 /// use makefile_lossless::Rule;
830 /// let mut rule: Rule = "target: dep1\n".parse().unwrap();
831 /// rule.add_prerequisite("dep2").unwrap();
832 /// assert_eq!(rule.prerequisites().collect::<Vec<_>>(), vec!["dep1", "dep2"]);
833 /// ```
834 pub fn add_prerequisiterust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_prerequisite().(&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#> {
835 let mut current_prereqs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = self.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().();
836 current_prereqs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(target.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
837 self.set_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_prerequisites().(current_prereqs.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().(|s| s.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
838 }
839
840 /// Set the prerequisites for this rule, replacing any existing ones
841 ///
842 /// # Example
843 /// ```
844 /// use makefile_lossless::Rule;
845 /// let mut rule: Rule = "target: old_dep\n".parse().unwrap();
846 /// rule.set_prerequisites(vec!["new_dep1", "new_dep2"]).unwrap();
847 /// assert_eq!(rule.prerequisites().collect::<Vec<_>>(), vec!["new_dep1", "new_dep2"]);
848 /// ```
849 pub fn set_prerequisitesrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_prerequisites().(&mut self, prereqs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&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#> {
850 // Find the PREREQUISITES node after the OPERATOR, or the position to insert it
851 let mut prereqs_index = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
852 let mut operator_found = false;
853
854 for child in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().() {
855 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(token) = child.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().() {
856 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().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR# {
857 operator_found = true;
858 }
859 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
860 if operator_found && 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().PREREQUISITESrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#PREREQUISITES# {
861 prereqs_index = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((node.indexrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]index().(), true)); // (index, exists)
862 break;
863 }
864 }
865 }
866
867 match prereqs_index {
868 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((idx, true)) => {
869 // Check if there's whitespace between OPERATOR and PREREQUISITES
870 let has_external_whitespace = self
871 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
872 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
873 .skip_whilerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip_while().(|e| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(e.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().()), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#)))
874 .nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) // Skip the OPERATOR itself and get next
875 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|e| matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(e.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().()), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(WHITESPACErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#WHITESPACE#)))
876 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false);
877
878 let new_prereqs = build_prerequisites_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_prerequisites_node().(
879 &prereqs.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().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).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#<_>>(),
880 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_external_whitespace, // Include leading space only if no external whitespace
881 );
882 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
883 .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!![new_prereqs.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
884 }
885 _ => {
886 // Insert new PREREQUISITES (need leading space inside node)
887 let new_prereqs = build_prerequisites_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_prerequisites_node().(
888 &prereqs.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().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).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#<_>>(),
889 true, // Include leading space
890 );
891
892 let insert_pos = self
893 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
894 .children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().()
895 .positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#position().(|t| t.as_tokenrust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_token().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|t| t.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxToken<L>`]kind().() rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().==rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq(). rust-analyzer cargo makefile-lossless 0.3.40 impl#[SyntaxKind][`PartialEq<Self>`]eq().OPERATORrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#OPERATOR#).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(false))
896 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| p 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)
897 .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
898 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# {
899 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# {
900 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "No operator found in rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
901 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
902 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "set_prerequisites".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
903 }],
904 })
905 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
906
907 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
908 .splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(insert_pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#insert_pos, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_prereqs.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()]);
909 }
910 }
911
912 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
913 }
914
915 /// Rename a target in this rule
916 ///
917 /// Returns `Ok(true)` if the target was found and renamed, `Ok(false)` if the target was not found.
918 ///
919 /// # Example
920 /// ```
921 /// use makefile_lossless::Rule;
922 /// let mut rule: Rule = "old_target: dependency\n\tcommand".parse().unwrap();
923 /// rule.rename_target("old_target", "new_target").unwrap();
924 /// assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["new_target"]);
925 /// ```
926 pub fn rename_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]rename_target().(&mut self, old_name: &str, new_name: &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#> {
927 // Collect current targets
928 let current_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = self.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().();
929
930 // Check if the target to rename exists
931 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().current_targets.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|t| t rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().old_name) {
932 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
933 }
934
935 // Create new target list with the renamed target
936 let new_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = current_targets
937 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
938 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|t| {
939 if 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().old_name {
940 new_name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
941 } else {
942 t
943 }
944 })
945 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
946
947 // Find the TARGETS node
948 let mut targets_index = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
949 for (idx, child) in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
950 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
951 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().TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS# {
952 targets_index = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(idx);
953 break;
954 }
955 }
956 }
957
958 let targets_index = targets_index.ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
959 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# {
960 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# {
961 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "No TARGETS node found in rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
962 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
963 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "rename_target".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
964 }],
965 })
966 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
967
968 // Build new targets node
969 let new_targets_node = build_targets_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_targets_node().(&new_targets);
970
971 // Replace the TARGETS node
972 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
973 targets_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#targets_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,
974 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_targets_node.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
975 );
976
977 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true)
978 }
979
980 /// Add a target to this rule
981 ///
982 /// # Example
983 /// ```
984 /// use makefile_lossless::Rule;
985 /// let mut rule: Rule = "target1: dependency\n\tcommand".parse().unwrap();
986 /// rule.add_target("target2").unwrap();
987 /// assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["target1", "target2"]);
988 /// ```
989 pub fn add_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]add_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#> {
990 let mut current_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = self.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().();
991 current_targets.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(target.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
992 self.set_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_targets().(current_targets.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().(|s| s.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
993 }
994
995 /// Set the targets for this rule, replacing any existing ones
996 ///
997 /// Returns an error if the targets list is empty (rules must have at least one target).
998 ///
999 /// # Example
1000 /// ```
1001 /// use makefile_lossless::Rule;
1002 /// let mut rule: Rule = "old_target: dependency\n\tcommand".parse().unwrap();
1003 /// rule.set_targets(vec!["new_target1", "new_target2"]).unwrap();
1004 /// assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["new_target1", "new_target2"]);
1005 /// ```
1006 pub fn set_targetsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]set_targets().(&mut self, targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&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#> {
1007 // Ensure targets list is not empty
1008 if targets.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1009 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# {
1010 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# {
1011 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "Cannot set empty targets list for a rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1012 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1013 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "set_targets".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1014 }],
1015 }));
1016 }
1017
1018 // Find the TARGETS node
1019 let mut targets_index = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1020 for (idx, child) in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
1021 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
1022 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().TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS# {
1023 targets_index = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(idx);
1024 break;
1025 }
1026 }
1027 }
1028
1029 let targets_index = targets_index.ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
1030 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# {
1031 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# {
1032 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "No TARGETS node found in rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1033 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1034 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "set_targets".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1035 }],
1036 })
1037 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1038
1039 // Build new targets node
1040 let new_targets_node =
1041 build_targets_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_targets_node().(&targets.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().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).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#<_>>());
1042
1043 // Replace the TARGETS node
1044 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
1045 targets_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#targets_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,
1046 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_targets_node.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
1047 );
1048
1049 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1050 }
1051
1052 /// Check if this rule has a specific target
1053 ///
1054 /// # Example
1055 /// ```
1056 /// use makefile_lossless::Rule;
1057 /// let rule: Rule = "target1 target2: dependency\n\tcommand".parse().unwrap();
1058 /// assert!(rule.has_target("target1"));
1059 /// assert!(rule.has_target("target2"));
1060 /// assert!(!rule.has_target("target3"));
1061 /// ```
1062 pub fn has_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]has_target().(&self, target: &str) -> bool {
1063 self.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)
1064 }
1065
1066 /// Remove a target from this rule
1067 ///
1068 /// Returns `Ok(true)` if the target was found and removed, `Ok(false)` if the target was not found.
1069 /// Returns an error if attempting to remove the last target (rules must have at least one target).
1070 ///
1071 /// # Example
1072 /// ```
1073 /// use makefile_lossless::Rule;
1074 /// let mut rule: Rule = "target1 target2: dependency\n\tcommand".parse().unwrap();
1075 /// rule.remove_target("target1").unwrap();
1076 /// assert_eq!(rule.targets().collect::<Vec<_>>(), vec!["target2"]);
1077 /// ```
1078 pub fn remove_targetrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove_target().(&mut self, target_name: &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#> {
1079 // Collect current targets
1080 let current_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = self.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().();
1081
1082 // Check if the target exists
1083 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().current_targets.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|t| t rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().target_name) {
1084 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false);
1085 }
1086
1087 // Filter out the target to remove
1088 let new_targets: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = current_targets
1089 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
1090 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|t| t rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().target_name)
1091 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1092
1093 // If no targets remain, return an error
1094 if new_targets.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 remove all targets from a rule".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.: "remove_target".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1100 }],
1101 }));
1102 }
1103
1104 // Find the TARGETS node
1105 let mut targets_index = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
1106 for (idx, child) in self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().children_with_tokensrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children_with_tokens().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
1107 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(node) = child.as_noderust-analyzer cargo rowan 0.16.1 utility_types/impl#[`NodeOrToken<N, T>`]as_node().() {
1108 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().TARGETSrust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#TARGETS# {
1109 targets_index = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(idx);
1110 break;
1111 }
1112 }
1113 }
1114
1115 let targets_index = targets_index.ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| {
1116 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# {
1117 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# {
1118 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "No TARGETS node found in rule".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1119 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1120 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "remove_target".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1121 }],
1122 })
1123 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1124
1125 // Build new targets node
1126 let new_targets_node = build_targets_noderust-analyzer cargo makefile-lossless 0.3.40 ast/rule/build_targets_node().(&new_targets);
1127
1128 // Replace the TARGETS node
1129 self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().().splice_childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]splice_children().(
1130 targets_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#targets_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,
1131 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![new_targets_node.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()],
1132 );
1133
1134 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true)
1135 }
1136
1137 /// Remove this rule from its parent Makefile
1138 ///
1139 /// # Example
1140 /// ```
1141 /// use makefile_lossless::Makefile;
1142 /// let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
1143 /// let rule = makefile.rules().next().unwrap();
1144 /// rule.remove().unwrap();
1145 /// assert_eq!(makefile.rules().count(), 1);
1146 /// ```
1147 ///
1148 /// This will also remove any preceding comments and up to 1 empty line before the rule.
1149 /// When removing the last rule in a makefile, this will also trim any trailing blank lines
1150 /// from the previous rule to avoid leaving extra whitespace at the end of the file.
1151 pub fn removerust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Rule]remove().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo makefile-lossless 0.3.40 lossless/Error#> {
1152 let parent = self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]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().(|| {
1153 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# {
1154 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# {
1155 messagerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#message.: "Rule has no parent".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1156 linerust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#line.: 1,
1157 contextrust-analyzer cargo makefile-lossless 0.3.40 lossless/ErrorInfo#context.: "remove".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
1158 }],
1159 })
1160 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1161
1162 // Check if this is the last rule by seeing if there's any next sibling that's a RULE
1163 let is_last_rule = self
1164 .syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().()
1165 .siblingsrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]siblings().(rowanrust-analyzer cargo rowan 0.16.1 crate/::Directionrust-analyzer cargo rowan 0.16.1 utility_types/Direction#::Nextrust-analyzer cargo rowan 0.16.1 utility_types/Direction#Next#)
1166 .skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1) // Skip self
1167 .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|sibling| sibling.kindrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]kind().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().RULErust-analyzer cargo makefile-lossless 0.3.40 SyntaxKind#RULE#);
1168
1169 remove_with_preceding_commentsrust-analyzer cargo makefile-lossless 0.3.40 lossless/remove_with_preceding_comments().(self.syntaxrust-analyzer cargo makefile-lossless 0.3.40 lossless/impl#[Rule][AstNode]syntax().(), &parent);
1170
1171 // If we removed the last rule, trim trailing newlines from the last remaining RULE
1172 if is_last_rule {
1173 // Find the last RULE node in the parent
1174 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last_rule_node) = parent
1175 .childrenrust-analyzer cargo rowan 0.16.1 api/impl#[`SyntaxNode<L>`]children().()
1176 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|child| child.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#)
1177 .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#last().()
1178 {
1179 trim_trailing_newlinesrust-analyzer cargo makefile-lossless 0.3.40 lossless/trim_trailing_newlines().(&last_rule_node);
1180 }
1181 }
1182
1183 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1184 }
1185 }
1186
1187 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile# {
1188 fn defaultrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Makefile][Default]default().() -> Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Makefile][Default] {
1189 Selfrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/impl#[Makefile][Default]::newrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]new().()
1190 }
1191 }
1192
1193 #[cfg(test)]
1194 mod testsrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/tests/ {
1195 use craterust-analyzer cargo makefile-lossless 0.3.40 crate/::Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#;
1196
1197 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1198 fn test_rules_with_pipe_in_shell_continuationrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/tests/test_rules_with_pipe_in_shell_continuation().() {
1199 let input = "VAR ?= $(shell cmd | \\\n\t\tsed -e 's/foo/bar/')\n\n%:\n\tdh $@\n";
1200 let (makefile, _errors) = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_str_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_str_relaxed().(input);
1201 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().();
1202 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().(), 1, "Expected 1 rule");
1203 }
1204
1205 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1206 fn test_roundtrip_with_backslash_in_variable_continuationrust-analyzer cargo makefile-lossless 0.3.40 ast/rule/tests/test_roundtrip_with_backslash_in_variable_continuation().() {
1207 let input = "DEB_UPSTREAM_VERSION ?= $(shell dpkg-parsechangelog | \\\n\
1208 \t\t\t sed -rne 's,^Version: ([^-]+).*,\\1,p')\n\
1209 \n\
1210 %:\n\
1211 \tdh $@ --with autoreconf\n\
1212 \n\
1213 override_dh_strip:\n\
1214 \tdh_strip --dbg-package=f2fs-tools-dbg\n";
1215 let (makefile, errors) = Makefilerust-analyzer cargo makefile-lossless 0.3.40 lossless/Makefile#::from_str_relaxedrust-analyzer cargo makefile-lossless 0.3.40 ast/makefile/impl#[Makefile]from_str_relaxed().(input);
1216 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(errors.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().(), "Unexpected parse errors: {:?}", errors);
1217
1218 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().();
1219 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, "Expected 2 rules, got {}", rules.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
1220
1221 let output = makefile.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
1222 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(input, output, "Round-trip failed");
1223 }
1224 }