phino 0.0.0.54 → 0.0.0.55
raw patch · 6 files changed
+32/−23 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +1/−1
- phino.cabal +1/−1
- src/CLI.hs +5/−5
- src/LaTeX.hs +4/−4
- test/CLISpec.hs +19/−12
- test/LaTeXSpec.hs +2/−0
README.md view
@@ -29,7 +29,7 @@ ```bash cabal update-cabal install --overwrite-policy=always phino-0.0.0.53+cabal install --overwrite-policy=always phino-0.0.0.54 phino --version ```
phino.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: phino-version: 0.0.0.54+version: 0.0.0.55 license: MIT synopsis: Command-Line Manipulator of 𝜑-Calculus Expressions description: Please see the README on GitHub at <https://github.com/objectionary/phino#readme>
src/CLI.hs view
@@ -504,11 +504,11 @@ (True, _, Just file) -> do logDebug (printf "The option '--in-place' is specified, writing back to '%s'..." file) writeFile file prog- logInfo (printf "The file '%s' was modified in-place" file)+ logDebug (printf "The file '%s' was modified in-place" file) (False, Just file, _) -> do logDebug (printf "The option '--target' is specified, printing to '%s'..." file) writeFile file prog- logInfo (printf "The command result was saved in '%s'" file)+ logDebug (printf "The command result was saved in '%s'" file) (False, Nothing, _) -> do logDebug "The option '--target' is not specified, printing to console..." putStrLn prog@@ -585,13 +585,13 @@ input <- readInput inputFile prog <- parseProgram input PHI if isNothing pattern- then logInfo "The --pattern is not provided, no substitutions are built"+ then logDebug "The --pattern is not provided, no substitutions are built" else do ptn <- parseExpressionThrows (fromJust pattern) condition <- traverse parseConditionThrows when' substs <- matchProgramWithRule prog (rule ptn condition) (RuleContext buildTerm) if null substs- then logInfo "Provided pattern was not matched, no substitutions are built"+ then logDebug "Provided pattern was not matched, no substitutions are built" else putStrLn (P.printSubsts' substs (sugarType, UNICODE, flat)) where rule :: Expression -> Maybe Y.Condition -> Y.Rule@@ -711,4 +711,4 @@ Just file -> do logDebug (printf "The option '--target' is specified, printing to '%s'..." file) writeFile file content- logInfo (printf "The command result was saved in '%s'" file)+ logDebug (printf "The command result was saved in '%s'" file)
src/LaTeX.hs view
@@ -22,7 +22,6 @@ import Lining (LineFormat (MULTILINE, SINGLELINE), withLineFormat) import Matcher import Misc-import Printer (printProgram') import Render (Render (render)) import Replacer (ReplaceContext (ReplaceCtx), replaceProgram) import Rewriter (Rewritten (..))@@ -99,12 +98,13 @@ in case frequent of Just expr -> let met' = map (filter (== expr)) met- substs = matchProgram expr first- prog = replaceProgram (first, map (const expr) substs, map (const (ExPhiMeet prefix idx)) substs)+ (subst : substs) = matchProgram expr first+ prog = replaceProgram (first, [expr], [ExPhiMeet prefix idx])+ prog' = replaceProgram (prog, map (const expr) substs, map (const (ExPhiAgain prefix idx)) substs) rest' = zipWith (\prgm exprs -> replaceProgram (prgm, exprs, map (const (ExPhiAgain prefix idx)) exprs)) rest met' found = filter (not . null) met' in if length met' > 1 && toDouble (length found) / toDouble (length met') >= 0.5- then prog : meetInPrograms' (idx + 1) rest'+ then prog' : meetInPrograms' (idx + 1) rest' else next _ -> next
test/CLISpec.hs view
@@ -451,6 +451,19 @@ ] ] + it "should not print \\phiMeet{} twice" $+ withStdin "{[[ ex -> [[ x -> [[ y -> ?, k -> [[ t -> 42]] ]]( y -> [[ t -> 42 ]]) ]].i ]]}" $+ testCLISucceeded+ ["rewrite", "--normalize", "--sequence", "--flat", "--compress", "--output=latex", "--sweet"]+ [ unlines+ [ "\\begin{phiquation}"+ , "\\Big\\{[[ |ex| -> [[ |x| -> [[ |y| -> ?, |k| -> \\phiMeet{1}{[[ |t| -> 42 ]]} ]]( |y| -> \\phiAgain{1} ) ]].|i| ]]\\Big\\} \\leadsto_{\\nameref{r:copy}}"+ , " \\leadsto \\Big\\{[[ |ex| -> [[ |x| -> [[ |y| -> \\phiAgain{1}, |k| -> \\phiAgain{1} ]] ]].|i| ]]\\Big\\} \\leadsto_{\\nameref{r:stop}}"+ , " \\leadsto \\Big\\{[[ |ex| -> T ]]\\Big\\}."+ , "\\end{phiquation}"+ ]+ ]+ it "prints input as listing in XMIR" $ withStdin "{[[ app -> [[]] ]]}" $ testCLISucceeded@@ -523,9 +536,7 @@ withStdin "Q -> [[ ]]" $ withTempFile "targetXXXXXX.tmp" $ \(path, h) -> do hClose h- testCLISucceeded- ["rewrite", "--sweet", printf "--target=%s" path]- [printf "The command result was saved in '%s'" path]+ testCLISucceeded ["rewrite", "--sweet", printf "--target=%s" path] [] content <- readFile path content `shouldBe` "{⟦⟧}" @@ -533,9 +544,7 @@ withTempFile "inplaceXXXXXX.phi" $ \(path, h) -> do hPutStr h "Q -> [[ x -> \"foo\" ]]" hClose h- testCLISucceeded- ["rewrite", rule "simple.yaml", "--in-place", "--sweet", path]- [printf "The file '%s' was modified in-place" path]+ testCLISucceeded ["rewrite", rule "simple.yaml", "--in-place", "--sweet", path] [] content <- readFile path content `shouldBe` "{⟦\n x ↦ \"bar\"\n⟧}" @@ -706,9 +715,7 @@ (\(path, _) -> removeFile path) ( \(path, h) -> do hClose h- testCLISucceeded- ["explain", "--normalize", printf "--target=%s" path]- [printf "was saved in '%s'" path]+ testCLISucceeded ["explain", "--normalize", printf "--target=%s" path] [] content <- readFile path content `shouldContain` "\\documentclass{article}" content `shouldContain` "\\begin{document}"@@ -756,14 +763,14 @@ describe "match" $ do it "takes from stdin" $ withStdin "{[[]]}" $- testCLISucceeded ["match"] ["[INFO]"]+ testCLISucceeded ["match", "--log-level=debug"] ["[DEBUG]"] it "takes from file" $- testCLISucceeded ["match", "test-resources/cli/foo.phi"] ["[INFO]"]+ testCLISucceeded ["match", "test-resources/cli/foo.phi", "--log-level=debug"] ["[DEBUG]"] it "does not print substitutions without pattern" $ withStdin "{[[]]}" $- testCLISucceeded ["match"] ["[INFO]: The --pattern is not provided, no substitutions are built"]+ testCLISucceeded ["match", "--log-level=debug"] ["[DEBUG]: The --pattern is not provided, no substitutions are built"] it "prints one substitution" $ withStdin "{[[ x -> Q.x ]]}" $
test/LaTeXSpec.hs view
@@ -25,6 +25,8 @@ , ("Q.x.y twice", "{Q.x.y}", "{[[ x -> Q.x.y, y -> Q.x.y.z ]]}", ["Q.x.y", "Q.x.y"]) , ("Q.x.y.z.a and Q.x.y", "{Q.x.y.z.a}", "{[[ x -> Q.x.y, y -> Q.x.y.z ]]}", ["Q.x.y.z", "Q.x.y", "Q.x.y"]) , ("Ignore data objects", "{[[ x -> \"foo\" ]]}", "{Q.x( y -> \"foo\" )}", [])+ , ("Not found [[ t -> 42 ]]", "{⟦ ex ↦ ⟦ x ↦ ⟦ t ↦ 42 ⟧.t ⟧.x ⟧}", "{⟦ ex ↦ ⟦ x ↦ 42 ⟧.x ⟧}", [])+ , ("Missed [[ t -> 42 ]]", "{⟦ ex ↦ ⟦ x ↦ ⟦ t ↦ 42 ⟧.t ⟧.x ⟧}", "{⟦ ex ↦ 42 ⟧}", []) ] ( \(desc, first, second, exprs) -> it desc $ do ptn <- parseProgramThrows first