exon 1.6.0.2 → 1.6.1.0
raw patch · 6 files changed
+46/−24 lines, 6 filesdep ~incipit-basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: incipit-base
API changes (from Hackage documentation)
Files
- exon.cabal +2/−1
- lib/Exon/Parse.hs +30/−22
- lib/Exon/Quote.hs +1/−0
- test/Exon/Test/BasicTest.hs +1/−0
- test/Exon/Test/ParseTest.hs +9/−0
- test/Main.hs +3/−1
exon.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: exon-version: 1.6.0.2+version: 1.6.1.0 synopsis: Customizable quasiquote interpolation description: See https://hackage.haskell.org/package/exon/docs/Exon.html category: String@@ -99,6 +99,7 @@ Exon.Test.BasicTest Exon.Test.BuildTest Exon.Test.NewtypeTest+ Exon.Test.ParseTest Exon.Test.Quote Exon.Test.ShowsPrecTest Exon.Test.SkipWsTest
lib/Exon/Parse.hs view
@@ -10,12 +10,10 @@ anyChar, char, choice,+ eof, getState, lookAhead,- many1, modifyState,- notFollowedBy,- option, putState, runParser, satisfy,@@ -36,10 +34,6 @@ whitespace = WsSegment <$> some ws -takeRestUnless :: Parser Char -> Parser String-takeRestUnless end =- many1 (notFollowedBy end *> anyChar)- expr :: Parser String expr = choice [try opening, try closing, anyChars]@@ -77,26 +71,40 @@ interpolations = try autoInterpolation <|> try verbatimInterpolation -stopHerald :: Parser String-stopHerald =- "" <$ lookAhead (try (string "##{") <|> try (string "#{"))--hash :: Parser Char-hash = char '#'+verbatimStep :: Bool -> Parser Bool+verbatimStep =+ lookAhead . \case+ True -> False <$ ws <|> basic+ False -> basic+ where+ basic =+ False <$ (try (string "##{") <|> try (string "#{"))+ <|>+ False <$ eof+ <|>+ pure True -verbatimWith :: Parser Char -> Parser String-verbatimWith end =- go+verbatimWith :: Parser Bool -> Parser String+verbatimWith step =+ step >>= \case+ False -> fail "Empty verbatim segment"+ True -> go where- go = takeRestUnless end <> (stopHerald <|> option "" (string "#" <> option "" go))+ go =+ step >>= \case+ False -> pure ""+ True -> do+ h <- anyChar+ t <- go+ pure (h : t) verbatim :: Parser String verbatim =- verbatimWith hash+ verbatimWith (verbatimStep False) verbatimWs :: Parser String verbatimWs =- verbatimWith (ws <|> hash)+ verbatimWith (verbatimStep True) text :: Parser RawSegment text =@@ -116,15 +124,15 @@ parser :: Parser [RawSegment] parser =- many segment+ many segment <* eof parserWs :: Parser [RawSegment] parserWs =- many segmentWs+ many segmentWs <* eof parseWith :: Parser [RawSegment] -> String -> Either Text [RawSegment] parseWith p =- first show . runParser p 0 ""+ first (unwords . lines . show) . runParser p 0 "" parse :: String -> Either Text [RawSegment] parse =
lib/Exon/Quote.hs view
@@ -51,6 +51,7 @@ QOrIO m => String -> m Exp+reifyExp "" = exonError ("Empty interpolation" :: String) reifyExp s = do exts <- fileExtensions case parseExpWithExts exts s of
test/Exon/Test/BasicTest.hs view
@@ -46,6 +46,7 @@ "Philip J. | FRY" === [exon|Philip J.#{up lastName}|] ("abc" :: Text) === skipWs [exonws|a ##{"b" :: Text} #{"c"}|] ("one #" :: Text) === [exon|one #|]+ ("one ##bug} two three" :: Text) === [exon|one ##bug} two #{"three"}|] where var :: IsString a => a var =
+ test/Exon/Test/ParseTest.hs view
@@ -0,0 +1,9 @@+module Exon.Test.ParseTest where++import Hedgehog (TestT, assert)+import Exon.Parse (parse)++test_parser :: TestT IO ()+test_parser = do+ assert (isLeft (parse "pre #{incomplete"))+ assert (isLeft (parse "pre ##{incomplete"))
test/Main.hs view
@@ -3,6 +3,7 @@ import Exon.Test.BasicTest (test_basic, test_customWhitespace) import Exon.Test.BuildTest (test_build) import Exon.Test.NewtypeTest (test_newtype)+import Exon.Test.ParseTest (test_parser) import Exon.Test.ShowsPrecTest (test_showsPrec) import Exon.Test.SkipWsTest (test_skipWs) import Hedgehog (TestT, property, test, withTests)@@ -24,7 +25,8 @@ unitTest "custom whitespace handling" test_customWhitespace, unitTest "concat showsPrec fragments" test_showsPrec, unitTest "skip whitespace quoter" test_skipWs,- unitTest "segment newtype conversion" test_newtype+ unitTest "segment newtype conversion" test_newtype,+ unitTest "parser" test_parser ] main :: IO ()