{-# LANGUAGE DeriveGeneric          #-}
{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses  #-}
{-# LANGUAGE PostfixOperators       #-}
{-# LANGUAGE Safe                   #-}

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

-- |
-- Copyright: © Oren Ben-Kiki 2007,
--            © Herbert Valerio Riedel 2015-2018
-- SPDX-License-Identifier: GPL-2.0-or-later
--
-- Tokenizer for the YAML 1.2 syntax as defined in <http://yaml.org/spec/1.2/spec.html>.
--
module Data.YAML.Token
  ( tokenize
  , Token(..)
  , Code(..)
  , Encoding(..)
  ) where

import qualified Data.ByteString.Lazy.Char8 as BLC
import qualified Data.DList                 as D
import           Prelude                    hiding ((*), (+), (-), (/), (^))
import qualified Prelude

import           Data.YAML.Token.Encoding   (Encoding (..), decode)

import           Util                       hiding (empty)
import qualified Util

-- * Generic operators
--
-- ** Numeric operators
--
-- We rename the four numerical operators @+@ @-@ @*@ @\/@ to start with @.@
-- (@.+@, @.-@, @.*@, @.\/@). This allows us to use the originals for BNF
-- notation (we also hijack the @^@ operator). This is not a generally
-- recommended practice. It is justified in this case since we have very little
-- arithmetic operations, and a lot of BNF rules which this makes extremely
-- readable.

infixl 6 .+
-- | \".+\" is the numeric addition (we use \"+\" for postfix \"one or more\").
(.+) :: Int -> Int -> Int
.+ :: Int -> Int -> Int
(.+) = Int -> Int -> Int
forall a. Num a => a -> a -> a
(Prelude.+)

infixl 6 .-
-- | \".-\" is the numeric subtraction (we use \"-\" for infix \"and not\").
(.-) :: Int -> Int -> Int
.- :: Int -> Int -> Int
(.-) = Int -> Int -> Int
forall a. Num a => a -> a -> a
(Prelude.-)

{-
infixl 7 .*
-- | \".*\" is the numeric multiplication (we use \"*\" for postfix \"zero or
-- more\").
(.*) :: Int -> Int -> Int
(.*) = (Prelude.*)
-}

-- ** Record field access
--
-- We also define @^.@ for record access for increased readability.

infixl 8 ^.
-- | @record ^. field@ is the same as @field record@,  but is more readable.
--
-- NB: This trivially emulates the @lens@ operator
(^.) :: record -> (record -> value) -> value
record
record ^. :: forall record value. record -> (record -> value) -> value
^. record -> value
field = record -> value
field record
record

-- * Result tokens
--
-- The parsing result is a stream of tokens rather than a parse tree. The idea
-- is to convert the YAML input into \"byte codes\". These byte codes are
-- intended to be written into a byte codes file (or more likely a UNIX pipe)
-- for further processing.

-- | 'Token' codes.
data Code = Bom             -- ^ BOM, contains \"@TF8@\", \"@TF16LE@\", \"@TF32BE@\", etc.
          | Text            -- ^ Content text characters.
          | Meta            -- ^ Non-content (meta) text characters.
          | Break           -- ^ Separation line break.
          | LineFeed        -- ^ Line break normalized to content line feed.
          | LineFold        -- ^ Line break folded to content space.
          | Indicator       -- ^ Character indicating structure.
          | White           -- ^ Separation white space.
          | Indent          -- ^ Indentation spaces.
          | DirectivesEnd   -- ^ Document start marker.
          | DocumentEnd     -- ^ Document end marker.
          | BeginEscape     -- ^ Begins escape sequence.
          | EndEscape       -- ^ Ends escape sequence.
          | BeginComment    -- ^ Begins comment.
          | EndComment      -- ^ Ends comment.
          | BeginDirective  -- ^ Begins directive.
          | EndDirective    -- ^ Ends directive.
          | BeginTag        -- ^ Begins tag.
          | EndTag          -- ^ Ends tag.
          | BeginHandle     -- ^ Begins tag handle.
          | EndHandle       -- ^ Ends tag handle.
          | BeginAnchor     -- ^ Begins anchor.
          | EndAnchor       -- ^ Ends anchor.
          | BeginProperties -- ^ Begins node properties.
          | EndProperties   -- ^ Ends node properties.
          | BeginAlias      -- ^ Begins alias.
          | EndAlias        -- ^ Ends alias.
          | BeginScalar     -- ^ Begins scalar content.
          | EndScalar       -- ^ Ends scalar content.
          | BeginSequence   -- ^ Begins sequence content.
          | EndSequence     -- ^ Ends sequence content.
          | BeginMapping    -- ^ Begins mapping content.
          | EndMapping      -- ^ Ends mapping content.
          | BeginPair       -- ^ Begins mapping key:value pair.
          | EndPair         -- ^ Ends mapping key:value pair.
          | BeginNode       -- ^ Begins complete node.
          | EndNode         -- ^ Ends complete node.
          | BeginDocument   -- ^ Begins document.
          | EndDocument     -- ^ Ends document.
          | BeginStream     -- ^ Begins YAML stream.
          | EndStream       -- ^ Ends YAML stream.
          | Error           -- ^ Parsing error at this point.
          | Unparsed        -- ^ Unparsed due to errors (or at end of test).
          | Detected        -- ^ Detected parameter (for testing).
  deriving (Int -> Code -> ShowS
[Code] -> ShowS
Code -> String
(Int -> Code -> ShowS)
-> (Code -> String) -> ([Code] -> ShowS) -> Show Code
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Code -> ShowS
showsPrec :: Int -> Code -> ShowS
$cshow :: Code -> String
show :: Code -> String
$cshowList :: [Code] -> ShowS
showList :: [Code] -> ShowS
Show,Code -> Code -> Bool
(Code -> Code -> Bool) -> (Code -> Code -> Bool) -> Eq Code
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Code -> Code -> Bool
== :: Code -> Code -> Bool
$c/= :: Code -> Code -> Bool
/= :: Code -> Code -> Bool
Eq,(forall x. Code -> Rep Code x)
-> (forall x. Rep Code x -> Code) -> Generic Code
forall x. Rep Code x -> Code
forall x. Code -> Rep Code x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Code -> Rep Code x
from :: forall x. Code -> Rep Code x
$cto :: forall x. Rep Code x -> Code
to :: forall x. Rep Code x -> Code
Generic)

-- | @since 0.2.0
instance NFData Code where
  rnf :: Code -> ()
rnf Code
x = Code -> () -> ()
forall a b. a -> b -> b
seq Code
x ()

{-
-- | @show code@ converts a 'Code' to the one-character YEAST token code char.
-- The list of byte codes is also documented in the @yaml2yeast@ program.
instance Show Code where
  show code = case code of
                   Bom             -> "U"
                   Text            -> "T"
                   Meta            -> "t"
                   Break           -> "b"
                   LineFeed        -> "L"
                   LineFold        -> "l"
                   Indicator       -> "I"
                   White           -> "w"
                   Indent          -> "i"
                   DirectivesEnd   -> "K"
                   DocumentEnd     -> "k"
                   BeginEscape     -> "E"
                   EndEscape       -> "e"
                   BeginComment    -> "C"
                   EndComment      -> "c"
                   BeginDirective  -> "D"
                   EndDirective    -> "d"
                   BeginTag        -> "G"
                   EndTag          -> "g"
                   BeginHandle     -> "H"
                   EndHandle       -> "h"
                   BeginAnchor     -> "A"
                   EndAnchor       -> "a"
                   BeginProperties -> "P"
                   EndProperties   -> "p"
                   BeginAlias      -> "R"
                   EndAlias        -> "r"
                   BeginScalar     -> "S"
                   EndScalar       -> "s"
                   BeginSequence   -> "Q"
                   EndSequence     -> "q"
                   BeginMapping    -> "M"
                   EndMapping      -> "m"
                   BeginNode       -> "N"
                   EndNode         -> "n"
                   BeginPair       -> "X"
                   EndPair         -> "x"
                   BeginDocument   -> "O"
                   EndDocument     -> "o"
                   Error           -> "!"
                   Unparsed        -> "-"
                   Detected        -> "$"
-}

-- | Parsed token.
data Token = Token {
    Token -> Int
tByteOffset :: !Int,   -- ^ 0-base byte offset in stream.
    Token -> Int
tCharOffset :: !Int,   -- ^ 0-base character offset in stream.
    Token -> Int
tLine       :: !Int,   -- ^ 1-based line number.
    Token -> Int
tLineChar   :: !Int,   -- ^ 0-based character in line.
    Token -> Code
tCode       :: !Code,  -- ^ Specific token 'Code'.
    Token -> String
tText       :: !String -- ^ Contained input chars, if any.
  } deriving (Int -> Token -> ShowS
[Token] -> ShowS
Token -> String
(Int -> Token -> ShowS)
-> (Token -> String) -> ([Token] -> ShowS) -> Show Token
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Token -> ShowS
showsPrec :: Int -> Token -> ShowS
$cshow :: Token -> String
show :: Token -> String
$cshowList :: [Token] -> ShowS
showList :: [Token] -> ShowS
Show,(forall x. Token -> Rep Token x)
-> (forall x. Rep Token x -> Token) -> Generic Token
forall x. Rep Token x -> Token
forall x. Token -> Rep Token x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Token -> Rep Token x
from :: forall x. Token -> Rep Token x
$cto :: forall x. Rep Token x -> Token
to :: forall x. Rep Token x -> Token
Generic)

-- | @since 0.2.0
instance NFData Token where
  rnf :: Token -> ()
rnf Token { tText :: Token -> String
tText = String
txt } = String -> ()
forall a. NFData a => a -> ()
rnf String
txt

-- * Parsing framework
--
-- Haskell has no shortage of parsing frameworks. We use our own because:
--
--  * Most available frameworks are inappropriate because of their focus on
--    building a parse tree, and completing all of it before any of it is
--    accessible to the caller. We return a stream of tokens, and would like
--    its head to be accessible as soon as possible to allow for streaming. To
--    do this with bounded memory usage we use a combination of continuation
--    passing style and difference lists for the collected tokens.
--
--  * Haskell makes it so easy to roll your own parsing framework. We need some
--    specialized machinery (limited lookahead, forbidden patterns). It is
--    possible to build these on top of existing frameworks but the end result
--    isn't much shorter than rolling our own.
--
-- Since we roll our own framework we don't bother with making it generalized,
-- so we maintain a single 'State' type rather than having a generic one that
-- contains a polymorphic \"UserState\" field etc.

-- | A 'Data.YAML.Token.Parser' is basically a function computing a 'Reply'.
newtype Parser result = Parser (State -> Reply result)

applyParser :: Parser result -> State -> Reply result
applyParser :: forall result. Parser result -> State -> Reply result
applyParser (Parser State -> Reply result
p) State
s = State -> Reply result
p State
s

-- | The 'Result' of each invocation is either an error, the actual result, or
-- a continuation for computing the actual result.
data Result result = Failed String        -- ^ Parsing aborted with a failure.
                   | Result result        -- ^ Parsing completed with a result.
                   | More (Parser result) -- ^ Parsing is ongoing with a continuation.

{-
-- Showing a 'Result' is only used in debugging.
instance (Show result) => Show (Result result) where
  show result = case result of
                     Failed message -> "Failed " ++ message
                     Result result  -> "Result " ++ (show result)
                     More _         -> "More"
-}

-- | Each invocation of a 'Data.YAML.Token.Parser' yields a 'Reply'. The 'Result' is only one
-- part of the 'Reply'.
data Reply result = Reply {
    forall result. Reply result -> Result result
rResult :: !(Result result), -- ^ Parsing result.
    forall result. Reply result -> DList Token
rTokens :: !(D.DList Token), -- ^ Tokens generated by the parser.
    forall result. Reply result -> Maybe Decision
rCommit :: !(Maybe Decision),  -- ^ Commitment to a decision point.
    forall result. Reply result -> State
rState  :: !State            -- ^ The updated parser state.
  }

{-
-- Showing a 'State' is only used in debugging.
instance (Show result) => Show (Reply result) where
  show reply = "Result: "    ++ (show $ reply^.rResult)
            ++ ", Tokens: "  ++ (show $ D.toList $ reply^.rTokens)
            ++ ", Commit: "  ++ (show $ reply^.rCommit)
            ++ ", State: { " ++ (show $ reply^.rState) ++ "}"
-}

-- A 'Pattern' is a parser that doesn't have an (interesting) result.
type Pattern = Parser ()

-- ** Parsing state

-- | The internal parser state. We don't bother with parameterising it with a
-- \"UserState\", we just bundle the generic and specific fields together (not
-- that it is that easy to draw the line - is @sLine@ generic or specific?).
data State = State {
    State -> Encoding
sEncoding        :: !Encoding,        -- ^ The input UTF encoding.
    State -> Decision
sDecision        :: !Decision,        -- ^ Current decision name.
    State -> Int
sLimit           :: !Int,             -- ^ Lookahead characters limit.
    State -> Maybe Pattern
sForbidden       :: !(Maybe Pattern), -- ^ Pattern we must not enter into.
    State -> Bool
sIsPeek          :: !Bool,            -- ^ Disables token generation.
    State -> Bool
sIsSol           :: !Bool,            -- ^ Is at start of line?
    State -> String
sChars           :: ![Char],          -- ^ (Reversed) characters collected for a token.
    State -> Int
sCharsByteOffset :: !Int,             -- ^ Byte offset of first collected character.
    State -> Int
sCharsCharOffset :: !Int,             -- ^ Char offset of first collected character.
    State -> Int
sCharsLine       :: !Int,             -- ^ Line of first collected character.
    State -> Int
sCharsLineChar   :: !Int,             -- ^ Character in line of first collected character.
    State -> Int
sByteOffset      :: !Int,             -- ^ Offset in bytes in the input.
    State -> Int
sCharOffset      :: !Int,             -- ^ Offset in characters in the input.
    State -> Int
sLine            :: !Int,             -- ^ Builds on YAML's line break definition.
    State -> Int
sLineChar        :: !Int,             -- ^ Character number in line.
    State -> Code
sCode            :: !Code,            -- ^ Of token we are collecting chars for.
    State -> Char
sLast            :: !Char,            -- ^ Last matched character.
    State -> [(Int, Char)]
sInput           :: ![(Int, Char)]    -- ^ The decoded input characters.
  }

{-
-- Showing a 'State' is only used in debugging. Note that forcing dump of
-- @sInput@ will disable streaming it.
instance Show State where
  show state = "Encoding: "          ++ (show $ state^.sEncoding)
            ++ ", Decision: "        ++ (show $ state^.sDecision)
            ++ ", Limit: "           ++ (show $ state^.sLimit)
            ++ ", IsPeek: "          ++ (show $ state^.sIsPeek)
            ++ ", IsSol: "           ++ (show $ state^.sIsSol)
            ++ ", Chars: >>>"        ++ (reverse $ state^.sChars) ++ "<<<"
            ++ ", CharsByteOffset: " ++ (show $ state^.sCharsByteOffset)
            ++ ", CharsCharOffset: " ++ (show $ state^.sCharsCharOffset)
            ++ ", CharsLine: "       ++ (show $ state^.sCharsLine)
            ++ ", CharsLineChar: "   ++ (show $ state^.sCharsLineChar)
            ++ ", ByteOffset: "      ++ (show $ state^.sByteOffset)
            ++ ", CharOffset: "      ++ (show $ state^.sCharOffset)
            ++ ", Line: "            ++ (show $ state^.sLine)
            ++ ", LineChar: "        ++ (show $ state^.sLineChar)
            ++ ", Code: "            ++ (show $ state^.sCode)
            ++ ", Last: "            ++ (show $ state^.sLast)
--          ++ ", Input: >>>"        ++ (show $ state^.sInput) ++ "<<<"
-}

-- | @initialState name input@ returns an initial 'State' for parsing the
-- /input/ (with /name/ for error messages).
initialState :: BLC.ByteString -> State
initialState :: ByteString -> State
initialState ByteString
input
  = State { sEncoding :: Encoding
sEncoding        = Encoding
encoding
          , sDecision :: Decision
sDecision        = Decision
DeNone
          , sLimit :: Int
sLimit           = -Int
1
          , sForbidden :: Maybe Pattern
sForbidden       = Maybe Pattern
forall a. Maybe a
Nothing
          , sIsPeek :: Bool
sIsPeek          = Bool
False
          , sIsSol :: Bool
sIsSol           = Bool
True
          , sChars :: String
sChars           = []
          , sCharsByteOffset :: Int
sCharsByteOffset = -Int
1
          , sCharsCharOffset :: Int
sCharsCharOffset = -Int
1
          , sCharsLine :: Int
sCharsLine       = -Int
1
          , sCharsLineChar :: Int
sCharsLineChar   = -Int
1
          , sByteOffset :: Int
sByteOffset      = Int
0
          , sCharOffset :: Int
sCharOffset      = Int
0
          , sLine :: Int
sLine            = Int
1
          , sLineChar :: Int
sLineChar        = Int
0
          , sCode :: Code
sCode            = Code
Unparsed
          , sLast :: Char
sLast            = Char
' '
          , sInput :: [(Int, Char)]
sInput           = [(Int, Char)]
decoded
          }
  where
    (Encoding
encoding, [(Int, Char)]
decoded) = ByteString -> (Encoding, [(Int, Char)])
decode ByteString
input

-- *** Setters
--
-- We need four setter functions to pass them around as arguments. For some
-- reason, Haskell only generates getter functions.

-- | @setLimit limit state@ sets the @sLimit@ field to /limit/.
setLimit :: Int -> State -> State
setLimit :: Int -> State -> State
setLimit Int
limit State
state = State
state { sLimit = limit }
{-# INLINE setLimit #-}

-- | @setForbidden forbidden state@ sets the @sForbidden@ field to /forbidden/.
setForbidden :: Maybe Pattern -> State -> State
setForbidden :: Maybe Pattern -> State -> State
setForbidden Maybe Pattern
forbidden State
state = State
state { sForbidden = forbidden }
{-# INLINE setForbidden #-}

-- | @setCode code state@ sets the @sCode@ field to /code/.
setCode :: Code -> State -> State
setCode :: Code -> State -> State
setCode Code
code State
state = State
state { sCode = code }
{-# INLINE setCode #-}

-- ** Implicit parsers
--
-- It is tedious to have to wrap each expected character (or character range)
-- in an explicit 'Parse' constructor. We let Haskell do that for us using a
-- 'Match' class.

-- | @Match parameter result@ specifies that we can convert the /parameter/ to
-- a 'Data.YAML.Token.Parser' returning the /result/.
class Match parameter result | parameter -> result where
    match :: parameter -> Parser result

-- | We don't need to convert a 'Data.YAML.Token.Parser', it already is one.
instance Match (Parser result) result where
    match :: Parser result -> Parser result
match = Parser result -> Parser result
forall a. a -> a
id

-- | We convert 'Char' to a parser for a character (that returns nothing).
instance Match Char () where
    match :: Char -> Pattern
match Char
code = (Char -> Bool) -> Pattern
nextIf (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
code)

-- | We convert a 'Char' tuple to a parser for a character range (that returns
-- nothing).
instance Match (Char, Char) () where
    match :: (Char, Char) -> Pattern
match (Char
low, Char
high) = (Char -> Bool) -> Pattern
nextIf ((Char -> Bool) -> Pattern) -> (Char -> Bool) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ Char
code -> Char
low Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
code Bool -> Bool -> Bool
&& Char
code Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
high

-- | We convert 'String' to a parser for a sequence of characters (that returns
-- nothing).
instance Match String () where
    match :: String -> Pattern
match = (Char -> Pattern -> Pattern) -> Pattern -> String -> Pattern
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Char -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
(&) Pattern
empty

-- ** Reply constructors

-- | @returnReply state result@ prepares a 'Reply' with the specified /state/
-- and /result/.
returnReply :: State -> result -> Reply result
returnReply :: forall result. State -> result -> Reply result
returnReply State
state result
result = Reply { rResult :: Result result
rResult = result -> Result result
forall result. result -> Result result
Result result
result,
                                   rTokens :: DList Token
rTokens = DList Token
forall a. DList a
D.empty,
                                   rCommit :: Maybe Decision
rCommit = Maybe Decision
forall a. Maybe a
Nothing,
                                   rState :: State
rState  = State
state }

-- | @tokenReply state token@ returns a 'Reply' containing the /state/ and
-- /token/. Any collected characters are cleared (either there are none, or we
-- put them in this token, or we don't want them).
tokenReply :: State -> Token -> Reply ()
tokenReply :: State -> Token -> Reply ()
tokenReply State
state Token
token = Reply { rResult :: Result ()
rResult = () -> Result ()
forall result. result -> Result result
Result (),
                                 rTokens :: DList Token
rTokens = Token -> DList Token
forall a. a -> DList a
D.singleton Token
token,
                                 rCommit :: Maybe Decision
rCommit = Maybe Decision
forall a. Maybe a
Nothing,
                                 rState :: State
rState  = State
state { sCharsByteOffset = -1,
                                                   sCharsCharOffset = -1,
                                                   sCharsLine       = -1,
                                                   sCharsLineChar   = -1,
                                                   sChars           = [] } }

-- | @failReply state message@ prepares a 'Reply' with the specified /state/
-- and error /message/.
failReply :: State -> String -> Reply result
failReply :: forall result. State -> String -> Reply result
failReply State
state String
message = Reply { rResult :: Result result
rResult = String -> Result result
forall result. String -> Result result
Failed String
message,
                                  rTokens :: DList Token
rTokens = DList Token
forall a. DList a
D.empty,
                                  rCommit :: Maybe Decision
rCommit = Maybe Decision
forall a. Maybe a
Nothing,
                                  rState :: State
rState  = State
state }

-- | @unexpectedReply state@ returns a @failReply@ for an unexpected character.
unexpectedReply :: State -> Reply result
unexpectedReply :: forall result. State -> Reply result
unexpectedReply State
state = case State
stateState -> (State -> [(Int, Char)]) -> [(Int, Char)]
forall record value. record -> (record -> value) -> value
^.State -> [(Int, Char)]
sInput of
                             ((Int
_, Char
char):[(Int, Char)]
_) -> State -> String -> Reply result
forall result. State -> String -> Reply result
failReply State
state (String -> Reply result) -> String -> Reply result
forall a b. (a -> b) -> a -> b
$ String
"Unexpected '" String -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char
char] String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"'"
                             []            -> State -> String -> Reply result
forall result. State -> String -> Reply result
failReply State
state String
"Unexpected end of input"


instance Functor Parser where
  fmap :: forall a b. (a -> b) -> Parser a -> Parser b
fmap a -> b
g Parser a
f = (State -> Reply b) -> Parser b
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply b) -> Parser b) -> (State -> Reply b) -> Parser b
forall a b. (a -> b) -> a -> b
$ \State
state ->
    let reply :: Reply a
reply = Parser a -> State -> Reply a
forall result. Parser result -> State -> Reply result
applyParser Parser a
f State
state
    in case Reply a
replyReply a -> (Reply a -> Result a) -> Result a
forall record value. record -> (record -> value) -> value
^.Reply a -> Result a
forall result. Reply result -> Result result
rResult of
       Failed String
message -> Reply a
reply { rResult = Failed message }
       Result a
x       -> Reply a
reply { rResult = Result (g x) }
       More Parser a
parser    -> Reply a
reply { rResult = More $ fmap g parser }


instance Applicative Parser where
  pure :: forall a. a -> Parser a
pure a
result = (State -> Reply a) -> Parser a
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply a) -> Parser a) -> (State -> Reply a) -> Parser a
forall a b. (a -> b) -> a -> b
$ \State
state -> State -> a -> Reply a
forall result. State -> result -> Reply result
returnReply State
state a
result

  <*> :: forall a b. Parser (a -> b) -> Parser a -> Parser b
(<*>) = Parser (a -> b) -> Parser a -> Parser b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

  Parser a
left *> :: forall a b. Parser a -> Parser b -> Parser b
*> Parser b
right = (State -> Reply b) -> Parser b
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply b) -> Parser b) -> (State -> Reply b) -> Parser b
forall a b. (a -> b) -> a -> b
$ \State
state ->
    let reply :: Reply a
