##// END OF EJS Templates
rust-filepatterns: allow overriding default syntax...
Raphaël Gomès -
r50377:5fbdd888 default
parent child Browse files
Show More
@@ -329,6 +329,7 b' pub enum PatternFileWarning {'
329 pub fn parse_pattern_file_contents(
329 pub fn parse_pattern_file_contents(
330 lines: &[u8],
330 lines: &[u8],
331 file_path: &Path,
331 file_path: &Path,
332 default_syntax_override: Option<&[u8]>,
332 warn: bool,
333 warn: bool,
333 ) -> Result<(Vec<IgnorePattern>, Vec<PatternFileWarning>), PatternError> {
334 ) -> Result<(Vec<IgnorePattern>, Vec<PatternFileWarning>), PatternError> {
334 let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap();
335 let comment_regex = Regex::new(r"((?:^|[^\\])(?:\\\\)*)#.*").unwrap();
@@ -338,7 +339,8 b' pub fn parse_pattern_file_contents('
338 let mut inputs: Vec<IgnorePattern> = vec![];
339 let mut inputs: Vec<IgnorePattern> = vec![];
339 let mut warnings: Vec<PatternFileWarning> = vec![];
340 let mut warnings: Vec<PatternFileWarning> = vec![];
340
341
341 let mut current_syntax = b"relre:".as_ref();
342 let mut current_syntax =
343 default_syntax_override.unwrap_or(b"relre:".as_ref());
342
344
343 for (line_number, mut line) in lines.split(|c| *c == b'\n').enumerate() {
345 for (line_number, mut line) in lines.split(|c| *c == b'\n').enumerate() {
344 let line_number = line_number + 1;
346 let line_number = line_number + 1;
@@ -413,7 +415,7 b' pub fn read_pattern_file('
413 match std::fs::read(file_path) {
415 match std::fs::read(file_path) {
414 Ok(contents) => {
416 Ok(contents) => {
415 inspect_pattern_bytes(&contents);
417 inspect_pattern_bytes(&contents);
416 parse_pattern_file_contents(&contents, file_path, warn)
418 parse_pattern_file_contents(&contents, file_path, None, warn)
417 }
419 }
418 Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok((
420 Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok((
419 vec![],
421 vec![],
@@ -601,9 +603,14 b' mod tests {'
601 let lines = b"syntax: glob\n*.elc";
603 let lines = b"syntax: glob\n*.elc";
602
604
603 assert_eq!(
605 assert_eq!(
604 parse_pattern_file_contents(lines, Path::new("file_path"), false)
606 parse_pattern_file_contents(
605 .unwrap()
607 lines,
606 .0,
608 Path::new("file_path"),
609 None,
610 false
611 )
612 .unwrap()
613 .0,
607 vec![IgnorePattern::new(
614 vec![IgnorePattern::new(
608 PatternSyntax::RelGlob,
615 PatternSyntax::RelGlob,
609 b"*.elc",
616 b"*.elc",
@@ -614,16 +621,26 b' mod tests {'
614 let lines = b"syntax: include\nsyntax: glob";
621 let lines = b"syntax: include\nsyntax: glob";
615
622
616 assert_eq!(
623 assert_eq!(
617 parse_pattern_file_contents(lines, Path::new("file_path"), false)
624 parse_pattern_file_contents(
618 .unwrap()
625 lines,
619 .0,
626 Path::new("file_path"),
627 None,
628 false
629 )
630 .unwrap()
631 .0,
620 vec![]
632 vec![]
621 );
633 );
622 let lines = b"glob:**.o";
634 let lines = b"glob:**.o";
623 assert_eq!(
635 assert_eq!(
624 parse_pattern_file_contents(lines, Path::new("file_path"), false)
636 parse_pattern_file_contents(
625 .unwrap()
637 lines,
626 .0,
638 Path::new("file_path"),
639 None,
640 false
641 )
642 .unwrap()
643 .0,
627 vec![IgnorePattern::new(
644 vec![IgnorePattern::new(
628 PatternSyntax::RelGlob,
645 PatternSyntax::RelGlob,
629 b"**.o",
646 b"**.o",
General Comments 0
You need to be logged in to leave comments. Login now