refactor(parser): rename RstParser to Parser

This commit is contained in:
Orhun Parmaksız 2021-10-28 13:49:32 +03:00
parent f7a084260f
commit 6f3df91efb
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
4 changed files with 13 additions and 11 deletions

View file

@ -54,7 +54,7 @@ impl Paragraph {
}
}
/// Representation of a parsed document.
/// Representation of a parsed document which consists of paragraphs.
#[derive(Clone, Debug)]
pub struct Document {
/// Paragraphs in the document.

View file

@ -2,10 +2,10 @@
#![warn(missing_docs, clippy::unwrap_used)]
/// RST parser.
/// Document parser.
pub mod parser;
/// Parsed document.
/// Parse results.
pub mod document;
/// Error implementation.

View file

@ -5,16 +5,19 @@ use regex::{Captures, Regex, RegexBuilder};
use std::path::Path;
use std::result::Result as StdResult;
/// Parser for the reStructuredText format.
/// Regex-powered parser for text documents.
///
/// It is responsible for traversing the path specified with
/// a glob pattern and parsing the contents of the files.
#[derive(Clone, Debug)]
pub struct RstParser<'a> {
pub struct Parser<'a> {
/// Glob pattern to specify the files to parse.
pub glob_path: &'a str,
/// Regular expression to use for parsing.
pub regex: Regex,
}
impl<'a> RstParser<'a> {
impl<'a> Parser<'a> {
/// Constructs a new instance.
pub fn new(glob_path: &'a str, regex: &'a str) -> Result<Self, Error> {
Ok(Self {

View file

@ -11,27 +11,26 @@ use std::sync::Mutex;
use systeroid_core::error::{Error, Result};
use systeroid_core::sysctl::Sysctl;
use systeroid_parser::document::Document;
use systeroid_parser::parser::RstParser;
use systeroid_parser::parser::Parser;
/// Runs `systeroid`.
pub fn run(args: Args) -> Result<()> {
let mut sysctl = Sysctl::init()?;
let parsers = vec![
RstParser::new("admin-guide/sysctl/*.rst", "^\n([a-z].*)\n[=,-]{2,}+\n\n")?,
RstParser::new(
Parser::new("admin-guide/sysctl/*.rst", "^\n([a-z].*)\n[=,-]{2,}+\n\n")?,
Parser::new(
"networking/*-sysctl.rst",
"^([a-zA-Z0-9_/-]+)[ ]-[ ][a-zA-Z].*$",
)?,
];
let documents = if let Some(kernel_docs) = args.kernel_docs {
let documents = Mutex::new(Vec::new());
parsers.par_iter().try_for_each(|s| {
let mut documents = documents
.lock()
.map_err(|e| Error::ThreadLockError(e.to_string()))?;
let mut parse = |parser: RstParser| -> Result<()> {
let mut parse = |parser: Parser| -> Result<()> {
documents.extend(parser.parse(&kernel_docs)?);
Ok(())
};