mirror of
https://github.com/orhun/systeroid
synced 2024-07-22 02:45:19 +00:00
refactor(parser): rename RstParser
to Parser
This commit is contained in:
parent
f7a084260f
commit
6f3df91efb
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(())
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue