1 use crate::{ |
1 use crate::{ |
2 utils::{files::get_path_from_bytes, replace_slice, SliceExt}, |
2 utils::{files::get_path_from_bytes, SliceExt}, |
3 LineNumber, PatternError, PatternFileError, |
3 LineNumber, PatternError, PatternFileError, |
4 }; |
4 }; |
5 use lazy_static::lazy_static; |
5 use lazy_static::lazy_static; |
6 use regex::bytes::Regex; |
6 use regex::bytes::{NoExpand, Regex}; |
7 use std::collections::HashMap; |
7 use std::collections::HashMap; |
8 use std::fs::File; |
8 use std::fs::File; |
9 use std::io::Read; |
9 use std::io::Read; |
10 use std::vec::Vec; |
10 use std::vec::Vec; |
11 |
11 |
233 lines: &[u8], |
233 lines: &[u8], |
234 file_path: &[u8], |
234 file_path: &[u8], |
235 warn: bool, |
235 warn: bool, |
236 ) -> (Vec<PatternTuple>, Vec<WarningTuple>) { |
236 ) -> (Vec<PatternTuple>, Vec<WarningTuple>) { |
237 let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap(); |
237 let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap(); |
|
238 let comment_escape_regex = Regex::new(r"\\#").unwrap(); |
238 let mut inputs: Vec<PatternTuple> = vec![]; |
239 let mut inputs: Vec<PatternTuple> = vec![]; |
239 let mut warnings: Vec<WarningTuple> = vec![]; |
240 let mut warnings: Vec<WarningTuple> = vec![]; |
240 |
241 |
241 let mut current_syntax = b"relre:".as_ref(); |
242 let mut current_syntax = b"relre:".as_ref(); |
242 |
243 |
243 for (line_number, mut line) in lines.split(|c| *c == b'\n').enumerate() { |
244 for (line_number, mut line) in lines.split(|c| *c == b'\n').enumerate() { |
244 let line_number = line_number + 1; |
245 let line_number = line_number + 1; |
245 |
246 |
|
247 let line_buf; |
246 if line.contains(&b'#') { |
248 if line.contains(&b'#') { |
247 if let Some(cap) = comment_regex.captures(line) { |
249 if let Some(cap) = comment_regex.captures(line) { |
248 line = &line[..cap.get(1).unwrap().end()] |
250 line = &line[..cap.get(1).unwrap().end()] |
249 } |
251 } |
250 let mut line = line.to_owned(); |
252 line_buf = comment_escape_regex.replace_all(line, NoExpand(b"#")); |
251 replace_slice(&mut line, br"\#", b"#"); |
253 line = &line_buf; |
252 } |
254 } |
253 |
255 |
254 let mut line = line.trim_end(); |
256 let mut line = line.trim_end(); |
255 |
257 |
256 if line.is_empty() { |
258 if line.is_empty() { |