reply = Parser a -> State -> Reply a
forall result. Parser result -> State -> Reply result
applyParser Parser a
left State
state
    in case Reply a
replyReply a -> (Reply a -> Result a) -> Result a
forall record value. record -> (record -> value) -> value
^.Reply a -> Result a
forall result. Reply result -> Result result
rResult of
       Failed String
message -> Reply a
reply { rResult = Failed message }
       Result a
_       -> Reply a
reply { rResult = More right }
       More Parser a
parser    -> Reply a
reply { rResult = More $ parser *> right }

-- | Allow using the @do@ notation for our parsers, which makes for short and
-- sweet @do@ syntax when we want to examine the results (we typically don't).
instance Monad Parser where

  -- @return result@ does just that - return a /result/.
  return :: forall a. a -> Parser a
return = a -> Parser a
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

  -- @left >>= right@ applies the /left/ parser, and if it didn't fail
  -- applies the /right/ one (well, the one /right/ returns).
  Parser a
left >>= :: forall a b. Parser a -> (a -> Parser b) -> Parser b
>>= a -> Parser b
right = (State -> Reply b) -> Parser b
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply b) -> Parser b) -> (State -> Reply b) -> Parser b
forall a b. (a -> b) -> a -> b
$ \State
state ->
    let reply :: Reply a
reply = Parser a -> State -> Reply a
forall result. Parser result -> State -> Reply result
applyParser Parser a
left State
state
    in case Reply a
replyReply a -> (Reply a -> Result a) -> Result a
forall record value. record -> (record -> value) -> value
^.Reply a -> Result a
forall result. Reply result -> Result result
rResult of
       Failed String
message -> Reply a
reply { rResult = Failed message }
       Result a
value   -> Reply a
reply { rResult = More $ right value }
       More Parser a
parser    -> Reply a
reply { rResult = More $ parser >>= right }

  >> :: forall a b. Parser a -> Parser b -> Parser b
(>>) = Parser a -> Parser b -> Parser b
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)

-- | @fail message@ does just that - fails with a /message/.
pfail :: String -> Parser a
pfail :: forall a. String -> Parser a
pfail String
message = (State -> Reply a) -> Parser a
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply a) -> Parser a) -> (State -> Reply a) -> Parser a
forall a b. (a -> b) -> a -> b
$ \State
state -> State -> String -> Reply a
forall result. State -> String -> Reply result
failReply State
state String
message

-- ** Parsing operators
--
-- Here we reap the benefits of renaming the numerical operators. The Operator
-- precedence, in decreasing strength:
--
-- @repeated % n@, @repeated <% n@, @match - rejected@, @match ! decision@,
-- @match ?! decision@, @choice ^ (first \/ second)@.
--
-- @match - first - second@ is @(match - first) - second@.
--
-- @first & second & third@ is @first & (second & third)@. Note that @first -
-- rejected & second@ is @(first - rejected) & second@, etc.
--
-- @match \/ alternative \/ otherwise@ is @match \/ (alternative \/
-- otherwise)@. Note that @first & second \/ third@ is @(first & second) \/
-- third@.
--
-- @( match *)@, @(match +)@, @(match ?)@, @(match <?)@, @(match >?)@, @(match
-- >!)@, @(match <!)@ are the weakest and require the surrounding @()@.

infix  3 ^
infix  3 %
infix  3 <%
infix  3 !
infix  3 ?!
infixl 3 -
infixr 2 &
infixr 1 /
infix  0 ?
infix  0 *
infix  0 +
infix  0 <?
infix  0 >?
infix  0 >!

-- | @parser % n@ repeats /parser/ exactly /n/ times.
(%) :: (Match match result) => match -> Int -> Pattern
match
parser % :: forall match result. Match match result => match -> Int -> Pattern
% Int
n
  | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0    = Pattern
empty
  | Bool
otherwise = Parser result
parser' Parser result -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser result
parser' Parser result -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
% Int
n Int -> Int -> Int
.- Int
1)
  where
    parser' :: Parser result
parser' = match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser

-- | @parser <% n@ matches fewer than /n/ occurrences of /parser/.
(<%) :: (Match match result) => match -> Int -> Pattern
match
parser <% :: forall match result. Match match result => match -> Int -> Pattern
<% Int
n = case Int
n Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Int
1 of
  Ordering
LT -> String -> Pattern
forall a. String -> Parser a
pfail String
"Fewer than 0 repetitions"
  Ordering
EQ -> match -> Maybe String -> Pattern
forall match result.
Match match result =>
match -> Maybe String -> Pattern
reject match
parser Maybe String
forall a. Maybe a
Nothing
  Ordering
GT -> Decision
DeLess Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( ((match
parser match -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeLess) Pattern -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (match
parser match -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
<% Int
n Int -> Int -> Int
.- Int
1)) Pattern -> Pattern -> Pattern
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Pattern
empty )

data Decision = DeNone -- ""
              | DeStar -- "*"
              | DeLess -- "<%"
              | DeDirective
              | DeDoc
              | DeEscape
              | DeEscaped
              | DeFold
              | DeKey
              | DeHeader
              | DeMore
              | DeNode
              | DePair
              deriving (Int -> Decision -> ShowS
[Decision] -> ShowS
Decision -> String
(Int -> Decision -> ShowS)
-> (Decision -> String) -> ([Decision] -> ShowS) -> Show Decision
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Decision -> ShowS
showsPrec :: Int -> Decision -> ShowS
$cshow :: Decision -> String
show :: Decision -> String
$cshowList :: [Decision] -> ShowS
showList :: [Decision] -> ShowS
Show,Decision -> Decision -> Bool
(Decision -> Decision -> Bool)
-> (Decision -> Decision -> Bool) -> Eq Decision
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Decision -> Decision -> Bool
== :: Decision -> Decision -> Bool
$c/= :: Decision -> Decision -> Bool
/= :: Decision -> Decision -> Bool
Eq)

-- | @decision ^ (option \/ option \/ ...)@ provides a /decision/ name to the
-- choice about to be made, to allow to @commit@ to it.
(^) :: (Match match result) => Decision -> match -> Parser result
Decision
decision ^ :: forall match result.
Match match result =>
Decision -> match -> Parser result
^ match
parser = Decision -> Parser result -> Parser result
forall result. Decision -> Parser result -> Parser result
choice Decision
decision (Parser result -> Parser result) -> Parser result -> Parser result
forall a b. (a -> b) -> a -> b
$ match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser

-- | @parser ! decision@ commits to /decision/ (in an option) after
-- successfully matching the /parser/.
(!) :: (Match match result) => match -> Decision -> Pattern
match
parser ! :: forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
decision = match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser Parser result -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Decision -> Pattern
commit Decision
decision

-- | @parser ?! decision@ commits to /decision/ (in an option) if the current
-- position matches /parser/, without consuming any characters.
(?!) :: (Match match result) => match -> Decision -> Pattern
match
parser ?! :: forall match result.
Match match result =>
match -> Decision -> Pattern
?! Decision
decision = match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
peek match
parser Parser result -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Decision -> Pattern
commit Decision
decision

-- | @lookbehind <?@ matches the current point without consuming any
-- characters, if the previous character matches the lookbehind parser (single
-- character positive lookbehind).
(<?) :: (Match match result) => match -> Parser result
<? :: forall parameter result.
Match parameter result =>
parameter -> Parser result
(<?) match
lookbehind = match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
prev match
lookbehind

-- | @lookahead >?@ matches the current point without consuming any characters
-- if it matches the lookahead parser (positive lookahead).
(>?) :: (Match match result) => match -> Parser result
>? :: forall parameter result.
Match parameter result =>
parameter -> Parser result
(>?) match
lookahead = match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
peek match
lookahead

-- | @lookahead >!@ matches the current point without consuming any characters
-- if it matches the lookahead parser (negative lookahead).
(>!) :: (Match match result) => match -> Pattern
>! :: forall match result. Match match result => match -> Pattern
(>!) match
lookahead = match -> Maybe String -> Pattern
forall match result.
Match match result =>
match -> Maybe String -> Pattern
reject match
lookahead Maybe String
forall a. Maybe a
Nothing

