aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/macro.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/macro.rs')
-rw-r--r--src/makefile/macro.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs
index 88397c5..0b7a27d 100644
--- a/src/makefile/macro.rs
+++ b/src/makefile/macro.rs
@@ -9,26 +9,26 @@ use super::functions;
use super::token::{Token, TokenString};
#[derive(Debug, Clone)]
-pub(crate) enum MacroSource {
+pub enum MacroSource {
File,
CommandLineOrMakeflags,
Environment,
Builtin,
}
-pub(crate) trait LookupInternal: for<'a> Fn(&'a str) -> anyhow::Result<String> {}
+pub trait LookupInternal: for<'a> Fn(&'a str) -> anyhow::Result<String> {}
impl<F: for<'a> Fn(&'a str) -> anyhow::Result<String>> LookupInternal for F {}
#[derive(Clone)]
-pub(crate) struct MacroSet<'parent, 'lookup> {
+pub struct MacroSet<'parent, 'lookup> {
parent: Option<&'parent MacroSet<'parent, 'lookup>>,
data: HashMap<String, (MacroSource, TokenString)>,
lookup_internal: Option<&'lookup dyn LookupInternal>,
}
impl<'parent, 'lookup> MacroSet<'parent, 'lookup> {
- pub(crate) fn new() -> Self {
+ pub fn new() -> Self {
Self {
parent: None,
data: HashMap::new(),
@@ -36,13 +36,13 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> {
}
}
- pub(crate) fn add_builtins(&mut self) {
+ pub fn add_builtins(&mut self) {
for (k, v) in builtins() {
self.data.insert(k.into(), (MacroSource::Builtin, v));
}
}
- pub(crate) fn add_env(&mut self) {
+ pub fn add_env(&mut self) {
for (k, v) in env::vars() {
if k != "MAKEFLAGS" && k != "SHELL" {
self.data
@@ -61,26 +61,26 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> {
}
}
- pub(crate) fn get(&self, name: &str) -> Option<&(MacroSource, TokenString)> {
+ pub fn get(&self, name: &str) -> Option<&(MacroSource, TokenString)> {
self.data
.get(name)
.or_else(|| self.parent.and_then(|parent| parent.get(name)))
}
- pub(crate) fn set(&mut self, name: String, source: MacroSource, text: TokenString) {
+ pub fn set(&mut self, name: String, source: MacroSource, text: TokenString) {
self.data.insert(name, (source, text));
}
- pub(crate) fn is_defined(&self, name: &str) -> bool {
+ pub fn is_defined(&self, name: &str) -> bool {
self.data.contains_key(name)
}
// `remove` is fine, but I think for "remove-and-return" `pop` is better
- pub(crate) fn pop(&mut self, name: &str) -> Option<(MacroSource, TokenString)> {
+ pub fn pop(&mut self, name: &str) -> Option<(MacroSource, TokenString)> {
self.data.remove(name)
}
- pub(crate) fn expand(&self, text: &TokenString) -> anyhow::Result<String> {
+ pub fn expand(&self, text: &TokenString) -> anyhow::Result<String> {
let mut result = String::new();
for token in text.tokens() {
match token {
@@ -121,10 +121,7 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> {
Ok(result)
}
- pub(crate) fn with_lookup<'l, 's: 'l>(
- &'s self,
- lookup: &'l dyn LookupInternal,
- ) -> MacroSet<'s, 'l> {
+ pub fn with_lookup<'l, 's: 'l>(&'s self, lookup: &'l dyn LookupInternal) -> MacroSet<'s, 'l> {
MacroSet {
parent: Some(self),
data: HashMap::new(),
@@ -132,7 +129,7 @@ impl<'parent, 'lookup> MacroSet<'parent, 'lookup> {
}
}
- pub(crate) fn with_overlay<'s>(&'s self) -> MacroSet<'s, 'lookup> {
+ pub fn with_overlay<'s>(&'s self) -> MacroSet<'s, 'lookup> {
MacroSet {
parent: Some(self),
data: HashMap::new(),