Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 53 lines (47 sloc) 1.827 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
import Data.Object.Yaml
import Data.Object
import Control.Monad
import qualified Text.Libyaml as Y
import Control.Failure
import Control.Applicative
import Debug.Trace
import System.Environment

main = do
    args <- getArgs
    case args of
        ["easy"] -> mainEasy
        ["efficient"] -> mainEfficient
        _ -> putStrLn "Please specify either eays or efficient"

mainEasy = do
    yo <- join $ decodeFile "entries.yaml"
    s <- fromSequence (yo :: YamlObject)
    print $ length s

mainEfficient = do
    l <- fmap stateComplete $ join $ try <$> Y.decodeFile "entries.yaml" helper StateNeedStream
    print l

data Ignore = Seq | Map
    deriving Show

data State = StateNeedStream | StateNeedDoc | StateNeedSeq
           | StateCount Int | StateIgnore [Ignore] Int
           | StateComplete { stateComplete :: Int }
    deriving Show
helper' s e = traceShow (s, e) $ helper s e

helper StateNeedStream Y.EventStreamStart = Right StateNeedDoc
helper StateNeedDoc Y.EventDocumentStart = Right StateNeedSeq
helper StateNeedSeq Y.EventSequenceStart = Right $ StateCount 0
helper (StateCount i) Y.EventSequenceEnd = Left $ StateComplete i
helper (StateCount i) (Y.EventScalar{}) = Right $ StateCount $ i + 1
helper (StateCount i) Y.EventSequenceStart =
    Right $ StateIgnore [Seq] $ i + 1
helper (StateCount i) Y.EventMappingStart =
    Right $ StateIgnore [Map] $ i + 1
helper (StateIgnore [] i) e = helper (StateCount i) e
helper (StateIgnore is i) Y.EventSequenceStart =
    Right $ StateIgnore (Seq : is) i
helper (StateIgnore is i) Y.EventMappingStart =
    Right $ StateIgnore (Map : is) i
helper (StateIgnore (Seq:is) i) Y.EventSequenceEnd =
    Right $ StateIgnore is i
helper (StateIgnore (Map:is) i) Y.EventMappingEnd =
    Right $ StateIgnore is i
helper (StateIgnore is i) _ = Right $ StateIgnore is i
Something went wrong with that request. Please try again.