Skip to content

Commit

Permalink
Remove the TS prefix for public APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 committed May 26, 2020
1 parent 1e1b25f commit a1c88ad
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/comment_rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::traits::*;

const CR: [u8; 8192] = [b'\n'; 8192];

pub fn rm_comments<T: TSParserTrait>(parser: &T) -> Option<Vec<u8>> {
pub fn rm_comments<T: ParserTrait>(parser: &T) -> Option<Vec<u8>> {
let node = parser.get_root();
let mut stack = Vec::new();
let mut cursor = node.walk();
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Callback for CommentRm {
type Res = std::io::Result<()>;
type Cfg = CommentRmCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
if let Some(new_source) = rm_comments(parser) {
if cfg.in_place {
write_file(&cfg.path, &new_source)?;
Expand Down
4 changes: 2 additions & 2 deletions src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex};

use crate::traits::*;

pub fn count<'a, T: TSParserTrait>(parser: &'a T, filters: &[String]) -> (usize, usize) {
pub fn count<'a, T: ParserTrait>(parser: &'a T, filters: &[String]) -> (usize, usize) {
let filters = parser.get_filters(filters);
let node = parser.get_root();
let mut cursor = node.walk();
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Callback for Count {
type Res = std::io::Result<()>;
type Cfg = CountCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
let (good, total) = count(parser, &cfg.filters);
let mut results = cfg.stats.lock().unwrap();
results.good += good;
Expand Down
4 changes: 2 additions & 2 deletions src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tree_sitter::Node;
use crate::dump::*;
use crate::traits::*;

pub fn find<'a, T: TSParserTrait>(parser: &'a T, filters: &[String]) -> Option<Vec<Node<'a>>> {
pub fn find<'a, T: ParserTrait>(parser: &'a T, filters: &[String]) -> Option<Vec<Node<'a>>> {
let filters = parser.get_filters(filters);
let node = parser.get_root();
let mut cursor = node.walk();
Expand Down Expand Up @@ -47,7 +47,7 @@ impl Callback for Find {
type Res = std::io::Result<()>;
type Cfg = FindCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
if let Some(good) = find(parser, &cfg.filters) {
if !good.is_empty() {
println!("In file {:?}", cfg.path);
Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct FunctionSpan {
pub error: bool,
}

pub fn function<T: TSParserTrait>(parser: &T) -> Vec<FunctionSpan> {
pub fn function<T: ParserTrait>(parser: &T) -> Vec<FunctionSpan> {
let root = parser.get_root();
let code = parser.get_code();
let mut spans = Vec::new();
Expand Down Expand Up @@ -106,7 +106,7 @@ impl Callback for Function {
type Res = std::io::Result<()>;
type Cfg = FunctionCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
dump_spans(function(parser), cfg.path)
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub use crate::tools::*;
mod traits;
pub use crate::traits::*;

mod ts_parser;
pub use crate::ts_parser::*;
mod parser;
pub use crate::parser::*;

mod checker;
pub use crate::checker::*;
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ macro_rules! mk_code {
stringify!($camel)
}
}
pub type $parser = TSParser<$code>;
pub type $parser = Parser<$code>;
)*
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/output/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Callback for Dump {
type Res = std::io::Result<()>;
type Cfg = DumpCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
dump_node(
&parser.get_code(),
&parser.get_root(),
Expand Down
10 changes: 5 additions & 5 deletions src/ts_parser.rs → src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::marker::PhantomData;
use std::path::PathBuf;
use std::sync::Arc;
use tree_sitter::{Node, Parser, Tree};
use tree_sitter::{Node, Parser as TSParser, Tree};

use crate::c_macro;
use crate::checker::*;
Expand All @@ -11,7 +11,7 @@ use crate::preproc::{get_macros, PreprocResults};
use crate::traits::*;
use crate::web::alterator::Alterator;

pub struct TSParser<T: TSLanguage + Checker + Getter + Alterator + CodeMetricsT> {
pub struct Parser<T: TSLanguage + Checker + Getter + Alterator + CodeMetricsT> {
code: Vec<u8>,
tree: Tree,
phantom: PhantomData<T>,
Expand Down Expand Up @@ -62,8 +62,8 @@ fn get_fake_code<T: TSLanguage>(
}
}

impl<T: 'static + TSLanguage + Checker + Getter + Alterator + CodeMetricsT> TSParserTrait
for TSParser<T>
impl<T: 'static + TSLanguage + Checker + Getter + Alterator + CodeMetricsT> ParserTrait
for Parser<T>
{
type Checker = T;
type Getter = T;
Expand All @@ -76,7 +76,7 @@ impl<T: 'static + TSLanguage + Checker + Getter + Alterator + CodeMetricsT> TSPa
type Exit = T;

fn new(code: Vec<u8>, path: &PathBuf, pr: Option<Arc<PreprocResults>>) -> Self {
let mut parser = Parser::new();
let mut parser = TSParser::new();
parser.set_language(T::get_language()).unwrap();
let fake_code = get_fake_code::<T>(&code, path, pr);
/*let tree = if let Some(fake) = fake_code {
Expand Down
4 changes: 2 additions & 2 deletions src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn finalize<'a>(space_stack: &mut Vec<FuncSpace<'a>>, diff_level: usize) {
}
}

pub fn metrics<'a, T: TSParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option<FuncSpace<'a>> {
pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option<FuncSpace<'a>> {
let code = parser.get_code();
let node = parser.get_root();
let mut cursor = node.walk();
Expand Down Expand Up @@ -221,7 +221,7 @@ impl Callback for Metrics {
type Res = std::io::Result<()>;
type Cfg = MetricsCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
if let Some(space) = metrics(parser, &cfg.path) {
if let Some(output_format) = cfg.output_format {
dump_formats(
Expand Down
6 changes: 3 additions & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::langs::*;
use crate::loc::Loc;
use crate::mi::Mi;
use crate::nom::Nom;
use crate::parser::Filter;
use crate::preproc::PreprocResults;
use crate::ts_parser::Filter;
use crate::web::alterator::Alterator;

pub trait CodeMetricsT: Cyclomatic + Exit + Halstead + NArgs + Loc + Nom + Mi {}
Expand All @@ -26,7 +26,7 @@ pub trait TSLanguage {
fn get_lang_name() -> &'static str;
}

pub trait TSParserTrait {
pub trait ParserTrait {
type Checker: Alterator + Checker;
type Getter: Getter;
type Cyclomatic: Cyclomatic;
Expand All @@ -48,7 +48,7 @@ pub trait Callback {
type Res;
type Cfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
}

pub trait Search<'a> {
Expand Down
6 changes: 3 additions & 3 deletions src/web/ast.bak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::rc::Rc;
use tree_sitter::Node;

use crate::checker::Checker;
use crate::traits::{Callback, TSParserTrait};
use crate::traits::{Callback, ParserTrait};

type Span = Option<(usize, usize, usize, usize)>;

Expand Down Expand Up @@ -82,7 +82,7 @@ fn get_ast_node<T: Checker>(
}
}

fn build<T: TSParserTrait>(parser: &T, span: bool, comment: bool) -> Option<AstNode> {
fn build<T: ParserTrait>(parser: &T, span: bool, comment: bool) -> Option<AstNode> {
let code = parser.get_code();
let root = parser.get_root();
let mut cursor = root.walk();
Expand Down Expand Up @@ -124,7 +124,7 @@ impl Callback for AstCallback {
type Res = AstResponse;
type Cfg = AstCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
AstResponse {
id: cfg.id,
root: build(parser, cfg.span, cfg.comment),
Expand Down
6 changes: 3 additions & 3 deletions src/web/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::ser::{SerializeStruct, Serializer};
use serde::{Deserialize, Serialize};

use super::alterator::Alterator;
use crate::traits::{Callback, TSParserTrait};
use crate::traits::{Callback, ParserTrait};

pub type Span = Option<(usize, usize, usize, usize)>;

Expand Down Expand Up @@ -54,7 +54,7 @@ impl AstNode {
}
}

fn build<T: TSParserTrait>(parser: &T, span: bool, comment: bool) -> Option<AstNode> {
fn build<T: ParserTrait>(parser: &T, span: bool, comment: bool) -> Option<AstNode> {
let code = parser.get_code();
let root = parser.get_root();
let mut cursor = root.walk();
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Callback for AstCallback {
type Res = AstResponse;
type Cfg = AstCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
AstResponse {
id: cfg.id,
root: build(parser, cfg.span, cfg.comment),
Expand Down
4 changes: 2 additions & 2 deletions src/web/comment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::comment_rm::rm_comments;
use crate::traits::{Callback, TSParserTrait};
use crate::traits::{Callback, ParserTrait};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebCommentPayload {
Expand Down Expand Up @@ -31,7 +31,7 @@ impl Callback for WebCommentCallback {
type Res = WebCommentResponse;
type Cfg = WebCommentCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
WebCommentResponse {
id: cfg.id,
code: rm_comments(parser),
Expand Down
4 changes: 2 additions & 2 deletions src/web/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use serde_json::{self, Value};

use crate::function::{function, FunctionSpan};
use crate::traits::{Callback, TSParserTrait};
use crate::traits::{Callback, ParserTrait};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebFunctionPayload {
Expand Down Expand Up @@ -32,7 +32,7 @@ impl Callback for WebFunctionCallback {
type Res = Value;
type Cfg = WebFunctionCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
let spans = function(parser);
serde_json::to_value(WebFunctionResponse { id: cfg.id, spans }).unwrap()
}
Expand Down
4 changes: 2 additions & 2 deletions src/web/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_json::{self, Value};
use std::path::PathBuf;

use crate::spaces::{metrics, FuncSpace};
use crate::traits::{Callback, TSParserTrait};
use crate::traits::{Callback, ParserTrait};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebMetricsPayload {
Expand Down Expand Up @@ -39,7 +39,7 @@ impl Callback for WebMetricsCallback {
type Res = Value;
type Cfg = WebMetricsCfg;

fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
let spaces = metrics(parser, &cfg.path);
let spaces = if cfg.unit {
if let Some(mut spaces) = spaces {
Expand Down

0 comments on commit a1c88ad

Please sign in to comment.