You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6KB

  1. //! This program is mainly intended for generating the dumps that are compiled in to
  2. //! syntect, not as a helpful example for beginners.
  3. //! Although it is a valid example for serializing syntaxes, you probably won't need
  4. //! to do this yourself unless you want to cache your own compiled grammars.
  5. extern crate syntect;
  6. use syntect::parsing::SyntaxSet;
  7. use syntect::highlighting::ThemeSet;
  8. use syntect::dumps::*;
  9. use std::env;
  10. fn usage_and_exit() -> ! {
  11. println!("USAGE: gendata synpack source-dir newlines.packdump nonewlines.packdump\n
  12. gendata themepack source-dir themepack.themedump");
  13. ::std::process::exit(2);
  14. }
  15. fn main() {
  16. let mut a = env::args().skip(1);
  17. match (a.next(), a.next(), a.next(), a.next()) {
  18. (Some(ref cmd),
  19. Some(ref package_dir),
  20. Some(ref packpath_newlines),
  21. Some(ref packpath_nonewlines)) if cmd == "synpack" => {
  22. let mut ps = SyntaxSet::new();
  23. ps.load_plain_text_syntax();
  24. ps.load_syntaxes(package_dir, true).unwrap();
  25. dump_to_file(&ps, packpath_newlines).unwrap();
  26. ps = SyntaxSet::new();
  27. ps.load_plain_text_syntax();
  28. ps.load_syntaxes(package_dir, false).unwrap();
  29. dump_to_file(&ps, packpath_nonewlines).unwrap();
  30. }
  31. (Some(ref s), Some(ref theme_dir), Some(ref packpath), None) if s == "themepack" => {
  32. let ts = ThemeSet::load_from_folder(theme_dir).unwrap();
  33. for (path, _) in &ts.themes {
  34. println!("{:?}", path);
  35. }
  36. dump_to_file(&ts, packpath).unwrap();
  37. }
  38. _ => usage_and_exit(),
  39. }
  40. }