Skip to content

Commit

Permalink
continue to think through boolstructs
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Oct 12, 2021
1 parent b134406 commit 14c5d53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
26 changes: 16 additions & 10 deletions mengwong/mp/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,24 @@ pRegRuleSugary depth = do
myTraceM $ "pRegRule: returning " ++ show toreturn
return ( toreturn : brs )

-- EVERY person
-- WHO sings
-- MAY eat a potato
-- BEFORE midnight
-- IF a potato is available

pRegRuleNormal :: Depth -> Parser [Rule]
pRegRuleNormal = do
pRegRuleNormal depth = do
leftX <- lookAhead pXLocation -- this is the column where we expect IF/AND/OR etc.
guard $ leftX >= depth
entitytype <- pActor Party <|> pActor Every
(ewho, (ebs, ebrs)) <- mergePBRS <$> many (preambleBoolRules leftX) <* dnl
(party_every, entitytype) <- pActor Party <|> pActor Every
(ewho, (ebs, ebrs)) <- optional (preambleBoolRules leftX) <* dnl
-- the below are going to be permutables
rulebody <- permutations
-- deontic <- pDeontic <* dnl
-- temporal <- optional pTemporal
-- action <- pAction
let (who, (cbs, brs)) = mergePBRS $ pbrs rulebody
let (who, (cbs, brs)) = mergePBRS $ rbpbrs rulebody
let toreturn = Regulative entitytype (newPre (Text.pack $ show ewho) ebs) cbs deontic action temporal
myTraceM $ "pRegRule: the specifier is " ++ show who
myTraceM $ "pRegRule: returning " ++ show toreturn
Expand All @@ -331,7 +337,7 @@ pRegRuleNormal = do
in (w,( a : mconcat pre_a
, concat (b ++ (snd <$> tail xs)) ) )


pTemporal :: Parser (TemporalConstraint Text.Text))
pTemporal = do
t1 <- pToken Before <|> pToken After <|> pToken By <* dnl
t2 <- pOtherVal <* dnl
Expand All @@ -358,11 +364,11 @@ pAction depth = do
-- we create a permutation parser returning one or more RuleBodies, which we treat as monoidal,
-- though later we may object if there is more than one.

data RuleBody :: RuleBody { pbrs :: [(Preamble, BoolRules)] -- not subject to the party
, action :: [(Text.Text,[(Text.Text,Text.Text)])] -- pay(to=Seller, amount=$100)
, deontic :: [Deontic]
, temporal :: [TemporalConstraint Text.Text]
}
data RuleBody = RuleBody { rbpbrs :: [(Preamble, BoolRules)] -- not subject to the party
, rbaction :: [(Text.Text,[(Text.Text,Text.Text)])] -- pay(to=Seller, amount=$100)
, rbdeon :: [Deontic]
, rbtemporal :: [TemporalConstraint Text.Text]
}
deriving (Ord, Eq, Show, Read, Generic)
deriving (Semigroup, Monoid) via Generically RuleBody

Expand Down
12 changes: 8 additions & 4 deletions mengwong/mp/test/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,21 @@ We parse this into a tree of rules; other rules are now welcome to refer to this
:TABLE_EXPORT_FORMAT: orgtbl-to-csv
:END:

Preambles include:
Preambles are:
- WHO
- WHEN
- IF
- UNLESS

*** Positional Preambles
*** Subject Qualifier BoolStructs

Preambles which occur immediately after the PARTY or EVERY line apply to the entity who is the subject of the rule.
Immediately after the PARTY or EVERY line, a single WHO preamble may appear, followed by a BoolStruct. The BoolStruct applies to the entity who is the subject of the rule.

Preambles which occur after the deontic apply generally -- they do not refer to the entity.
We have seen this form above.

*** General Boolstructs

Anywhere else in the stanza, a WHEN, IF, or UNLESS preamble, may appear, followed by a BoolStruct. Such BoolStructs apply generally -- they do not refer to the entity.

Below we use pilcrows to set off two stanzas which are identical but for permutation.

Expand Down

0 comments on commit 14c5d53

Please sign in to comment.