pub struct Makefile(/* private fields */);Expand description
An AST node for $ast
Implementations§
Source§impl Makefile
impl Makefile
Sourcepub fn read_relaxed<R: Read>(r: R) -> Result<Makefile, Error>
pub fn read_relaxed<R: Read>(r: R) -> Result<Makefile, Error>
Read makefile from a reader, but allow syntax errors
Sourcepub fn rules(&self) -> impl Iterator<Item = Rule> + '_
pub fn rules(&self) -> impl Iterator<Item = Rule> + '_
Retrieve the rules in the makefile
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "rule: dependency\n\tcommand\n".parse().unwrap();
assert_eq!(makefile.rules().count(), 1);Sourcepub fn rules_by_target<'a>(
&'a self,
target: &'a str,
) -> impl Iterator<Item = Rule> + 'a
pub fn rules_by_target<'a>( &'a self, target: &'a str, ) -> impl Iterator<Item = Rule> + 'a
Get all rules that have a specific target
Sourcepub fn variable_definitions(&self) -> impl Iterator<Item = VariableDefinition>
pub fn variable_definitions(&self) -> impl Iterator<Item = VariableDefinition>
Get all variable definitions in the makefile
Sourcepub fn find_variable<'a>(
&'a self,
name: &'a str,
) -> impl Iterator<Item = VariableDefinition> + 'a
pub fn find_variable<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = VariableDefinition> + 'a
Find all variables by name
Returns an iterator over all variable definitions with the given name. Makefiles can have multiple definitions of the same variable.
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "VAR1 = value1\nVAR2 = value2\nVAR1 = value3\n".parse().unwrap();
let vars: Vec<_> = makefile.find_variable("VAR1").collect();
assert_eq!(vars.len(), 2);
assert_eq!(vars[0].raw_value(), Some("value1".to_string()));
assert_eq!(vars[1].raw_value(), Some("value3".to_string()));Sourcepub fn add_rule(&mut self, target: &str) -> Rule
pub fn add_rule(&mut self, target: &str) -> Rule
Add a new rule to the makefile
§Example
use makefile_lossless::Makefile;
let mut makefile = Makefile::new();
makefile.add_rule("rule");
assert_eq!(makefile.to_string(), "rule:\n");Sourcepub fn replace_rule(
&mut self,
index: usize,
new_rule: Rule,
) -> Result<(), Error>
pub fn replace_rule( &mut self, index: usize, new_rule: Rule, ) -> Result<(), Error>
Replace rule at given index with a new rule
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
let new_rule: makefile_lossless::Rule = "new_rule:\n\tnew_command\n".parse().unwrap();
makefile.replace_rule(0, new_rule).unwrap();
assert!(makefile.rules().any(|r| r.targets().any(|t| t == "new_rule")));Sourcepub fn remove_rule(&mut self, index: usize) -> Result<Rule, Error>
pub fn remove_rule(&mut self, index: usize) -> Result<Rule, Error>
Remove rule at given index
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
let removed = makefile.remove_rule(0).unwrap();
assert_eq!(removed.targets().collect::<Vec<_>>(), vec!["rule1"]);
assert_eq!(makefile.rules().count(), 1);Sourcepub fn insert_rule(&mut self, index: usize, new_rule: Rule) -> Result<(), Error>
pub fn insert_rule(&mut self, index: usize, new_rule: Rule) -> Result<(), Error>
Insert rule at given position
§Example
use makefile_lossless::Makefile;
let mut makefile: Makefile = "rule1:\n\tcommand1\nrule2:\n\tcommand2\n".parse().unwrap();
let new_rule: makefile_lossless::Rule = "inserted_rule:\n\tinserted_command\n".parse().unwrap();
makefile.insert_rule(1, new_rule).unwrap();
let targets: Vec<_> = makefile.rules().flat_map(|r| r.targets().collect::<Vec<_>>()).collect();
assert_eq!(targets, vec!["rule1", "inserted_rule", "rule2"]);Sourcepub fn includes(&self) -> impl Iterator<Item = Include>
pub fn includes(&self) -> impl Iterator<Item = Include>
Get all include directives in the makefile
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "include config.mk\n-include .env\n".parse().unwrap();
let includes = makefile.includes().collect::<Vec<_>>();
assert_eq!(includes.len(), 2);Sourcepub fn included_files(&self) -> impl Iterator<Item = String> + '_
pub fn included_files(&self) -> impl Iterator<Item = String> + '_
Get all included file paths
§Example
use makefile_lossless::Makefile;
let makefile: Makefile = "include config.mk\n-include .env\n".parse().unwrap();
let paths = makefile.included_files().collect::<Vec<_>>();
assert_eq!(paths, vec!["config.mk", ".env"]);Trait Implementations§
impl Eq for Makefile
impl StructuralPartialEq for Makefile
Auto Trait Implementations§
impl Freeze for Makefile
impl !RefUnwindSafe for Makefile
impl !Send for Makefile
impl !Sync for Makefile
impl Unpin for Makefile
impl !UnwindSafe for Makefile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more