From 6f3df91efbae3a05e434a1d08b8ac29956b3f557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Thu, 28 Oct 2021 13:49:32 +0300 Subject: [PATCH] refactor(parser): rename `RstParser` to `Parser` --- systeroid-parser/src/document.rs | 2 +- systeroid-parser/src/lib.rs | 4 ++-- systeroid-parser/src/parser.rs | 9 ++++++--- systeroid/src/lib.rs | 9 ++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/systeroid-parser/src/document.rs b/systeroid-parser/src/document.rs index 6dda974..ba80963 100644 --- a/systeroid-parser/src/document.rs +++ b/systeroid-parser/src/document.rs @@ -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. diff --git a/systeroid-parser/src/lib.rs b/systeroid-parser/src/lib.rs index 80de0fa..f024b78 100644 --- a/systeroid-parser/src/lib.rs +++ b/systeroid-parser/src/lib.rs @@ -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. diff --git a/systeroid-parser/src/parser.rs b/systeroid-parser/src/parser.rs index b6f1262..d1dfe02 100644 --- a/systeroid-parser/src/parser.rs +++ b/systeroid-parser/src/parser.rs @@ -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 { Ok(Self { diff --git a/systeroid/src/lib.rs b/systeroid/src/lib.rs index c5f8189..6ec761e 100644 --- a/systeroid/src/lib.rs +++ b/systeroid/src/lib.rs @@ -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(()) };