refactor(parser): rename crate

This commit is contained in:
Orhun Parmaksız 2022-02-24 00:17:26 +03:00
parent d694181740
commit 01a4f3fb81
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
17 changed files with 54 additions and 43 deletions

24
Cargo.lock generated
View file

@ -483,6 +483,16 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "parseit"
version = "0.1.0"
dependencies = [
"flate2",
"globwalk",
"regex",
"thiserror",
]
[[package]]
name = "pkg-config"
version = "0.3.24"
@ -707,8 +717,8 @@ name = "systeroid"
version = "0.1.0"
dependencies = [
"getopts",
"parseit",
"systeroid-core",
"systeroid-parser",
]
[[package]]
@ -718,21 +728,11 @@ dependencies = [
"colored",
"dirs-next",
"lazy_static",
"parseit",
"rayon",
"serde",
"serde_json",
"sysctl",
"systeroid-parser",
"thiserror",
]
[[package]]
name = "systeroid-parser"
version = "0.1.0"
dependencies = [
"flate2",
"globwalk",
"regex",
"thiserror",
]

View file

@ -1,9 +1,9 @@
[workspace]
members = [
"systeroid-parser",
"systeroid-core",
"systeroid-tui",
"systeroid"
"systeroid",
"parseit",
]
[profile.dev]

View file

@ -1,13 +1,17 @@
[package]
name = "systeroid-parser"
name = "parseit"
version = "0.1.0"
description = "Simple text file parsing library powered by regex and glob patterns"
authors = ["Orhun Parmaksız <orhunparmaksiz@gmail.com>"]
repository = "https://github.com/orhun/systeroid"
license = "MIT OR Apache-2.0"
edition = "2021"
[features]
gzip = ["flate2"]
[dependencies]
regex = "1.5.4"
globwalk = "0.8.1"
thiserror = "1.0.29"
flate2 = "1.0.22"
flate2 = { version = "1.0.22", optional = true }

View file

@ -1,6 +1,6 @@
use parseit::error::Error;
use parseit::parser::Parser;
use std::path::PathBuf;
use systeroid_parser::error::Error;
use systeroid_parser::parser::Parser;
// Parse Cargo manifest and print sections.
fn main() -> Result<(), Error> {

View file

@ -1,4 +1,4 @@
//! systeroid-parser
//! Simple text file parsing library powered by [regex](https://en.wikipedia.org/wiki/Regular_expression) and [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)).
#![warn(missing_docs, clippy::unwrap_used)]
@ -11,7 +11,7 @@ pub use globwalk;
/// Document parser.
pub mod parser;
/// Parse results.
/// Parser results.
pub mod document;
/// Error implementation.

View file

@ -6,7 +6,7 @@ use regex::{Captures, Regex, RegexBuilder};
use std::path::Path;
use std::result::Result as StdResult;
/// Regex-powered parser for text documents.
/// Parser for text files.
///
/// It is responsible for traversing the path specified with
/// a glob pattern and parsing the contents of the files.
@ -59,11 +59,16 @@ impl<'a> Parser<'a> {
.ok_or_else(|| Error::MissingFileError(file_name.to_string()))
})?;
for file in glob_files {
let input = if file.path().extension().and_then(|ext| ext.to_str()) == Some("gz") {
reader::read_gzip(file.path())?
} else {
reader::read_to_string(file.path())?
};
let input = {
#[cfg(feature = "gzip")]
if file.path().extension().and_then(|ext| ext.to_str()) == Some("gz") {
reader::read_gzip(file.path())
} else {
reader::read_to_string(file.path())
}
#[cfg(not(feature = "gzip"))]
reader::read_to_string(file.path())
}?;
let capture_group = self
.regex
.captures_iter(&input)

View file

@ -1,7 +1,6 @@
use flate2::read::GzDecoder;
use std::fs::File;
use std::io::{
BufRead, BufReader as IoBufReader, Error as IoError, ErrorKind as IoErrorKind, Read,
BufRead, BufReader as IoBufReader, Error as IoError, ErrorKind as IoErrorKind,
Result as IoResult,
};
use std::path::Path;
@ -80,12 +79,14 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> IoResult<String> {
/// Reads (decodes) the given gzip file into a string.
///
/// Uses [`BufReader`] under the hood.
#[cfg(feature = "gzip")]
pub fn read_gzip<P: AsRef<Path>>(path: P) -> IoResult<String> {
use std::io::Read;
let mut bytes = Vec::<u8>::new();
for read_bytes in BufReader::open(path, None)? {
bytes.extend(read_bytes?.to_vec());
}
let mut gz = GzDecoder::new(&bytes[..]);
let mut gz = flate2::read::GzDecoder::new(&bytes[..]);
let mut data = String::new();
gz.read_to_string(&mut data)?;
Ok(data)

View file

@ -1,6 +1,6 @@
use parseit::error::Error;
use parseit::parser::Parser;
use std::path::PathBuf;
use systeroid_parser::error::Error;
use systeroid_parser::parser::Parser;
#[test]
fn test_parser() -> Result<(), Error> {

View file

@ -16,6 +16,7 @@ serde = { version = "1.0.135", features = ["derive"] }
serde_json = "1.0.78"
dirs-next = "2.0.0"
[dependencies.systeroid-parser]
[dependencies.parseit]
version = "0.1.0"
path = "../systeroid-parser"
path = "../parseit"
features = ["gzip"]

View file

@ -1,11 +1,11 @@
use crate::error::{Error, Result};
use parseit::reader;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::fs::{self, File};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use systeroid_parser::reader;
/// Cache data to store on the file system.
#[derive(Debug, Serialize, Deserialize)]

View file

@ -20,7 +20,7 @@ pub enum Error {
SystemTimeError(#[from] std::time::SystemTimeError),
/// Error that may occur while parsing documents.
#[error(transparent)]
ParseError(#[from] systeroid_parser::error::Error),
ParseError(#[from] parseit::error::Error),
/// Error that may occur while handling sysctl operations.
#[error("sysctl error: `{0}`")]
SysctlError(#[from] sysctl::SysctlError),

View file

@ -6,7 +6,7 @@
extern crate lazy_static;
/// Export regex crate.
pub use systeroid_parser::regex;
pub use parseit::regex;
/// Sysctl implementation.
pub mod sysctl;

View file

@ -1,9 +1,9 @@
use crate::error::{Error, Result};
use parseit::document::Document;
use parseit::parser::Parser;
use parseit::regex::RegexBuilder;
use rayon::prelude::*;
use std::path::Path;
use systeroid_parser::document::Document;
use systeroid_parser::parser::Parser;
use systeroid_parser::regex::RegexBuilder;
lazy_static! {
/// Possible locations for the Linux kernel documentation.

View file

@ -14,9 +14,9 @@ live-tests = []
[dependencies]
getopts = "0.2.21"
[dependencies.systeroid-parser]
[dependencies.parseit]
version = "0.1.0"
path = "../systeroid-parser"
path = "../parseit"
[dependencies.systeroid-core]
version = "0.1.0"

View file

@ -1,4 +1,6 @@
use crate::output::OutputType;
use parseit::globwalk;
use parseit::reader;
use std::env;
use std::io::Write;
use std::path::PathBuf;
@ -10,8 +12,6 @@ use systeroid_core::sysctl::controller::Sysctl;
use systeroid_core::sysctl::parameter::Parameter;
use systeroid_core::sysctl::{DEPRECATED_PARAMS, SYSTEM_PRELOAD};
use systeroid_core::tree::{Tree, TreeNode};
use systeroid_parser::globwalk;
use systeroid_parser::reader;
/// Application controller.
#[derive(Debug)]