-- | @parser - rejected@ matches /parser/, except if /rejected/ matches at this
-- point.
(-) :: (Match match1 result1, Match match2 result2) => match1 -> match2 -> Parser result1
match1
parser - :: forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- match2
rejected = match2 -> Maybe String -> Pattern
forall match result.
Match match result =>
match -> Maybe String -> Pattern
reject match2
rejected Maybe String
forall a. Maybe a
Nothing Pattern -> Parser result1 -> Parser result1
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> match1 -> Parser result1
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match1
parser

-- | @before & after@ parses /before/ and, if it succeeds, parses /after/. This
-- basically invokes the monad's @>>=@ (bind) method.
(&) :: (Match match1 result1, Match match2 result2) => match1 -> match2 -> Parser result2
match1
before & :: forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& match2
after = match1 -> Parser result1
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match1
before Parser result1 -> Parser result2 -> Parser result2
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> match2 -> Parser result2
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match2
after

-- | @first \/ second@ tries to parse /first/, and failing that parses
-- /second/, unless /first/ has committed in which case is fails immediately.
(/) :: (Match match1 result, Match match2 result) => match1 -> match2 -> Parser result
match1
first / :: forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ match2
second = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser (match1 -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match1
first Parser result -> Parser result -> Parser result
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> match2 -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match2
second)

-- | @(optional ?)@ tries to match /parser/, otherwise does nothing.
(?) :: (Match match result) => match -> Pattern
? :: forall match result. Match match result => match -> Pattern
(?) match
optional = (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
optional Parser result -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Pattern
empty) Pattern -> Pattern -> Pattern
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Pattern
empty

-- | @(parser *)@ matches zero or more occurrences of /repeat/, as long as each
-- one actually consumes input characters.
(*) :: (Match match result) => match -> Pattern
* :: forall match result. Match match result => match -> Pattern
(*) match
parser = Decision
DeStar Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ Pattern
zomParser
  where
    zomParser :: Pattern
zomParser = ((match
parser match -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeStar) Pattern -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
match Pattern
zomParser) Pattern -> Pattern -> Pattern
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Pattern
empty

-- | @(parser +)@ matches one or more occurrences of /parser/, as long as each
-- one actually consumed input characters.
(+) :: (Match match result) => match -> Pattern
+ :: forall match result. Match match result => match -> Pattern
(+) match
parser = match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser Parser result -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (match
parser *)

-- ** Basic parsers

-- | @first <|> second@ tries to parse /first/, and failing that parses
-- /second/, unless /first/ has committed in which case is fails immediately.
instance Alternative Parser where
  empty :: forall a. Parser a
empty = String -> Parser a
forall a. String -> Parser a
pfail String
"empty"

  Parser a
left <|> :: forall a. Parser a -> Parser a -> Parser a
<|> Parser a
right = (State -> Reply a) -> Parser a
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply a) -> Parser a) -> (State -> Reply a) -> Parser a
forall a b. (a -> b) -> a -> b
$ \State
state -> State -> DList Token -> Parser a -> Parser a -> State -> Reply a
forall {result}.
State
-> DList Token
-> Parser result
-> Parser result
-> State
-> Reply result
decideParser State
state DList Token
forall a. DList a
D.empty Parser a
left Parser a
right State
state
    where
      decideParser :: State
-> DList Token
-> Parser result
-> Parser result
-> State
-> Reply result
decideParser State
point DList Token
tokens Parser result
left Parser result
right State
state =
        let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
left State
state
            tokens' :: DList Token
