madlang 2.1.0.0 → 2.1.0.1
raw patch · 6 files changed
+34/−12 lines, 6 filesdep ~hspecdep ~madlang
Dependency ranges changed: hspec, madlang
Files
- madlang.cabal +6/−5
- src/Text/Madlibs/Ana/Parse.hs +2/−2
- src/Text/Madlibs/Ana/ParseUtils.hs +4/−3
- stack.yaml +1/−1
- test/Spec.hs +7/−1
- test/templates/ordered.mad +14/−0
madlang.cabal view
@@ -1,5 +1,5 @@ name: madlang-version: 2.1.0.0+version: 2.1.0.1 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -18,6 +18,7 @@ test/templates/fortune-teller.mad test/templates/gambling.mad test/templates/var.mad+ test/templates/ordered.mad test/templates/include.mad test/templates/err/*.mad bench/templates/*.mad@@ -72,7 +73,7 @@ main-is: Main.hs build-depends: base >=4.9.1.0 && <4.10,- madlang >=2.1.0.0 && <2.2+ madlang >=2.1.0.1 && <2.2 default-language: Haskell2010 hs-source-dirs: app @@ -81,8 +82,8 @@ main-is: Spec.hs build-depends: base >=4.9.1.0 && <4.10,- madlang >=2.1.0.0 && <2.2,- hspec >=2.4.2 && <2.5,+ madlang >=2.1.0.1 && <2.2,+ hspec >=2.4.3 && <2.5, megaparsec >=5.2.0 && <5.3, text >=1.2.2.1 && <1.3, mtl >=2.2.1 && <2.3,@@ -102,7 +103,7 @@ build-depends: base >=4.9.1.0 && <4.10, criterion >=1.1.4.0 && <1.2,- madlang >=2.1.0.0 && <2.2,+ madlang >=2.1.0.1 && <2.2, megaparsec >=5.2.0 && <5.3, text >=1.2.2.1 && <1.3 default-language: Haskell2010
src/Text/Madlibs/Ana/Parse.hs view
@@ -141,12 +141,12 @@ -- | Parse text as a list of functions parseTokF :: FilePath -> [(Key, RandTok)] -> [T.Text] -> T.Text -> Either (ParseError Char Dec) [(Key, RandTok)] parseTokF filename state ins f = (flip execState (filterTemplate state)) <$> runParser (parseTokM ins) filename f - where filterTemplate = map (\(i,j) -> if i == "Template" then (T.pack filename, j) else (i,j)) -- problem: doesn't tell what file we're reading FROM+ where filterTemplate = map (\(i,j) -> if i == "Template" then (strip filename, j) else (i,j)) -- problem: doesn't tell what file we're reading FROM -- | Parse text as a list of tokens, suitable for printing as a tree. parseTreeF :: FilePath -> [(Key, RandTok)] -> [T.Text] -> T.Text -> Either (ParseError Char Dec) [(Key, RandTok)] parseTreeF filename state ins f = (flip execState (filterTemplate state)) <$> runParser (parseTreeM ins) filename f - where filterTemplate = map (\(i,j) -> if i == "Template" then (T.pack filename, j) else (i,j))+ where filterTemplate = map (\(i,j) -> if i == "Template" then (strip filename, j) else (i,j)) -- | Parse text as a token --
src/Text/Madlibs/Ana/ParseUtils.hs view
@@ -13,6 +13,8 @@ --TODO consider moving Ana.ParseUtils to Cata.Sorting +strip = T.pack . reverse . drop 4 . reverse+ -- | Get the :return value takeTemplate :: [(Key, RandTok)] -> RandTok takeTemplate = snd . head . filter (\(i,j) -> i == "Template")@@ -69,7 +71,6 @@ orderKeys (key1, l1) (key2, l2) | key1 == "Template" = GT | key2 == "Template" = LT- | any (\pair -> any (T.isInfixOf key1) (map unTok . snd $ pair)) l1 = LT- | any (\pair -> any (T.isInfixOf key2) (map unTok . snd $ pair)) l1 = GT- -- issue: if we define nationality, subject object NOW object can't be used in subject?+ | any (\pair -> any (T.isInfixOf key1) (map unTok . snd $ pair)) l1 = GT+ | any (\pair -> any (T.isInfixOf key2) (map unTok . snd $ pair)) l1 = LT | otherwise = EQ
stack.yaml view
@@ -1,4 +1,4 @@-resolver: lts-8.5+resolver: lts-8.6 packages: - '.' extra-deps:
test/Spec.hs view
@@ -38,6 +38,9 @@ --parallel $ it "parses tibetan numerals" $ do -- file <- madFileTibetan -- parseTok "" [] file `shouldParse` (List [(1.0,List [(0.5,Value "heads"),(0.5,Value "tails")])])+ describe "runFile" $ do+ it "parses file with inclusions" $ do+ runFile [] "test/templates/ordered.mad" >>= (`shouldSatisfy` (\a -> any (a==) ["heads","tails","on its side"])) semErr :: Selector SemanticError semErr = const True@@ -49,6 +52,9 @@ exampleTok :: RandTok exampleTok = List [(1.0,List [(0.5,Value "heads"),(0.5,Value "tails")])] +includeFile :: IO T.Text+includeFile = readFile' "test/templates/include.mad"+ madFile :: IO T.Text madFile = readFile' "test/templates/gambling.mad" @@ -59,7 +65,7 @@ madFileFailure = readFile' "test/templates/err/bad.mad" madComplexFile :: IO T.Text-madComplexFile = readFile' "test/templates/gambling.mad"+madComplexFile = readFile' "test/templates/ordered.mad" semErrFile :: IO T.Text semErrFile = readFile' "test/templates/err/sem-err.mad"
+ test/templates/ordered.mad view
@@ -0,0 +1,14 @@+:define something+ 1.0 "heads"+ 1.0 "tails"+ 1.0 somethingelse++:define somethingelse+ 1.0 "1"+ 1.0 "2"+ 1.0 "3"+ 1.0 "4"+ 1.0 "5"++:return+ 1.0 something