Skip to content

Commit

Permalink
fix(eo-phi-normalizer): use yegor's old rules by default
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Dec 27, 2024
1 parent 828e4a2 commit 094838f
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 26 deletions.
14 changes: 12 additions & 2 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ data CommandParser = CommandParser
}

rulesFile :: String
rulesFile = "new.yaml"
rulesFile = "yegor.yaml"

commandParser :: CommandParser
commandParser =
Expand Down Expand Up @@ -606,7 +606,7 @@ main = withCorrectLocale do
-- Temporary hack while rules are not stabilized.
-- Nothing -> return (True, "Yegor's rules (builtin)", [fastYegorInsideOutAsRule])
Nothing -> do
ruleSet :: RuleSet <- decodeThrow $(embedFileRelative "test/eo/phi/rules/new.yaml")
ruleSet :: RuleSet <- decodeThrow $(embedFileRelative "test/eo/phi/rules/yegor.yaml")
return (False, ruleSet.title, convertRuleNamed <$> ruleSet.rules)
unless (single || json || latex) $ logStrLn ruleSetTitle
bindingsWithDeps <- case deepMergePrograms (program' : deps) of
Expand Down Expand Up @@ -702,6 +702,16 @@ main = withCorrectLocale do
bindingsWithDeps <- case deepMergePrograms (program' : deps) of
Left err -> throwIO (CouldNotMergeDependencies err)
Right (Program bindingsWithDeps) -> return bindingsWithDeps
-- (builtin, ruleSetTitle, rules) <-
-- case rulesPath of
-- Just path -> do
-- ruleSet <- parseRuleSetFromFile path
-- return (False, ruleSet.title, convertRuleNamed <$> ruleSet.rules)
-- -- Temporary hack while rules are not stabilized.
-- -- Nothing -> return (True, "Yegor's rules (builtin)", [fastYegorInsideOutAsRule])
-- Nothing -> do
-- ruleSet :: RuleSet <- decodeThrow $(embedFileRelative "test/eo/phi/rules/new.yaml")
-- return (False, ruleSet.title, convertRuleNamed <$> ruleSet.rules)
(builtin, _ruleSetTitle, rules) <-
case rulesPath of
Just path -> do
Expand Down
1 change: 1 addition & 0 deletions eo-phi-normalizer/eo-phi-normalizer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ extra-source-files:
data/0.49.4/org/eolang/while.phi
test/eo/phi/rules/new.yaml
test/eo/phi/rules/streams.yaml
test/eo/phi/rules/yegor.yaml

source-repository head
type: git
Expand Down
2 changes: 1 addition & 1 deletion eo-phi-normalizer/src/Language/EO/Phi/Rules/RunYegor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ yegorRuleSet :: Yaml.RuleSet
{-# NOINLINE yegorRuleSet #-}
yegorRuleSet =
unsafePerformIO $
Yaml.parseRuleSetFromFile "eo-phi-normalizer/test/eo/phi/rules/new.yaml"
Yaml.parseRuleSetFromFile "eo-phi-normalizer/test/eo/phi/rules/yegor.yaml"

yegorRules :: [NamedRule]
yegorRules = map Yaml.convertRuleNamed (Yaml.rules yegorRuleSet)
11 changes: 8 additions & 3 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Language.EO.Phi.Syntax (
module Language.EO.Phi.Syntax.Abs,
desugar,
printTree,
printTreeDontSugar,

-- * Conversion to 'Bytes'
intToBytes,
Expand Down Expand Up @@ -662,11 +663,15 @@ unsafeParseWith parser input =
Left parseError -> error parseError
Right object -> object

-- | The top-level printing method.
printTree :: (Pretty a, SugarableFinally a) => a -> String
printTree =
printTreeDontSugar :: (Pretty a) => a -> String
printTreeDontSugar =
T.unpack
. renderStrict
. layoutPretty defaultLayoutOptions{layoutPageWidth = Unbounded}
. pretty

-- | The top-level printing method.
printTree :: (Pretty a, SugarableFinally a) => a -> String
printTree =
printTreeDontSugar
. sugarFinally
42 changes: 24 additions & 18 deletions eo-phi-normalizer/test/Language/EO/Phi/DataizeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Language.EO.Phi.DataizeSpec where
import Control.Monad (forM_)
import Test.Hspec

import Language.EO.Phi (printTree)
import Language.EO.Phi (printTree, printTreeDontSugar)
import Language.EO.Phi qualified as Phi
import Language.EO.Phi.Dataize (dataizeRecursively)
import Language.EO.Phi.Dataize.Context (defaultContext)
Expand Down Expand Up @@ -62,23 +62,29 @@ getProgram inputFile = do
spec :: Spec
spec = do
DataizeTestGroup{..} <- runIO (dataizationTests "test/eo/phi/dataization.yaml")
ruleset <- runIO $ parseRuleSetFromFile "test/eo/phi/rules/new.yaml"
let rules = map convertRuleNamed ruleset.rules
describe title $
forM_ tests $
\test -> do
deps <- runIO $ mapM getProgram test.dependencies
let mergedProgs = case deepMergePrograms (test.input : deps) of
Left err -> error ("Error merging programs: " ++ err)
Right prog -> prog
let ctx = defaultContext rules (progToObj mergedProgs)
let inputObj = progToObj test.input
let expectedResult = case test.output of
Object obj -> Left obj
Bytes bytes -> Right bytes
it test.name $ do
let dataizedResult = dataizeRecursively ctx inputObj
ObjectOrBytes dataizedResult `shouldBe` ObjectOrBytes expectedResult
forM_
[ ("Old Yegor's rules", "test/eo/phi/rules/yegor.yaml")
-- TODO #617:10m Enable
-- , ("New Yegor's rules", "test/eo/phi/rules/new.yaml")
]
$ \(title, rulesFile) -> do
ruleset <- runIO $ parseRuleSetFromFile rulesFile
let rules = map convertRuleNamed ruleset.rules
describe title $
forM_ tests $
\test -> do
deps <- runIO $ mapM getProgram test.dependencies
let mergedProgs = case deepMergePrograms (test.input : deps) of
Left err -> error ("Error merging programs: " ++ err)
Right prog -> prog
let ctx = defaultContext rules (progToObj mergedProgs)
let inputObj = progToObj test.input
let expectedResult = case test.output of
Object obj -> Left obj
Bytes bytes -> Right bytes
it test.name $ do
let dataizedResult = dataizeRecursively ctx inputObj
ObjectOrBytes dataizedResult `shouldBe` ObjectOrBytes expectedResult

progToObj :: Phi.Program -> Phi.Object
progToObj (Phi.Program bindings) = Phi.Formation bindings
5 changes: 3 additions & 2 deletions eo-phi-normalizer/test/Language/EO/Rules/PhiPaperSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,13 @@ spec :: Spec
spec =
forM_
[ ("New Yegor's rules", "test/eo/phi/rules/new.yaml")
, ("Old Yegor's rules", "test/eo/phi/rules/yegor.yaml")
]
$ \(name, rulesFile) -> do
$ \(title, rulesFile) -> do
ruleset <- runIO $ parseRuleSetFromFile rulesFile
let rulesFromYaml = map convertRuleNamed (rules ruleset)
inputs <- runIO $ parseTests "test/eo/phi/confluence.yaml"
describe name $ do
describe title $ do
it "Are confluent (via QuickCheck)" (confluent rulesFromYaml)
describe
"Are confluent (regression tests)"
Expand Down
1 change: 1 addition & 0 deletions eo-phi-normalizer/test/Language/EO/YamlSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ spec :: Spec
spec =
Test.spec
[ "test/eo/phi/rules/new.yaml"
, "test/eo/phi/rules/yegor.yaml"
, "test/eo/phi/rules/streams.yaml"
]
Loading

0 comments on commit 094838f

Please sign in to comment.