Skip to content

Commit

Permalink
Merge pull request #438 from jplatte/macro-use
Browse files Browse the repository at this point in the history
Reduce dependencies and #[macro_use] usage
  • Loading branch information
trishume authored Jul 12, 2022
2 parents 333c35c + 3623290 commit 606450b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 35 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ onig = { version = "6.0", optional = true, default-features = false }
fancy-regex = { version = "0.7", optional = true }
walkdir = "2.0"
regex-syntax = { version = "0.6", optional = true }
lazy_static = "1.0"
bitflags = "1.0.4"
plist = { version = "1.3", optional = true }
bincode = { version = "1.0", optional = true }
flate2 = { version = "1.0", optional = true }
fnv = { version = "1.0", optional = true }
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
once_cell = "1.8"
thiserror = "1.0"
Expand Down
33 changes: 17 additions & 16 deletions examples/syntest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// you can tell it where to parse them from - the following will execute only 1 syntax test after
// parsing the sublime-syntax files in the JavaScript folder:
// cargo run --example syntest testdata/Packages/JavaScript/syntax_test_json.json testdata/Packages/JavaScript/
#[macro_use]
extern crate lazy_static;

use syntect::easy::ScopeRegionIterator;
use syntect::highlighting::ScopeSelectors;
Expand All @@ -22,6 +20,7 @@ use std::str::FromStr;
use std::time::Instant;

use getopts::Options;
use once_cell::sync::Lazy;
use regex::Regex;
use walkdir::{DirEntry, WalkDir};

Expand All @@ -37,24 +36,26 @@ pub enum SyntaxTestFileResult {
Success(usize),
}

lazy_static! {
pub static ref SYNTAX_TEST_HEADER_PATTERN: Regex = Regex::new(
pub static SYNTAX_TEST_HEADER_PATTERN: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?xm)
^(?P<testtoken_start>\s*\S+)
\s+SYNTAX\sTEST\s+
"(?P<syntax_file>[^"]+)"
\s*(?P<testtoken_end>\S+)?$
"#
^(?P<testtoken_start>\s*\S+)
\s+SYNTAX\sTEST\s+
"(?P<syntax_file>[^"]+)"
\s*(?P<testtoken_end>\S+)?$
"#,
)
.unwrap();
pub static ref SYNTAX_TEST_ASSERTION_PATTERN: Regex = Regex::new(
.unwrap()
});
pub static SYNTAX_TEST_ASSERTION_PATTERN: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?xm)
\s*(?:
(?P<begin_of_token><-)|(?P<range>\^+)
)(.*)$"#
\s*(?:
(?P<begin_of_token><-)|(?P<range>\^+)
)(.*)$"#,
)
.unwrap();
}
.unwrap()
});

#[derive(Clone, Copy)]
struct OutputOptions {
Expand Down
1 change: 1 addition & 0 deletions src/highlighting/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// released under the MIT license by @defuz
use crate::parsing::{Scope, ScopeStack, MatchPower, ParseScopeError};
use std::str::FromStr;
use serde::{Deserialize, Serialize};

/// A single selector consisting of a stack to match and a possible stack to
/// exclude from being matched.
Expand Down
1 change: 1 addition & 0 deletions src/highlighting/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Code based on [https://github.com/defuz/sublimate/blob/master/src/core/syntax/scope.rs](https://github.com/defuz/sublimate/blob/master/src/core/syntax/scope.rs)
// released under the MIT license by @defuz
use bitflags::bitflags;
use serde::{Deserialize, Serialize};

/// Foreground and background colors, with font style
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/highlighting/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use super::style::*;
use super::selector::*;
use serde::{Deserialize, Serialize};

/// A theme parsed from a `.tmTheme` file.
///
Expand Down
1 change: 1 addition & 0 deletions src/highlighting/theme_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::settings::*;
use super::super::LoadingError;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct ThemeSet {
Expand Down
6 changes: 3 additions & 3 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ pub fn css_for_theme_with_class_style(theme: &Theme, style: ClassStyle) -> Resul

if let Some(fs) = i.style.font_style {
if fs.contains(FontStyle::UNDERLINE) {
css.push_str(&"font-style: underline;\n".to_string());
css.push_str("font-style: underline;\n");
}
if fs.contains(FontStyle::BOLD) {
css.push_str(&"font-weight: bold;\n".to_string());
css.push_str("font-weight: bold;\n");
}
if fs.contains(FontStyle::ITALIC) {
css.push_str(&"font-style: italic;\n".to_string());
css.push_str("font-style: italic;\n");
}
}
css.push_str("}\n");
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

#![doc(html_root_url = "https://docs.rs/syntect/5.0.0")]

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
Expand Down
17 changes: 9 additions & 8 deletions src/parsing/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::u64;
use std::cmp::{Ordering, min};
use std::mem;

use once_cell::sync::Lazy;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{Error, Visitor};

Expand All @@ -25,14 +26,14 @@ pub enum ScopeError {
/// [`MatchPower`]: struct.MatchPower.html
pub const ATOM_LEN_BITS: u16 = 3;

lazy_static! {
/// The global scope repo, exposed in case you want to minimize locking and unlocking.
///
/// Ths shouldn't be necessary for you to use. See the [`ScopeRepository`] docs.
///
/// [`ScopeRepository`]: struct.ScopeRepository.html
pub static ref SCOPE_REPO: Mutex<ScopeRepository> = Mutex::new(ScopeRepository::new());
}
/// The global scope repo, exposed in case you want to minimize locking and unlocking.
///
/// Ths shouldn't be necessary for you to use. See the [`ScopeRepository`] docs.
///
/// [`ScopeRepository`]: struct.ScopeRepository.html
pub static SCOPE_REPO: Lazy<Mutex<ScopeRepository>> =
Lazy::new(|| Mutex::new(ScopeRepository::new()));


/// A hierarchy of atoms with semi-standardized names used to accord semantic information to a
/// specific piece of text.
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/syntax_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::hash::Hash;
use super::{scope::*, ParsingError};
use super::regex::{Regex, Region};
use regex_syntax::escape;
use serde::{Serialize, Serializer};
use serde::{Deserialize, Serialize, Serializer};
use crate::parsing::syntax_set::SyntaxSet;

pub type CaptureMapping = Vec<(usize, Vec<Scope>)>;
Expand Down
1 change: 1 addition & 0 deletions src/parsing/syntax_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::mem;
use super::regex::Regex;
use crate::parsing::syntax_definition::ContextId;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};

/// A syntax set holds multiple syntaxes that have been linked together.
///
Expand Down

0 comments on commit 606450b

Please sign in to comment.