From a2e04ff18ad27be4dc1c66079941baaec79e003f Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 4 Jan 2023 15:57:41 -0800 Subject: Copy the last version of the parse_wiki_text crate in for development --- parse_wiki_text/src/warning.rs | 110 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 parse_wiki_text/src/warning.rs (limited to 'parse_wiki_text/src/warning.rs') diff --git a/parse_wiki_text/src/warning.rs b/parse_wiki_text/src/warning.rs new file mode 100644 index 0000000..22e1421 --- /dev/null +++ b/parse_wiki_text/src/warning.rs @@ -0,0 +1,110 @@ +// Copyright 2019 Fredrik Portström +// This is free software distributed under the terms specified in +// the file LICENSE at the top-level directory of this distribution. + +use std::fmt; + +/// Warning from the parser telling that something is not well-formed. +#[derive(Debug)] +pub struct Warning { + /// The byte position in the wiki text where the warning ends. + pub end: usize, + + /// An identifier for the kind of warning. + pub message: WarningMessage, + + /// The byte position in the wiki text where the warning starts. + pub start: usize, +} + +/// Identifier for a kind of warning from the parser. +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +pub enum WarningMessage { + /// List broken by definition term. + DefinitionTermContinuation, + + /// End tag in comment. + EndTagInComment, + + /// Invalid character. + InvalidCharacter, + + /// Invalid heading syntax. Rewinding. + InvalidHeadingSyntaxRewinding, + + /// Invalid link syntax. + InvalidLinkSyntax, + + /// Invalid parameter syntax. + InvalidParameterSyntax, + + /// Invalid tag syntax. + InvalidTagSyntax, + + /// Missing end tag. Rewinding. + MissingEndTagRewinding, + + /// Repeated empty line. + RepeatedEmptyLine, + + /// Stray text in table. + StrayTextInTable, + + /// Wiki text comes after a redirect. + TextAfterRedirect, + + /// The end tag does not match the last start tag. Rewinding. + UnexpectedEndTagRewinding, + + /// An end tag was found with no preceeding start tag. + UnexpectedEndTag, + + /// Expected heading of higher level. Correcting start of heading. + UnexpectedHeadingLevelCorrecting, + + /// A tag with an unrecognized tag name was found. + UnrecognizedTagName, + + /// Useless text in parameter. + UselessTextInParameter, + + /// Useless text in redirect. + UselessTextInRedirect, +} + +impl WarningMessage { + /// Human-readable description of the warning. + pub fn message(self) -> &'static str { + match self { + WarningMessage::DefinitionTermContinuation => "List broken by definition term.", + WarningMessage::EndTagInComment => "End tag in comment.", + WarningMessage::InvalidCharacter => "Invalid character.", + WarningMessage::InvalidHeadingSyntaxRewinding => "Invalid heading syntax. Rewinding.", + WarningMessage::InvalidLinkSyntax => "Invalid link syntax.", + WarningMessage::InvalidParameterSyntax => "Invalid parameter syntax.", + WarningMessage::InvalidTagSyntax => "Invalid tag syntax.", + WarningMessage::MissingEndTagRewinding => "Missing end tag. Rewinding.", + WarningMessage::RepeatedEmptyLine => "Repeated empty line.", + WarningMessage::StrayTextInTable => "Stray text in table.", + WarningMessage::TextAfterRedirect => "Wiki text comes after a redirect.", + WarningMessage::UnexpectedEndTagRewinding => { + "The end tag does not match the last start tag. Rewinding." + } + WarningMessage::UnexpectedEndTag => { + "An end tag was found with no preceeding start tag." + } + WarningMessage::UnexpectedHeadingLevelCorrecting => { + "Expected heading of higher level. Correcting start of heading." + } + WarningMessage::UnrecognizedTagName => "A tag with an unrecognized tag name was found.", + WarningMessage::UselessTextInParameter => "Useless text in parameter.", + WarningMessage::UselessTextInRedirect => "Useless text in redirect.", + } + } +} + +impl fmt::Display for WarningMessage { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str(self.message()) + } +} -- cgit v1.2.3-70-g09d2