From da2793d39aa9142422e319a664cd68534054221a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 7 Jan 2023 11:33:59 +0200 Subject: refactor: move RikiError::WikitextSyntax into src/parser.rs Sponsored-by: author --- src/error.rs | 8 ++++---- src/parser.rs | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 6d4d13b..a3944c3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,9 @@ pub enum RikiError { #[error(transparent)] Directive(#[from] crate::directive::DirectiveError), + #[error(transparent)] + Parser(#[from] crate::parser::ParserError), + #[error("string formatting error: {0}")] Format(#[source] std::fmt::Error), @@ -36,9 +39,6 @@ pub enum RikiError { #[error(transparent)] PageSpec(#[from] crate::pagespec::PageSpecError), - #[error("failed to parse wikitext, line {0}, column {1}: {2:?}")] - WikitextSyntax(usize, usize, Vec), - #[error(transparent)] HtmlError(#[from] HtmlError), } @@ -46,6 +46,6 @@ pub enum RikiError { impl RikiError { pub fn wikitext_syntax(line: usize, col: usize, tokens: &[crate::token::TokenKind]) -> Self { let tokens = tokens.to_vec(); - Self::WikitextSyntax(line, col, tokens) + crate::parser::ParserError::WikitextSyntax(line, col, tokens).into() } } diff --git a/src/parser.rs b/src/parser.rs index 81eda42..e13363e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -5,6 +5,12 @@ use line_col::LineColLookup; use log::{debug, trace}; use std::collections::HashMap; +#[derive(Debug, thiserror::Error)] +pub enum ParserError { + #[error("failed to parse wikitext, line {0}, column {1}: {2:?}")] + WikitextSyntax(usize, usize, Vec), +} + #[derive(Debug)] pub struct WikitextParser { tokens: Vec, -- cgit v1.2.1