From b8b57a819920ee99402500226f0a5d93956a74ae Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 31 Jan 2022 16:30:53 -0500 Subject: [PATCH] Remove OpGetter from files --- mps-interpreter/src/lang/vocabulary/files.rs | 6 +-- mps-interpreter/src/processing/filesystem.rs | 50 ++++++-------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/mps-interpreter/src/lang/vocabulary/files.rs b/mps-interpreter/src/lang/vocabulary/files.rs index 11377b9..dd0b82f 100644 --- a/mps-interpreter/src/lang/vocabulary/files.rs +++ b/mps-interpreter/src/lang/vocabulary/files.rs @@ -9,7 +9,7 @@ use crate::lang::repeated_tokens; use crate::lang::utility::{assert_token, assert_token_raw}; use crate::lang::MpsLanguageDictionary; use crate::lang::{MpsFunctionFactory, MpsFunctionStatementFactory, MpsIteratorItem, MpsOp}; -use crate::lang::{RuntimeError, SyntaxError}; +use crate::lang::{PseudoOp, RuntimeError, RuntimeOp, SyntaxError}; use crate::processing::general::FileIter; #[derive(Debug)] @@ -73,16 +73,14 @@ impl Iterator for FilesStatement { } else { self.has_tried = true; } - let self_clone = self.clone(); let iter = self.context.as_mut().unwrap().filesystem.raw( self.folder.as_deref(), self.regex.as_deref(), self.recursive.unwrap_or(true), - &mut move || (Box::new(self_clone.clone()) as Box).into(), ); self.file_iter = Some(match iter { 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() { diff --git a/mps-interpreter/src/processing/filesystem.rs b/mps-interpreter/src/processing/filesystem.rs index ac4d56a..7c007d9 100644 --- a/mps-interpreter/src/processing/filesystem.rs +++ b/mps-interpreter/src/processing/filesystem.rs @@ -5,8 +5,7 @@ use std::path::{Path, PathBuf}; use regex::Regex; -use super::OpGetter; -use crate::lang::{MpsTypePrimitive, RuntimeError}; +use crate::lang::{MpsTypePrimitive, RuntimeMsg}; use crate::MpsItem; const DEFAULT_REGEX: &str = r"/(?P[^/]+)/(?P[^/]+)/(?:(?:(?P\d+)\s+)?(?P\d+)\.?\s+)?(?P[^/]+)\.(?P<format>(?:mp3)|(?:wav)|(?:ogg)|(?:flac)|(?:mp4)|(?:aac))$"; @@ -82,8 +81,7 @@ impl FileIter { root: Option<P>, pattern: Option<&str>, recurse: bool, - op: &mut OpGetter, - ) -> Result<Self, RuntimeError> { + ) -> Result<Self, RuntimeMsg> { let root_path = match root { None => crate::lang::utility::music_folder(), Some(p) => p.as_ref().to_path_buf(), @@ -93,11 +91,7 @@ impl FileIter { vec.push( root_path .read_dir() - .map_err(|e| RuntimeError { - line: 0, - op: op(), - msg: format!("Directory read error: {}", e), - })? + .map_err(|e| RuntimeMsg(format!("Directory read error: {}", e)))? .into(), ); vec @@ -105,19 +99,15 @@ impl FileIter { Vec::with_capacity(DEFAULT_VEC_CACHE_SIZE) }; let pattern_re = if let Some(pattern) = pattern { - Some(Regex::new(pattern).map_err(|e| RuntimeError { - line: 0, - op: op(), - msg: format!("Regex compile error: {}", e), - })?) + Some( + Regex::new(pattern) + .map_err(|e| RuntimeMsg(format!("Regex compile error: {}", e)))?, + ) } else { None }; - let tags_re = Regex::new(DEFAULT_REGEX).map_err(|e| RuntimeError { - line: 0, - op: op(), - msg: format!("Regex compile error: {}", e), - })?; + let tags_re = Regex::new(DEFAULT_REGEX) + .map_err(|e| RuntimeMsg(format!("Regex compile error: {}", e)))?; Ok(Self { root: root_path, pattern: pattern_re, @@ -320,23 +310,14 @@ pub trait MpsFilesystemQuerier: Debug { folder: Option<&str>, pattern: Option<&str>, recursive: bool, - op: &mut OpGetter, - ) -> Result<FileIter, RuntimeError>; + ) -> Result<FileIter, RuntimeMsg>; - fn expand( - &self, - folder: Option<&str>, - #[allow(unused_variables)] op: &mut OpGetter, - ) -> Result<Option<String>, RuntimeError> { + fn expand(&self, folder: Option<&str>) -> Result<Option<String>, RuntimeMsg> { #[cfg(feature = "shellexpand")] match folder { Some(path) => Ok(Some( shellexpand::full(path) - .map_err(|e| RuntimeError { - line: 0, - op: op(), - msg: format!("Path expansion error: {}", e), - })? + .map_err(|e| RuntimeMsg(format!("Path expansion error: {}", e)))? .into_owned(), )), None => Ok(None), @@ -355,9 +336,8 @@ impl MpsFilesystemQuerier for MpsFilesystemExecutor { folder: Option<&str>, pattern: Option<&str>, recursive: bool, - op: &mut OpGetter, - ) -> Result<FileIter, RuntimeError> { - let folder = self.expand(folder, op)?; - FileIter::new(folder, pattern, recursive, op) + ) -> Result<FileIter, RuntimeMsg> { + let folder = self.expand(folder)?; + FileIter::new(folder, pattern, recursive) } }