Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the TS prefix for public APIs #192

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rust-code-analysis-cli/src/web/comment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use rust_code_analysis::{rm_comments, Callback, TSParserTrait};
use rust_code_analysis::{rm_comments, Callback, ParserTrait};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebCommentPayload {
Expand Down Expand Up @@ -30,7 +30,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 rust-code-analysis-cli/src/web/function.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use serde_json::{self, Value};

use rust_code_analysis::{function, Callback, FunctionSpan, TSParserTrait};
use rust_code_analysis::{function, Callback, FunctionSpan, ParserTrait};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebFunctionPayload {
Expand Down Expand Up @@ -31,7 +31,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 rust-code-analysis-cli/src/web/metrics.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 std::path::PathBuf;

use rust_code_analysis::{metrics, Callback, FuncSpace, TSParserTrait};
use rust_code_analysis::{metrics, Callback, FuncSpace, ParserTrait};

#[derive(Debug, Deserialize, Serialize)]
pub struct WebMetricsPayload {
Expand Down Expand Up @@ -38,7 +38,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
4 changes: 2 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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 @@ -142,7 +142,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/comment_rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::traits::*;
const CR: [u8; 8192] = [b'\n'; 8192];

/// Removes comments from a code.
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 @@ -76,7 +76,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 @@ -8,7 +8,7 @@ use crate::traits::*;

/// Counts the types of nodes specified in the input slice
/// and the number of nodes in a code.
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 @@ -58,7 +58,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 @@ -5,7 +5,7 @@ use crate::dump::*;
use crate::traits::*;

/// Finds the types of nodes specified in the input slice.
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 @@ -62,7 +62,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.to_str().unwrap());
Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct FunctionSpan {
/// Returns a vector containing the [`FunctionSpan`] of each function
///
/// [`FunctionSpan`]: struct.FunctionSpan.html
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 @@ -122,7 +122,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 @@ -105,8 +105,8 @@ pub use crate::tools::*;
mod traits;
pub use crate::traits::*;

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

mod comment_rm;
pub use crate::comment_rm::*;
3 changes: 2 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,11 @@ macro_rules! mk_code {
stringify!($camel)
}
}

#[doc = "The `"]
#[doc = $docname]
#[doc = "` language parser."]
pub type $parser = TSParser<$code>;
pub type $parser = Parser<$code>;
)*
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/output/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::traits::*;
/// ```
/// use std::path::PathBuf;
///
/// use rust_code_analysis::{dump_node, CppParser, TSParserTrait};
/// use rust_code_analysis::{dump_node, CppParser, ParserTrait};
///
/// # fn main() {
/// let source_code = "int a = 42;";
Expand Down Expand Up @@ -172,7 +172,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::alterator::Alterator;
use crate::c_macro;
Expand All @@ -11,7 +11,7 @@ use crate::langs::*;
use crate::preproc::{get_macros, PreprocResults};
use crate::traits::*;

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
6 changes: 3 additions & 3 deletions src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn finalize<'a>(space_stack: &mut Vec<FuncSpace<'a>>, diff_level: usize) {
/// ```
/// use std::path::PathBuf;
///
/// use rust_code_analysis::{CppParser, metrics, TSParserTrait};
/// use rust_code_analysis::{CppParser, metrics, ParserTrait};
///
/// # fn main() {
/// let source_code = "int a = 42;";
Expand All @@ -190,7 +190,7 @@ fn finalize<'a>(space_stack: &mut Vec<FuncSpace<'a>>, diff_level: usize) {
/// metrics(&parser, &path).unwrap();
/// # }
/// ```
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 @@ -282,7 +282,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 @@ -13,8 +13,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;

/// A trait for callback functions.
///
Expand All @@ -27,7 +27,7 @@ pub trait Callback {
type Cfg;

/// Calls a function inside the library and returns its value
fn call<T: TSParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
}

#[doc(hidden)]
Expand All @@ -43,7 +43,7 @@ pub trait TSLanguage {
}

#[doc(hidden)]
pub trait TSParserTrait {
pub trait ParserTrait {
type Checker: Alterator + Checker;
type Getter: Getter;
type Cyclomatic: Cyclomatic;
Expand Down