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

Accepts multiple GIVETH variables #607

Merged
merged 1 commit into from
Aug 8, 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
2 changes: 1 addition & 1 deletion lib/haskell/natural4/src/TextuaL4.cf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ HornlikeMeans. Rule3 ::= Text "MEANS" BoolStruct ;
-- because there is no MEANS that breaks the RelationalPredicate
HornlikeDecide. Rule3 ::= "DECIDE" [HornClause] ;
-- Only Hornlikes have GIVETH
HlikeGiveth. Rule3 ::= "GIVETH" IsA "DECIDE" [HornClause] ;
HlikeGiveth. Rule3 ::= "GIVETH" [IsA] "DECIDE" [HornClause] ;

HeadBody. HornClause ::= RelationalPredicate "IF" BoolStruct ;
HeadOtherwise. HornClause ::= RelationalPredicate "OTHERWISE" ;
Expand Down
2 changes: 1 addition & 1 deletion lib/haskell/natural4/src/TextuaL4/AbsTextuaL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data Rule
| RegWhoInline BoolStruct Who InlineHornlike Deontic BoolStruct
| HornlikeMeans Text BoolStruct
| HornlikeDecide [HornClause]
| HlikeGiveth IsA [HornClause]
| HlikeGiveth [IsA] [HornClause]
deriving (C.Eq, C.Ord, C.Show, C.Read)

data HornClause
Expand Down
14 changes: 7 additions & 7 deletions lib/haskell/natural4/src/TextuaL4/ParTextuaL.hs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/haskell/natural4/src/TextuaL4/ParTextuaL.y
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Rule3
| 'EVERY' BoolStruct Who InlineHornlike Deontic BoolStruct { TextuaL4.AbsTextuaL.RegWhoInline $2 $3 $4 $5 $6 }
| Text 'MEANS' BoolStruct { TextuaL4.AbsTextuaL.HornlikeMeans $1 $3 }
| 'DECIDE' ListHornClause { TextuaL4.AbsTextuaL.HornlikeDecide $2 }
| 'GIVETH' IsA 'DECIDE' ListHornClause { TextuaL4.AbsTextuaL.HlikeGiveth $2 $4 }
| 'GIVETH' ListIsA 'DECIDE' ListHornClause { TextuaL4.AbsTextuaL.HlikeGiveth $2 $4 }

HornClause :: { TextuaL4.AbsTextuaL.HornClause }
HornClause
Expand Down
8 changes: 5 additions & 3 deletions lib/haskell/natural4/src/TextuaL4/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ transRule x = case x of

-- Only Hornlikes have GIVETH
-- GIVETH foo (IS A bar) DECIDE relpred
TL4.HlikeGiveth giveth hhead ->
TL4.HlikeGiveth (giv:givs) hhead ->
let simple = transRule $ TL4.HornlikeDecide hhead
in simple {
giveth = Just $ isa2pt giveth
giveth = Just $ fmap isa2tm (giv :| givs)
}

-- TypeDecl
TL4.HlikeGiveth _ hhead -> transRule $ TL4.HornlikeDecide hhead

-- TypeDecl
-- DECLARE Foo (IS A Bar) (HAS …)?
TL4.TypeDecl isa fields ->
let isaRule = transIsA isa
Expand Down
1 change: 1 addition & 0 deletions lib/haskell/natural4/test/LS/TextuaL4Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ goldenGeneric name output_ = Golden
spec :: Spec
spec = do
describe "TextuaL4 output" do
test "GIVETH x ; y DECIDE x IS 5; y IS 4" "hornlike-2-giveths"
test "GIVEN foo GIVETH bar DECIDE bar IS 1 > 2" "hornlike-given-giveth-1"
test "GIVEN foo IS A Number GIVETH bar IS A Boolean DECIDE bar IS foo > 2" "hornlike-given-giveth-2"
test "EVERY tame ANY (Person, Animal) WHO Qualifies MEANS ALL(walks, ANY(eats, drinks), climbs) MUST ANY (sing, dance)" "regulative-any-tame-person-animal"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Hornlike
{ name =
[ MTT "x" ]
, super = Nothing
, keyword = Decide
, given = Nothing
, giveth = Just
(
( MTT "x" :| []
, Nothing
) :|
[
( MTT "y" :| []
, Nothing
)
]
)
, upon = Nothing
, clauses =
[ HC
{ hHead = RPConstraint
[ MTT "x" ] RPis
[ MTI 5 ]
, hBody = Nothing
}
, HC
{ hHead = RPConstraint
[ MTT "y" ] RPis
[ MTI 4 ]
, hBody = Nothing
}
]
, rlabel = Nothing
, lsource = Nothing
, wwhere = []
, srcref = Just
( SrcRef
{ url = "test/Spec"
, short = "test/Spec"
, srcrow = 1
, srccol = 1
, version = Nothing
}
)
, defaults = []
, symtab = []
}
Loading