Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jun 11, 2016
1 parent 8e408de commit 0f0db93
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/syncat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use syntect::package_set::PackageSet;
use syntect::parser::*;
use syntect::theme::highlighter::*;
use syntect::theme::style::*;
use syntect::util::{as_24_bit_terminal_escaped, debug_print_ops};
use syntect::util::as_24_bit_terminal_escaped;

use std::io::BufReader;
use std::io::BufRead;
Expand Down
7 changes: 5 additions & 2 deletions src/package_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ fn load_syntax_file(p: &Path,

impl PackageSet {
pub fn new() -> PackageSet {
PackageSet { syntaxes: Vec::new(), is_linked: true }
PackageSet {
syntaxes: Vec::new(),
is_linked: true,
}
}

/// Convenience constructor calling `new` and then `load_syntaxes` on the resulting set
Expand Down Expand Up @@ -191,7 +194,7 @@ impl PackageSet {
Direct(_) => None,
};
if let Some(new_context) = maybe_new_context {
let mut new_ref = Direct(LinkerLink {link: Rc::downgrade(&new_context)});
let mut new_ref = Direct(LinkerLink { link: Rc::downgrade(&new_context) });
mem::swap(context_ref, &mut new_ref);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ impl ParseState {

let mut regions = Region::with_capacity(8);
let mut match_cache: MatchCache = Vec::with_capacity(64); // TODO find best capacity
while self.parse_next_token(line, &mut match_start, &mut match_cache, &mut regions, &mut res) {
while self.parse_next_token(line,
&mut match_start,
&mut match_cache,
&mut regions,
&mut res) {
}
return res;
}
Expand Down Expand Up @@ -105,7 +109,7 @@ impl ParseState {
line.len(),
onig::SEARCH_OPTION_NONE,
Some(regions));
if overall_index >= cache.len() { // add it to the cache
if overall_index >= cache.len() {
cache.push(matched.is_some());
} // TODO update the cache even if this is another time over
if let Some(match_start) = matched {
Expand Down Expand Up @@ -150,7 +154,8 @@ impl ParseState {
line: &str,
reg_match: RegexMatch,
level_context_ptr: ContextPtr,
ops: &mut Vec<(usize, ScopeStackOp)>) -> bool {
ops: &mut Vec<(usize, ScopeStackOp)>)
-> bool {
let (match_start, match_end) = reg_match.regions.pos(0).unwrap();
let context = reg_match.context.borrow();
let pat = context.match_at(reg_match.pat_index);
Expand Down
40 changes: 22 additions & 18 deletions src/syntax_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ impl Iterator for MatchIter {
Pattern::Include(ref ctx_ref) => {
let ctx_ptr = match ctx_ref {
&ContextReference::Inline(ref ctx_ptr) => ctx_ptr.clone(),
&ContextReference::Direct(ref ctx_ptr) => ctx_ptr.link.upgrade().unwrap(),
&ContextReference::Direct(ref ctx_ptr) => {
ctx_ptr.link.upgrade().unwrap()
}
_ => panic!("Can only iterate patterns after linking: {:?}", ctx_ref),
};
self.ctx_stack.push(ctx_ptr);
Expand Down Expand Up @@ -192,8 +194,8 @@ impl MatchPattern {

fn compile_regex(&mut self) {
let compiled = Regex::with_options(&self.regex_str,
onig::REGEX_OPTION_CAPTURE_GROUP,
Syntax::default())
onig::REGEX_OPTION_CAPTURE_GROUP,
Syntax::default())
.unwrap();
self.regex = Some(compiled);
}
Expand All @@ -202,7 +204,9 @@ impl MatchPattern {
/// May compile the regex if it isn't, panicing if compilation fails.
#[inline]
pub fn ensure_compiled_if_possible(&mut self) {
if self.regex.is_none() && !self.has_captures { self.compile_regex(); }
if self.regex.is_none() && !self.has_captures {
self.compile_regex();
}
}
}

Expand All @@ -223,21 +227,21 @@ impl Encodable for MatchPattern {

/// Syntaxes decoded by this won't have compiled regexes
impl Decodable for MatchPattern {
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
d.read_struct("MatchPattern", 6, |d| {
let match_pat = MatchPattern {
has_captures: try!(d.read_struct_field("has_captures", 0, Decodable::decode)),
regex: None,
regex_str: try!(d.read_struct_field("regex_str", 1, Decodable::decode)),
scope: try!(d.read_struct_field("scope", 2, Decodable::decode)),
captures: try!(d.read_struct_field("captures", 3, Decodable::decode)),
operation: try!(d.read_struct_field("operation", 4, Decodable::decode)),
with_prototype: try!(d.read_struct_field("with_prototype", 5, Decodable::decode)),
};
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
d.read_struct("MatchPattern", 6, |d| {
let match_pat = MatchPattern {
has_captures: try!(d.read_struct_field("has_captures", 0, Decodable::decode)),
regex: None,
regex_str: try!(d.read_struct_field("regex_str", 1, Decodable::decode)),
scope: try!(d.read_struct_field("scope", 2, Decodable::decode)),
captures: try!(d.read_struct_field("captures", 3, Decodable::decode)),
operation: try!(d.read_struct_field("operation", 4, Decodable::decode)),
with_prototype: try!(d.read_struct_field("with_prototype", 5, Decodable::decode)),
};

Ok(match_pat)
})
}
Ok(match_pat)
})
}
}

/// Just panics, we can't do anything with linked up syntaxes
Expand Down
5 changes: 4 additions & 1 deletion src/yaml_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ impl SyntaxDefinition {
.map(|v| v.iter().filter_map(|y| y.as_str()).map(|x| x.to_owned()).collect())
.unwrap_or_else(|_| Vec::new())
},
first_line_match: get_key(h, "first_line_match", |x| x.as_str()).ok().map(|s| s.to_owned()),
// TODO maybe cache a compiled version of this Regex
first_line_match: get_key(h, "first_line_match", |x| x.as_str())
.ok()
.map(|s| s.to_owned()),
hidden: get_key(h, "hidden", |x| x.as_bool()).unwrap_or(false),

variables: state.variables.clone(),
Expand Down

0 comments on commit 0f0db93

Please sign in to comment.