Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

482 failed key when not found #578

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ data Rule = Rule
, pattern :: Object
, result :: Object
, fresh :: Maybe [FreshMetaId]
, when :: [Condition]
, tests :: [RuleTest]
, when :: Maybe [Condition]
, tests :: Maybe [RuleTest]
}
deriving (Generic, FromJSON, Show)

Expand Down Expand Up @@ -183,7 +183,7 @@ convertRule Rule{..} ctx obj = do
let pattern' = applySubst contextSubsts pattern
result' = applySubst contextSubsts result
subst <- matchObject pattern' obj
guard $ all (\cond -> checkCond ctx cond (contextSubsts <> subst)) when
guard $ all (\cond -> checkCond ctx cond (contextSubsts <> subst)) (fromMaybe [] when)
let substFresh = mkFreshSubst ctx result' fresh
result'' = applySubst (contextSubsts <> subst <> substFresh) result'
-- TODO #152:30m what context should we pass to evaluate meta funcs?
Expand Down
6 changes: 3 additions & 3 deletions eo-phi-normalizer/src/Language/EO/Phi/ToLaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ instance ToLatex RuleAttribute where
instance ToLatex Condition where
toLatex (IsNF nf) = inMathMode $ toLatex nf <> "\\in\\mathcal{N}"
toLatex (IsNFInsideFormation nf_inside_formation) =
(inMathMode $ toLatex nf_inside_formation) <> " is nf inside formation"
inMathMode (toLatex nf_inside_formation) <> " is nf inside formation"
toLatex (PresentAttrs (AttrsInBindings attrs bindings)) =
inMathMode $ fold (intersperse ", " (map toLatex attrs)) <> " \\in " <> foldMap toLatex bindings
toLatex (AbsentAttrs (AttrsInBindings attrs bindings)) =
Expand Down Expand Up @@ -147,7 +147,7 @@ instance ToLatex Rule where
<> inMathMode (toLatex result)
<> (if not (null when) || isNonEmptyContext context then "\\\\\\text {if }" else mempty)
<> maybe mempty (\c -> "&" <> toLatex c <> "\\\\") context
<> fold (intersperse ",\\\\" (map (("&" <>) . toLatex) when))
<> fold (intersperse ",\\\\" (maybe [] (map (("&" <>) . toLatex)) when))

instance ToLatex [Rule] where
toLatex rules =
Expand All @@ -166,7 +166,7 @@ ruleToLatexCompact (Rule name _ context _ pattern result _ when _) =
<> inMathMode (toLatex result)
<> (if not (null when) || isNonEmptyContext context then "\\quad\\text {if }" else "")
<> maybe mempty (\c -> toLatex c <> ", ") context
<> fold (intersperse ", " (map toLatex when))
<> fold (intersperse ", " (maybe [] (map toLatex) when))

rulesToLatexCompact :: [Rule] -> LaTeX
rulesToLatexCompact rules =
Expand Down
4 changes: 3 additions & 1 deletion eo-phi-normalizer/src/Language/EO/Test/YamlSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
module Language.EO.Test.YamlSpec where

