Skip to content

Commit ec47d71

Browse files
committed
allow syntaxes to be loaded from disk or default binary dump for syntest
1 parent 4e6de36 commit ec47d71

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

examples/syntest.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,34 @@ fn test_file(ss: &SyntaxSet, path: &Path, parse_test_lines: bool) -> Result<Synt
207207
}
208208

209209
fn main() {
210-
let ss = SyntaxSet::load_defaults_newlines(); // note we load the version with newlines
211-
212210
let args: Vec<String> = std::env::args().collect();
213-
let path = if args.len() < 2 {
211+
let tests_path = if args.len() < 2 {
214212
"."
215213
} else {
216214
&args[1]
217215
};
216+
let syntaxes_path = if args.len() == 3 {
217+
&args[2]
218+
} else {
219+
""
220+
};
221+
222+
// load the syntaxes from disk if told to
223+
// (as opposed to from the binary dumps)
224+
// this helps to ensure that a recompile isn't needed
225+
// when using this for syntax development
226+
let mut ss = if syntaxes_path.is_empty() {
227+
SyntaxSet::load_defaults_newlines() // note we load the version with newlines
228+
} else {
229+
SyntaxSet::new()
230+
};
231+
if !syntaxes_path.is_empty() {
232+
println!("loading syntax definitions from {}", syntaxes_path);
233+
ss.load_syntaxes(&syntaxes_path, true).unwrap(); // note that we load the version with newlines
234+
ss.link_syntaxes();
235+
}
218236

219-
let exit_code = recursive_walk(&ss, &path);
237+
let exit_code = recursive_walk(&ss, &tests_path);
220238
std::process::exit(exit_code);
221239

222240
}

0 commit comments

Comments
 (0)