Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Data.Attoparsec.NBT where
- import Prelude hiding (take)
- import Control.Applicative hiding (empty)
- import Control.Monad.Error
- import Data.Attoparsec
- import Data.Attoparsec.Combinator
- import Data.Serialize.Get (runGet, getWord8, getWord16be, getWord32be, getWord64be)
- import Data.NBT
- data ParseError = ParseError String
- type Fallible = Either ParseError
- parseTag :: Parser (Fallible Tag)
- parseTag = parseEnd
- <|> parseByte
- <|> parseShort
- parseEnd :: Parser (Fallible Tag)
- parseEnd = do
- word8 0x00
- return $ Right TAG_End
- parseByte :: Parser (Fallible Tag)
- parseByte = do
- word8 0x01
- b <- anyWord8
- return $ Right (TAG_Byte $ fromIntegral b)
- parseShort :: Parser (Fallible Tag)
- parseShort = do
- word8 0x02
- s <- take 2
- case runGet getWord16be s of
- Left e -> return $ Left (ParseError "Failed to parse short.")
- Right a -> return $ Right (TAG_Short $ fromIntegral a)
Add Comment
Please, Sign In to add comment