packages feed

phino 0.0.102 → 0.0.103

raw patch · 3 files changed

+25/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

phino.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: phino-version: 0.0.102+version: 0.0.103 license: MIT synopsis: Command-Line Manipulator of 𝜑-Calculus Expressions description: Please see the README on GitHub at <https://github.com/objectionary/phino#readme>
src/LaTeX.hs view
@@ -93,9 +93,13 @@  {- | Here we're trying to compress a sequence of expressions with \phinoMeet{} and \phinoAgain LaTeX functions. We process the sequence of expressions and trying to find all sub-expressions in the first expression which are present-in the following expressions. Then we find ONE expression which is the most frequently encountered.+in the following expressions. Then we find the one which is the most frequently encountered. If it's encountered in more than specific percentage (_meetPopularity) of the following expressions - we replace it with \phinoAgain{} in the following expressions and with \phinoMeet{} in the first expression.+We then keep re-scanning that same first expression for further meets: the parts already factored out become+\phinoMeet{}/\phinoAgain{}, which the scanner skips, so each pass yields strictly fewer candidates and the loop+terminates. This lets a single step host several \phinoMeet{}s when it carries several independent recurring+sub-expressions, rather than only the single most frequent one. -} meetInExpressions :: [Expression] -> LatexContext -> [Expression] meetInExpressions exprs LatexContext{..} = go exprs 1@@ -127,7 +131,7 @@                       rest' = zipWith (\other exprs' -> replaceExpression (other, exprs', map (const (ExPhiAgain _meetPrefix idx)) exprs')) rest met'                       found = filter (not . null) met'                    in if length met' > 1 && toDouble (length found) / toDouble (length met') >= popularity-                        then withAgain : go rest' (idx + 1)+                        then go (withAgain : rest') (idx + 1)                         else next                 [] -> next             _ -> next
test/LaTeXSpec.hs view
@@ -10,9 +10,10 @@  import AST (Expression (ExMeta)) import Control.Monad (forM_)-import LaTeX (conditionToLatex, meetInExpression)+import Data.Text qualified as T+import LaTeX (LatexContext (..), conditionToLatex, defaultLatexContext, meetInExpression, meetInExpressions) import Parser (parseExpressionThrows)-import Test.Hspec (Spec, describe, it, shouldBe)+import Test.Hspec (Spec, describe, expectationFailure, it, shouldBe) import Yaml qualified as Y  spec :: Spec@@ -32,6 +33,21 @@           res <- traverse parseExpressionThrows exprs           meetInExpression ptn 4 tgt `shouldBe` res       )++  describe "meets several sub-expressions in a single step" $+    -- A step routinely carries several independent recurring sub-expressions.+    -- The first step here holds two distinct recurring formations+    -- ([[ p -> Q.a ]] and [[ q -> Q.b ]]); both must be factored, so the first+    -- rendered step ends up with two \phinoMeet{}s, not just the single most+    -- frequent one (see #976).+    it "factors every recurring sub-expression, not only one" $ do+      let step :: String -> String+          step lastAttr = "[[ r -> [[ p -> Q.a ]], s -> [[ q -> Q.b ]], tag -> Q." <> lastAttr <> " ]]"+      exprs <- traverse parseExpressionThrows [step "one", step "two", step "three"]+      let ctx = defaultLatexContext{_compress = True, _meetLength = 6, _meetPopularity = 1}+      case meetInExpressions exprs ctx of+        (firstStep : _) -> T.count "ExPhiMeet" (T.pack (show firstStep)) `shouldBe` 2+        [] -> expectationFailure "meetInExpressions returned no expressions"    describe "renders the 'formation' condition" $     forM_