Permalink
Browse files

version 5: optimised stats, language generation

  • Loading branch information...
Aaronepower committed Jan 2, 2017
1 parent 5e11c48 commit c08f113c2d6cd0036ec1373a64d0ec62d0dfa7c0
Showing with 296 additions and 317 deletions.
  1. +1 −0 .gitattributes
  2. +13 −11 Cargo.lock
  3. +29 −26 Cargo.toml
  4. +2 −3 build.rs
  5. +1 −1 cli.yml
  6. +4 −5 languages.json
  7. +20 −31 src/language/language.rs
  8. +16 −6 src/language/language_type.hbs.rs
  9. +16 −143 src/language/languages.rs
  10. +23 −51 src/main.rs
  11. +3 −2 src/serde_types.in.rs
  12. +42 −22 src/stats.rs
  13. +6 −14 src/utils/fs.rs
  14. +2 −2 src/utils/multi_line.rs
  15. +59 −0 tests/accuracy.rs
  16. +8 −0 tests/data/d.d
  17. +13 −0 tests/data/fsharp.fs
  18. +38 −0 tests/data/rust.rs
View
@@ -0,0 +1 @@
tests/data/* linguist-documentation
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,67 +8,70 @@ license = "MIT/Apache-2.0"
name = "tokei"
readme = "README.md"
repository = "https://github.com/Aaronepower/tokei.git"
version = "4.5.4"
version = "5.0.3"
[profile.release]
panic="abort"
[build-dependencies]
serde = "~0.8.19"
serde_json = "~0.8.4"
errln = "0.1.0"
serde = "0.8"
serde_json = "0.8"
errln = "0.1"
[build-dependencies.handlebars]
features = ["serde_type"]
version = "0.21.1"
version = "~0.24"
[build-dependencies.serde_codegen]
optional = true
version = "0.8.19"
version = "0.8"
[dependencies]
encoding = "~0.2.33"
errln = "0.1.0"
ignore = "~0.1.5"
lazy_static = "~0.2.1"
log = "~0.3.6"
maplit = "~0.1.3"
rayon = "=0.4.2"
regex = "~0.1.80"
encoding = "0.2"
errln = "0.1"
ignore = "0.1"
lazy_static = "0.2"
log = "0.3"
maplit = "0.1"
rayon = "0.6"
regex = "0.1"
[dependencies.clap]
features = ["yaml"]
version = "~2.19.1"
version = "2.19"
[dependencies.env_logger]
features = []
version = "~0.3.5"
version = "0.3"
[dependencies.hex]
version = "0.2"
optional = true
[dependencies.serde]
optional = true
version = "~0.8.19"
version = "0.8"
[dependencies.serde_cbor]
optional = true
version = "~0.4.0"
version = "0.4"
[dependencies.serde_json]
optional = true
version = "~0.8.4"
version = "0.8"
[dependencies.serde_yaml]
optional = true
version = "~0.4.0"
version = "0.4"
[dependencies.toml]
default-features = false
features = ["serde"]
optional = true
version = "~0.2.1"
version = "0.2"
[dev-dependencies]
tempdir = "~0.3.5"
[dependencies.hex]
version = "~0.2.0"
optional = true
tempdir = "0.3"
[features]
all = ["json", "cbor", "toml-io", "yaml"]
View
@@ -5,7 +5,7 @@ extern crate handlebars;
#[macro_use] extern crate errln;
use serde_json::Value;
use handlebars::{Context, Handlebars};
use handlebars::Handlebars;
use std::fs::File;
use std::env;
use std::path::{Path, PathBuf};
@@ -62,11 +62,10 @@ fn render_handlebars(out_dir: &OsString) -> PathBuf {
let mut handlebars = Handlebars::new();
handlebars.register_escape_fn(handlebars::no_escape);
let raw_data: Value = serde_json::from_reader(
let data: Value = serde_json::from_reader(
File::open(&"languages.json").expect("Can't open JSON")
).expect("Can't parse JSON");
let data = Context::wraps(&raw_data);
let out = Path::new(&out_dir).join("language_type.rs");
let mut source_template = File::open(&"src/language/language_type.hbs.rs")
.expect("Can't find Template");
View
@@ -5,7 +5,7 @@ about: Count Code, Quickly.
author: Aaron P. <theaaronepower@gmail.com>
bin_name: Tokei
name: Tokei
version: 4.5.4
version: '5'
args:
- exclude:
help: Ignore all files & directories containing the word.
View
@@ -85,7 +85,7 @@
]
},
"Sh":{
"name":"sh",
"name":"Shell",
"base":"hash",
"quotes":[
[
@@ -452,10 +452,9 @@
"single":[
"//"
],
"multi":[[
"(*",
"*)"
]],
"multi":[
["(*", "*)"]
],
"extensions":[
"fs",
"fsi",
View
@@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::ops::AddAssign;
use std::path::PathBuf;
use std::mem;
use regex::{self, Regex};
@@ -24,10 +25,15 @@ fn generate_regex(multi_line: &[(&'static str, &'static str)]) -> Cow<'static, R
Cow::Owned(Regex::new(&raw_regex).unwrap())
}
lazy_static! {
static ref C_REGEX: Regex = Regex::new(r"/\*").unwrap();
fn get_c_regex() -> &'static Regex {
lazy_static! {
static ref C_REGEX: Regex = Regex::new(r"/\*").unwrap();
}
&*C_REGEX
}
impl Language {
/// Constructs a new empty Language with the comments provided.
///
@@ -43,6 +49,7 @@ impl Language {
line_comment: line_comment,
regex: Some(generate_regex(&multi_line)),
multi_line: multi_line,
quotes: vec![("\"", "\"")],
..Self::default()
}
}
@@ -76,7 +83,7 @@ impl Language {
line_comment: vec!["//"],
multi_line: vec![("/*", "*/")],
quotes: vec![("\"", "\"")],
regex: Some(Cow::Borrowed(&*C_REGEX)),
regex: Some(Cow::Borrowed(get_c_regex())),
..Self::default()
}
}
@@ -94,7 +101,7 @@ impl Language {
/// ```
pub fn new_func() -> Self {
lazy_static! {
static ref FUNC_REGEX: Regex = Regex::new(r"\(\*").unwrap();
static ref FUNC_REGEX: Regex = Regex::new(&regex::quote(r"\(\*")).unwrap();
}
Language {
multi_line: vec![("(*", "*)")],
@@ -155,7 +162,7 @@ impl Language {
/// ```
pub fn new_haskell() -> Self {
lazy_static! {
static ref HASKELL_REGEX: Regex = Regex::new(r"\{-").unwrap();
static ref HASKELL_REGEX: Regex = Regex::new(&regex::quote(r"\{-")).unwrap();
}
Language {
@@ -199,7 +206,7 @@ impl Language {
line_comment: vec!["%"],
multi_line: vec![("/*", "*/")],
quotes: vec![("\"", "\"")],
regex: Some(Cow::Borrowed(&*C_REGEX)),
regex: Some(Cow::Borrowed(get_c_regex())),
..Self::default()
}
}
@@ -302,10 +309,12 @@ impl Language {
/// panic!'s if given the wrong category.
///
/// ```
/// # use tokei::*;
/// use tokei::{Language, Stats, Sort};
/// use std::path::PathBuf;
///
/// let mut rust = Language::new_c();
/// let mut foo_stats = Stats::new("foo");
/// let mut bar_stats = Stats::new("bar");
/// let mut foo_stats = Stats::new(PathBuf::from("foo"));
/// let mut bar_stats = Stats::new(PathBuf::from("bar"));
///
/// foo_stats.code += 20;
/// bar_stats.code += 10;
@@ -332,32 +341,12 @@ impl Language {
}
impl AddAssign for Language {
fn add_assign(&mut self, rhs: Self) {
self.lines += rhs.lines;
self.comments += rhs.comments;
self.blanks += rhs.blanks;
self.code += rhs.code;
self.stats.extend_from_slice(&*rhs.stats);
}
}
impl<'a> AddAssign<&'a Language> for Language {
fn add_assign(&mut self, rhs: &'a Self) {
self.lines += rhs.lines;
self.comments += rhs.comments;
self.blanks += rhs.blanks;
self.code += rhs.code;
self.stats.extend_from_slice(&*rhs.stats);
}
}
impl<'a> AddAssign<&'a mut Language> for Language {
fn add_assign(&mut self, rhs: &mut Self) {
fn add_assign(&mut self, mut rhs: Self) {
self.lines += rhs.lines;
self.comments += rhs.comments;
self.blanks += rhs.blanks;
self.code += rhs.code;
self.stats.extend_from_slice(&*rhs.stats);
self.stats.extend(mem::replace(&mut rhs.stats, Vec::new()));
}
}
Oops, something went wrong.

0 comments on commit c08f113

Please sign in to comment.