{-|
Description:    Well-typed errors which may be raised by the HTML parsing algorithm.

Copyright:      (c) 2020 Sam May
License:        MPL-2.0
Maintainer:     ag.eitilt@gmail.com

Stability:      experimental
Portability:    portable
-}
module Web.Mangrove.Parse.Common.Error
    ( ParseError ( .. )
    ) where


import qualified Data.ByteString.Short as BS.SH
import qualified Data.Text as T

import qualified Numeric.Natural as Z

import Web.Willow.DOM


-- | __HTML:__
--      @[parse errors]
--      (https://html.spec.whatwg.org/multipage/parsing.html#parse-errors)@
--      (constructor names directly reflect the identifiers in the spec)
-- 
-- Indicators that something syntactically unexpected was found in an HTML
-- file.  Given the focus on recovery in the parse algorithm, these are more
-- properly warnings than errors, but the name follows that in the
-- specification.
-- 
-- This datatype consists of the union of the errors raised by any of the
-- various stages of the algorithm; no distinction is made between an "encoding
-- error" and a "tree-building error".
-- 
-- Several constructors wrap a payload which would otherwise be unrecoverable
-- from the DOM, to enable richer error reporting.
data ParseError
    = AbruptTemplateFragment
    | AbruptClosingOfEmptyComment
    | AbruptDoctypePublicIdentifier
    | AbruptDoctypeSystemIdentifier
    | AbsenceOfDigitsInNumericCharacterReference
    | BREndTag
    | CDataInHtmlContent
    | CharacterReferenceOutsideUnicodeRange Z.Natural
    | ControlCharacterInInputStream
    | ControlCharacterReference
    | DuplicateAttribute BasicAttribute
    | DuplicateSingletonElement ElementParams
    | EndTagWithAttributes
    | EndTagWithTrailingSolidus
    | EOFBeforeTagName
    | EOFInCData
    | EOFInComment
    | EOFInDoctype
    | EOFInScriptHtmlCommentLikeText
    | EOFInTag -- Payload?
    | EOFInTemplate
    | EOFInText
    | FramesetInBody ElementParams
    | IncompletelyClosedFormattingElement
    | IncorrectlyClosedComment
    | IncorrectlyOpenedComment
    | InvalidByteSequence BS.SH.ShortByteString
    | InvalidCharacterSequenceAfterDoctypeName
    | InvalidFirstCharacterOfTagName
    | LegacyDoctype
    | MalformedTableStructure ElementParams
    | MissingAttributeValue
    | MissingDoctype
    | MissingDoctypeName
    | MissingDoctypePublicIdentifier
    | MissingDoctypeSystemIdentifier
    | MissingEndTagName
    | MissingQuoteBeforeDoctypePublicIdentifier
    | MissingQuoteBeforeDoctypeSystemIdentifier
    | MissingSemicolonAfterCharacterReference
    | MissingWhitespaceAfterDoctypePublicKeyword
    | MissingWhitespaceAfterDoctypeSystemKeyword
    | MissingWhitespaceBeforeDoctypeName
    | MissingWhitespaceBetweenAttributes
    | MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers
    | NestedComment
    | NestedElementForAdoptionAgency
    | NestedNonRecursiveElement
    | NestedSingletonElement
    | NoncharacterCharacterReference Char
    | NoncharacterInInputStream
    | NonVoidHtmlElementStartTagWithTrailingSolidus
    | NullCharacterReference
    | ObsoleteTagName T.Text
    | OverlappingFormattingElements
    | OverlappingHeaderElements
    | OverlappingInputElements
    | SurrogateCharacterReference Char
    | SurrogateInInputStream
    | UnexpectedCharacterAfterDoctypeSystemIdentifier Char
    | UnexpectedCharacterInAttributeName
    | UnexpectedCharacterInUnquotedAttributeValue
    | UnexpectedContentAfterBody
    | UnexpectedDescendantElement ElementParams
    | UnexpectedDoctype DocumentTypeParams
    | UnexpectedElementInTableStructure
    | UnexpectedElementWithImpliedEndTag
    | UnexpectedEqualsSignBeforeAttributeName
    | UnexpectedEndColInColumnGroup
    | UnexpectedEndOfBody
    | UnexpectedEndTag ElementParams
    | UnexpectedFormattingElementOutOfScope
    | UnexpectedHtmlElementInForeignContent
    | UnexpectedMetadataOutsideOfHead
    | UnexpectedNodeAfterFrameset -- Payload?
    | UnexpectedNodeInFrameset -- Payload?
    | UnexpectedNodeInHeadNoscript
    | UnexpectedNodeInTableStructure
    | UnexpectedNullCharacter
    | UnexpectedQuestionMarkInsteadOfTagName
    | UnexpectedSolidusInTag
    | UnexpectedTableCellOutsideOfRow
    | UnexpectedTextInTableStructure
    | UnknownNamedCharacterReference
    | UnmatchedEndTag ElementParams
    | UnmatchedEndPTag
    | XmlnsAttribtuteWithMismatchedValue
  deriving ( ParseError -> ParseError -> Bool
(ParseError -> ParseError -> Bool)
-> (ParseError -> ParseError -> Bool) -> Eq ParseError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParseError -> ParseError -> Bool
$c/= :: ParseError -> ParseError -> Bool
== :: ParseError -> ParseError -> Bool
$c== :: ParseError -> ParseError -> Bool
Eq, Int -> ParseError -> ShowS
[ParseError] -> ShowS
ParseError -> String
(Int -> ParseError -> ShowS)
-> (ParseError -> String)
-> ([ParseError] -> ShowS)
-> Show ParseError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParseError] -> ShowS
$cshowList :: [ParseError] -> ShowS
show :: ParseError -> String
$cshow :: ParseError -> String
showsPrec :: Int -> ParseError -> ShowS
$cshowsPrec :: Int -> ParseError -> ShowS
Show, ReadPrec [ParseError]
ReadPrec ParseError
Int -> ReadS ParseError
ReadS [ParseError]
(Int -> ReadS ParseError)
-> ReadS [ParseError]
-> ReadPrec ParseError
-> ReadPrec [ParseError]
-> Read ParseError
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ParseError]
$creadListPrec :: ReadPrec [ParseError]
readPrec :: ReadPrec ParseError
$creadPrec :: ReadPrec ParseError
readList :: ReadS [ParseError]
$creadList :: ReadS [ParseError]
readsPrec :: Int -> ReadS ParseError
$creadsPrec :: Int -> ReadS ParseError
Read )