import Control.Monad (forM_)
import Data.Maybe (fromMaybe)
import Language.EO.Phi.Dataize.Context (defaultContext)
import Language.EO.Phi.Rules.Common (applyOneRule)
import Language.EO.Phi.Rules.Yaml (Rule (..), RuleSet (..), RuleTest (..), RuleTestOption (..), convertRuleNamed)
Expand All @@ -40,7 +41,8 @@ spec testPaths = describe "User-defined rules unit tests" do
describe ruleset.title do
forM_ ruleset.rules $ \rule -> do
describe rule.name do
forM_ rule.tests $ \ruleTest -> do
let tests' = fromMaybe [] rule.tests
forM_ tests' $ \ruleTest -> do
it ruleTest.name $
let rule' = convertRuleNamed rule
resultOneStep = applyOneRule (defaultContext [rule'] ruleTest.input) ruleTest.input
Expand Down
16 changes: 8 additions & 8 deletions site/docs/src/eo-phi-normalizer/print-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ eo-phi-normalizer print-rules --tex
\rrule{COPY1}: & $ [[ \tau -> ?, B ]]( 0-> b1 ) $ \(\trans\) $ [[ \tau -> \mathbb{S}(b1, b2), B ]] $ \\\text {if }& $ b2 $ is the scope of the redex\\&not in subformations,\\& $ b1\in\mathcal{N} $ \\\\
\rrule{COPY2}: & $ [[ \tau1 -> ?, \tau2 -> ?, B ]]( 0-> b1, 1-> b2 ) $ \(\trans\) $ [[ \tau1 -> \mathbb{S}(b1, b3), \tau2 -> \mathbb{S}(b2, b3), B ]] $ \\\text {if }& $ b3 $ is the scope of the redex\\&not in subformations,\\& $ b1\in\mathcal{N} $ ,\\& $ b2\in\mathcal{N} $ \\\\
\rrule{COPYdelta}: & $ [[ D> ?, B ]]( D> y ) $ \(\trans\) $ [[ D> y, B ]] $ \\\text {if }&not in subformations\\\\
\rrule{EMPTY}: & $ [[ B1 ]]( ) $ \(\trans\) $ [[ B1 ]] $ \\\\
\rrule{OVER}: & $ [[ \tau -> b1, B1 ]]( \tau -> b2, B2 ) $ \(\trans\) $ \dead $ \\\\
\rrule{EMPTY}: & $ [[ B1 ]]( ) $ \(\trans\) $ [[ B1 ]] $ \\\text {if }\\\\
\rrule{OVER}: & $ [[ \tau -> b1, B1 ]]( \tau -> b2, B2 ) $ \(\trans\) $ \dead $ \\\text {if }\\\\
\rrule{STOP}: & $ [[ B ]].\tau $ \(\trans\) $ \dead $ \\\text {if }& $ \tau, @, \lambda \notin B $ ,\\& $ ^ \in B $ ,\\& $ [[ B ]]\in\mathcal{N} $ \\\\
\rrule{MISS}: & $ [[ B1 ]]( \tau -> b, B2 ) $ \(\trans\) $ \dead $ \\\text {if }& $ \tau, @, \lambda \notin B1 $ \\\\
\rrule{DD}: & $ \dead.\tau $ \(\trans\) $ \dead $ \\\\
\rrule{DC}: & $ \dead( B ) $ \(\trans\) $ \dead $
\rrule{DD}: & $ \dead.\tau $ \(\trans\) $ \dead $ \\\text {if }\\\\
\rrule{DC}: & $ \dead( B ) $ \(\trans\) $ \dead $ \\\text {if }
\end{tabular}
\end{figure*}
```
Expand All @@ -74,11 +74,11 @@ eo-phi-normalizer print-rules --tex --compact
\rrule{COPY1}: $ [[ \tau -> ?, B ]]( 0-> b1 ) $ \(\trans\) $ [[ \tau -> \mathbb{S}(b1, b2), B ]] $ \quad\text {if } $ b2 $ is the scope of the redex, not in subformations, $ b1\in\mathcal{N} $ \\\vspace*{0.5em}
\rrule{COPY2}: $ [[ \tau1 -> ?, \tau2 -> ?, B ]]( 0-> b1, 1-> b2 ) $ \(\trans\) $ [[ \tau1 -> \mathbb{S}(b1, b3), \tau2 -> \mathbb{S}(b2, b3), B ]] $ \quad\text {if } $ b3 $ is the scope of the redex, not in subformations, $ b1\in\mathcal{N} $ , $ b2\in\mathcal{N} $ \\\vspace*{0.5em}
\rrule{COPYdelta}: $ [[ D> ?, B ]]( D> y ) $ \(\trans\) $ [[ D> y, B ]] $ \quad\text {if }not in subformations\\\vspace*{0.5em}
\rrule{EMPTY}: $ [[ B1 ]]( ) $ \(\trans\) $ [[ B1 ]] $ \\\vspace*{0.5em}
\rrule{OVER}: $ [[ \tau -> b1, B1 ]]( \tau -> b2, B2 ) $ \(\trans\) $ \dead $ \\\vspace*{0.5em}
\rrule{EMPTY}: $ [[ B1 ]]( ) $ \(\trans\) $ [[ B1 ]] $ \quad\text {if }\\\vspace*{0.5em}
\rrule{OVER}: $ [[ \tau -> b1, B1 ]]( \tau -> b2, B2 ) $ \(\trans\) $ \dead $ \quad\text {if }\\\vspace*{0.5em}
\rrule{STOP}: $ [[ B ]].\tau $ \(\trans\) $ \dead $ \quad\text {if } $ \tau, @, \lambda \notin B $ , $ ^ \in B $ , $ [[ B ]]\in\mathcal{N} $ \\\vspace*{0.5em}
\rrule{MISS}: $ [[ B1 ]]( \tau -> b, B2 ) $ \(\trans\) $ \dead $ \quad\text {if } $ \tau, @, \lambda \notin B1 $ \\\vspace*{0.5em}
\rrule{DD}: $ \dead.\tau $ \(\trans\) $ \dead $ \\\vspace*{0.5em}
\rrule{DC}: $ \dead( B ) $ \(\trans\) $ \dead $
\rrule{DD}: $ \dead.\tau $ \(\trans\) $ \dead $ \quad\text {if }\\\vspace*{0.5em}
\rrule{DC}: $ \dead( B ) $ \(\trans\) $ \dead $ \quad\text {if }
\end{figure*}
```
4 changes: 2 additions & 2 deletions site/docs/src/eo-phi-normalizer/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ User-defined rules unit tests
Should match in subformation [✔]
Should work with empty formation [✔]
OVER
Language.EO.Test.YamlSpec[44:13] [✔]
Language.EO.Test.YamlSpec[46:13] [✔]
STOP
Accessing nonexistent attribute [✔]
MISS
Language.EO.Test.YamlSpec[44:13] [✔]
Language.EO.Test.YamlSpec[46:13] [✔]
Should not match if attr is present [✔]
Should not match if phi is present [✔]
Should apply in subformations [✔]
Expand Down