tokens' = DList Token -> DList Token -> DList Token
forall a. DList a -> DList a -> DList a
D.append DList Token
tokens (DList Token -> DList Token) -> DList Token -> DList Token
forall a b. (a -> b) -> a -> b
$ Reply result
replyReply result -> (Reply result -> DList Token) -> DList Token
forall record value. record -> (record -> value) -> value
^.Reply result -> DList Token
forall result. Reply result -> DList Token
rTokens
        in case (Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult, Reply result
replyReply result -> (Reply result -> Maybe Decision) -> Maybe Decision
forall record value. record -> (record -> value) -> value
^.Reply result -> Maybe Decision
forall result. Reply result -> Maybe Decision
rCommit) of
                (Failed String
_,    Maybe Decision
_)      -> Reply { rState :: State
rState  = State
point,
                                                 rTokens :: DList Token
rTokens = DList Token
forall a. DList a
D.empty,
                                                 rResult :: Result result
rResult = Parser result -> Result result
forall result. Parser result -> Result result
More Parser result
right,
                                                 rCommit :: Maybe Decision
rCommit = Maybe Decision
forall a. Maybe a
Nothing }
                (Result result
_,   Maybe Decision
_)       -> Reply result
reply { rTokens = tokens' }
                (More Parser result
_, Just Decision
_)      -> Reply result
reply { rTokens = tokens' }
                (More Parser result
left', Maybe Decision
Nothing) -> State
-> DList Token
-> Parser result
-> Parser result
-> State
-> Reply result
decideParser State
point DList Token
tokens' Parser result
left' Parser result
right (Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState)


-- | @choice decision parser@ provides a /decision/ name to the choice about to
-- be made in /parser/, to allow to @commit@ to it.
choice :: Decision -> Parser result -> Parser result
choice :: forall result. Decision -> Parser result -> Parser result
choice Decision
decision Parser result
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser (Decision -> Decision -> Parser result -> Parser result
forall {result}.
Decision -> Decision -> Parser result -> Parser result
choiceParser (State
stateState -> (State -> Decision) -> Decision
forall record value. record -> (record -> value) -> value
^.State -> Decision
sDecision) Decision
decision Parser result
parser) State
state { sDecision = decision }
  where choiceParser :: Decision -> Decision -> Parser result -> Parser result
choiceParser Decision
parentDecision Decision
makingDecision Parser result
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
          let reply :: Reply result
reply   = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
              commit' :: Maybe Decision
commit' = case Reply result
replyReply result -> (Reply result -> Maybe Decision) -> Maybe Decision
forall record value. record -> (record -> value) -> value
^.Reply result -> Maybe Decision
forall result. Reply result -> Maybe Decision
rCommit of
                             Maybe Decision
Nothing                                    -> Maybe Decision
forall a. Maybe a
Nothing
                             Just Decision
decision | Decision
decision Decision -> Decision -> Bool
forall a. Eq a => a -> a -> Bool
== Decision
makingDecision -> Maybe Decision
forall a. Maybe a
Nothing
                                           | Bool
otherwise                  -> Reply result
replyReply result -> (Reply result -> Maybe Decision) -> Maybe Decision
forall record value. record -> (record -> value) -> value
^.Reply result -> Maybe Decision
forall result. Reply result -> Maybe Decision
rCommit
              reply' :: Reply result
reply'  = case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
                             More Parser result
parser' -> Reply result
reply { rCommit = commit',
                                                     rResult = More $ choiceParser parentDecision makingDecision parser' }
                             Result result
_            -> Reply result
reply { rCommit = commit',
                                                     rState = (reply^.rState) { sDecision = parentDecision } }
          in Reply result
reply'

-- | @parser ``recovery`` pattern@ parses the specified /parser/; if it fails,
-- it continues to the /recovery/ parser to recover.
recovery :: (Match match1 result) => match1 -> Parser result -> Parser result
recovery :: forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
recovery match1
pattern Parser result
recover =
  (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
    let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser (match1 -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match1
pattern) State
state
    in if State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsPeek
          then Reply result
reply
          else case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
                    Result result
_       -> Reply result
reply
                    More Parser result
more      -> Reply result
reply { rResult = More $ more `recovery` recover }
                    Failed String
message -> Reply result
reply { rResult = More $ fake Error message *> unparsed *> recover }
    where unparsed :: Pattern
unparsed = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state -> Pattern -> State -> Reply ()
forall result. Parser result -> State -> Reply result
applyParser (Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
match Pattern
finishToken) (State -> Reply ()) -> State -> Reply ()
forall a b. (a -> b) -> a -> b
$ State
state { sCode = Unparsed }

-- | @prev parser@ succeeds if /parser/ matches at the previous character. It
-- does not consume any input.
prev :: (Match match result) => match -> Parser result
prev :: forall parameter result.
Match parameter result =>
parameter -> Parser result
prev match
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  State -> Parser result -> State -> Reply result
forall {result}. State -> Parser result -> State -> Reply result
prevParser State
state (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser) State
state { sIsPeek = True, sInput = (-1, state^.sLast) : state^.sInput }
  where prevParser :: State -> Parser result -> State -> Reply result
prevParser State
point Parser result
parser State
state =
          let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
          in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
                  Failed String
message -> State -> String -> Reply result
forall result. State -> String -> Reply result
failReply State
point String
message
                  Result result
value   -> State -> result -> Reply result
forall result. State -> result -> Reply result
returnReply State
point result
value
                  More Parser result
parser'   -> State -> Parser result -> State -> Reply result
prevParser State
point Parser result
parser' (State -> Reply result) -> State -> Reply result
forall a b. (a -> b) -> a -> b
$ Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState

-- | @peek parser@ succeeds if /parser/ matches at this point, but does not
-- consume any input.
peek :: (Match match result) => match -> Parser result
peek :: forall parameter result.
Match parameter result =>
parameter -> Parser result
peek match
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  State -> Parser result -> State -> Reply result
forall {result}. State -> Parser result -> State -> Reply result
peekParser State
state (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser) State
state { sIsPeek = True }
  where peekParser :: State -> Parser result -> State -> Reply result
peekParser State
point Parser result
parser State
state =
          let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
          in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
                  Failed String
message -> State -> String -> Reply result
forall result. State -> String -> Reply result
failReply State
point String
message
                  Result result
value   -> State -> result -> Reply result
forall result. State -> result -> Reply result
returnReply State
point result
value
                  More Parser result
parser'   -> State -> Parser result -> State -> Reply result
peekParser State
point Parser result
parser' (State -> Reply result) -> State -> Reply result
forall a b. (a -> b) -> a -> b
$ Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState

-- | @reject parser name@ fails if /parser/ matches at this point, and does
-- nothing otherwise. If /name/ is provided, it is used in the error message,
-- otherwise the messages uses the current character.
reject :: (Match match result) => match -> Maybe String -> Pattern
reject :: forall match result.
Match match result =>
match -> Maybe String -> Pattern
reject match
parser Maybe String
name = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
    State -> Maybe String -> Parser result -> State -> Reply ()
forall {result}.
State -> Maybe String -> Parser result -> State -> Reply ()
rejectParser State
state Maybe String
name (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser) State
state { sIsPeek = True }
  where
    rejectParser :: State -> Maybe String -> Parser result -> State -> Reply ()
rejectParser State
point Maybe String
name Parser result
parser State
state =
      let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
      in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
              Failed String
_message -> State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
point ()
              Result result
_value   -> case Maybe String
name of
                                     Maybe String
Nothing   -> State -> Reply ()
forall result. State -> Reply result
unexpectedReply State
point
                                     Just String
text -> State -> String -> Reply ()
forall result. State -> String -> Reply result
failReply State
point (String -> Reply ()) -> String -> Reply ()
forall a b. (a -> b) -> a -> b
$ String
"Unexpected " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
text
              More Parser result
parser'    -> State -> Maybe String -> Parser result -> State -> Reply ()
rejectParser State
point Maybe String
name Parser result
parser' (State -> Reply ()) -> State -> Reply ()
forall a b. (a -> b) -> a -> b
$ Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState

-- | @upto parser@ consumes all the character up to and not including the next
-- point where the specified parser is a match.
upto :: Pattern -> Pattern
upto :: Pattern -> Pattern
upto Pattern
parser = ( ( Pattern
parser >!) Pattern -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> Bool) -> Pattern
nextIf (Bool -> Char -> Bool
forall a b. a -> b -> a
const Bool
True) *)

-- | @nonEmpty parser@ succeeds if /parser/ matches some non-empty input
-- characters at this point.
nonEmpty :: (Match match result) => match -> Parser result
nonEmpty :: forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty match
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
    Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser (Int -> Parser result -> Parser result
forall {result}. Int -> Parser result -> Parser result
nonEmptyParser (State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharOffset) (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser)) State
state
  where
    nonEmptyParser :: Int -> Parser result -> Parser result
nonEmptyParser Int
offset Parser result
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
      let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
          state' :: State
state' = Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState
      in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
              Failed String
_message -> Reply result
reply
              Result result
_value   -> if State
state'State -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharOffset Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
offset
                                   then Reply result
reply
                                   else State -> String -> Reply result
forall result. State -> String -> Reply result
failReply State
state' String
"Matched empty pattern"
              More Parser result
parser'    -> Reply result
reply { rResult = More $ nonEmptyParser offset parser' }

-- | @empty@ always matches without consuming any input.
empty :: Pattern
empty :: Pattern
empty = () -> Pattern
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | @eof@ matches the end of the input.
eof :: Pattern
eof :: Pattern
eof = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  if [(Int, Char)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (State
stateState -> (State -> [(Int, Char)]) -> [(Int, Char)]
forall record value. record -> (record -> value) -> value
^.State -> [(Int, Char)]
sInput)
     then State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state ()
     else State -> Reply ()
forall result. State -> Reply result
unexpectedReply State
state

-- | @sol@ matches the start of a line.
sol :: Pattern
sol :: Pattern
sol = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  if State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsSol
     then State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state ()
     else State -> String -> Reply ()
forall result. State -> String -> Reply result
failReply State
state String
"Expected start of line"

-- ** State manipulation pseudo-parsers

-- | @commit decision@ commits the parser to all the decisions up to the most
-- recent parent /decision/. This makes all tokens generated in this parsing
-- path immediately available to the caller.
commit :: Decision -> Pattern
commit :: Decision -> Pattern
commit Decision
decision = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  Reply { rState :: State
rState  = State
state,
          rTokens :: DList Token
rTokens = DList Token
forall a. DList a
D.empty,
          rResult :: Result ()
rResult = () -> Result ()
forall result. result -> Result result
Result (),
          rCommit :: Maybe Decision
rCommit = Decision -> Maybe Decision
forall a. a -> Maybe a
Just Decision
decision }

-- | @nextLine@ increments @sLine@ counter and resets @sLineChar@.
nextLine :: Pattern
nextLine :: Pattern
nextLine = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state { sIsSol    = True,
                      sLine     = state^.sLine .+ 1,
                      sLineChar = 0 }
              ()

-- | @with setField getField value parser@ invokes the specified /parser/ with
-- the value of the specified field set to /value/ for the duration of the
-- invocation, using the /setField/ and /getField/ functions to manipulate it.
with :: (value -> State -> State) -> (State -> value) -> value -> Parser result -> Parser result
with :: forall value result.
(value -> State -> State)
-> (State -> value) -> value -> Parser result -> Parser result
with value -> State -> State
setField State -> value
getField value
value Parser result
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
    let value' :: value
value' = State -> value
getField State
state
        Parser State -> Reply result
parser' = value
value' value -> Parser result -> Parser result
forall a b. a -> b -> b
`seq` value -> Parser result -> Parser result
forall {result}. value -> Parser result -> Parser result
withParser value
value' Parser result
parser
    in State -> Reply result
parser' (State -> Reply result) -> State -> Reply result
forall a b. (a -> b) -> a -> b
$ value -> State -> State
setField value
value State
state
  where
    withParser :: value -> Parser result -> Parser result
withParser value
parentValue Parser result
parser = (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
        let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
        in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
             Failed String
_     -> Reply result
reply { rState = setField parentValue $ reply^.rState }
             Result result
_     -> Reply result
reply { rState = setField parentValue $ reply^.rState }
             More Parser result
parser' -> Reply result
reply { rResult = More $ withParser parentValue parser' }
{-# INLINE with #-}

-- | @parser ``forbidding`` pattern@ parses the specified /parser/ ensuring
-- that it does not contain anything matching the /forbidden/ parser.
forbidding :: (Match match1 result1) => match1 -> Parser result1 -> Parser result1
forbidding :: forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
forbidding match1
parser Parser result1
forbidden = (Maybe Pattern -> State -> State)
-> (State -> Maybe Pattern)
-> Maybe Pattern
-> Parser result1
-> Parser result1
forall value result.
(value -> State -> State)
-> (State -> value) -> value -> Parser result -> Parser result
with Maybe Pattern -> State -> State
setForbidden State -> Maybe Pattern
sForbidden (Pattern -> Maybe Pattern
forall a. a -> Maybe a
Just (Pattern -> Maybe Pattern) -> Pattern -> Maybe Pattern
forall a b. (a -> b) -> a -> b
$ Parser result1
forbidden Parser result1 -> Pattern -> Pattern
forall a b. Parser a -> Parser b -> Parser b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Pattern
empty) (match1 -> Parser result1
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match1
parser)

-- | @parser ``limitedTo`` limit@ parses the specified /parser/
-- ensuring that it does not consume more than the /limit/ input chars.
limitedTo :: (Match match result) => match -> Int -> Parser result
limitedTo :: forall match result.
Match match result =>
match -> Int -> Parser result
limitedTo match
parser Int
limit = (Int -> State -> State)
-> (State -> Int) -> Int -> Parser result -> Parser result
forall value result.
(value -> State -> State)
-> (State -> value) -> value -> Parser result -> Parser result
with Int -> State -> State
setLimit State -> Int
sLimit Int
limit (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser)

-- ** Consuming input characters

-- | @nextIf test@ fails if the current position matches the 'State' forbidden
-- pattern or if the 'State' lookahead limit is reached. Otherwise it consumes
-- (and buffers) the next input char if it satisfies /test/.
nextIf :: (Char -> Bool) -> Pattern
nextIf :: (Char -> Bool) -> Pattern
nextIf Char -> Bool
test = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
    case State
stateState -> (State -> Maybe Pattern) -> Maybe Pattern
forall record value. record -> (record -> value) -> value
^.State -> Maybe Pattern
sForbidden of
         Maybe Pattern
Nothing     -> State -> Reply ()
limitedNextIf State
state
         Just Pattern
parser -> let reply :: Reply ()
reply = Pattern -> State -> Reply ()
forall result. Parser result -> State -> Reply result
applyParser (Pattern -> Maybe String -> Pattern
forall match result.
Match match result =>
match -> Maybe String -> Pattern
reject Pattern
parser (Maybe String -> Pattern) -> Maybe String -> Pattern
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just String
"forbidden pattern") State
state { sForbidden = Nothing }
                        in case Reply ()
replyReply () -> (Reply () -> Result ()) -> Result ()
forall record value. record -> (record -> value) -> value
^.Reply () -> Result ()
forall result. Reply result -> Result result
rResult of
                                Failed String
_ -> Reply ()
reply
                                Result ()
_ -> State -> Reply ()
limitedNextIf State
state
                                More Pattern
_   -> String -> Reply ()
forall a. HasCallStack => String -> a
error String
"unexpected Result More _ pattern"
  where
    limitedNextIf :: State -> Reply ()
limitedNextIf State
state =
        case State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLimit of
          -1     -> State -> Reply ()
consumeNextIf State
state
          Int
0      -> State -> String -> Reply ()
forall result. State -> String -> Reply result
failReply State
state String
"Lookahead limit reached"
          Int
_limit -> State -> Reply ()
consumeNextIf State
state { sLimit = state^.sLimit .- 1 }

    consumeNextIf :: State -> Reply ()
consumeNextIf State
state =
        case State
stateState -> (State -> [(Int, Char)]) -> [(Int, Char)]
forall record value. record -> (record -> value) -> value
^.State -> [(Int, Char)]
sInput of
          ((Int
offset, Char
char):[(Int, Char)]
rest) | Char -> Bool
test Char
char -> let chars :: String
chars       = if State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsPeek then [] else Char
charChar -> ShowS
forall a. a -> [a] -> [a]
:(State
stateState -> (State -> String) -> String
forall record value. record -> (record -> value) -> value
^.State -> String
sChars)
                                                   byte_offset :: Int
byte_offset = (State -> Int) -> (State -> Int) -> Int
forall {a}. Num a => (State -> a) -> (State -> a) -> a
charsOf State -> Int
sByteOffset State -> Int
sCharsByteOffset
                                                   char_offset :: Int
char_offset = (State -> Int) -> (State -> Int) -> Int
forall {a}. Num a => (State -> a) -> (State -> a) -> a
charsOf State -> Int
sCharOffset State -> Int
sCharsCharOffset
                                                   line :: Int
line        = (State -> Int) -> (State -> Int) -> Int
forall {a}. Num a => (State -> a) -> (State -> a) -> a
charsOf State -> Int
sLine       State -> Int
sCharsLine
                                                   line_char :: Int
line_char   = (State -> Int) -> (State -> Int) -> Int
forall {a}. Num a => (State -> a) -> (State -> a) -> a
charsOf State -> Int
sLineChar   State -> Int
sCharsLineChar
                                                   is_sol :: Bool
is_sol      = Char
char Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\xFEFF' Bool -> Bool -> Bool
&& State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsSol
                                                   state' :: State
state' = State
state { sInput           = rest,
                                                                    sLast            = char,
                                                                    sChars           = chars,
                                                                    sCharsByteOffset = byte_offset,
                                                                    sCharsCharOffset = char_offset,
                                                                    sCharsLine       = line,
                                                                    sCharsLineChar   = line_char,
                                                                    sIsSol           = is_sol,
                                                                    sByteOffset      = offset,
                                                                    sCharOffset      = state^.sCharOffset .+ 1,
                                                                    sLineChar        = state^.sLineChar .+ 1 }
                                               in State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state' ()
                      | Bool
otherwise -> State -> Reply ()
forall result. State -> Reply result
unexpectedReply State
state
          []                      -> State -> Reply ()
forall result. State -> Reply result
unexpectedReply State
state
      where
        charsOf :: (State -> a) -> (State -> a) -> a
charsOf State -> a
field State -> a
charsField
          | State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsPeek       = -a
1
          | String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (State
stateState -> (State -> String) -> String
forall record value. record -> (record -> value) -> value
^.State -> String
sChars) = State
stateState -> (State -> a) -> a
forall record value. record -> (record -> value) -> value
^.State -> a
field
          | Bool
otherwise            = State
stateState -> (State -> a) -> a
forall record value. record -> (record -> value) -> value
^.State -> a
charsField

-- ** Producing tokens

-- | @finishToken@ places all collected text into a new token and begins a new
-- one, or does nothing if there are no collected characters.
finishToken :: Pattern
finishToken :: Pattern
finishToken = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  let state' :: State
state' = State
state { sChars           = [],
                       sCharsByteOffset = -1,
                       sCharsCharOffset = -1,
                       sCharsLine       = -1,
                       sCharsLineChar   = -1 }
  in if State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsPeek
        then State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state' ()
        else case State
stateState -> (State -> String) -> String
forall record value. record -> (record -> value) -> value
^.State -> String
sChars of
                  []          -> State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state' ()
                  chars :: String
chars@(Char
_:String
_) -> State -> Token -> Reply ()
tokenReply State
state' Token { tByteOffset :: Int
tByteOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharsByteOffset,
                                                           tCharOffset :: Int
tCharOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharsCharOffset,
                                                           tLine :: Int
tLine       = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharsLine,
                                                           tLineChar :: Int
tLineChar   = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharsLineChar,
                                                           tCode :: Code
tCode       = State
stateState -> (State -> Code) -> Code
forall record value. record -> (record -> value) -> value
^.State -> Code
sCode,
                                                           tText :: String
tText       = ShowS
forall a. [a] -> [a]
reverse String
chars }

-- | @wrap parser@ invokes the /parser/, ensures any unclaimed input characters
-- are wrapped into a token (only happens when testing productions), ensures no
-- input is left unparsed, and returns the parser's result.
wrap :: (Match match result) => match -> Parser result
wrap :: forall parameter result.
Match parameter result =>
parameter -> Parser result
wrap match
parser = do result
result <- match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
parser
                 Pattern
finishToken
                 Pattern
eof
                 result -> Parser result
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return result
result

-- | @token code parser@ places all text matched by /parser/ into a 'Token' with
-- the specified /code/ (unless it is empty). Note it collects the text even if
-- there is an error.
token :: (Match match result) => Code -> match -> Pattern
token :: forall match result. Match match result => Code -> match -> Pattern
token Code
code match
parser = Pattern
finishToken Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& (Code -> State -> State)
-> (State -> Code) -> Code -> Pattern -> Pattern
forall value result.
(value -> State -> State)
-> (State -> value) -> value -> Parser result -> Parser result
with Code -> State -> State
setCode State -> Code
sCode Code
code (match
parser match -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
finishToken)

-- | @fake code text@ creates a token with the specified /code/ and \"fake\"
-- /text/ characters, instead of whatever characters are collected so far.
fake :: Code -> String -> Pattern
fake :: Code -> String -> Pattern
fake Code
code String
text = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
  if State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsPeek
     then State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state ()
     else State -> Token -> Reply ()
tokenReply State
state Token { tByteOffset :: Int
tByteOffset = State -> (State -> Int) -> (State -> Int) -> Int
forall {t} {t}. (Eq t, Num t) => t -> (t -> t) -> (t -> t) -> t
value State
state State -> Int
sByteOffset State -> Int
sCharsByteOffset,
                                   tCharOffset :: Int
tCharOffset = State -> (State -> Int) -> (State -> Int) -> Int
forall {t} {t}. (Eq t, Num t) => t -> (t -> t) -> (t -> t) -> t
value State
state State -> Int
sCharOffset State -> Int
sCharsCharOffset,
                                   tLine :: Int
tLine       = State -> (State -> Int) -> (State -> Int) -> Int
forall {t} {t}. (Eq t, Num t) => t -> (t -> t) -> (t -> t) -> t
value State
state State -> Int
sLine State -> Int
sCharsLine,
                                   tLineChar :: Int
tLineChar   = State -> (State -> Int) -> (State -> Int) -> Int
forall {t} {t}. (Eq t, Num t) => t -> (t -> t) -> (t -> t) -> t
value State
state State -> Int
sLineChar State -> Int
sCharsLineChar,
                                   tCode :: Code
tCode       = Code
code,
                                   tText :: String
tText       = String
text }
    where value :: t -> (t -> t) -> (t -> t) -> t
value t
state t -> t
field1 t -> t
field2 =
            if t -> t
field2 t
state t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== -t
1
               then t -> t
field1 t
state
               else t -> t
field2 t
state

-- | @meta parser@ collects the text matched by the specified /parser/ into a
-- | @Meta@ token.
meta :: (Match match result) => match -> Pattern
meta :: forall match result. Match match result => match -> Pattern
meta match
parser = Code -> match -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Meta match
parser

-- | @indicator code@ collects the text matched by the specified /parser/ into an
-- @Indicator@ token.
indicator :: (Match match result) => match -> Pattern
indicator :: forall match result. Match match result => match -> Pattern
indicator match
parser = Code -> match -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Indicator (match -> Pattern) -> match -> Pattern
forall a b. (a -> b) -> a -> b
$ match
parser

-- | @text parser@  collects the text matched by the specified /parser/ into a
-- @Text@ token.
text :: (Match match result) => match -> Pattern
text :: forall match result. Match match result => match -> Pattern
text match
parser = Code -> match -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Text match
parser

-- | @emptyToken code@ returns an empty token.
emptyToken :: Code -> Pattern
emptyToken :: Code -> Pattern
emptyToken Code
code = Pattern
finishToken Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Code -> Pattern
parser Code
code
  where parser :: Code -> Pattern
parser Code
code = (State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state ->
          if State
stateState -> (State -> Bool) -> Bool
forall record value. record -> (record -> value) -> value
^.State -> Bool
sIsPeek
             then State -> () -> Reply ()
forall result. State -> result -> Reply result
returnReply State
state ()
             else State -> Token -> Reply ()
tokenReply State
state Token { tByteOffset :: Int
tByteOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sByteOffset,
                                           tCharOffset :: Int
tCharOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharOffset,
                                           tLine :: Int
tLine       = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLine,
                                           tLineChar :: Int
tLineChar   = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLineChar,
                                           tCode :: Code
tCode       = Code
code,
                                           tText :: String
tText       = String
"" }

-- | @wrapTokens beginCode endCode parser@ wraps the specified /parser/ with
-- matching /beginCode/ and /endCode/ tokens.
wrapTokens :: Code -> Code -> Pattern -> Pattern
wrapTokens :: Code -> Code -> Pattern -> Pattern
wrapTokens Code
beginCode Code
endCode Pattern
pattern = Code -> Pattern
emptyToken Code
beginCode
                                      Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern -> Pattern
forall match result.
Match match result =>
match -> Pattern -> Parser result
prefixErrorWith Pattern
pattern (Code -> Pattern
emptyToken Code
endCode)
                                      Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Code -> Pattern
emptyToken Code
endCode

-- | @prefixErrorWith pattern prefix@ will invoke the @prefix@ parser if an
-- error is detected during the @pattern@ parser, and then return the error.
prefixErrorWith :: (Match match result) => match -> Pattern -> Parser result
prefixErrorWith :: forall match result.
Match match result =>
match -> Pattern -> Parser result
prefixErrorWith match
pattern Pattern
prefix =
  (State -> Reply result) -> Parser result
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply result) -> Parser result)
-> (State -> Reply result) -> Parser result
forall a b. (a -> b) -> a -> b
$ \ State
state ->
    let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser (match -> Parser result
forall parameter result.
Match parameter result =>
parameter -> Parser result
match match
pattern) State
state
    in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
         Result result
_       -> Reply result
reply
         More Parser result
more      -> Reply result
reply { rResult = More $ prefixErrorWith more prefix }
         Failed String
message -> Reply result
reply { rResult = More $ prefix & (pfail message :: Parser result) }

-- * Production parameters

-- | Production context.
data Context = BlockOut     -- ^ Outside block sequence.
             | BlockIn      -- ^ Inside block sequence.
             | FlowOut      -- ^ Outside flow collection.
             | FlowIn       -- ^ Inside flow collection.
             | BlockKey     -- ^ Implicit block key.
             | FlowKey      -- ^ Implicit flow key.

{-
-- | @show context@ converts a 'Context' to a 'String'.
instance Show Context where
  show context = case context of
                      BlockOut -> "block-out"
                      BlockIn  -> "block-in"
                      FlowOut  -> "flow-out"
                      FlowIn   -> "flow-in"
                      BlockKey -> "block-key"
                      FlowKey  -> "flow-key"

-- | @read context@ converts a 'String' to a 'Context'. We trust our callers to
-- convert any @-@ characters into @_@ to allow the built-in @lex@ function to
-- handle the names as single identifiers.
instance Read Context where
  readsPrec _ text = [ ((r word), tail) | (word, tail) <- lex text ]
    where r word = case word of
                        "block_out" -> BlockOut
                        "block_in"  -> BlockIn
                        "flow_out"  -> FlowOut
                        "flow_in"   -> FlowIn
                        "block_key" -> BlockKey
                        "flow_key"  -> FlowKey
                        _           -> error $ "unknown context: " ++ word
-}

-- | Chomp method.
data Chomp = Strip -- ^ Remove all trailing line breaks.
           | Clip  -- ^ Keep first trailing line break.
           | Keep  -- ^ Keep all trailing line breaks.

{-
-- | @show chomp@ converts a 'Chomp' to a 'String'.
instance Show Chomp where
  show chomp = case chomp of
                    Strip -> "strip"
                    Clip  -> "clip"
                    Keep  -> "keep"

-- | @read chomp@ converts a 'String' to a 'Chomp'.
instance Read Chomp where
  readsPrec _ text = [ ((r word), tail) | (word, tail) <- lex text ]
    where r word = case word of
                        "strip" -> Strip
                        "clip"  -> Clip
                        "keep"  -> Keep
                        _       -> error $ "unknown chomp: " ++ word
-}

-- * Tokenizers
--
-- We encapsulate the 'Data.YAML.Token.Parser' inside a 'Tokenizer'. This allows us to hide the
-- implementation details from our callers.

-- | 'Tokenizer' converts a input text into a list of 'Token'. Errors
-- are reported as tokens with the @Error@ 'Code', and the unparsed text
-- following an error may be attached as a final token (if the @Bool@ is
-- @True@). Note that tokens are available \"immediately\", allowing for
-- streaming of large YAML files with memory requirements depending only on the
-- YAML nesting level.
type Tokenizer = BLC.ByteString -> Bool -> [Token]

-- | @patternTokenizer pattern@ converts the /pattern/ to a simple 'Tokenizer'.
patternTokenizer :: Pattern -> Tokenizer
patternTokenizer :: Pattern -> Tokenizer
patternTokenizer Pattern
pattern ByteString
input Bool
withFollowing =
    DList Token -> [Token]
forall a. DList a -> [a]
D.toList (DList Token -> [Token]) -> DList Token -> [Token]
forall a b. (a -> b) -> a -> b
$ Pattern -> State -> DList Token
forall {result}. Parser result -> State -> DList Token
patternParser (Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
wrap Pattern
pattern) (ByteString -> State
initialState ByteString
input)
  where
    patternParser :: Parser result -> State -> DList Token
patternParser Parser result
parser State
state =
      let reply :: Reply result
reply = Parser result -> State -> Reply result
forall result. Parser result -> State -> Reply result
applyParser Parser result
parser State
state
          tokens :: DList Token
tokens = Reply result -> DList Token
forall result. Reply result -> DList Token
commitBugs Reply result
reply
          state' :: State
state' = Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState
      in case Reply result
replyReply result -> (Reply result -> Result result) -> Result result
forall record value. record -> (record -> value) -> value
^.Reply result -> Result result
forall result. Reply result -> Result result
rResult of
              Failed String
message -> DList Token -> State -> String -> Bool -> DList Token
errorTokens DList Token
tokens State
state' String
message Bool
withFollowing
              Result result
_       -> DList Token
tokens
              More Parser result
parser'   -> DList Token -> DList Token -> DList Token
forall a. DList a -> DList a -> DList a
D.append DList Token
tokens (DList Token -> DList Token) -> DList Token -> DList Token
forall a b. (a -> b) -> a -> b
$ Parser result -> State -> DList Token
patternParser Parser result
parser' State
state'

-- | @errorTokens tokens state message withFollowing@ appends an @Error@ token
-- with the specified /message/ at the end of /tokens/, and if /withFollowing/
-- also appends the unparsed text following the error as a final @Unparsed@
-- token.
errorTokens :: D.DList Token -> State -> String -> Bool -> D.DList Token
errorTokens :: DList Token -> State -> String -> Bool -> DList Token
errorTokens DList Token
tokens State
state String
message Bool
withFollowing =
    let tokens' :: DList Token
tokens' = DList Token -> DList Token -> DList Token
forall a. DList a -> DList a -> DList a
D.append DList Token
tokens (DList Token -> DList Token) -> DList Token -> DList Token
forall a b. (a -> b) -> a -> b
$ Token -> DList Token
forall a. a -> DList a
D.singleton Token { tByteOffset :: Int
tByteOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sByteOffset,
                                                        tCharOffset :: Int
tCharOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharOffset,
                                                        tLine :: Int
tLine       = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLine,
                                                        tLineChar :: Int
tLineChar   = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLineChar,
                                                        tCode :: Code
tCode       = Code
Error,
                                                        tText :: String
tText       = String
message }
    in if Bool
withFollowing Bool -> Bool -> Bool
&& State
stateState -> (State -> [(Int, Char)]) -> [(Int, Char)]
forall record value. record -> (record -> value) -> value
^.State -> [(Int, Char)]
sInput [(Int, Char)] -> [(Int, Char)] -> Bool
forall a. Eq a => a -> a -> Bool
/= []
       then DList Token -> DList Token -> DList Token
forall a. DList a -> DList a -> DList a
D.append DList Token
tokens' (DList Token -> DList Token) -> DList Token -> DList Token
forall a b. (a -> b) -> a -> b
$ Token -> DList Token
forall a. a -> DList a
D.singleton Token { tByteOffset :: Int
tByteOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sByteOffset,
                                                   tCharOffset :: Int
tCharOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharOffset,
                                                   tLine :: Int
tLine       = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLine,
                                                   tLineChar :: Int
tLineChar   = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLineChar,
                                                   tCode :: Code
tCode       = Code
Unparsed,
                                                   tText :: String
tText       = ((Int, Char) -> Char) -> [(Int, Char)] -> String
forall a b. (a -> b) -> [a] -> [b]
map (Int, Char) -> Char
forall a b. (a, b) -> b
snd ([(Int, Char)] -> String) -> [(Int, Char)] -> String
forall a b. (a -> b) -> a -> b
$ State
stateState -> (State -> [(Int, Char)]) -> [(Int, Char)]
forall record value. record -> (record -> value) -> value
^.State -> [(Int, Char)]
sInput }
       else DList Token
tokens'

-- | @commitBugs reply@ inserts an error token if a commit was made outside a
-- named choice. This should never happen outside tests.
commitBugs :: Reply result -> D.DList Token
commitBugs :: forall result. Reply result -> DList Token
commitBugs Reply result
reply =
  let tokens :: DList Token
tokens = Reply result
replyReply result -> (Reply result -> DList Token) -> DList Token
forall record value. record -> (record -> value) -> value
^.Reply result -> DList Token
forall result. Reply result -> DList Token
rTokens
      state :: State
state = Reply result
replyReply result -> (Reply result -> State) -> State
forall record value. record -> (record -> value) -> value
^.Reply result -> State
forall result. Reply result -> State
rState
  in case Reply result
replyReply result -> (Reply result -> Maybe Decision) -> Maybe Decision
forall record value. record -> (record -> value) -> value
^.Reply result -> Maybe Decision
forall result. Reply result -> Maybe Decision
rCommit of
          Maybe Decision
Nothing     -> DList Token
tokens
          Just Decision
commit -> DList Token -> DList Token -> DList Token
forall a. DList a -> DList a -> DList a
D.append DList Token
tokens (DList Token -> DList Token) -> DList Token -> DList Token
forall a b. (a -> b) -> a -> b
$ Token -> DList Token
forall a. a -> DList a
D.singleton Token { tByteOffset :: Int
tByteOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sByteOffset,
                                                               tCharOffset :: Int
tCharOffset = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sCharOffset,
                                                               tLine :: Int
tLine       = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLine,
                                                               tLineChar :: Int
tLineChar   = State
stateState -> (State -> Int) -> Int
forall record value. record -> (record -> value) -> value
^.State -> Int
sLineChar,
                                                               tCode :: Code
tCode       = Code
Error,
                                                               tText :: String
tText       = String
"Commit to " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Decision -> String
forall a. Show a => a -> String
show Decision
commit String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" was made outside it" }

-- | @'tokenize' input emit_unparsed@ converts the Unicode /input/
-- (using the UTF-8, UTF-16 (LE or BE), or UTF-32 (LE or BE) encoding)
-- to a list of 'Token' according to the YAML 1.2 specification.
--
-- Errors are reported as tokens with @'Error' :: 'Code'@, and the
-- unparsed text following an error may be attached as a final 'Unparsed' token
-- (if the /emit_unparsed/ argument is @True@). Note that tokens are available
-- \"immediately\", allowing for streaming of large YAML files with
-- memory requirements depending only on the YAML nesting level.
tokenize :: BLC.ByteString -> Bool -> [Token]
tokenize :: Tokenizer
tokenize = Pattern -> Tokenizer
patternTokenizer Pattern
l_yaml_stream

-- * Productions

-- ** BNF compatibility helpers

-- | @detect_utf_encoding@ doesn't actually detect the encoding, we just call it
-- this way to make the productions compatible with the spec. Instead it simply
-- reports the encoding (which was already detected when we started parsing).
bom :: Match match1 result1 => match1 -> Parser ()
bom :: forall match result. Match match result => match -> Pattern
bom match1
code = match1
code
         match1 -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ((State -> Reply ()) -> Pattern
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply ()) -> Pattern) -> (State -> Reply ()) -> Pattern
forall a b. (a -> b) -> a -> b
$ \ State
state -> let text :: String
text = case State
stateState -> (State -> Encoding) -> Encoding
forall record value. record -> (record -> value) -> value
^.State -> Encoding
sEncoding of
                                                Encoding
UTF8    -> String
"TF-8"
                                                Encoding
UTF16LE -> String
"TF-16LE"
                                                Encoding
UTF16BE -> String
"TF-16BE"
                                                Encoding
UTF32LE -> String
"TF-32LE"
                                                Encoding
UTF32BE -> String
"TF-32BE"
                                in Pattern -> State -> Reply ()
forall result. Parser result -> State -> Reply result
applyParser (Code -> String -> Pattern
fake Code
Bom String
text) State
state)

-- | @na@ is the \"non-applicable\" indentation value. We use Haskell's laziness
-- to verify it really is never used.
na :: Int
na :: Int
na = String -> Int
forall a. HasCallStack => String -> a
error String
"Accessing non-applicable indentation"

-- | @asInteger@ returns the last consumed character, which is assumed to be a
-- decimal digit, as an integer.
asInteger :: Parser Int
asInteger :: Parser Int
asInteger = (State -> Reply Int) -> Parser Int
forall result. (State -> Reply result) -> Parser result
Parser ((State -> Reply Int) -> Parser Int)
-> (State -> Reply Int) -> Parser Int
forall a b. (a -> b) -> a -> b
$ \ State
state -> State -> Int -> Reply Int
forall result. State -> result -> Reply result
returnReply State
state (Int -> Reply Int) -> Int -> Reply Int
forall a b. (a -> b) -> a -> b
$ Char -> Int
ord (State
stateState -> (State -> Char) -> Char
forall record value. record -> (record -> value) -> value
^.State -> Char
sLast) Int -> Int -> Int
.- Int
48

-- | @result value@ is the same as /return value/ except that we give the
-- Haskell type deduction the additional boost it needs to figure out this is
-- wrapped in a 'Data.YAML.Token.Parser'.
result :: result -> Parser result
result :: forall a. a -> Parser a
result = result -> Parser result
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return

----------------------------------------------------------------------------

-- ** Spec productions
--
-- These are copied directly from the spec, with the sprinkling of
-- additional token and decision point directives.

-- 5.1 Character Set

c_printable :: Pattern
c_printable {- 1 -} = Char
'\x9' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'\xA' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'\xD' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\x20', Char
'\x7E')
                    (Char, Char) -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'\x85' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\xA0', Char
'\xD7FF') (Char, Char) -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\xE000', Char
'\xFFFD')
                    (Char, Char) -> (Char, Char) -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\x10000', Char
'\x10FFFF')

