aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/functions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/functions.rs')
-rw-r--r--src/makefile/functions.rs49
1 files changed, 20 insertions, 29 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 97f05b6..a4d206f 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -1,8 +1,10 @@
+use eyre::{bail, Result};
+
use super::pattern::r#match;
use super::r#macro::{Set as MacroSet, Source as MacroSource};
use super::token::TokenString;
-pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyhow::Result<String> {
+pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result<String> {
match name {
"filter" => {
assert_eq!(args.len(), 2);
@@ -53,21 +55,15 @@ pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyho
"shell" => todo!(),
// fallback
- _ => anyhow::bail!("function not implemented: {}", name),
+ _ => bail!("function not implemented: {}", name),
}
}
// Text Functions
mod text {
- use super::r#match;
- use super::MacroSet;
- use super::TokenString;
+ use super::*;
- pub fn filter(
- macros: &MacroSet,
- patterns: &TokenString,
- text: &TokenString,
- ) -> anyhow::Result<String> {
+ pub fn filter(macros: &MacroSet, patterns: &TokenString, text: &TokenString) -> Result<String> {
let patterns = macros.expand(patterns)?;
let patterns = patterns.split_whitespace().collect::<Vec<_>>();
let text = macros.expand(text)?;
@@ -88,7 +84,7 @@ mod text {
macros: &MacroSet,
patterns: &TokenString,
text: &TokenString,
- ) -> anyhow::Result<String> {
+ ) -> Result<String> {
let patterns = macros.expand(patterns)?;
let patterns = patterns.split_whitespace().collect::<Vec<_>>();
let text = macros.expand(text)?;
@@ -105,7 +101,7 @@ mod text {
Ok(result_pieces.join(" "))
}
- pub fn sort(macros: &MacroSet, words: &TokenString) -> anyhow::Result<String> {
+ pub fn sort(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
let mut words = words.split_whitespace().collect::<Vec<_>>();
words.sort_unstable();
@@ -120,12 +116,11 @@ mod file_name {
use std::ffi::OsStr;
use std::path::Path;
- use anyhow::Context;
+ use eyre::WrapErr;
- use super::MacroSet;
- use super::TokenString;
+ use super::*;
- pub fn notdir(macros: &MacroSet, words: &TokenString) -> anyhow::Result<String> {
+ pub fn notdir(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
let words = words
.split_whitespace()
@@ -139,7 +134,7 @@ mod file_name {
Ok(words.join(" "))
}
- pub fn basename(macros: &MacroSet, words: &TokenString) -> anyhow::Result<String> {
+ pub fn basename(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
let words = words
.split_whitespace()
@@ -157,7 +152,7 @@ mod file_name {
macros: &MacroSet,
prefix: &TokenString,
targets: &TokenString,
- ) -> anyhow::Result<String> {
+ ) -> Result<String> {
let prefix = macros.expand(prefix)?;
let targets = macros.expand(targets)?;
let results = targets
@@ -167,7 +162,7 @@ mod file_name {
Ok(results.join(" "))
}
- pub fn wildcard(macros: &MacroSet, pattern: &TokenString) -> anyhow::Result<String> {
+ pub fn wildcard(macros: &MacroSet, pattern: &TokenString) -> Result<String> {
let pattern = macros.expand(pattern)?;
let home_dir = env::var("HOME")
.ok()
@@ -190,16 +185,14 @@ mod file_name {
// foreach
mod foreach {
- use super::MacroSet;
- use super::MacroSource;
- use super::TokenString;
+ use super::*;
pub fn foreach(
macros: &MacroSet,
var: &TokenString,
list: &TokenString,
text: &TokenString,
- ) -> anyhow::Result<String> {
+ ) -> Result<String> {
let var = macros.expand(var)?;
let list = macros.expand(list)?;
let words = list.split_whitespace();
@@ -217,14 +210,12 @@ mod foreach {
// call
mod call {
- use super::MacroSet;
- use super::MacroSource;
- use super::TokenString;
+ use super::*;
pub fn call<'a>(
macros: &MacroSet,
args: impl Iterator<Item = &'a TokenString>,
- ) -> anyhow::Result<String> {
+ ) -> Result<String> {
let args = args
.map(|arg| macros.expand(arg))
.collect::<Result<Vec<_>, _>>()?;
@@ -244,9 +235,9 @@ mod test {
use crate::makefile::r#macro::{Set as MacroSet, Source as MacroSource};
- type R = anyhow::Result<()>;
+ type R = Result<()>;
- fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyhow::Result<String> {
+ fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result<String> {
super::expand_call(name, args, macros)
}