aboutsummaryrefslogtreecommitdiff
path: root/parse_wiki_text/src/warning.rs
diff options
context:
space:
mode:
authorJJ2023-01-04 23:57:41 +0000
committerJJ2023-01-04 23:57:48 +0000
commita2e04ff18ad27be4dc1c66079941baaec79e003f (patch)
tree256201497d3c3ef3dba9031ee985d407b80b95a6 /parse_wiki_text/src/warning.rs
parentbaf2f93b3002c2a0769bbd53f37d845c7717d95b (diff)
Copy the last version of the parse_wiki_text crate in for development
Diffstat (limited to 'parse_wiki_text/src/warning.rs')
-rw-r--r--parse_wiki_text/src/warning.rs110
1 files changed, 110 insertions, 0 deletions
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 <https://portstrom.com>
+// 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())
+ }
+}