nb_json :: Pattern
nb_json {- 2 -} = Char
'\x9' Char -> (Char, Char) -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\x20', Char
'\x10FFFF')

-- 5.2 Character Encodings

c_byte_order_mark :: Pattern
c_byte_order_mark {- 3 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
bom Char
'\xFEFF'

-- 5.3 Indicator Characters

c_sequence_entry :: Pattern
c_sequence_entry {-  4 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'-'
c_mapping_key :: Pattern
c_mapping_key    {-  5 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'?'
c_mapping_value :: Pattern
c_mapping_value  {-  6 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
':'

c_collect_entry :: Pattern
c_collect_entry  {-  7 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
','
c_sequence_start :: Pattern
c_sequence_start {-  8 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'['
c_sequence_end :: Pattern
c_sequence_end   {-  9 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
']'
c_mapping_start :: Pattern
c_mapping_start  {- 10 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'{'
c_mapping_end :: Pattern
c_mapping_end    {- 11 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'}'

c_comment :: Pattern
c_comment        {- 12 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'#'

c_anchor :: Pattern
c_anchor         {- 13 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'&'
c_alias :: Pattern
c_alias          {- 14 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'*'
c_tag :: Pattern
c_tag            {- 15 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'!'

c_literal :: Pattern
c_literal        {- 16 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'|'
c_folded :: Pattern
c_folded         {- 17 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'>'

c_single_quote :: Pattern
c_single_quote   {- 18 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'\''
c_double_quote :: Pattern
c_double_quote   {- 19 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'"'

c_directive :: Pattern
c_directive      {- 20 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'%'

c_reserved :: Pattern
c_reserved       {- 21 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
indicator ( Char
'@' Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/  Char
'`' )

c_indicator :: Pattern
c_indicator {- 22 -} = Pattern
c_sequence_entry Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_mapping_key Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_mapping_value Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_collect_entry
                     Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_sequence_start Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_sequence_end Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_mapping_start Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_mapping_end
                     Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_comment Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_anchor Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_alias Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_tag
                     Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_literal Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_folded Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_single_quote Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_double_quote
                     Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_directive Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_reserved

c_flow_indicator :: Pattern
c_flow_indicator {- 23 -} = Pattern
c_collect_entry Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_sequence_start Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_sequence_end Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_mapping_start Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_mapping_end

-- 5.4 Line Break Characters

b_line_feed :: Char
b_line_feed       {- 24 -} = Char
'\xA'
b_carriage_return :: Char
b_carriage_return {- 25 -} = Char
'\xD'
b_char :: Pattern
b_char            {- 26 -} = Char
b_line_feed Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
b_carriage_return

nb_char :: Pattern
nb_char {- 27 -} = Pattern
c_printable Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
b_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_byte_order_mark

b_break :: Pattern
b_break {- 28 -} = ( Char
b_carriage_return Char -> Char -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Char
b_line_feed
                   Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
b_carriage_return
                   Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
b_line_feed )
                 Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
nextLine

b_as_line_feed :: Pattern
b_as_line_feed {- 29 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
LineFeed Pattern
b_break

b_non_content :: Pattern
b_non_content {- 30 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Break Pattern
b_break

-- 5.5 White Space Characters

s_space :: Char
s_space {- 31 -} = Char
'\x20'
s_tab :: Char
s_tab   {- 32 -} = Char
'\x9'
s_white :: Pattern
s_white {- 33 -} = Char
s_space Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
s_tab

ns_char :: Pattern
ns_char {- 34 -} = Pattern
nb_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
s_white

-- 5.6 Miscellaneous Characters

ns_dec_digit :: (Char, Char)
ns_dec_digit {- 35 -} = (Char
'\x30', Char
'\x39')

ns_hex_digit :: Pattern
ns_hex_digit {- 36 -} = (Char, Char)
ns_dec_digit
                      (Char, Char) -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\x41', Char
'\x46') (Char, Char) -> (Char, Char) -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\x61', Char
'\x66')

ns_ascii_letter :: Pattern
ns_ascii_letter {- 37 -} = (Char
'\x41', Char
'\x5A') (Char, Char) -> (Char, Char) -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ (Char
'\x61', Char
'\x7A')

ns_word_char :: Pattern
ns_word_char {- 38 -} = (Char, Char)
ns_dec_digit (Char, Char) -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_ascii_letter Pattern -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'-'

ns_uri_char :: Pattern
ns_uri_char {- 39 -} = Decision
DeEscape
                     Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Char
'%' Char -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscape Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_hex_digit Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_hex_digit Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_word_char Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'#'
                       Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
';' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'/' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'?' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
':' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'@' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'&'  Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'=' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'+' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'$' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
','
                       Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'_' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'.' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'!' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'~' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'*' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'\'' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'(' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
')' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'[' Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
']' )

ns_tag_char :: Pattern
ns_tag_char {- 40 -} = Pattern
ns_uri_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_tag Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_flow_indicator

-- 5.7 Escaped Characters

c_escape :: Pattern
c_escape {- 41 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'\\'

ns_esc_null :: Pattern
ns_esc_null                {- 42 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'0'
ns_esc_bell :: Pattern
ns_esc_bell                {- 43 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'a'
ns_esc_backspace :: Pattern
ns_esc_backspace           {- 44 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'b'
ns_esc_horizontal_tab :: Pattern
ns_esc_horizontal_tab      {- 45 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Char
't' Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'\x9' )
ns_esc_line_feed :: Pattern
ns_esc_line_feed           {- 46 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'n'
ns_esc_vertical_tab :: Pattern
ns_esc_vertical_tab        {- 47 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'v'
ns_esc_form_feed :: Pattern
ns_esc_form_feed           {- 48 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'f'
ns_esc_carriage_return :: Pattern
ns_esc_carriage_return     {- 49 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'r'
ns_esc_escape :: Pattern
ns_esc_escape              {- 50 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'e'
ns_esc_space :: Pattern
ns_esc_space               {- 51 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'\x20'
ns_esc_double_quote :: Pattern
ns_esc_double_quote        {- 52 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'"'
ns_esc_slash :: Pattern
ns_esc_slash               {- 53 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'/'
ns_esc_backslash :: Pattern
ns_esc_backslash           {- 54 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'\\'
ns_esc_next_line :: Pattern
ns_esc_next_line           {- 55 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'N'
ns_esc_non_breaking_space :: Pattern
ns_esc_non_breaking_space  {- 56 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'_'
ns_esc_line_separator :: Pattern
ns_esc_line_separator      {- 57 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'L'
ns_esc_paragraph_separator :: Pattern
ns_esc_paragraph_separator {- 58 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'P'
ns_esc_8_bit :: Pattern
ns_esc_8_bit               {- 59 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'x' Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscaped Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_hex_digit Pattern -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
% Int
2 )
ns_esc_16_bit :: Pattern
ns_esc_16_bit              {- 60 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'u' Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscaped Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_hex_digit Pattern -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
% Int
4 )
ns_esc_32_bit :: Pattern
ns_esc_32_bit              {- 61 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'U' Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscaped Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_hex_digit Pattern -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
% Int
8 )

c_ns_esc_char :: Pattern
c_ns_esc_char {- 62 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginEscape Code
EndEscape
                       (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_escape Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscape
                       Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Decision
DeEscaped
                       Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Pattern
ns_esc_null Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_bell Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_backspace
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_horizontal_tab Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_line_feed
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_vertical_tab Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_form_feed
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_carriage_return Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_escape Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_space
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_double_quote Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_slash Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_backslash
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_next_line Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_non_breaking_space
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_line_separator Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_paragraph_separator
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_8_bit Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_16_bit Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_esc_32_bit )

-- 6.1 Indentation Spaces

s_indent :: Int -> Pattern
s_indent    Int
n {- 63 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Indent ( Char
s_space Char -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
% Int
n )

s_indent_lt :: Int -> Pattern
s_indent_lt Int
n {- 64 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Indent ( Char
s_space Char -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
<% Int
n )
s_indent_le :: Int -> Pattern
s_indent_le Int
n {- 65 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Indent ( Char
s_space Char -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
<% (Int
n Int -> Int -> Int
.+ Int
1) )

-- 6.2 Separation Spaces

s_separate_in_line :: Pattern
s_separate_in_line {- 66 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
White ( Pattern
s_white +) Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
sol

-- 6.3 Line Prefixes

s_line_prefix :: Int -> Context -> Pattern
s_line_prefix Int
n Context
c {- 67 -} = case Context
c of
                                  Context
BlockOut -> Int -> Pattern
s_block_line_prefix Int
n
                                  Context
BlockIn  -> Int -> Pattern
s_block_line_prefix Int
n
                                  Context
FlowOut  -> Int -> Pattern
s_flow_line_prefix Int
n
                                  Context
FlowIn   -> Int -> Pattern
s_flow_line_prefix Int
n
                                  Context
_        -> String -> Pattern
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in s_line_prefix"

s_block_line_prefix :: Int -> Pattern
s_block_line_prefix Int
n {- 68 -} = Int -> Pattern
s_indent Int
n
s_flow_line_prefix :: Int -> Pattern
s_flow_line_prefix  Int
n {- 69 -} = Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_separate_in_line ?)

-- 6.4 Empty Lines

l_empty :: Int -> Context -> Pattern
l_empty Int
n Context
c {- 70 -} = ( Int -> Context -> Pattern
s_line_prefix Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
s_indent_lt Int
n )
                     Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_as_line_feed

-- 6.5 Line Folding

b_l_trimmed :: Int -> Context -> Pattern
b_l_trimmed  Int
n Context
c {- 71 -} = Pattern
b_non_content Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
l_empty Int
n Context
c +)

b_as_space :: Pattern
b_as_space {- 72 -} = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
LineFold Pattern
b_break

b_l_folded :: Int -> Context -> Pattern
b_l_folded Int
n Context
c  {- 73 -} = Int -> Context -> Pattern
b_l_trimmed Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
b_as_space

s_flow_folded :: Int -> Pattern
s_flow_folded Int
n {- 74 -} = ( Pattern
s_separate_in_line ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
b_l_folded Int
n Context
FlowIn
                         Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
s_flow_line_prefix Int
n

-- 6.6 Comments

c_nb_comment_text :: Pattern
c_nb_comment_text {- 75 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginComment Code
EndComment
                           (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_comment Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
nb_char *)

b_comment :: Pattern
b_comment {- 76 -} = Pattern
b_non_content Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
eof

s_b_comment :: Pattern
s_b_comment {- 77 -} = ( Pattern
s_separate_in_line Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
c_nb_comment_text ?) ?)
                     Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_comment

l_comment :: Pattern
l_comment {- 78 -} = Pattern
s_separate_in_line Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
c_nb_comment_text ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_comment

s_l_comments :: Pattern
s_l_comments {- 79 -} = ( Pattern
s_b_comment Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
sol )
                      Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_comment *)

-- 6.7 Separation Lines

s_separate :: Int -> Context -> Pattern
s_separate Int
n Context
c      {- 80 -} = case Context
c of
                                    Context
BlockOut -> Int -> Pattern
s_separate_lines Int
n
                                    Context
BlockIn  -> Int -> Pattern
s_separate_lines Int
n
                                    Context
FlowOut  -> Int -> Pattern
s_separate_lines Int
n
                                    Context
FlowIn   -> Int -> Pattern
s_separate_lines Int
n
                                    Context
BlockKey -> Pattern
s_separate_in_line
                                    Context
FlowKey  -> Pattern
s_separate_in_line
s_separate_lines :: Int -> Pattern
s_separate_lines Int
n {- 81 -} = Pattern
s_l_comments Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
s_flow_line_prefix Int
n
                            Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
s_separate_in_line

-- 6.8 Directives

l_directive :: Pattern
l_directive {- 82 -} = ( Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginDirective Code
EndDirective
                       (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_directive Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeDoc
                       Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Decision
DeDirective
                       Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Pattern
ns_yaml_directive
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_tag_directive
                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_reserved_directive ) )
                     Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_l_comments

ns_reserved_directive :: Pattern
ns_reserved_directive  {- 83 -} = Pattern
ns_directive_name
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_separate_in_line Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_directive_parameter *)
ns_directive_name :: Pattern
ns_directive_name      {- 84 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_char +)
ns_directive_parameter :: Pattern
ns_directive_parameter {- 85 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_char +)

-- 6.8.1 Yaml Directives

ns_yaml_directive :: Pattern
ns_yaml_directive {- 86 -} = String -> Pattern
forall match result. Match match result => match -> Pattern
meta [ Char
'Y', Char
'A', Char
'M', Char
'L' ] Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeDirective
                           Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_separate_in_line Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_yaml_version
ns_yaml_version :: Pattern
ns_yaml_version   {- 87 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( ( (Char, Char)
ns_dec_digit +) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Char
'.' Char -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( (Char, Char)
ns_dec_digit +) )

-- 6.8.2 Tag Directives

ns_tag_directive :: Pattern
ns_tag_directive {- 88 -} = String -> Pattern
forall match result. Match match result => match -> Pattern
meta [ Char
'T', Char
'A', Char
'G' ] Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeDirective
                          Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_separate_in_line Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_tag_handle
                          Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_separate_in_line Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_tag_prefix

-- 6.8.2.1 Tag Handles

c_tag_handle :: Pattern
c_tag_handle {- 89 -} = Pattern
c_named_tag_handle
                      Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_secondary_tag_handle
                      Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_primary_tag_handle

c_primary_tag_handle :: Pattern
c_primary_tag_handle   {- 90 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginHandle Code
EndHandle
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_tag

c_secondary_tag_handle :: Pattern
c_secondary_tag_handle {- 91 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginHandle Code
EndHandle
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_tag Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_tag

c_named_tag_handle :: Pattern
c_named_tag_handle     {- 92 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginHandle Code
EndHandle
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_tag Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_word_char +) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_tag

-- 6.8.2.2 Tag Prefixes

ns_tag_prefix :: Pattern
ns_tag_prefix {- 93 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginTag Code
EndTag
                       (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( Pattern
c_ns_local_tag_prefix Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
ns_global_tag_prefix )

c_ns_local_tag_prefix :: Pattern
c_ns_local_tag_prefix {- 94 -} = Pattern
c_tag Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_uri_char *)

ns_global_tag_prefix :: Pattern
ns_global_tag_prefix  {- 95 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_tag_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
ns_uri_char *) )

-- 6.9 Node Properties

c_ns_properties :: Int -> Context -> Pattern
c_ns_properties Int
n Context
c {- 96 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginProperties Code
EndProperties
                             (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( Pattern
c_ns_tag_property
                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_ns_anchor_property ?) )
                             Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
c_ns_anchor_property
                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_ns_tag_property ?) )

-- 6.9.1 Node Tags

c_ns_tag_property :: Pattern
c_ns_tag_property {- 97 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginTag Code
EndTag
                           (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_verbatim_tag
                           Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_ns_shorthand_tag
                           Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_non_specific_tag

c_verbatim_tag :: Pattern
c_verbatim_tag     {- 98 -} = Pattern
c_tag Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'<' Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_uri_char +) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'>'

c_ns_shorthand_tag :: Pattern
c_ns_shorthand_tag {- 99 -} = Pattern
c_tag_handle Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_tag_char +)

c_non_specific_tag :: Pattern
c_non_specific_tag {- 100 -} = Pattern
c_tag

-- 6.9.2 Node Anchors

c_ns_anchor_property :: Pattern
c_ns_anchor_property {- 101 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginAnchor Code
EndAnchor
                               (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_anchor Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_anchor_name

ns_anchor_char :: Pattern
ns_anchor_char {- 102 -} = Pattern
ns_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_flow_indicator
ns_anchor_name :: Pattern
ns_anchor_name {- 103 -} = Pattern -> Pattern
forall match result. Match match result => match -> Pattern
meta ( Pattern
ns_anchor_char +)

-- 7.1 Alias Nodes

c_ns_alias_node :: Pattern
c_ns_alias_node {- 104 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginAlias Code
EndAlias
                          (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_alias Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_anchor_name

-- 7.2 Empty Nodes

e_scalar :: Pattern
e_scalar {- 105 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginScalar Code
EndScalar Pattern
empty

e_node :: Pattern
e_node {- 106 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode Pattern
e_scalar

-- 7.3.1 Double Quoted Style

nb_double_char :: Pattern
nb_double_char {- 107 -} = Decision
DeEscape Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Pattern
c_ns_esc_char Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
nb_json Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_escape Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_double_quote ) )
ns_double_char :: Pattern
ns_double_char {- 108 -} = Pattern
nb_double_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
s_white

c_double_quoted :: Int -> Context -> Pattern
c_double_quoted Int
n Context
c {- 109 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginScalar Code
EndScalar
                              (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_double_quote Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
text ( Int -> Context -> Pattern
nb_double_text Int
n Context
c ) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_double_quote
nb_double_text :: Int -> Context -> Pattern
nb_double_text Int
n Context
c  {- 110 -} = case Context
c of
                                     Context
FlowOut  -> Int -> Pattern
nb_double_multi_line Int
n
                                     Context
FlowIn   -> Int -> Pattern
nb_double_multi_line Int
n
                                     Context
BlockKey -> Pattern
nb_double_one_line
                                     Context
FlowKey  -> Pattern
nb_double_one_line
                                     Context
_        -> String -> Pattern
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in nb_double_text"

nb_double_one_line :: Pattern
nb_double_one_line  {- 111 -} = ( Pattern
nb_double_char *)

s_double_escaped :: Int -> Pattern
s_double_escaped Int
n {- 112 -} = ( Pattern
s_white *)
                             Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginEscape Code
EndEscape ( Pattern
c_escape Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscape Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_non_content )
                             Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
l_empty Int
n Context
FlowIn *)
                             Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
s_flow_line_prefix Int
n
s_double_break :: Int -> Pattern
s_double_break Int
n   {- 113 -} = Decision
DeEscape Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Int -> Pattern
s_double_escaped Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
s_flow_folded Int
n )

nb_ns_double_in_line :: Pattern
nb_ns_double_in_line    {- 114 -} = ( ( Pattern
s_white *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_double_char *)
s_double_next_line :: Int -> Pattern
s_double_next_line Int
n {- 115 -} = Int -> Pattern
s_double_break Int
n
                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
ns_double_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
nb_ns_double_in_line
                                 Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
s_double_next_line Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
s_white *) ) ?)
nb_double_multi_line :: Int -> Pattern
nb_double_multi_line Int
n  {- 116 -} = Pattern
nb_ns_double_in_line
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
s_double_next_line Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
s_white *) )

-- 7.3.2 Single Quoted Style

c_quoted_quote :: Pattern
c_quoted_quote {- 117 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginEscape Code
EndEscape
                         (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_single_quote Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeEscape Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Char -> Pattern
forall match result. Match match result => match -> Pattern
meta Char
'\''
nb_single_char :: Pattern
nb_single_char {- 118 -} = Decision
DeEscape Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Pattern
c_quoted_quote Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
nb_json Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_single_quote ) )
ns_single_char :: Pattern
ns_single_char {- 119 -} = Pattern
nb_single_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
s_white

c_single_quoted :: Int -> Context -> Pattern
c_single_quoted  Int
n Context
c {- 120 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginScalar Code
EndScalar
                               (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_single_quote Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern -> Pattern
forall match result. Match match result => match -> Pattern
text ( Int -> Context -> Pattern
nb_single_text Int
n Context
c ) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_single_quote
nb_single_text :: Int -> Context -> Pattern
nb_single_text Int
n Context
c {- 121 -} = case Context
c of
                                    Context
FlowOut  -> Int -> Pattern
nb_single_multi_line Int
n
                                    Context
FlowIn   -> Int -> Pattern
nb_single_multi_line Int
n
                                    Context
BlockKey -> Pattern
nb_single_one_line
                                    Context
FlowKey  -> Pattern
nb_single_one_line
                                    Context
_        -> String -> Pattern
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in nb_single_text"

nb_single_one_line :: Pattern
nb_single_one_line {- 122 -} = ( Pattern
nb_single_char *)

nb_ns_single_in_line :: Pattern
nb_ns_single_in_line    {- 123 -} = ( ( Pattern
s_white *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_single_char *)
s_single_next_line :: Int -> Pattern
s_single_next_line Int
n {- 124 -} = Int -> Pattern
s_flow_folded Int
n
                                 Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
ns_single_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
nb_ns_single_in_line
                                    Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
s_single_next_line Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
s_white *) ) ?)
nb_single_multi_line :: Int -> Pattern
nb_single_multi_line Int
n  {- 125 -} = Pattern
nb_ns_single_in_line
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
s_single_next_line Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
s_white *) )

-- 7.3.3 Plain Style

ns_plain_first :: Context -> Pattern
ns_plain_first Context
_c  {- 126 -} = Pattern
ns_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_indicator
                            Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Char
':' Char -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'?' Char -> Char -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
'-' ) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( (Context -> Pattern
ns_plain_safe Context
_c) >?)

ns_plain_safe :: Context -> Pattern
ns_plain_safe Context
c   {- 127 -} = case Context
c of
                                   Context
FlowOut  -> Pattern
ns_plain_safe_out
                                   Context
FlowIn   -> Pattern
ns_plain_safe_in
                                   Context
BlockKey -> Pattern
ns_plain_safe_out
                                   Context
FlowKey  -> Pattern
ns_plain_safe_in
                                   Context
_        -> String -> Pattern
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in ns_plain_safe"

ns_plain_safe_out :: Pattern
ns_plain_safe_out {- 128 -} = Pattern
ns_char
ns_plain_safe_in :: Pattern
ns_plain_safe_in  {- 129 -} = Pattern
ns_char Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Pattern
c_flow_indicator
ns_plain_char :: Context -> Pattern
ns_plain_char Context
c   {- 130 -} = Context -> Pattern
ns_plain_safe Context
c Pattern -> Char -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Char
':' Pattern -> Char -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Char
'#'
                            Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
ns_char <?) Pattern -> Char -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Char
'#'
                            Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char
':' Char -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( (Context -> Pattern
ns_plain_safe Context
c) >?)

ns_plain :: Int -> Context -> Pattern
ns_plain Int
n Context
c          {- 131 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginScalar Code
EndScalar
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern -> Pattern
forall match result. Match match result => match -> Pattern
text (case Context
c of
                                             Context
FlowOut  -> Int -> Context -> Pattern
ns_plain_multi_line Int
n Context
c
                                             Context
FlowIn   -> Int -> Context -> Pattern
ns_plain_multi_line Int
n Context
c
                                             Context
BlockKey -> Context -> Pattern
ns_plain_one_line Context
c
                                             Context
FlowKey  -> Context -> Pattern
ns_plain_one_line Context
c
                                             Context
_        -> String -> Pattern
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in ns_plain")

nb_ns_plain_in_line :: Context -> Pattern
nb_ns_plain_in_line Context
c {- 132 -} = ( ( Pattern
s_white *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Context -> Pattern
ns_plain_char Context
c *)
ns_plain_one_line :: Context -> Pattern
ns_plain_one_line Context
c   {- 133 -} = Context -> Pattern
ns_plain_first Context
c Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Context -> Pattern
nb_ns_plain_in_line Context
c

s_ns_plain_next_line :: Int -> Context -> Pattern
s_ns_plain_next_line Int
n Context
c {- 134 -} = Int -> Pattern
s_flow_folded Int
n
                                   Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Context -> Pattern
ns_plain_char Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Context -> Pattern
nb_ns_plain_in_line Context
c
ns_plain_multi_line :: Int -> Context -> Pattern
ns_plain_multi_line Int
n Context
c  {- 135 -} = Context -> Pattern
ns_plain_one_line Context
c
                                   Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_ns_plain_next_line Int
n Context
c *)

-- 7.4 Flow Collection Styles

in_flow :: Context -> Context
in_flow Context
c {- 136 -} = case Context
c of
                           Context
FlowOut  -> Context
FlowIn
                           Context
FlowIn   -> Context
FlowIn
                           Context
BlockKey -> Context
FlowKey
                           Context
FlowKey  -> Context
FlowKey
                           Context
_        -> String -> Context
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in in_flow"

-- 7.4.1 Flow Sequences

c_flow_sequence :: Int -> Context -> Pattern
c_flow_sequence Int
n Context
c {- 137 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginSequence Code
EndSequence
                              (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_sequence_start Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
ns_s_flow_seq_entries Int
n (Context -> Context
in_flow Context
c) ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_sequence_end

ns_s_flow_seq_entries :: Int -> Context -> Pattern
ns_s_flow_seq_entries Int
n Context
c {- 138 -} = Int -> Context -> Pattern
ns_flow_seq_entry Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                    Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
c_collect_entry Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                      Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
ns_s_flow_seq_entries Int
n Context
c ?) ?)

ns_flow_seq_entry :: Int -> Context -> Pattern
ns_flow_seq_entry Int
n Context
c {- 139 -} = Decision
DePair Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Int -> Context -> Pattern
ns_flow_pair Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ Int -> Context -> Pattern
ns_flow_node Int
n Context
c )

-- 7.4.2 Flow Mappings

c_flow_mapping :: Int -> Context -> Pattern
c_flow_mapping Int
n Context
c        {- 140 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginMapping Code
EndMapping
                                    (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_mapping_start Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                    Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
ns_s_flow_map_entries Int
n (Context -> Context
in_flow Context
c) ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_mapping_end
ns_s_flow_map_entries :: Int -> Context -> Pattern
ns_s_flow_map_entries Int
n Context
c {- 141 -} = Int -> Context -> Pattern
ns_flow_map_entry Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                    Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
c_collect_entry Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                      Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
ns_s_flow_map_entries Int
n Context
c ?) ?)

ns_flow_map_entry :: Int -> Context -> Pattern
ns_flow_map_entry Int
n Context
c {- 142 -}          = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginPair Code
EndPair
                                         (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Decision
DeKey Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( ( Pattern
c_mapping_key Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeKey Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_separate Int
n Context
c
                                                     Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_map_explicit_entry Int
n Context
c )
                                                   Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
ns_flow_map_implicit_entry Int
n Context
c )
ns_flow_map_explicit_entry :: Int -> Context -> Pattern
ns_flow_map_explicit_entry Int
n Context
c {- 143 -} = Int -> Context -> Pattern
ns_flow_map_implicit_entry Int
n Context
c
                                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
e_node
                                           Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
e_node )

ns_flow_map_implicit_entry :: Int -> Context -> Pattern
ns_flow_map_implicit_entry Int
n Context
c {- 144 -}    = Decision
DePair
                                            Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Int -> Context -> Pattern
c_ns_flow_map_json_key_entry Int
n Context
c
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
ns_flow_map_yaml_key_entry Int
n Context
c
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_ns_flow_map_empty_key_entry Int
n Context
c )
ns_flow_map_yaml_key_entry :: Int -> Context -> Pattern
ns_flow_map_yaml_key_entry Int
n Context
c {- 145 -}    = ( Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ Int -> Context -> Pattern
ns_flow_yaml_node Int
n Context
c ) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DePair
                                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_ns_flow_map_separate_value Int
n Context
c )
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node )
c_ns_flow_map_empty_key_entry :: Int -> Context -> Pattern
c_ns_flow_map_empty_key_entry Int
n Context
c {- 146 -} = Pattern
e_node
                                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_ns_flow_map_separate_value Int
n Context
c

c_ns_flow_map_separate_value :: Int -> Context -> Pattern
c_ns_flow_map_separate_value Int
n Context
c {- 147 -}  = Pattern
c_mapping_value Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( (Context -> Pattern
ns_plain_safe Context
c) >!) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DePair
                                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( Int -> Context -> Pattern
s_separate Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_node Int
n Context
c )
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node )

c_ns_flow_map_json_key_entry :: Int -> Context -> Pattern
c_ns_flow_map_json_key_entry Int
n Context
c {- 148 -} = ( Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ Int -> Context -> Pattern
c_flow_json_node Int
n Context
c ) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DePair
                                           Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_ns_flow_map_adjacent_value Int
n Context
c )
                                             Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node )
c_ns_flow_map_adjacent_value :: Int -> Context -> Pattern
c_ns_flow_map_adjacent_value Int
n Context
c {- 149 -} = Pattern
c_mapping_value Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DePair
                                           Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( ( Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_node Int
n Context
c )
                                               Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node )

ns_flow_pair :: Int -> Context -> Pattern
ns_flow_pair Int
n Context
c {- 150 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginMapping Code
EndMapping
                           (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginPair Code
EndPair
                           (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( ( Pattern
c_mapping_key Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DePair Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_separate Int
n Context
c
                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_map_explicit_entry Int
n Context
c )
                             Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
ns_flow_pair_entry Int
n Context
c )

ns_flow_pair_entry :: Int -> Context -> Pattern
ns_flow_pair_entry Int
n Context
c            {- 151 -} = ( Int -> Context -> Pattern
ns_flow_pair_yaml_key_entry Int
n Context
c
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_ns_flow_map_empty_key_entry Int
n Context
c
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_ns_flow_pair_json_key_entry Int
n Context
c )
ns_flow_pair_yaml_key_entry :: Int -> Context -> Pattern
ns_flow_pair_yaml_key_entry Int
n Context
c   {- 152 -} = Context -> Pattern
ns_s_implicit_yaml_key Context
FlowKey
                                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_ns_flow_map_separate_value Int
n Context
c
c_ns_flow_pair_json_key_entry :: Int -> Context -> Pattern
c_ns_flow_pair_json_key_entry Int
n Context
c {- 153 -} = Context -> Pattern
c_s_implicit_json_key Context
FlowKey
                                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_ns_flow_map_adjacent_value Int
n Context
c
ns_s_implicit_yaml_key :: Context -> Pattern
ns_s_implicit_yaml_key Context
c          {- 154 -} = ( Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Int -> Context -> Pattern
ns_flow_yaml_node Int
na Context
c ) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_separate_in_line ?) )
                                            Pattern -> Int -> Pattern
forall match result.
Match match result =>
match -> Int -> Parser result
`limitedTo` Int
1024
c_s_implicit_json_key :: Context -> Pattern
c_s_implicit_json_key Context
c           {- 155 -} = ( Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Int -> Context -> Pattern
c_flow_json_node  Int
na Context
c ) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_separate_in_line ?) )
                                            Pattern -> Int -> Pattern
forall match result.
Match match result =>
match -> Int -> Parser result
`limitedTo` Int
1024

-- 7.5 Flow Nodes

ns_flow_yaml_content :: Int -> Context -> Pattern
ns_flow_yaml_content Int
n Context
c {- 156 -} = Int -> Context -> Pattern
ns_plain Int
n Context
c
c_flow_json_content :: Int -> Context -> Pattern
c_flow_json_content Int
n Context
c  {- 157 -} = Int -> Context -> Pattern
c_flow_sequence Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_flow_mapping Int
n Context
c
                                   Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_single_quoted Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_double_quoted Int
n Context
c
ns_flow_content :: Int -> Context -> Pattern
ns_flow_content Int
n Context
c      {- 158 -} = Int -> Context -> Pattern
ns_flow_yaml_content Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
c_flow_json_content Int
n Context
c

ns_flow_yaml_node :: Int -> Context -> Pattern
ns_flow_yaml_node Int
n Context
c {- 159 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_ns_alias_node
                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
ns_flow_yaml_content Int
n Context
c
                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Int -> Context -> Pattern
c_ns_properties Int
n Context
c
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( Int -> Context -> Pattern
s_separate Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_yaml_content Int
n Context
c )
                                    Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_scalar ) )
c_flow_json_node :: Int -> Context -> Pattern
c_flow_json_node Int
n Context
c  {- 160 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( Int -> Context -> Pattern
c_ns_properties Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_separate Int
n Context
c ?)
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_flow_json_content Int
n Context
c
ns_flow_node :: Int -> Context -> Pattern
ns_flow_node Int
n Context
c      {- 161 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode
                                (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Pattern
c_ns_alias_node
                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
ns_flow_content Int
n Context
c
                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Int -> Context -> Pattern
c_ns_properties Int
n Context
c
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( Int -> Context -> Pattern
s_separate Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_content Int
n Context
c )
                                    Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_scalar ) )

-- 8.1.1 Block Scalar Headers

c_b_block_header :: Int -> Parser (Int, Chomp)
c_b_block_header Int
n {- 162 -} = Decision
DeHeader
                             Decision -> Parser (Int, Chomp) -> Parser (Int, Chomp)
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( do Int
m <- Int -> Parser Int
c_indentation_indicator Int
n
                                    Chomp
t <- Parser Chomp
c_chomping_indicator
                                    ( Pattern
s_white Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
b_char ) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
?! Decision
DeHeader
                                    Pattern
s_b_comment
                                    (Int, Chomp) -> Parser (Int, Chomp)
forall a. a -> Parser a
result (Int
m, Chomp
t)
                               Parser (Int, Chomp) -> Parser (Int, Chomp) -> Parser (Int, Chomp)
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ do Chomp
t <- Parser Chomp
c_chomping_indicator
                                    Int
m <- Int -> Parser Int
c_indentation_indicator Int
n
                                    Pattern
s_b_comment
                                    (Int, Chomp) -> Parser (Int, Chomp)
forall a. a -> Parser a
result (Int
m, Chomp
t) )

-- 8.1.1.1 Block Indentation Indicator

c_indentation_indicator :: Int -> Parser Int
c_indentation_indicator Int
n {- 163 -} = (Int -> Int) -> Parser Int -> Parser Int
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Int
fixup (Pattern -> Pattern
forall match result. Match match result => match -> Pattern
indicator ( (Char, Char)
ns_dec_digit (Char, Char) -> Char -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result1
- Char
'0' ) Pattern -> Parser Int -> Parser Int
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Parser Int
asInteger)
                                    Parser Int -> Parser Int -> Parser Int
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Parser Int
detect_scalar_indentation Int
n
  where
    fixup :: Int -> Int
fixup | Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== -Int
1   = (Int -> Int -> Int
.+ Int
1) -- compensate for anomaly at left-most n
          | Bool
otherwise = Int -> Int
forall a. a -> a
id

detect_scalar_indentation :: Int -> Parser Int
detect_scalar_indentation Int
n = Parser Int -> Parser Int
forall parameter result.
Match parameter result =>
parameter -> Parser result
peek (Parser Int -> Parser Int) -> Parser Int -> Parser Int
forall a b. (a -> b) -> a -> b
$ ( Pattern
nb_char *)
                              -- originally:
                              --   & ( b_non_content & ( l_empty n BlockIn *) ?)
                                   Pattern -> Parser Int -> Parser Int
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
b_break Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( (Char
s_space *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_break *) ?)
                                   Pattern -> Parser Int -> Parser Int
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Parser Int
count_spaces (-Int
n)

count_spaces :: Int -> Parser Int
count_spaces Int
n  = (Char
s_space Char -> Parser Int -> Parser Int
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Parser Int
count_spaces (Int
n Int -> Int -> Int
.+ Int
1))
                Parser Int -> Parser Int -> Parser Int
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Parser Int
forall a. a -> Parser a
result (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
n)

-- 8.1.1.2 Chomping Indicator

c_chomping_indicator :: Parser Chomp
c_chomping_indicator {- 164 -} = Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'-' Pattern -> Parser Chomp -> Parser Chomp
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Chomp -> Parser Chomp
forall a. a -> Parser a
result Chomp
Strip
                               Parser Chomp -> Parser Chomp -> Parser Chomp
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Char -> Pattern
forall match result. Match match result => match -> Pattern
indicator Char
'+' Pattern -> Parser Chomp -> Parser Chomp
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Chomp -> Parser Chomp
forall a. a -> Parser a
result Chomp
Keep
                               Parser Chomp -> Parser Chomp -> Parser Chomp
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Chomp -> Parser Chomp
forall a. a -> Parser a
result Chomp
Clip

end_block_scalar :: Chomp -> Pattern
end_block_scalar Chomp
t = case Chomp
t of
                          Chomp
Strip -> Code -> Pattern
emptyToken Code
EndScalar
                          Chomp
Clip  -> Code -> Pattern
emptyToken Code
EndScalar
                          Chomp
Keep  -> Pattern
empty

b_chomped_last :: Chomp -> Pattern
b_chomped_last Chomp
t {- 165 -} = case Chomp
t of
                                  Chomp
Strip -> Code -> Pattern
emptyToken Code
EndScalar Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_non_content
                                  Chomp
Clip  -> Pattern
b_as_line_feed Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Code -> Pattern
emptyToken Code
EndScalar
                                  Chomp
Keep  -> Pattern
b_as_line_feed

l_chomped_empty :: Int -> Chomp -> Pattern
l_chomped_empty Int
n Chomp
t {- 166 -} = case Chomp
t of
                                     Chomp
Strip -> Int -> Pattern
l_strip_empty Int
n
                                     Chomp
Clip  -> Int -> Pattern
l_strip_empty Int
n
                                     Chomp
Keep  -> Int -> Pattern
l_keep_empty Int
n
l_strip_empty :: Int -> Pattern
l_strip_empty Int
n     {- 167 -} = ( Int -> Pattern
s_indent_le Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_non_content *)
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
l_trail_comments Int
n ?)
l_keep_empty :: Int -> Pattern
l_keep_empty Int
n      {- 168 -} = ( Int -> Context -> Pattern
l_empty Int
n Context
BlockIn *)
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Code -> Pattern
emptyToken Code
EndScalar
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
l_trail_comments Int
n ?)

l_trail_comments :: Int -> Pattern
l_trail_comments Int
n {- 169 -} = Int -> Pattern
s_indent_lt Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_nb_comment_text Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
b_comment
                             Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_comment *)

-- 8.1.2 Literal Style

c_l__literal :: Int -> Pattern
c_l__literal Int
n {- 170 -} = do Code -> Pattern
emptyToken Code
BeginScalar
                              Pattern
c_literal Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode
                              (Int
m, Chomp
t) <- Int -> Parser (Int, Chomp)
c_b_block_header Int
n Parser (Int, Chomp) -> Pattern -> Parser (Int, Chomp)
forall match result.
Match match result =>
match -> Pattern -> Parser result
`prefixErrorWith` Code -> Pattern
emptyToken Code
EndScalar
                              Pattern -> Pattern
forall match result. Match match result => match -> Pattern
text ( Int -> Chomp -> Pattern
l_literal_content (Int
n Int -> Int -> Int
.+ Int
m) Chomp
t )

l_nb_literal_text :: Int -> Pattern
l_nb_literal_text Int
n   {- 171 -} = ( Int -> Context -> Pattern
l_empty Int
n Context
BlockIn *)
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
nb_char +)
b_nb_literal_next :: Int -> Pattern
b_nb_literal_next Int
n   {- 172 -} = Pattern
b_as_line_feed
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
l_nb_literal_text Int
n
l_literal_content :: Int -> Chomp -> Pattern
l_literal_content Int
n Chomp
t {- 173 -} = ( ( Int -> Pattern
l_nb_literal_text Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
b_nb_literal_next Int
n *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Chomp -> Pattern
b_chomped_last Chomp
t )
                                  Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Chomp -> Pattern
end_block_scalar Chomp
t )
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Chomp -> Pattern
l_chomped_empty Int
n Chomp
t

-- 8.1.3 Folded Style

c_l__folded :: Int -> Pattern
c_l__folded Int
n {- 174 -} = do Code -> Pattern
emptyToken Code
BeginScalar
                             Pattern
c_folded Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode
                             (Int
m, Chomp
t) <- Int -> Parser (Int, Chomp)
c_b_block_header Int
n Parser (Int, Chomp) -> Pattern -> Parser (Int, Chomp)
forall match result.
Match match result =>
match -> Pattern -> Parser result
`prefixErrorWith` Code -> Pattern
emptyToken Code
EndScalar
                             Pattern -> Pattern
forall match result. Match match result => match -> Pattern
text ( Int -> Chomp -> Pattern
l_folded_content (Int
n Int -> Int -> Int
.+ Int
m) Chomp
t )

s_nb_folded_text :: Int -> Pattern
s_nb_folded_text Int
n  {- 175 -} = Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
ns_char Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeFold Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
nb_char *)
l_nb_folded_lines :: Int -> Pattern
l_nb_folded_lines Int
n {- 176 -} = Int -> Pattern
s_nb_folded_text Int
n
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
b_l_folded Int
n Context
BlockIn Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
s_nb_folded_text Int
n *)

s_nb_spaced_text :: Int -> Pattern
s_nb_spaced_text Int
n  {- 177 -} = Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_white Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeFold Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
nb_char *)
b_l_spaced :: Int -> Pattern
b_l_spaced        Int
n {- 178 -} = Pattern
b_as_line_feed
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
l_empty Int
n Context
BlockIn *)
l_nb_spaced_lines :: Int -> Pattern
l_nb_spaced_lines Int
n {- 179 -} = Int -> Pattern
s_nb_spaced_text Int
n
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
b_l_spaced Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
s_nb_spaced_text Int
n *)

l_nb_same_lines :: Int -> Pattern
l_nb_same_lines Int
n {- 180 -} = ( Int -> Context -> Pattern
l_empty Int
n Context
BlockIn *)
                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Decision
DeFold Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Int -> Pattern
l_nb_folded_lines Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
l_nb_spaced_lines Int
n )

l_nb_diff_lines :: Int -> Pattern
l_nb_diff_lines Int
n {- 181 -} = Int -> Pattern
l_nb_same_lines Int
n
                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
b_as_line_feed Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
l_nb_same_lines Int
n *)

l_folded_content :: Int -> Chomp -> Pattern
l_folded_content Int
n Chomp
t {- 182 -} = ( ( Int -> Pattern
l_nb_diff_lines Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Chomp -> Pattern
b_chomped_last Chomp
t )
                                 Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Chomp -> Pattern
end_block_scalar Chomp
t )
                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Chomp -> Pattern
l_chomped_empty Int
n Chomp
t

-- 8.2.1 Block Sequences

detect_collection_indentation :: Int -> Parser Int
detect_collection_indentation Int
n = Parser Int -> Parser Int
forall parameter result.
Match parameter result =>
parameter -> Parser result
peek (Parser Int -> Parser Int) -> Parser Int -> Parser Int
forall a b. (a -> b) -> a -> b
$ ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_comment* ) Pattern -> Parser Int -> Parser Int
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Parser Int
count_spaces (-Int
n)
detect_inline_indentation :: Parser Int
detect_inline_indentation       = Parser Int -> Parser Int
forall parameter result.
Match parameter result =>
parameter -> Parser result
peek (Parser Int -> Parser Int) -> Parser Int -> Parser Int
forall a b. (a -> b) -> a -> b
$ Int -> Parser Int
count_spaces Int
0

l__block_sequence :: Int -> Pattern
l__block_sequence Int
n   {- 183 -} = do Int
m  <- Int -> Parser Int
detect_collection_indentation Int
n
                                     Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginSequence Code
EndSequence (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( Int -> Pattern
s_indent (Int
n Int -> Int -> Int
.+ Int
m) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
c_l_block_seq_entry (Int
n Int -> Int -> Int
.+ Int
m) +)
c_l_block_seq_entry :: Int -> Pattern
c_l_block_seq_entry Int
n {- 184 -} = Pattern
c_sequence_entry Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
ns_char >!) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_l__block_indented Int
n Context
BlockIn

s_l__block_indented :: Int -> Context -> Pattern
s_l__block_indented Int
n Context
c {- 185 -} = do Int
m <- Parser Int
detect_inline_indentation
                                       Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( ( Int -> Pattern
s_indent Int
m
                                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
ns_l_in_line_sequence (Int
n Int -> Int -> Int
.+ Int
1 Int -> Int -> Int
.+ Int
m)
                                                    Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
ns_l_in_line_mapping (Int
n Int -> Int -> Int
.+ Int
1 Int -> Int -> Int
.+ Int
m) ) )
                                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
s_l__block_node Int
n Context
c
                                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
e_node Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_l_comments ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
unparsed (Int
n Int -> Int -> Int
.+ Int
1) ) ) Pattern -> Pattern -> Pattern
forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
`recovery` Int -> Pattern
unparsed (Int
n Int -> Int -> Int
.+ Int
1)
ns_l_in_line_sequence :: Int -> Pattern
ns_l_in_line_sequence Int
n {- 186 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode
                                  (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginSequence Code
EndSequence
                                  (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Int -> Pattern
c_l_block_seq_entry Int
n
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
c_l_block_seq_entry Int
n *)

-- 8.2.2 Block Mappings

l__block_mapping :: Int -> Pattern
l__block_mapping Int
n = {- 187 -} do Int
m <- Int -> Parser Int
detect_collection_indentation Int
n
                                  Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginMapping Code
EndMapping (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( Int -> Pattern
s_indent (Int
n Int -> Int -> Int
.+ Int
m) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
ns_l_block_map_entry (Int
n Int -> Int -> Int
.+ Int
m) +)

ns_l_block_map_entry :: Int -> Pattern
ns_l_block_map_entry Int
n {- 188 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginPair Code
EndPair
                                 (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Int -> Pattern
c_l_block_map_explicit_entry Int
n
                                 Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
ns_l_block_map_implicit_entry Int
n
c_l_block_map_explicit_entry :: Int -> Pattern
c_l_block_map_explicit_entry Int
n {- 189 -} = Int -> Pattern
c_l_block_map_explicit_key Int
n
                                         Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
l_block_map_explicit_value Int
n
                                         Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node )
c_l_block_map_explicit_key :: Int -> Pattern
c_l_block_map_explicit_key Int
n   {- 190 -} = Pattern
c_mapping_key Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
ns_char >!) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_l__block_indented Int
n Context
BlockOut
l_block_map_explicit_value :: Int -> Pattern
l_block_map_explicit_value Int
n   {- 191 -} = Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
c_mapping_value Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_l__block_indented Int
n Context
BlockOut

ns_l_block_map_implicit_entry :: Int -> Pattern
ns_l_block_map_implicit_entry Int
n {- 192 -} = ( Pattern
ns_s_block_map_implicit_key
                                            Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node )
                                          Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
c_l_block_map_implicit_value Int
n
ns_s_block_map_implicit_key :: Pattern
ns_s_block_map_implicit_key     {- 193 -} = Context -> Pattern
c_s_implicit_json_key Context
BlockKey
                                          Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Context -> Pattern
ns_s_implicit_yaml_key Context
BlockKey

c_l_block_map_implicit_value :: Int -> Pattern
c_l_block_map_implicit_value Int
n  {- 194 -} = Pattern
c_mapping_value Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeNode
                                          Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( Int -> Context -> Pattern
s_l__block_node Int
n Context
BlockOut
                                              Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
e_node Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_l_comments ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
unparsed (Int
n Int -> Int -> Int
.+ Int
1) ) ) Pattern -> Pattern -> Pattern
forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
`recovery` Int -> Pattern
unparsed (Int
n Int -> Int -> Int
.+ Int
1) )

ns_l_in_line_mapping :: Int -> Pattern
ns_l_in_line_mapping Int
n {- 195 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode
                                 (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginMapping Code
EndMapping
                                 (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Int -> Pattern
ns_l_block_map_entry Int
n
                                 Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
s_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
ns_l_block_map_entry Int
n *)

-- 8.2.3 Block Nodes

unparsed :: Int -> Pattern
unparsed Int
n = ( Pattern
sol Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
unparsed_text Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
unparsed_break )
           Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty ( Int -> Pattern
unparsed_indent Int
n Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
unparsed_text Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
unparsed_break ) *)
unparsed_indent :: Int -> Pattern
unparsed_indent Int
n = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Unparsed ( Char
s_space Char -> Int -> Pattern
forall match result. Match match result => match -> Int -> Pattern
% Int
n )
unparsed_text :: Pattern
unparsed_text = Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Unparsed ( Pattern -> Pattern
upto ( Pattern
eof Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_forbidden Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
b_break ) )
unparsed_break :: Pattern
unparsed_break = Pattern
eof Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
peek Pattern
c_forbidden Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Code -> Pattern -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
Unparsed Pattern
b_break Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
empty

s_l__block_node :: Int -> Context -> Pattern
s_l__block_node Int
n Context
c  {- 196 -} = Int -> Context -> Pattern
s_l__block_in_block Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
s_l__flow_in_block Int
n
s_l__flow_in_block :: Int -> Pattern
s_l__flow_in_block Int
n {- 197 -} = Int -> Context -> Pattern
s_separate (Int
n Int -> Int -> Int
.+ Int
1) Context
FlowOut
                               Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
ns_flow_node (Int
n Int -> Int -> Int
.+ Int
1) Context
FlowOut Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_l_comments

s_l__block_in_block :: Int -> Context -> Pattern
s_l__block_in_block Int
n Context
c {- 198 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginNode Code
EndNode
                                  (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ ( Int -> Context -> Pattern
s_l__block_scalar Int
n Context
c Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Context -> Pattern
s_l__block_collection Int
n Context
c )
s_l__block_scalar :: Int -> Context -> Pattern
s_l__block_scalar Int
n Context
c   {- 199 -} = Int -> Context -> Pattern
s_separate (Int
n Int -> Int -> Int
.+ Int
1) Context
c
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Context -> Pattern
c_ns_properties (Int
n Int -> Int -> Int
.+ Int
1) Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
s_separate (Int
n Int -> Int -> Int
.+ Int
1) Context
c ?)
                                  Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
c_l__literal Int
n Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
c_l__folded Int
n )

s_l__block_collection :: Int -> Context -> Pattern
s_l__block_collection Int
n Context
c {- 200 -} = ( Int -> Context -> Pattern
s_separate (Int
n Int -> Int -> Int
.+ Int
1) Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Context -> Pattern
c_ns_properties (Int
n Int -> Int -> Int
.+ Int
1) Context
c Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_l_comments >?) ?)
                                    Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_l_comments
                                    Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Int -> Pattern
l__block_sequence (Int -> Context -> Int
seq_spaces Int
n Context
c)
                                      Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Int -> Pattern
l__block_mapping Int
n )
seq_spaces :: Int -> Context -> Int
seq_spaces Int
n Context
c            {- 201 -} = case Context
c of
                                           Context
BlockOut -> Int
n Int -> Int -> Int
.- Int
1
                                           Context
BlockIn  -> Int
n
                                           Context
_        -> String -> Int
forall a. HasCallStack => String -> a
error String
"unexpected node style pattern in seq_spaces"

-- 9.1.1 Document Prefix

l_document_prefix :: Pattern
l_document_prefix {- 202 -} = ( Pattern
c_byte_order_mark ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_comment *)

-- 9.1.2 Document Markers

c_directives_end :: Pattern
c_directives_end  {- 203 -} = Code -> String -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
DirectivesEnd [ Char
'-', Char
'-', Char
'-' ]
c_document_end :: Pattern
c_document_end    {- 204 -} = Code -> String -> Pattern
forall match result. Match match result => Code -> match -> Pattern
token Code
DocumentEnd [ Char
'.', Char
'.', Char
'.' ]
l_document_suffix :: Pattern
l_document_suffix {- 205 -} = Pattern
c_document_end Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
s_l_comments
c_forbidden :: Pattern
c_forbidden       {- 206 -} = Pattern
sol
                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
c_directives_end Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
c_document_end )
                            Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
b_char Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
s_white Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
eof )

-- 9.1.3 Explicit Documents

l_bare_document :: Pattern
l_bare_document {- 207 -} = Decision
DeNode Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ Int -> Context -> Pattern
s_l__block_node (-Int
1) Context
BlockIn
                            Pattern -> Pattern -> Pattern
forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
`forbidding` Pattern
c_forbidden

-- 9.1.4 Explicit Documents

l_explicit_document :: Pattern
l_explicit_document {- 208 -} = ( Pattern
c_directives_end Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
b_char Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
s_white Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
eof >?)) Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeDoc
                              Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( ( Pattern
l_bare_document
                                  Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
e_node Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
s_l_comments ?) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Int -> Pattern
unparsed Int
0 ) Pattern -> Pattern -> Pattern
forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
`recovery` Int -> Pattern
unparsed Int
0 )

-- 9.1.5 Directives Documents

l_directives_document :: Pattern
l_directives_document {- 209 -} = ( Pattern
l_directive +)
                                Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Pattern
l_explicit_document

-- 9.2 Streams:

l_any_document :: Pattern
l_any_document   {- 210 -} = Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginDocument Code
EndDocument
                           (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ Decision
DeDoc Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Pattern
l_directives_document
                                     Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
l_explicit_document
                                     Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
l_bare_document ) Pattern -> Pattern -> Pattern
forall match1 result.
Match match1 result =>
match1 -> Parser result -> Parser result
`recovery` Int -> Pattern
unparsed Int
0

l_yaml_stream :: Pattern
l_yaml_stream {- 211 -} = ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_document_prefix *)
                        Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
eof Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern
c_document_end Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
b_char Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
s_white Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
eof ) >?) Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
l_any_document )
                        Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty ( Decision
DeMore Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( ( Pattern
l_document_suffix Pattern -> Decision -> Pattern
forall match result.
Match match result =>
match -> Decision -> Pattern
! Decision
DeMore +) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_document_prefix *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& ( Pattern
eof Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ Pattern
l_any_document )
                                                Pattern -> Pattern -> Pattern
forall match1 result match2.
(Match match1 result, Match match2 result) =>
match1 -> match2 -> Parser result
/ ( Pattern -> Pattern
forall parameter result.
Match parameter result =>
parameter -> Parser result
nonEmpty Pattern
l_document_prefix *) Pattern -> Pattern -> Pattern
forall match1 result1 match2 result2.
(Match match1 result1, Match match2 result2) =>
match1 -> match2 -> Parser result2
& Decision
DeDoc Decision -> Pattern -> Pattern
forall match result.
Match match result =>
Decision -> match -> Parser result
^ ( Code -> Code -> Pattern -> Pattern
wrapTokens Code
BeginDocument Code
EndDocument Pattern
l_explicit_document ?) ) ) *)