diff --git a/src/Yaml/Decode.elm b/src/Yaml/Decode.elm index 5e5f92d..cc9af22 100644 --- a/src/Yaml/Decode.elm +++ b/src/Yaml/Decode.elm @@ -1023,6 +1023,7 @@ fromMaybe err mby = singleResult : List (Result Error a) -> Result Error (List a) singleResult = let + each : Result error value -> Result error (List value) -> Result error (List value) each v r = case r of Err _ -> diff --git a/src/Yaml/Encode.elm b/src/Yaml/Encode.elm index bc65c4a..8389d79 100644 --- a/src/Yaml/Encode.elm +++ b/src/Yaml/Encode.elm @@ -169,6 +169,7 @@ int i = float : Float -> Encoder float f = let + val : String val = if isNaN f then ".nan" @@ -371,6 +372,7 @@ encodeDict key val state r = recordElement : ( k, v ) -> String recordElement ( key_, val_ ) = let + newState : EncoderState newState = { state | inRecord = True, col = state.col + state.indent } in @@ -435,9 +437,11 @@ encodeRecord state r = recordElement : ( String, Encoder ) -> String recordElement ( key, val ) = let + newState : EncoderState newState = { state | inRecord = True, col = state.col + state.indent } + encodedValue : String encodedValue = internalConvertToString newState val in diff --git a/src/Yaml/Parser.elm b/src/Yaml/Parser.elm index 190ae52..60e409e 100644 --- a/src/Yaml/Parser.elm +++ b/src/Yaml/Parser.elm @@ -122,6 +122,7 @@ value = list : Int -> P.Parser Ast.Value list indent = let + confirmed : Ast.Value -> P.Parser Ast.Value confirmed value_ = P.succeed Ast.List_ |= P.loop [ value_ ] (listStep indent) @@ -133,9 +134,11 @@ list indent = listStep : Int -> List Ast.Value -> P.Parser (P.Step (List Ast.Value) (List Ast.Value)) listStep indent values = let + finish : P.Step state (List Ast.Value) finish = P.Done (List.reverse values) + next : Ast.Value -> P.Step (List Ast.Value) a next value_ = P.Loop (value_ :: values) in @@ -291,6 +294,7 @@ listInlineOnDone elements element = recordOrString : Int -> Int -> P.Parser Ast.Value recordOrString indent indent_ = let + withString : String -> P.Parser Ast.Value withString string = P.oneOf [ P.succeed (Ast.fromString string) @@ -305,9 +309,11 @@ recordOrString indent indent_ = ) ] + addRemaining : String -> String -> Ast.Value addRemaining string remaining = Ast.fromString <| U.postProcessString (removeComment string ++ remaining) + removeComment : String -> String removeComment string = string |> String.split "#" @@ -331,6 +337,7 @@ recordOrString indent indent_ = quotedString : Int -> P.Parser Ast.Value quotedString indent = let + withQuote : String -> P.Parser Ast.Value withQuote quote = P.oneOf [ recordProperty indent quote @@ -357,6 +364,7 @@ recordProperty indent name = record : Int -> String -> P.Parser Ast.Value record indent property = let + confirmed : Ast.Value -> P.Parser Ast.Value confirmed value_ = P.succeed identity |= P.loop [ ( property, value_ ) ] (recordStep indent) @@ -370,9 +378,11 @@ record indent property = recordStep : Int -> List Ast.Property -> P.Parser (P.Step (List Ast.Property) (List Ast.Property)) recordStep indent values = let + finish : P.Step state (List Ast.Property) finish = P.Done (List.reverse values) + next : Ast.Property -> P.Step (List Ast.Property) a next value_ = P.Loop (value_ :: values) in @@ -393,6 +403,7 @@ recordStep indent values = recordElement : Int -> P.Parser Ast.Property recordElement indent = let + property : P.Parser String property = P.oneOf [ U.singleQuotes @@ -556,6 +567,7 @@ recordInlinePropertyNameString = recordInlinePropertyValue : P.Parser Ast.Value recordInlinePropertyValue = let + propVal : P.Parser Ast.Value propVal = P.oneOf [ listInline diff --git a/src/Yaml/Parser/Ast.elm b/src/Yaml/Parser/Ast.elm index 76e8f05..fa5f385 100644 --- a/src/Yaml/Parser/Ast.elm +++ b/src/Yaml/Parser/Ast.elm @@ -29,6 +29,7 @@ type alias Property = fromString : String -> Value fromString string = let + trimmed : String trimmed = String.trim string diff --git a/src/Yaml/Parser/String.elm b/src/Yaml/Parser/String.elm index b58470d..0fddb4e 100644 --- a/src/Yaml/Parser/String.elm +++ b/src/Yaml/Parser/String.elm @@ -9,6 +9,7 @@ import Yaml.Parser.Util as U exceptions : P.Parser Ast.Value exceptions = let + dashed : String -> String dashed s = "---" ++ s in diff --git a/src/Yaml/Parser/Util.elm b/src/Yaml/Parser/Util.elm index 2b542c9..24df365 100644 --- a/src/Yaml/Parser/Util.elm +++ b/src/Yaml/Parser/Util.elm @@ -1,12 +1,8 @@ module Yaml.Parser.Util exposing ( doubleQuotes - , either , indented , isColon , isComma - , isDash - , isDot - , isHash , isListEnd , isListStart , isNewLine @@ -17,7 +13,6 @@ module Yaml.Parser.Util exposing , neither , neither3 , postProcessFoldedString - , postProcessLiteralString , postProcessString , remaining , singleQuotes @@ -48,24 +43,6 @@ isComma = is ',' -{-| -} -isDot : Char -> Bool -isDot = - is '.' - - -{-| -} -isDash : Char -> Bool -isDash = - is '-' - - -{-| -} -isHash : Char -> Bool -isHash = - is '#' - - {-| -} isSpace : Char -> Bool isSpace = @@ -114,12 +91,6 @@ isDoubleQuote = is '"' -{-| -} -either : (Char -> Bool) -> (Char -> Bool) -> Char -> Bool -either f1 f2 char = - f1 char || f2 char - - {-| -} neither : (Char -> Bool) -> (Char -> Bool) -> Char -> Bool neither f1 f2 char = @@ -164,6 +135,7 @@ spaces = whitespace : P.Parser () whitespace = let + step : a -> P.Parser (P.Step () ()) step _ = P.oneOf [ P.succeed (P.Loop ()) @@ -201,6 +173,7 @@ multilineStep indent lines = multilineString lines_ = String.join "\n" (List.reverse lines_) + conclusion : String -> Maybe ( Int, Int ) -> P.Step (List String) String conclusion line next = case next of Just ( emptyLineCount, indent_ ) -> @@ -251,17 +224,20 @@ emptyLinesStep count = characters : (Char -> Bool) -> P.Parser String characters isOk = let + done : List String -> P.Step state String done chars = chars |> List.reverse |> String.concat |> P.Done + more : List b -> b -> P.Step (List b) a more chars char = char :: chars |> P.Loop + step : List String -> P.Parser (P.Step (List String) String) step chars = P.oneOf [ P.succeed (done chars) @@ -354,6 +330,7 @@ postProcessLiteralString str = case String.left 2 str of "|\n" -> let + content : String content = String.dropLeft 2 str in @@ -405,6 +382,7 @@ countLeadingSpacesInString str = indented : Int -> { smaller : P.Parser a, exactly : P.Parser a, larger : Int -> P.Parser a, ending : P.Parser a } -> P.Parser a indented indent next = let + check : Int -> P.Parser a check actual = P.oneOf [ P.andThen (\_ -> next.ending) P.end