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

Implement attribute inequality #80

Merged
merged 2 commits into from
Feb 2, 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
3 changes: 3 additions & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Language.EO.Phi.Syntax.Abs
instance FromJSON Object where parseJSON = fmap fromString . parseJSON
instance FromJSON Binding where parseJSON = fmap fromString . parseJSON
instance FromJSON MetaId where parseJSON = fmap MetaId . parseJSON
instance FromJSON Attribute where parseJSON = fmap fromString . parseJSON
instance FromJSON RuleAttribute where parseJSON = fmap fromString . parseJSON

instance FromJSON LabelId
Expand Down Expand Up @@ -60,6 +61,7 @@ data Condition
= IsNF {nf :: [MetaId]}
| PresentAttrs {present_attrs :: AttrsInBindings}
| AbsentAttrs {absent_attrs :: AttrsInBindings}
| AttrNotEqual {not_equal :: (Attribute, Attribute)}
deriving (Generic, Show)
instance FromJSON Condition where
parseJSON = genericParseJSON defaultOptions{sumEncoding = UntaggedValue}
Expand Down Expand Up @@ -95,6 +97,7 @@ checkCond _ctx (PresentAttrs (AttrsInBindings attrs bindings)) subst = any (`has
normalToRuleAttr a = ObjectAttr a
substitutedAttrs = map (normalToRuleAttr . applySubstAttr subst . ruleToNormalAttr) attrs
checkCond ctx (AbsentAttrs s) subst = not $ checkCond ctx (PresentAttrs s) subst
checkCond _ctx (AttrNotEqual (a1, a2)) subst = applySubstAttr subst a1 /= applySubstAttr subst a2

hasAttr :: RuleAttribute -> [Binding] -> Bool
hasAttr attr = any (isAttr attr)
Expand Down
12 changes: 12 additions & 0 deletions eo-phi-normalizer/test/eo/phi/rules/yegor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ rules:
- nf: ["!n"]
tests: []

- name: Rule 10
description: ""
pattern: ⟦ !t ↦ !b1, !B1 ⟧(!t ↦ !b2, !B2)
result: ⊥
when:
- not_equal: ["!t", "ρ"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I do not like using a tuple here, but I can't come up with a better alternative :)

tests:
- name: ''
input: '⟦ t ↦ ⟦ a ↦ ∅ ⟧ ⟧(t ↦ ⟦ b ↦ ∅ ⟧)'
output: '⊥'
matches: true

- name: Rule 11
description: ""
pattern: |
Expand Down
Loading