/
View dependency graph
Depends on
- dh-cargo (dh-sequence-cargo)
- rust-log (librust-log-0.4+default-dev)
- rust-rowan (librust-rowan-0.16+default-dev)
- cargo, debhelper-compat, librust-debian-analyzer-dev, librust-ognibuild-dev, librust-upstream-ontologist-dev, libstd-rust-dev, rustc
README (full)
Lossless parser for Makefiles
This crate provides a lossless parser for Makefiles, producing a concrete syntax tree (CST) that preserves all whitespace, comments and formatting. Because nothing is discarded, a parsed Makefile can be modified and written back out with only the intended changes applied.
Parsing
use makefile_lossless::Makefile;
let contents = r#"PYTHON = python3
.PHONY: all
all: build
build:
$(PYTHON) setup.py build
"#;
let makefile: Makefile = contents.parse().unwrap();
assert_eq!(makefile.rules().count(), 3);
for rule in makefile.rules() {
println!("targets: {:?}", rule.targets().collect::<Vec<_>>());
}
You can also read from any std::io::Read:
use std::fs::File;
use makefile_lossless::Makefile;
let makefile = Makefile::read(File::open("Makefile").unwrap()).unwrap();
Use Makefile::read_relaxed to tolerate syntax errors and still get a tree
back.
Modifying
The tree is mutable. Changes are applied in place and the rest of the file is left untouched:
use makefile_lossless::Makefile;
let mut makefile: Makefile = "all:\n".parse().unwrap();
let mut rule = makefile.add_rule("build");
rule.push_command("$(PYTHON) setup.py build");
print!("{}", makefile);
License
Apache-2.0
| dir | .github/ |
| dir | debian/ |
| dir | src/ |
| file | .cargo_vcs_info.json |
| file | .gitignore |
| file | Cargo.lock |
| file | Cargo.toml |
| file | Cargo.toml.orig |
| file | README.md |
| file | TODO |
| file | disperse.toml |