{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE Safe #-}
module Data.YAML.Event
(
parseEvents
, writeEvents
, writeEventsText
, EvStream
, Event(..)
, EvPos(..)
, Directives(..)
, ScalarStyle(..)
, NodeStyle(..)
, Chomp(..)
, IndentOfs(..)
, Tag, untagged, isUntagged, tagToText, mkTag
, Anchor
, Pos(..)
) where
import Data.YAML.Event.Internal
import Data.YAML.Event.Writer (writeEvents, writeEventsText)
import qualified Data.ByteString.Lazy as BS.L
import qualified Data.Char as C
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Data.YAML.Token as Y
import Numeric (readHex)
import Util
mkTag :: String -> Tag
mkTag :: String -> Tag
mkTag "" = String -> Tag
forall a. HasCallStack => String -> a
error "mkTag"
mkTag "!" = Maybe Text -> Tag
Tag (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$! String -> Text
T.pack "!")
mkTag s :: String
s = Maybe Text -> Tag
Tag (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$! String -> Text
tagUnescape String
s)
where
tagUnescape :: String -> Text
tagUnescape = String -> Text
T.pack (String -> Text) -> (String -> String) -> String -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
go
where
go :: String -> String
go [] = []
go ('%':h :: Char
h:l :: Char
l:cs :: String
cs)
| Just c :: Char
c <- String -> Maybe Char
decodeL1 [Char
h,Char
l] = Char
c Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
go String
cs
go (c :: Char
c:cs :: String
cs) = Char
c Char -> String -> String
forall a. a -> [a] -> [a]
: String -> String
go String
cs
mkTag' :: String -> Tag
mkTag' :: String -> Tag
mkTag' "" = String -> Tag
forall a. HasCallStack => String -> a
error "mkTag'"
mkTag' s :: String
s = Maybe Text -> Tag
Tag (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$! String -> Text
T.pack String
s)
mkTag'' :: String -> Tag
mkTag'' :: String -> Tag
mkTag'' "" = String -> Tag
forall a. HasCallStack => String -> a
error "mkTag''"
mkTag'' s :: String
s = Maybe Text -> Tag
Tag (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$! String -> Text
T.pack ("tag:yaml.org,2002:" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s))
tok2pos :: Y.Token -> Pos
tok2pos :: Token -> Pos
tok2pos Y.Token { tByteOffset :: Token -> Int
Y.tByteOffset = Int
posByteOffset, tCharOffset :: Token -> Int
Y.tCharOffset = Int
posCharOffset, tLine :: Token -> Int
Y.tLine = Int
posLine, tLineChar :: Token -> Int
Y.tLineChar = Int
posColumn } = $WPos :: Int -> Int -> Int -> Int -> Pos
Pos {..}
getEvPos :: Event -> Y.Token -> EvPos
getEvPos :: Event -> Token -> EvPos
getEvPos ev :: Event
ev tok :: Token
tok = $WEvPos :: Event -> Pos -> EvPos
EvPos { eEvent :: Event
eEvent = Event
ev , ePos :: Pos
ePos = Token -> Pos
tok2pos Token
tok }
initPos :: Pos
initPos :: Pos
initPos = $WPos :: Int -> Int -> Int -> Int -> Pos
Pos { posByteOffset :: Int
posByteOffset = 0 , posCharOffset :: Int
posCharOffset = 0 , posLine :: Int
posLine = 1 , posColumn :: Int
posColumn = 0 }
type TagHandle = Text
type Props = (Maybe Text,Tag)
getHandle :: [Y.Token] -> Maybe (TagHandle,[Y.Token])
getHandle :: [Token] -> Maybe (Text, [Token])
getHandle toks0 :: [Token]
toks0 = do
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginHandle } : toks1 :: [Token]
toks1 <- [Token] -> Maybe [Token]
forall a. a -> Maybe a
Just [Token]
toks0
(hs :: [Token]
hs,Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndHandle } : toks2 :: [Token]
toks2) <- ([Token], [Token]) -> Maybe ([Token], [Token])
forall a. a -> Maybe a
Just (([Token], [Token]) -> Maybe ([Token], [Token]))
-> ([Token], [Token]) -> Maybe ([Token], [Token])
forall a b. (a -> b) -> a -> b
$ (Token -> Bool) -> [Token] -> ([Token], [Token])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (\Y.Token { tCode :: Token -> Code
Y.tCode = Code
c } -> Code
c Code -> [Code] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Code
Y.Indicator,Code
Y.Meta]) [Token]
toks1
(Text, [Token]) -> Maybe (Text, [Token])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ (Token -> String) -> [Token] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Token -> String
Y.tText [Token]
hs, [Token]
toks2)
getUriTag :: [Y.Token] -> Maybe (Text,[Y.Token])
getUriTag :: [Token] -> Maybe (Text, [Token])
getUriTag toks0 :: [Token]
toks0 = do
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginTag } : toks1 :: [Token]
toks1 <- [Token] -> Maybe [Token]
forall a. a -> Maybe a
Just [Token]
toks0
(hs :: [Token]
hs,Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndTag } : toks2 :: [Token]
toks2) <- ([Token], [Token]) -> Maybe ([Token], [Token])
forall a. a -> Maybe a
Just (([Token], [Token]) -> Maybe ([Token], [Token]))
-> ([Token], [Token]) -> Maybe ([Token], [Token])
forall a b. (a -> b) -> a -> b
$ (Token -> Bool) -> [Token] -> ([Token], [Token])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (\Y.Token { tCode :: Token -> Code
Y.tCode = Code
c } -> Code
c Code -> [Code] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Code
Y.Indicator,Code
Y.Meta]) [Token]
toks1
(Text, [Token]) -> Maybe (Text, [Token])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ (Token -> String) -> [Token] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Token -> String
Y.tText [Token]
hs, [Token]
toks2)
fixUpEOS :: EvStream -> EvStream
fixUpEOS :: EvStream -> EvStream
fixUpEOS = Pos -> EvStream -> EvStream
go Pos
initPos
where
go :: Pos -> EvStream -> EvStream
go :: Pos -> EvStream -> EvStream
go _ [] = []
go p :: Pos
p [Right (EvPos StreamEnd _)] = [EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Pos -> EvPos
EvPos Event
StreamEnd Pos
p)]
go _ (e :: Either (Pos, String) EvPos
e@(Right (EvPos _ p :: Pos
p)):es :: EvStream
es) = Either (Pos, String) EvPos
e Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Pos -> EvStream -> EvStream
go Pos
p EvStream
es
go _ (e :: Either (Pos, String) EvPos
e@(Left (p :: Pos
p,_)):es :: EvStream
es) = Either (Pos, String) EvPos
e Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Pos -> EvStream -> EvStream
go Pos
p EvStream
es
parseEvents :: BS.L.ByteString -> EvStream
parseEvents :: ByteString -> EvStream
parseEvents = \bs0 :: ByteString
bs0 -> EvStream -> EvStream
fixUpEOS (EvStream -> EvStream) -> EvStream -> EvStream
forall a b. (a -> b) -> a -> b
$ EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Pos -> EvPos
EvPos Event
StreamStart Pos
initPos) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: (Tok2EvStream
go0 Tok2EvStream -> Tok2EvStream
forall a b. (a -> b) -> a -> b
$ (Token -> Bool) -> [Token] -> [Token]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Token -> Bool) -> Token -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token -> Bool
isWhite) ([Token] -> [Token]) -> [Token] -> [Token]
forall a b. (a -> b) -> a -> b
$ ByteString -> Bool -> [Token]
Y.tokenize ByteString
bs0 Bool
False)
where
isTCode :: Code -> Token -> Bool
isTCode tc :: Code
tc = (Code -> Code -> Bool
forall a. Eq a => a -> a -> Bool
== Code
tc) (Code -> Bool) -> (Token -> Code) -> Token -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Token -> Code
Y.tCode
skipPast :: Code -> [Token] -> [Token]
skipPast tc :: Code
tc (t :: Token
t : ts :: [Token]
ts)
| Code -> Token -> Bool
isTCode Code
tc Token
t = [Token]
ts
| Bool
otherwise = Code -> [Token] -> [Token]
skipPast Code
tc [Token]
ts
skipPast _ [] = String -> [Token]
forall a. HasCallStack => String -> a
error "the impossible happened"
isWhite :: Y.Token -> Bool
isWhite :: Token -> Bool
isWhite (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Bom }) = Bool
True
isWhite (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.White }) = Bool
True
isWhite (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indent }) = Bool
True
isWhite (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Break }) = Bool
True
isWhite _ = Bool
False
go0 :: Tok2EvStream
go0 :: Tok2EvStream
go0 [] = [EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Pos -> EvPos
EvPos Event
StreamEnd Pos
initPos )]
go0 toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) = Tok2EvStreamCont
goComment [Token]
toks0 Tok2EvStream
go0
go0 toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginDocument } : _) = DInfo -> Tok2EvStream
go1 DInfo
dinfo0 [Token]
toks0
go0 (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.DocumentEnd } : rest :: [Token]
rest) = Tok2EvStream
go0 [Token]
rest
go0 xs :: [Token]
xs = Tok2EvStream
err [Token]
xs
go1 :: DInfo -> Tok2EvStream
go1 :: DInfo -> Tok2EvStream
go1 m :: DInfo
m (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginDocument } : rest :: [Token]
rest) = DInfo -> Tok2EvStream
goDirs DInfo
m [Token]
rest
go1 _ (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndDocument } : Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.DocumentEnd } : rest :: [Token]
rest) = ( EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Bool -> Event
DocumentEnd Bool
True) Token
tok ))Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
go0 [Token]
rest
go1 _ (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndDocument } : rest :: [Token]
rest) = ( EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Bool -> Event
DocumentEnd Bool
False) Token
tok )) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
go0 [Token]
rest
go1 m :: DInfo
m toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) = Tok2EvStreamCont
goComment [Token]
toks0 (DInfo -> Tok2EvStream
go1 DInfo
m)
go1 m :: DInfo
m (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginNode } : rest :: [Token]
rest) = DInfo -> Tok2EvStreamCont
goNode0 DInfo
m [Token]
rest (DInfo -> Tok2EvStream
go1 DInfo
m)
go1 _ xs :: [Token]
xs = Tok2EvStream
err [Token]
xs
goDirs :: DInfo -> Tok2EvStream
goDirs :: DInfo -> Tok2EvStream
goDirs m :: DInfo
m (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginDirective } : rest :: [Token]
rest) = DInfo -> Tok2EvStream
goDir1 DInfo
m [Token]
rest
goDirs m :: DInfo
m toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) = Tok2EvStreamCont
goComment [Token]
toks0 (DInfo -> Tok2EvStream
goDirs DInfo
m)
goDirs m :: DInfo
m (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.DirectivesEnd } : rest :: [Token]
rest)
| Just (1,mi :: Word
mi) <- DInfo -> Maybe (Word, Word)
diVer DInfo
m = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Directives -> Event
DocumentStart (Word -> Directives
DirEndMarkerVersion Word
mi)) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: DInfo -> Tok2EvStream
go1 DInfo
m [Token]
rest
| Bool
otherwise = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Directives -> Event
DocumentStart Directives
DirEndMarkerNoVersion) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: DInfo -> Tok2EvStream
go1 DInfo
m [Token]
rest
goDirs _ xs :: [Token]
xs@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginDocument } : _) = Tok2EvStream
err [Token]
xs
goDirs m :: DInfo
m xs :: [Token]
xs = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right ( Event -> Token -> EvPos
getEvPos (Directives -> Event
DocumentStart Directives
NoDirEndMarker) ([Token] -> Token
forall a. [a] -> a
head [Token]
xs) )Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: DInfo -> Tok2EvStream
go1 DInfo
m [Token]
xs
goDir1 :: DInfo -> [Y.Token] -> EvStream
goDir1 :: DInfo -> Tok2EvStream
goDir1 m :: DInfo
m toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"%" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
"YAML" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
v } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndDirective } :
rest :: [Token]
rest)
| DInfo -> Maybe (Word, Word)
diVer DInfo
m Maybe (Word, Word) -> Maybe (Word, Word) -> Bool
forall a. Eq a => a -> a -> Bool
/= Maybe (Word, Word)
forall a. Maybe a
Nothing = String -> Tok2EvStream
errMsg "Multiple %YAML directives" [Token]
toks0
| Just (1,mi :: Word
mi) <- String -> Maybe (Word, Word)
decodeVer String
v = DInfo -> Tok2EvStream
goDirs (DInfo
m { diVer :: Maybe (Word, Word)
diVer = (Word, Word) -> Maybe (Word, Word)
forall a. a -> Maybe a
Just (1,Word
mi) }) [Token]
rest
| Bool
otherwise = String -> Tok2EvStream
errMsg ("Unsupported YAML version " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String -> String
forall a. Show a => a -> String
show String
v) [Token]
toks0
goDir1 m :: DInfo
m toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"%" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
"TAG" } :
rest :: [Token]
rest)
| Just (h :: Text
h, rest' :: [Token]
rest') <- [Token] -> Maybe (Text, [Token])
getHandle [Token]
rest
, Just (t :: Text
t, rest'' :: [Token]
rest'') <- [Token] -> Maybe (Text, [Token])
getUriTag [Token]
rest' = case Text -> Text -> Map Text Text -> Maybe (Map Text Text)
forall k a. Ord k => k -> a -> Map k a -> Maybe (Map k a)
mapInsertNoDupe Text
h Text
t (DInfo -> Map Text Text
diTags DInfo
m) of
Just tm :: Map Text Text
tm -> DInfo -> Tok2EvStream
goDirs (DInfo
m { diTags :: Map Text Text
diTags = Map Text Text
tm }) (Code -> [Token] -> [Token]
skipPast Code
Y.EndDirective [Token]
rest'')
Nothing -> String -> Tok2EvStream
errMsg ("Multiple %TAG definitions for handle " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
h) [Token]
toks0
goDir1 m :: DInfo
m (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"%" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
l } :
rest :: [Token]
rest) | String
l String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` ["TAG","YAML"] = DInfo -> Tok2EvStream
goDirs DInfo
m (Code -> [Token] -> [Token]
skipPast Code
Y.EndDirective [Token]
rest)
goDir1 _ xs :: [Token]
xs = Tok2EvStream
err [Token]
xs
decodeVer :: String -> Maybe (Word,Word)
decodeVer :: String -> Maybe (Word, Word)
decodeVer s :: String
s = do
(lhs :: String
lhs,'.':rhs :: String
rhs) <- (String, String) -> Maybe (String, String)
forall a. a -> Maybe a
Just ((Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='.') String
s)
(,) (Word -> Word -> (Word, Word))
-> Maybe Word -> Maybe (Word -> (Word, Word))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Maybe Word
forall a. Read a => String -> Maybe a
readMaybe String
lhs Maybe (Word -> (Word, Word)) -> Maybe Word -> Maybe (Word, Word)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Maybe Word
forall a. Read a => String -> Maybe a
readMaybe String
rhs
data DInfo = DInfo { DInfo -> Map Text Text
diTags :: Map.Map TagHandle Text
, DInfo -> Maybe (Word, Word)
diVer :: Maybe (Word,Word)
}
dinfo0 :: DInfo
dinfo0 :: DInfo
dinfo0 = Map Text Text -> Maybe (Word, Word) -> DInfo
DInfo Map Text Text
forall a. Monoid a => a
mempty Maybe (Word, Word)
forall a. Maybe a
Nothing
errMsg :: String -> Tok2EvStream
errMsg :: String -> Tok2EvStream
errMsg msg :: String
msg (tok :: Token
tok : _) = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left (Token -> Pos
tok2pos Token
tok, String
msg)]
errMsg msg :: String
msg [] = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left ((Int -> Int -> Int -> Int -> Pos
Pos (-1) (-1) (-1) (-1)), ("Unexpected end of token stream: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
msg))]
err :: Tok2EvStream
err :: Tok2EvStream
err (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Error, tText :: Token -> String
Y.tText = String
msg } : _) = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left (Token -> Pos
tok2pos Token
tok, String
msg)]
err (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Unparsed, tText :: Token -> String
Y.tText = String
txt } : _) = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left (Token -> Pos
tok2pos Token
tok, ("Lexical error near " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
txt))]
err (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
code } : _) = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left (Token -> Pos
tok2pos Token
tok, ("Parse failure near " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Code -> String
forall a. Show a => a -> String
show Code
code String -> String -> String
forall a. [a] -> [a] -> [a]
++ " token"))]
err [] = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left ((Int -> Int -> Int -> Int -> Pos
Pos (-1) (-1) (-1) (-1)), "Unexpected end of token stream")]
goNode0 :: DInfo -> Tok2EvStreamCont
goNode0 :: DInfo -> Tok2EvStreamCont
goNode0 DInfo {..} = Tok2EvStreamCont
goNode
where
seqInd :: String -> NodeStyle
seqInd "[" = NodeStyle
Flow
seqInd "-" = NodeStyle
Block
seqInd _ = String -> NodeStyle
forall a. HasCallStack => String -> a
error "seqInd: internal error"
mapInd :: String -> NodeStyle
mapInd "{" = NodeStyle
Flow
mapInd _ = String -> NodeStyle
forall a. HasCallStack => String -> a
error "mapInd: internal error"
goNode :: Tok2EvStreamCont
goNode :: Tok2EvStreamCont
goNode toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNode Tok2EvStream
cont)
goNode (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginScalar } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Pos -> Props -> Tok2EvStreamCont
goScalar (Token -> Pos
tok2pos Token
tok) (Maybe Text
forall a. Monoid a => a
mempty,Tag
untagged) [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginSequence } : Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
ind } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
SequenceStart Maybe Text
forall a. Maybe a
Nothing Tag
untagged (String -> NodeStyle
seqInd String
ind)) Token
tok)Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goSeq [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginMapping } : Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
ind } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
MappingStart Maybe Text
forall a. Maybe a
Nothing Tag
untagged (String -> NodeStyle
mapInd String
ind)) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goMap [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginMapping } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
MappingStart Maybe Text
forall a. Maybe a
Nothing Tag
untagged NodeStyle
Block) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goMap [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginProperties } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goProp (Maybe Text
forall a. Monoid a => a
mempty,Tag
untagged) [Token]
rest (\p :: Props
p rest' :: [Token]
rest' -> Props -> Tok2EvStreamCont
goNode' Props
p [Token]
rest' Tok2EvStream
cont)
goNode (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginAlias } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
anchor } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndAlias } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndNode } :
rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Text -> Event
Alias (String -> Text
T.pack String
anchor)) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
goNode xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goNode' :: Props -> Tok2EvStreamCont
goNode' :: Props -> Tok2EvStreamCont
goNode' props :: Props
props toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Props -> Tok2EvStreamCont
goNode' Props
props) Tok2EvStream
cont)
goNode' props :: Props
props (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginScalar } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Pos -> Props -> Tok2EvStreamCont
goScalar (Token -> Pos
tok2pos Token
tok) Props
props [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode' (manchor :: Maybe Text
manchor,mtag :: Tag
mtag) (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginSequence } : Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
ind } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
SequenceStart Maybe Text
manchor Tag
mtag (String -> NodeStyle
seqInd String
ind)) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goSeq [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode' (manchor :: Maybe Text
manchor,mtag :: Tag
mtag) (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginMapping } : Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
ind } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
MappingStart Maybe Text
manchor Tag
mtag (String -> NodeStyle
mapInd String
ind)) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goMap [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode' (manchor :: Maybe Text
manchor,mtag :: Tag
mtag) (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginMapping } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
MappingStart Maybe Text
manchor Tag
mtag NodeStyle
Block) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goMap [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNode' _ xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goNodeEnd :: Tok2EvStreamCont
goNodeEnd :: Tok2EvStreamCont
goNodeEnd toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goNodeEnd Tok2EvStream
cont)
goNodeEnd (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndNode } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStream
cont [Token]
rest
goNodeEnd xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goProp :: Props -> [Y.Token] -> (Props -> [Y.Token] -> EvStream) -> EvStream
goProp :: Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goProp props :: Props
props (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndProperties } : rest :: [Token]
rest) cont :: Props -> Tok2EvStream
cont = Props -> Tok2EvStream
cont Props
props [Token]
rest
goProp props :: Props
props (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginAnchor } : rest :: [Token]
rest) cont :: Props -> Tok2EvStream
cont = Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goAnchor Props
props [Token]
rest (\x :: Props
x y :: [Token]
y -> Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goProp Props
x [Token]
y Props -> Tok2EvStream
cont)
goProp props :: Props
props (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginTag } : rest :: [Token]
rest) cont :: Props -> Tok2EvStream
cont = Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goTag Props
props [Token]
rest (\x :: Props
x y :: [Token]
y -> Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goProp Props
x [Token]
y Props -> Tok2EvStream
cont)
goProp _props :: Props
_props xs :: [Token]
xs _cont :: Props -> Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goAnchor :: Props -> [Y.Token] -> (Props -> [Y.Token] -> EvStream) -> EvStream
goAnchor :: Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goAnchor props :: Props
props (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator } : rest :: [Token]
rest) cont :: Props -> Tok2EvStream
cont = Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goAnchor Props
props [Token]
rest Props -> Tok2EvStream
cont
goAnchor (_,tag :: Tag
tag) (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
anchor } : rest :: [Token]
rest) cont :: Props -> Tok2EvStream
cont = Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goAnchor (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$! String -> Text
T.pack String
anchor,Tag
tag) [Token]
rest Props -> Tok2EvStream
cont
goAnchor props :: Props
props (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndAnchor } : rest :: [Token]
rest) cont :: Props -> Tok2EvStream
cont = Props -> Tok2EvStream
cont Props
props [Token]
rest
goAnchor _ xs :: [Token]
xs _ = Tok2EvStream
err [Token]
xs
goTag :: Props -> [Y.Token] -> (Props -> [Y.Token] -> EvStream) -> EvStream
goTag :: Props -> [Token] -> (Props -> Tok2EvStream) -> EvStream
goTag (anchor :: Maybe Text
anchor,_) (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndTag } : rest :: [Token]
rest)
cont :: Props -> Tok2EvStream
cont = Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag' "!") [Token]
rest
goTag (anchor :: Maybe Text
anchor,_) (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginHandle } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndHandle } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
tag } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndTag } : rest :: [Token]
rest)
cont :: Props -> Tok2EvStream
cont
| Just t' :: Text
t' <- Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (String -> Text
T.pack ("!!")) Map Text Text
diTags
= Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag (Text -> String
T.unpack Text
t' String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
tag)) [Token]
rest
| Bool
otherwise = Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag'' String
tag) [Token]
rest
goTag (anchor :: Maybe Text
anchor,_) (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"<" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
tag } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
">" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndTag } : rest :: [Token]
rest)
cont :: Props -> Tok2EvStream
cont = Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag String
tag) [Token]
rest
goTag (anchor :: Maybe Text
anchor,_) xs :: [Token]
xs@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginHandle } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
h } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndHandle } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
tag } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndTag } : rest :: [Token]
rest)
cont :: Props -> Tok2EvStream
cont
| Just t' :: Text
t' <- Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (String -> Text
T.pack ("!" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
h String -> String -> String
forall a. [a] -> [a] -> [a]
++ "!")) Map Text Text
diTags
= Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag (Text -> String
T.unpack Text
t' String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
tag)) [Token]
rest
| Bool
otherwise = Tok2EvStream
err [Token]
xs
goTag (anchor :: Maybe Text
anchor,_) (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginHandle } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"!" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndHandle } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
tag } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndTag } : rest :: [Token]
rest)
cont :: Props -> Tok2EvStream
cont
| Just t' :: Text
t' <- Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (String -> Text
T.pack ("!")) Map Text Text
diTags
= Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag (Text -> String
T.unpack Text
t' String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
tag)) [Token]
rest
| Bool
otherwise = Props -> Tok2EvStream
cont (Maybe Text
anchor,String -> Tag
mkTag' ('!' Char -> String -> String
forall a. a -> [a] -> [a]
: String
tag)) [Token]
rest
goTag _ xs :: [Token]
xs _ = Tok2EvStream
err [Token]
xs
goScalar :: Pos -> Props -> Tok2EvStreamCont
goScalar :: Pos -> Props -> Tok2EvStreamCont
goScalar pos0 :: Pos
pos0 (manchor :: Maybe Text
manchor,tag :: Tag
tag) toks0 :: [Token]
toks0 cont :: Tok2EvStream
cont = Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
False ScalarStyle
Plain [Token]
toks0
where
go0 :: Bool -> ScalarStyle -> Tok2EvStream
go0 ii :: Bool
ii sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
ind } : rest :: [Token]
rest)
| String
"'" <- String
ind = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii "" ScalarStyle
SingleQuoted [Token]
rest
| String
"\"" <- String
ind = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii "" ScalarStyle
DoubleQuoted [Token]
rest
| String
"|" <- String
ind = Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
True (Chomp -> IndentOfs -> ScalarStyle
Literal Chomp
Clip IndentOfs
IndentAuto) [Token]
rest
| String
">" <- String
ind = Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
True (Chomp -> IndentOfs -> ScalarStyle
Folded Chomp
Clip IndentOfs
IndentAuto) [Token]
rest
| String
"+" <- String
ind = Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
ii (ScalarStyle -> Chomp -> ScalarStyle
chn ScalarStyle
sty Chomp
Keep) [Token]
rest
| String
"-" <- String
ind = Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
ii (ScalarStyle -> Chomp -> ScalarStyle
chn ScalarStyle
sty Chomp
Strip) [Token]
rest
| [c :: Char
c] <- String
ind, '1' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c, Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '9' = Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
False (ScalarStyle -> Int -> ScalarStyle
chn' ScalarStyle
sty (Char -> Int
C.digitToInt Char
c)) [Token]
rest
go0 ii :: Bool
ii sty :: ScalarStyle
sty tok :: [Token]
tok@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) = Tok2EvStreamCont
goComment [Token]
tok (Bool -> ScalarStyle -> Tok2EvStream
go0 Bool
ii ScalarStyle
sty)
go0 ii :: Bool
ii sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Text, tText :: Token -> String
Y.tText = String
t } : rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii String
t ScalarStyle
sty [Token]
rest
go0 ii :: Bool
ii sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.LineFold } : rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii " " ScalarStyle
sty [Token]
rest
go0 ii :: Bool
ii sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.LineFeed } : rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii "\n" ScalarStyle
sty [Token]
rest
go0 _ sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndScalar } : rest :: [Token]
rest) = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Pos -> EvPos
EvPos (Maybe Text -> Tag -> ScalarStyle -> Text -> Event
Scalar Maybe Text
manchor Tag
tag ScalarStyle
sty Text
forall a. Monoid a => a
mempty) Pos
pos0) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
go0 _ _ xs :: [Token]
xs = Tok2EvStream
err [Token]
xs
chn :: ScalarStyle -> Chomp -> ScalarStyle
chn :: ScalarStyle -> Chomp -> ScalarStyle
chn (Literal _ digit :: IndentOfs
digit) chmp :: Chomp
chmp = Chomp -> IndentOfs -> ScalarStyle
Literal Chomp
chmp IndentOfs
digit
chn (Folded _ digit :: IndentOfs
digit) chmp :: Chomp
chmp = Chomp -> IndentOfs -> ScalarStyle
Folded Chomp
chmp IndentOfs
digit
chn _ _ = String -> ScalarStyle
forall a. HasCallStack => String -> a
error "impossible"
chn' :: ScalarStyle -> Int -> ScalarStyle
chn' :: ScalarStyle -> Int -> ScalarStyle
chn' (Literal b :: Chomp
b _) digit :: Int
digit = Chomp -> IndentOfs -> ScalarStyle
Literal Chomp
b (Int -> IndentOfs
forall a. Enum a => Int -> a
toEnum Int
digit)
chn' (Folded b :: Chomp
b _) digit :: Int
digit = Chomp -> IndentOfs -> ScalarStyle
Folded Chomp
b (Int -> IndentOfs
forall a. Enum a => Int -> a
toEnum Int
digit)
chn' _ _ = String -> ScalarStyle
forall a. HasCallStack => String -> a
error "impossible"
go' :: Bool -> String -> ScalarStyle -> Tok2EvStream
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Text, tText :: Token -> String
Y.tText = String
t } : rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
t) ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.LineFold } : rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ " ") ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.LineFeed } : rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n") ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty@ScalarStyle
SingleQuoted
(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginEscape } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"'" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
"'" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndEscape } :
rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'") ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty@ScalarStyle
SingleQuoted
(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"'" } :
rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii String
acc ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty@ScalarStyle
DoubleQuoted
(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginEscape } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"\\" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndEscape } :
rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii String
acc ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty@ScalarStyle
DoubleQuoted
(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginEscape } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"\\" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
t } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndEscape } :
rest :: [Token]
rest)
| Just t' :: String
t' <- String -> Maybe String
unescape String
t = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
t') ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty@ScalarStyle
DoubleQuoted
(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginEscape } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"\\" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
pfx } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
ucode } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndEscape } :
rest :: [Token]
rest)
| String
pfx String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "U", Just c :: Char
c <- String -> Maybe Char
decodeCP2 String
ucode = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
c]) ScalarStyle
sty [Token]
rest
| String
pfx String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "u", Just c :: Char
c <- String -> Maybe Char
decodeCP String
ucode = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
c]) ScalarStyle
sty [Token]
rest
| String
pfx String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "x", Just c :: Char
c <- String -> Maybe Char
decodeL1 String
ucode = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii (String
acc String -> String -> String
forall a. [a] -> [a] -> [a]
++ [Char
c]) ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty@ScalarStyle
DoubleQuoted
(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"\"" } :
rest :: [Token]
rest) = Bool -> String -> ScalarStyle -> Tok2EvStream
go' Bool
ii String
acc ScalarStyle
sty [Token]
rest
go' ii :: Bool
ii acc :: String
acc sty :: ScalarStyle
sty (t :: Token
t@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndScalar } :
rest :: [Token]
rest)
| Bool
ii, String -> Bool
hasLeadingSpace String
acc = [(Pos, String) -> Either (Pos, String) EvPos
forall a b. a -> Either a b
Left (Token -> Pos
tok2pos Token
t, "leading empty lines contain more spaces than the first non-empty line in scalar: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
acc)]
| Bool
otherwise = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Pos -> EvPos
EvPos (Maybe Text -> Tag -> ScalarStyle -> Text -> Event
Scalar Maybe Text
manchor Tag
tag ScalarStyle
sty (String -> Text
T.pack String
acc)) Pos
pos0) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
go' _ _ _ xs :: [Token]
xs | Bool
False = String -> EvStream
forall a. HasCallStack => String -> a
error ([Token] -> String
forall a. Show a => a -> String
show [Token]
xs)
go' _ _ _ xs :: [Token]
xs = Tok2EvStream
err [Token]
xs
hasLeadingSpace :: String -> Bool
hasLeadingSpace (' ':_) = Bool
True
hasLeadingSpace ('\n':cs :: String
cs) = String -> Bool
hasLeadingSpace String
cs
hasLeadingSpace _ = Bool
False
goSeq :: Tok2EvStreamCont
goSeq :: Tok2EvStreamCont
goSeq (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndSequence } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos Event
SequenceEnd Token
tok)Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
goSeq toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goSeq Tok2EvStream
cont)
goSeq (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginNode } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goNode [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goSeq Tok2EvStream
cont)
goSeq (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginMapping } : Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
ind } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
MappingStart Maybe Text
forall a. Maybe a
Nothing Tag
untagged (String -> NodeStyle
mapInd String
ind)) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goMap [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goSeq Tok2EvStream
cont)
goSeq (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginMapping } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Maybe Text -> Tag -> NodeStyle -> Event
MappingStart Maybe Text
forall a. Maybe a
Nothing Tag
untagged NodeStyle
Block) Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStreamCont
goMap [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goSeq Tok2EvStream
cont)
goSeq (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goSeq [Token]
rest Tok2EvStream
cont
goSeq xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goMap :: Tok2EvStreamCont
goMap :: Tok2EvStreamCont
goMap (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndMapping } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos Event
MappingEnd Token
tok) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
goMap toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goMap Tok2EvStream
cont)
goMap (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginPair } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goPair1 [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goMap Tok2EvStream
cont)
goMap (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goMap [Token]
rest Tok2EvStream
cont
goMap xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goPair1 :: Tok2EvStreamCont
goPair1 (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginNode } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goNode [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goPair2 Tok2EvStream
cont)
goPair1 toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goPair1 Tok2EvStream
cont)
goPair1 (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goPair1 [Token]
rest Tok2EvStream
cont
goPair1 xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goPair2 :: Tok2EvStreamCont
goPair2 toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goPair2 Tok2EvStream
cont)
goPair2 (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginNode } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goNode [Token]
rest (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goPairEnd Tok2EvStream
cont)
goPair2 (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goPair2 [Token]
rest Tok2EvStream
cont
goPair2 xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goPairEnd :: Tok2EvStreamCont
goPairEnd toks0 :: [Token]
toks0@(Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} : _) cont :: Tok2EvStream
cont = Tok2EvStreamCont
goComment [Token]
toks0 (Tok2EvStreamCont -> Tok2EvStream -> Tok2EvStream
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tok2EvStreamCont
goPairEnd Tok2EvStream
cont)
goPairEnd (Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndPair } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = Tok2EvStream
cont [Token]
rest
goPairEnd xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
goComment :: Tok2EvStreamCont
(tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"#" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Meta, tText :: Token -> String
Y.tText = String
comment } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndComment } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = (EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Text -> Event
Comment (String -> Text
T.pack String
comment)) Token
tok)) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
goComment (tok :: Token
tok@Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.BeginComment} :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.Indicator, tText :: Token -> String
Y.tText = String
"#" } :
Y.Token { tCode :: Token -> Code
Y.tCode = Code
Y.EndComment } : rest :: [Token]
rest) cont :: Tok2EvStream
cont = (EvPos -> Either (Pos, String) EvPos
forall a b. b -> Either a b
Right (Event -> Token -> EvPos
getEvPos (Text -> Event
Comment Text
T.empty) Token
tok)) Either (Pos, String) EvPos -> EvStream -> EvStream
forall a. a -> [a] -> [a]
: Tok2EvStream
cont [Token]
rest
goComment xs :: [Token]
xs _cont :: Tok2EvStream
_cont = Tok2EvStream
err [Token]
xs
type Tok2EvStream = [Y.Token] -> EvStream
type Tok2EvStreamCont = [Y.Token] -> Cont EvStream [Y.Token]
type Cont r a = (a -> r) -> r
decodeCP2 :: String -> Maybe Char
decodeCP2 :: String -> Maybe Char
decodeCP2 s :: String
s = case String
s of
[_,_,_,_,_,_,_,_] | (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
C.isHexDigit String
s
, [(j :: Integer
j, "")] <- ReadS Integer
forall a. (Eq a, Num a) => ReadS a
readHex String
s -> Char -> Maybe Char
forall a. a -> Maybe a
Just (Int -> Char
chr (Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
j))
_ -> Maybe Char
forall a. Maybe a
Nothing
decodeCP :: String -> Maybe Char
decodeCP :: String -> Maybe Char
decodeCP s :: String
s = case String
s of
[_,_,_,_] | (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
C.isHexDigit String
s
, [(j :: Integer
j, "")] <- ReadS Integer
forall a. (Eq a, Num a) => ReadS a
readHex String
s -> Char -> Maybe Char
forall a. a -> Maybe a
Just (Int -> Char
chr (Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
j))
_ -> Maybe Char
forall a. Maybe a
Nothing
decodeL1 :: String -> Maybe Char
decodeL1 :: String -> Maybe Char
decodeL1 s :: String
s = case String
s of
[_,_] | (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
C.isHexDigit String
s
, [(j :: Integer
j, "")] <- ReadS Integer
forall a. (Eq a, Num a) => ReadS a
readHex String
s -> Char -> Maybe Char
forall a. a -> Maybe a
Just (Int -> Char
chr (Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
j))
_ -> Maybe Char
forall a. Maybe a
Nothing
unescape :: String -> Maybe String
unescape :: String -> Maybe String
unescape [c :: Char
c] = Char -> Map Char String -> Maybe String
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Char
c Map Char String
m
where
m :: Map Char String
m = [(Char, String)] -> Map Char String
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [ (Char
k,[Char
v]) | (k :: Char
k,v :: Char
v) <- [(Char, Char)]
escapes ]
escapes :: [(Char,Char)]
escapes :: [(Char, Char)]
escapes =
[ ('0', '\0')
, ('a', '\x7')
, ('b', '\x8')
, ('\x9', '\x9')
, ('t', '\x9')
, ('n', '\xa')
, ('v', '\xb')
, ('f', '\xc')
, ('r', '\xd')
, ('e', '\x1b')
, (' ', ' ')
, ('"', '"')
, ('/', '/')
, ('\\', '\\')
, ('N', '\x85')
, ('_', '\xa0')
, ('L', '\x2028')
, ('P', '\x2029')
]
unescape _ = Maybe String
forall a. Maybe a
Nothing