toml-parser 2.0.1.2 → 2.0.2.0
raw patch · 10 files changed
+53/−21 lines, 10 filesdep ~basedep ~template-haskelldep ~time
Dependency ranges changed: base, template-haskell, time
Files
- ChangeLog.md +7/−0
- README.lhs +1/−1
- README.md +1/−1
- src/Toml.hs +1/−1
- src/Toml/Pretty.hs +4/−0
- src/Toml/Syntax/Lexer.x +7/−5
- src/Toml/Syntax/Parser.y +11/−2
- src/Toml/Syntax/Token.hs +14/−4
- test/PrettySpec.hs +2/−2
- toml-parser.cabal +5/−5
ChangeLog.md view
@@ -1,5 +1,12 @@ # Revision history for toml-parser +## 2.0.2.0++* Update for TOML 1.1.0+ - Add \e and \x escapes+ - Allow omitting seconds in times+ - Allow newlines and trailing commas in inline tables+ ## 2.0.1.2 * Reject inputs with out-of-bounds time zone offsets in accordance
README.lhs view
@@ -1,6 +1,6 @@ # TOML Parser -This package implements a validating parser for [TOML 1.0.0](https://toml.io/en/v1.0.0).+This package implements a validating parser for [TOML 1.1.0](https://toml.io/en/v1.1.0). This package uses an [alex](https://haskell-alex.readthedocs.io/en/latest/)-generated lexer and [happy](https://haskell-happy.readthedocs.io/en/latest/)-generated parser.
README.md view
@@ -1,6 +1,6 @@ # TOML Parser -This package implements a validating parser for [TOML 1.0.0](https://toml.io/en/v1.0.0).+This package implements a validating parser for [TOML 1.1.0](https://toml.io/en/v1.1.0). This package uses an [alex](https://haskell-alex.readthedocs.io/en/latest/)-generated lexer and [happy](https://haskell-happy.readthedocs.io/en/latest/)-generated parser.
src/Toml.hs view
@@ -10,7 +10,7 @@ It enables parsing, printing, and conversion into and out of application-specific representations. -This parser implements TOML 1.0.0 <https://toml.io/en/v1.0.0>+This parser implements TOML 1.1.0 <https://toml.io/en/v1.1.0> as carefully as possible. Use "Toml.Schema" to implement functions mapping between TOML
src/Toml/Pretty.hs view
@@ -94,12 +94,14 @@ '"' : xs -> '\\' : '"' : go xs '\\' : xs -> '\\' : '\\' : go xs '\b' : xs -> '\\' : 'b' : go xs+ '\ESC':xs -> '\\' : 'e' : go xs '\f' : xs -> '\\' : 'f' : go xs '\n' : xs -> '\\' : 'n' : go xs '\r' : xs -> '\\' : 'r' : go xs '\t' : xs -> '\\' : 't' : go xs x : xs | isPrint x -> x : go xs+ | x <= '\xff' -> printf "\\x%02X%s" (ord x) (go xs) | x <= '\xffff' -> printf "\\u%04X%s" (ord x) (go xs) | otherwise -> printf "\\U%08X%s" (ord x) (go xs) @@ -112,6 +114,7 @@ '"' : '"' : '"' : xs -> "\"\"\\\"" ++ go xs '\\' : xs -> '\\' : '\\' : go xs '\b' : xs -> '\\' : 'b' : go xs+ '\ESC':xs -> '\\' : 'e' : go xs '\f' : xs -> '\\' : 'f' : go xs '\t' : xs -> '\\' : 't' : go xs '\n' : xs -> '\n' : go xs@@ -119,6 +122,7 @@ '\r' : xs -> '\\' : 'r' : go xs x : xs | isPrint x -> x : go xs+ | x <= '\xff' -> printf "\\x%02X%s" (ord x) (go xs) | x <= '\xffff' -> printf "\\u%04X%s" (ord x) (go xs) | otherwise -> printf "\\U%08X%s" (ord x) (go xs)
src/Toml/Syntax/Lexer.x view
@@ -63,8 +63,7 @@ $literal_char = [\x09 \x20-\x26 \x28-\x7E $non_ascii] -$mll_char = [\x09 \x20-\x26 \x28-\x7E $non_ascii]-@mll_content = $mll_char | @newline+@mll_content = $literal_char | @newline @mlb_escaped_nl = \\ @ws @newline ($wschar | @newline)* $unescaped = [$wschar \x21 \x23-\x5B \x5D-\x7E $non_ascii]@@ -82,7 +81,7 @@ @time_numoffset = [\+\-] @offset_hour ":" @offset_minute @time_offset = [Zz] | @time_numoffset -@partial_time = @time_hour ":" @time_minute ":" @time_second @time_secfrac?+@partial_time = @time_hour ":" @time_minute (":" @time_second @time_secfrac?)? @full_date = @date_fullyear "-" @date_month "-" @date_mday @full_time = @partial_time @time_offset @@ -164,15 +163,18 @@ } <mlbstr, bstr> {- \\ U $hexdig{8} { unicodeEscape }- \\ U { failure "\\U requires exactly 8 hex digits"}+ \\ x $hexdig{2} { unicodeEscape }+ \\ x { failure "\\x requires exactly 2 hex digits"} \\ u $hexdig{4} { unicodeEscape } \\ u { failure "\\u requires exactly 4 hex digits"}+ \\ U $hexdig{8} { unicodeEscape }+ \\ U { failure "\\U requires exactly 8 hex digits"} \\ n { strFrag . (Text.singleton '\n' <$) } \\ t { strFrag . (Text.singleton '\t' <$) } \\ r { strFrag . (Text.singleton '\r' <$) } \\ f { strFrag . (Text.singleton '\f' <$) } \\ b { strFrag . (Text.singleton '\b' <$) }+ \\ e { strFrag . (Text.singleton '\ESC' <$) } \\ \\ { strFrag . (Text.singleton '\\' <$) } \\ \" { strFrag . (Text.singleton '\"' <$) } \\ . { failure "unknown escape sequence" }
src/Toml/Syntax/Parser.y view
@@ -99,8 +99,17 @@ | inlinetable { locVal ValTable $1 } inlinetable :: { Located [(Key Position, Val Position)] }- : lhs '{' sepBy(keyval, ',') pop '}'- { Located $2 $3 }+ : lhs '{' inlinetablekeyvals newlines pop '}'+ { Located $2 (reverse $3) }+ | lhs '{' inlinetablekeyvals newlines ',' newlines pop '}'+ { Located $2 (reverse $3) }+ | lhs '{' newlines pop '}'+ { Located $2 [] }++inlinetablekeyvals :: { [(Key Position, Val Position)] }+ : newlines keyval { [$2] }+ | inlinetablekeyvals newlines ',' newlines keyval+ { $5 : $1 } array :: { Located [Val Position] } : rhs '[' newlines pop ']'
src/Toml/Syntax/Token.hs view
@@ -108,16 +108,26 @@ -- | Format strings for local time lexemes. localTimePatterns :: [String]-localTimePatterns = ["%H:%M:%S%Q"]+localTimePatterns =+ ["%H:%M:%S%Q",+ "%H:%M"] -- | Format strings for local datetime lexemes. localDateTimePatterns :: [String] localDateTimePatterns = ["%Y-%m-%dT%H:%M:%S%Q",- "%Y-%m-%d %H:%M:%S%Q"]+ "%Y-%m-%d %H:%M:%S%Q",+ "%Y-%m-%dT%H:%M",+ "%Y-%m-%d %H:%M"] -- | Format strings for offset datetime lexemes. offsetDateTimePatterns :: [String] offsetDateTimePatterns =- ["%Y-%m-%dT%H:%M:%S%Q%Ez","%Y-%m-%dT%H:%M:%S%QZ",- "%Y-%m-%d %H:%M:%S%Q%Ez","%Y-%m-%d %H:%M:%S%QZ"]+ ["%Y-%m-%dT%H:%M:%S%Q%Ez",+ "%Y-%m-%dT%H:%M:%S%QZ",+ "%Y-%m-%d %H:%M:%S%Q%Ez",+ "%Y-%m-%d %H:%M:%S%QZ",+ "%Y-%m-%dT%H:%M%Ez",+ "%Y-%m-%dT%H:%MZ",+ "%Y-%m-%d %H:%M%Ez",+ "%Y-%m-%d %H:%MZ"]
test/PrettySpec.hs view
@@ -61,9 +61,9 @@ y = 4|] it "renders escapes in strings" $- fmap tomlString (parse_ "a=\"\\\\\\b\\t\\r\\n\\f\\\"\\u007f\\U0001000c\"")+ fmap tomlString (parse_ "a=\"\\\\\\b\\t\\r\\n\\f\\e\\\"\\u007f\\U0001000c\"") `shouldBe` Right [quoteStr|- a = "\\\b\t\r\n\f\"\u007F\U0001000C"|]+ a = "\\\b\t\r\n\f\e\"\x7F\U0001000C"|] it "renders multiline strings" $ fmap tomlString (parse_ [quoteStr|
toml-parser.cabal view
@@ -1,10 +1,10 @@ cabal-version: 3.0 name: toml-parser-version: 2.0.1.2-synopsis: TOML 1.0.0 parser+version: 2.0.2.0+synopsis: TOML 1.1.0 parser description: TOML parser using generated lexers and parsers with- careful attention to the TOML 1.0.0 semantics for+ careful attention to the TOML 1.1.0 semantics for defining tables. license: ISC license-file: LICENSE@@ -13,7 +13,7 @@ copyright: 2023 Eric Mertens category: Text build-type: Simple-tested-with: GHC == {8.10.7, 9.0.2, 9.2.8, 9.4.8, 9.6.6, 9.8.2, 9.10.1, 9.12.2}+tested-with: GHC == {8.10.7, 9.0.2, 9.2.8, 9.4.8, 9.6.7, 9.8.4, 9.10.3, 9.12.2} extra-doc-files: ChangeLog.md@@ -75,7 +75,7 @@ containers ^>= {0.5, 0.6, 0.7, 0.8}, prettyprinter ^>= 1.7, text >= 0.2 && < 3,- time ^>= {1.9, 1.10, 1.11, 1.12, 1.14},+ time ^>= {1.9, 1.10, 1.11, 1.12, 1.14, 1.15}, transformers ^>= {0.5, 0.6}, build-tool-depends: alex:alex >= 3.2,