pub struct Recipe(/* private fields */);Expand description
An AST node for $ast
Implementations§
Source§impl Recipe
impl Recipe
Source§impl Recipe
impl Recipe
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Get the text content of this recipe line (the command to execute)
For single-line recipes, this returns the command text excluding the leading tab and trailing newline.
For multi-line recipes (with backslash continuations), this returns the full text including the internal newlines and continuation-line indentation, but still excluding the leading tab of the first line and the final newline. This preserves the exact content needed for a lossless round-trip.
For comment-only lines, this returns an empty string.
Sourcepub fn indent(&self) -> Option<String>
pub fn indent(&self) -> Option<String>
Get the indentation string of this recipe line.
Returns the leading indentation (typically a tab character) of this recipe line,
or None if no indent token is present.
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipe = rule.recipe_nodes().next().unwrap();
assert_eq!(recipe.indent(), Some("\t".to_string()));Sourcepub fn comment(&self) -> Option<String>
pub fn comment(&self) -> Option<String>
Get the comment content of this recipe line, if any
Returns the comment text (including the ‘#’ character) if this recipe line contains a comment, or None if there is no comment.
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "all:\n\t# This is a comment\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipes: Vec<_> = rule.recipe_nodes().collect();
assert_eq!(recipes[0].comment(), Some("# This is a comment".to_string()));
assert_eq!(recipes[1].comment(), None);Sourcepub fn full(&self) -> String
pub fn full(&self) -> String
Get the full content of this recipe line
Returns all content including command text, comments, and internal whitespace, but excluding the leading indent. This is useful for getting the complete content of a recipe line regardless of whether it’s a command, comment, or both.
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "all:\n\techo hello # inline comment\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipe = rule.recipe_nodes().next().unwrap();
assert_eq!(recipe.full(), "echo hello # inline comment");Sourcepub fn parent(&self) -> Option<Rule>
pub fn parent(&self) -> Option<Rule>
Get the parent rule containing this recipe
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipe = rule.recipe_nodes().next().unwrap();
let parent = recipe.parent().unwrap();
assert_eq!(parent.targets().collect::<Vec<_>>(), vec!["all"]);Sourcepub fn is_silent(&self) -> bool
pub fn is_silent(&self) -> bool
Check if this recipe has the silent prefix (@)
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "all:\n\t@echo hello\n\techo world\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipes: Vec<_> = rule.recipe_nodes().collect();
assert!(recipes[0].is_silent());
assert!(!recipes[1].is_silent());Sourcepub fn is_ignore_errors(&self) -> bool
pub fn is_ignore_errors(&self) -> bool
Check if this recipe has the ignore-errors prefix (-)
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "all:\n\t-echo hello\n\techo world\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipes: Vec<_> = rule.recipe_nodes().collect();
assert!(recipes[0].is_ignore_errors());
assert!(!recipes[1].is_ignore_errors());Sourcepub fn set_prefix(&mut self, prefix: &str)
pub fn set_prefix(&mut self, prefix: &str)
Set the command prefix for this recipe
The prefix can contain @ (silent), - (ignore errors), and/or + (always execute).
Pass an empty string to remove all prefixes.
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.set_prefix("@");
assert_eq!(recipe.text(), "@echo hello");
assert!(recipe.is_silent());Sourcepub fn replace_text(&mut self, new_text: &str)
pub fn replace_text(&mut self, new_text: &str)
Replace the text content of this recipe line
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.replace_text("echo world");
assert_eq!(recipe.text(), "echo world");Sourcepub fn insert_before(&self, text: &str)
pub fn insert_before(&self, text: &str)
Insert a new recipe line before this one
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "all:\n\techo world\n".parse().unwrap();
let mut rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.insert_before("echo hello");
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo hello", "echo world"]);Sourcepub fn insert_after(&self, text: &str)
pub fn insert_after(&self, text: &str)
Insert a new recipe line after this one
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let mut rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.insert_after("echo world");
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo hello", "echo world"]);Sourcepub fn remove(&self)
pub fn remove(&self)
Remove this recipe line from its parent
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "all:\n\techo hello\n\techo world\n".parse().unwrap();
let mut rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.remove();
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo world"]);