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