Remove OpGetter from files
This commit is contained in:
parent
9ea25c27de
commit
b8b57a8199
2 changed files with 17 additions and 39 deletions
|
@ -9,7 +9,7 @@ use crate::lang::repeated_tokens;
|
||||||
use crate::lang::utility::{assert_token, assert_token_raw};
|
use crate::lang::utility::{assert_token, assert_token_raw};
|
||||||
use crate::lang::MpsLanguageDictionary;
|
use crate::lang::MpsLanguageDictionary;
|
||||||
use crate::lang::{MpsFunctionFactory, MpsFunctionStatementFactory, MpsIteratorItem, MpsOp};
|
use crate::lang::{MpsFunctionFactory, MpsFunctionStatementFactory, MpsIteratorItem, MpsOp};
|
||||||
use crate::lang::{RuntimeError, SyntaxError};
|
use crate::lang::{PseudoOp, RuntimeError, RuntimeOp, SyntaxError};
|
||||||
use crate::processing::general::FileIter;
|
use crate::processing::general::FileIter;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -73,16 +73,14 @@ impl Iterator for FilesStatement {
|
||||||
} else {
|
} else {
|
||||||
self.has_tried = true;
|
self.has_tried = true;
|
||||||
}
|
}
|
||||||
let self_clone = self.clone();
|
|
||||||
let iter = self.context.as_mut().unwrap().filesystem.raw(
|
let iter = self.context.as_mut().unwrap().filesystem.raw(
|
||||||
self.folder.as_deref(),
|
self.folder.as_deref(),
|
||||||
self.regex.as_deref(),
|
self.regex.as_deref(),
|
||||||
self.recursive.unwrap_or(true),
|
self.recursive.unwrap_or(true),
|
||||||
&mut move || (Box::new(self_clone.clone()) as Box<dyn MpsOp>).into(),
|
|
||||||
);
|
);
|
||||||
self.file_iter = Some(match iter {
|
self.file_iter = Some(match iter {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => return Some(Err(e)),
|
Err(e) => return Some(Err(e.with(RuntimeOp(PseudoOp::from_printable(self))))),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
match self.file_iter.as_mut().unwrap().next() {
|
match self.file_iter.as_mut().unwrap().next() {
|
||||||
|
|
|
@ -5,8 +5,7 @@ use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use super::OpGetter;
|
use crate::lang::{MpsTypePrimitive, RuntimeMsg};
|
||||||
use crate::lang::{MpsTypePrimitive, RuntimeError};
|
|
||||||
use crate::MpsItem;
|
use crate::MpsItem;
|
||||||
|
|
||||||
const DEFAULT_REGEX: &str = r"/(?P<artist>[^/]+)/(?P<album>[^/]+)/(?:(?:(?P<disc>\d+)\s+)?(?P<track>\d+)\.?\s+)?(?P<title>[^/]+)\.(?P<format>(?:mp3)|(?:wav)|(?:ogg)|(?:flac)|(?:mp4)|(?:aac))$";
|
const DEFAULT_REGEX: &str = r"/(?P<artist>[^/]+)/(?P<album>[^/]+)/(?:(?:(?P<disc>\d+)\s+)?(?P<track>\d+)\.?\s+)?(?P<title>[^/]+)\.(?P<format>(?:mp3)|(?:wav)|(?:ogg)|(?:flac)|(?:mp4)|(?:aac))$";
|
||||||
|
@ -82,8 +81,7 @@ impl FileIter {
|
||||||
root: Option<P>,
|
root: Option<P>,
|
||||||
pattern: Option<&str>,
|
pattern: Option<&str>,
|
||||||
recurse: bool,
|
recurse: bool,
|
||||||
op: &mut OpGetter,
|
) -> Result<Self, RuntimeMsg> {
|
||||||
) -> Result<Self, RuntimeError> {
|
|
||||||
let root_path = match root {
|
let root_path = match root {
|
||||||
None => crate::lang::utility::music_folder(),
|
None => crate::lang::utility::music_folder(),
|
||||||
Some(p) => p.as_ref().to_path_buf(),
|
Some(p) => p.as_ref().to_path_buf(),
|
||||||
|
@ -93,11 +91,7 @@ impl FileIter {
|
||||||
vec.push(
|
vec.push(
|
||||||
root_path
|
root_path
|
||||||
.read_dir()
|
.read_dir()
|
||||||
.map_err(|e| RuntimeError {
|
.map_err(|e| RuntimeMsg(format!("Directory read error: {}", e)))?
|
||||||
line: 0,
|
|
||||||
op: op(),
|
|
||||||
msg: format!("Directory read error: {}", e),
|
|
||||||
})?
|
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
vec
|
vec
|
||||||
|
@ -105,19 +99,15 @@ impl FileIter {
|
||||||
Vec::with_capacity(DEFAULT_VEC_CACHE_SIZE)
|
Vec::with_capacity(DEFAULT_VEC_CACHE_SIZE)
|
||||||
};
|
};
|
||||||
let pattern_re = if let Some(pattern) = pattern {
|
let pattern_re = if let Some(pattern) = pattern {
|
||||||
Some(Regex::new(pattern).map_err(|e| RuntimeError {
|
Some(
|
||||||
line: 0,
|
Regex::new(pattern)
|
||||||
op: op(),
|
.map_err(|e| RuntimeMsg(format!("Regex compile error: {}", e)))?,
|
||||||
msg: format!("Regex compile error: {}", e),
|
)
|
||||||
})?)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let tags_re = Regex::new(DEFAULT_REGEX).map_err(|e| RuntimeError {
|
let tags_re = Regex::new(DEFAULT_REGEX)
|
||||||
line: 0,
|
.map_err(|e| RuntimeMsg(format!("Regex compile error: {}", e)))?;
|
||||||
op: op(),
|
|
||||||
msg: format!("Regex compile error: {}", e),
|
|
||||||
})?;
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
root: root_path,
|
root: root_path,
|
||||||
pattern: pattern_re,
|
pattern: pattern_re,
|
||||||
|
@ -320,23 +310,14 @@ pub trait MpsFilesystemQuerier: Debug {
|
||||||
folder: Option<&str>,
|
folder: Option<&str>,
|
||||||
pattern: Option<&str>,
|
pattern: Option<&str>,
|
||||||
recursive: bool,
|
recursive: bool,
|
||||||
op: &mut OpGetter,
|
) -> Result<FileIter, RuntimeMsg>;
|
||||||
) -> Result<FileIter, RuntimeError>;
|
|
||||||
|
|
||||||
fn expand(
|
fn expand(&self, folder: Option<&str>) -> Result<Option<String>, RuntimeMsg> {
|
||||||
&self,
|
|
||||||
folder: Option<&str>,
|
|
||||||
#[allow(unused_variables)] op: &mut OpGetter,
|
|
||||||
) -> Result<Option<String>, RuntimeError> {
|
|
||||||
#[cfg(feature = "shellexpand")]
|
#[cfg(feature = "shellexpand")]
|
||||||
match folder {
|
match folder {
|
||||||
Some(path) => Ok(Some(
|
Some(path) => Ok(Some(
|
||||||
shellexpand::full(path)
|
shellexpand::full(path)
|
||||||
.map_err(|e| RuntimeError {
|
.map_err(|e| RuntimeMsg(format!("Path expansion error: {}", e)))?
|
||||||
line: 0,
|
|
||||||
op: op(),
|
|
||||||
msg: format!("Path expansion error: {}", e),
|
|
||||||
})?
|
|
||||||
.into_owned(),
|
.into_owned(),
|
||||||
)),
|
)),
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
|
@ -355,9 +336,8 @@ impl MpsFilesystemQuerier for MpsFilesystemExecutor {
|
||||||
folder: Option<&str>,
|
folder: Option<&str>,
|
||||||
pattern: Option<&str>,
|
pattern: Option<&str>,
|
||||||
recursive: bool,
|
recursive: bool,
|
||||||
op: &mut OpGetter,
|
) -> Result<FileIter, RuntimeMsg> {
|
||||||
) -> Result<FileIter, RuntimeError> {
|
let folder = self.expand(folder)?;
|
||||||
let folder = self.expand(folder, op)?;
|
FileIter::new(folder, pattern, recursive)
|
||||||
FileIter::new(folder, pattern, recursive, op)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue