Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Yaml/Decode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ ->
Expand Down
4 changes: 4 additions & 0 deletions src/Yaml/Encode.elm
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ int i =
float : Float -> Encoder
float f =
let
val : String
val =
if isNaN f then
".nan"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Yaml/Parser.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 "#"
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -556,6 +567,7 @@ recordInlinePropertyNameString =
recordInlinePropertyValue : P.Parser Ast.Value
recordInlinePropertyValue =
let
propVal : P.Parser Ast.Value
propVal =
P.oneOf
[ listInline
Expand Down
1 change: 1 addition & 0 deletions src/Yaml/Parser/Ast.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type alias Property =
fromString : String -> Value
fromString string =
let
trimmed : String
trimmed =
String.trim string

Expand Down
1 change: 1 addition & 0 deletions src/Yaml/Parser/String.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Yaml.Parser.Util as U
exceptions : P.Parser Ast.Value
exceptions =
let
dashed : String -> String
dashed s =
"---" ++ s
in
Expand Down
36 changes: 7 additions & 29 deletions src/Yaml/Parser/Util.elm
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module Yaml.Parser.Util exposing
( doubleQuotes
, either
, indented
, isColon
, isComma
, isDash
, isDot
, isHash
, isListEnd
, isListStart
, isNewLine
Expand All @@ -17,7 +13,6 @@ module Yaml.Parser.Util exposing
, neither
, neither3
, postProcessFoldedString
, postProcessLiteralString
, postProcessString
, remaining
, singleQuotes
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -164,6 +135,7 @@ spaces =
whitespace : P.Parser ()
whitespace =
let
step : a -> P.Parser (P.Step () ())
step _ =
P.oneOf
[ P.succeed (P.Loop ())
Expand Down Expand Up @@ -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_ ) ->
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -354,6 +330,7 @@ postProcessLiteralString str =
case String.left 2 str of
"|\n" ->
let
content : String
content =
String.dropLeft 2 str
in
Expand Down Expand Up @@ -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
Expand Down