Skip to main content

sherlock_io/patterns/
matlab.rs

1use regex::Regex;
2
3pub struct MatlabPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl MatlabPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // MATLAB compiled files
13            Regex::new(r"\.p$").unwrap(),
14            Regex::new(r"\.mex").unwrap(),
15            Regex::new(r"\.mexw32$").unwrap(),
16            Regex::new(r"\.mexw64$").unwrap(),
17            Regex::new(r"\.mexa64$").unwrap(),
18            Regex::new(r"\.mexmaci64$").unwrap(),
19            
20            // MATLAB cache
21            Regex::new(r"\.asv$").unwrap(),
22            Regex::new(r"\.autosave$").unwrap(),
23            
24            // MATLAB temporary files
25            Regex::new(r"matlab_crash_dump\.").unwrap(),
26            Regex::new(r"\.tmp$").unwrap(),
27            
28            // Simulink files
29            Regex::new(r"\.slxc$").unwrap(),
30            Regex::new(r"\.slx\.autosave$").unwrap(),
31            Regex::new(r"\.mdl\.autosave$").unwrap(),
32            
33            // MATLAB projects
34            Regex::new(r"\.prj$").unwrap(),
35            
36            // Code generation
37            Regex::new(r"codegen/").unwrap(),
38            Regex::new(r"slprj/").unwrap(),
39            
40            // MATLAB Compiler
41            Regex::new(r"\.ctf$").unwrap(),
42            Regex::new(r"\.exe$").unwrap(),
43            Regex::new(r"\.app$").unwrap(),
44            
45            // MATLAB App Designer
46            Regex::new(r"\.mlappinstall$").unwrap(),
47            
48            // MATLAB Reports
49            Regex::new(r"\.rpt$").unwrap(),
50            
51            // MATLAB Profiler
52            Regex::new(r"profile_results").unwrap(),
53            
54            // MATLAB Coder
55            Regex::new(r"html/").unwrap(),
56            
57            // Temporary files
58            Regex::new(r"\.tmp/").unwrap(),
59            Regex::new(r"tmp/").unwrap(),
60            Regex::new(r"\.swp$").unwrap(),
61            Regex::new(r"\.swo$").unwrap(),
62            Regex::new(r"~$").unwrap(),
63            
64            // MATLAB specific temp files
65            Regex::new(r"\.bak$").unwrap(),
66            Regex::new(r"\.orig$").unwrap(),
67            
68            // MATLAB logs
69            Regex::new(r"\.log$").unwrap(),
70            Regex::new(r"logs/").unwrap(),
71        ];
72
73        let cache_patterns = vec![
74            // MATLAB cache
75            Regex::new(r"\.asv$").unwrap(),
76            
77            // Code generation cache
78            Regex::new(r"codegen/").unwrap(),
79            Regex::new(r"slprj/").unwrap(),
80            
81            // Compiled files
82            Regex::new(r"\.p$").unwrap(),
83            Regex::new(r"\.mex").unwrap(),
84            
85            // Reports cache
86            Regex::new(r"html/").unwrap(),
87        ];
88
89        let extensions = vec![
90            // MATLAB source files
91            "m".to_string(),
92            
93            // MATLAB Live Scripts
94            "mlx".to_string(),
95            
96            // MATLAB App Designer
97            "mlapp".to_string(),
98            
99            // Simulink models
100            "slx".to_string(),
101            "mdl".to_string(),
102            
103            // MATLAB Functions
104            "p".to_string(),
105            
106            // MATLAB Data
107            "mat".to_string(),
108            
109            // MATLAB Figure
110            "fig".to_string(),
111            
112            // MATLAB Projects
113            "prj".to_string(),
114            
115            // Configuration files
116            "yml".to_string(),
117            "yaml".to_string(),
118            "json".to_string(),
119            "xml".to_string(),
120            
121            // Documentation
122            "md".to_string(),
123            "rst".to_string(),
124            "txt".to_string(),
125            
126            // Data files
127            "csv".to_string(),
128            "tsv".to_string(),
129            "xlsx".to_string(),
130            "xls".to_string(),
131            
132            // Image files
133            "png".to_string(),
134            "jpg".to_string(),
135            "jpeg".to_string(),
136            "gif".to_string(),
137            "bmp".to_string(),
138            "tiff".to_string(),
139            "eps".to_string(),
140            "pdf".to_string(),
141            
142            // C/C++ (for MEX files)
143            "c".to_string(),
144            "cpp".to_string(),
145            "h".to_string(),
146            "hpp".to_string(),
147            
148            // Fortran (for MEX files)
149            "f".to_string(),
150            "f90".to_string(),
151            "f95".to_string(),
152            
153            // Shell scripts
154            "sh".to_string(),
155            "bash".to_string(),
156            "bat".to_string(),
157            "ps1".to_string(),
158        ];
159
160        Self {
161            external_patterns,
162            cache_patterns,
163            extensions,
164        }
165    }
166
167    pub fn get_external_patterns(&self) -> &[Regex] {
168        &self.external_patterns
169    }
170
171    pub fn get_cache_patterns(&self) -> &[Regex] {
172        &self.cache_patterns
173    }
174
175    pub fn get_extensions(&self) -> &[String] {
176        &self.extensions
177    }
178
179    pub fn get_script_names() -> Vec<&'static str> {
180        vec![
181            // MATLAB project files
182            "startup.m", "finish.m", "pathdef.m",
183            
184            // MATLAB toolbox files
185            "Contents.m", "info.xml",
186            
187            // MATLAB build files
188            "make.m", "build.m", "setup.m",
189            
190            // MATLAB test files
191            "runtests.m", "test.m",
192            
193            // MATLAB App files
194            "App.mlapp", "main.mlapp",
195            
196            // Simulink files
197            "model.slx", "library.slx",
198            
199            // MATLAB Compiler files
200            "compile.m", "package.m",
201            
202            // CI/CD
203            ".github/workflows/matlab.yml",
204            ".travis.yml", "appveyor.yml",
205            "azure-pipelines.yml",
206            
207            // Docker
208            "Dockerfile", "docker-compose.yml",
209            
210            // Editor
211            ".editorconfig", ".gitignore",
212            ".gitattributes",
213            
214            // Scripts
215            "run.sh", "build.sh", "deploy.sh",
216            "install.sh", "test.sh",
217            "run.bat", "build.bat",
218            
219            // Documentation
220            "README.md", "CHANGELOG.md",
221            "LICENSE", "LICENCE",
222            
223            // MATLAB specific
224            "license.txt", "getting_started.mlx",
225            "examples.mlx", "demo.m",
226        ]
227    }
228
229    pub fn get_common_directories() -> Vec<&'static str> {
230        vec![
231            // Source
232            "src/", "lib/", "functions/",
233            
234            // Tests
235            "tests/", "test/", "unit_tests/",
236            
237            // Documentation
238            "doc/", "docs/", "help/",
239            "examples/", "demos/",
240            
241            // Build
242            "build/", "dist/", "codegen/",
243            "slprj/", "html/",
244            
245            // Data
246            "data/", "datasets/", "results/",
247            
248            // Resources
249            "resources/", "assets/", "images/",
250            
251            // Tools
252            "tools/", "utils/", "utilities/",
253            
254            // Configuration
255            "config/", "settings/",
256            
257            // Apps
258            "apps/", "gui/",
259            
260            // Models
261            "models/", "simulink/",
262            
263            // Scripts
264            "scripts/", "batch/",
265            
266            // Output
267            "output/", "figures/", "plots/",
268        ]
269    }
270}