Skip to content

Commit

Permalink
preparing for inline aliases ("Aliases")
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Oct 20, 2021
1 parent 4c6eb86 commit cfde6dc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
5 changes: 3 additions & 2 deletions mengwong/mp/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pConstitutiveRule = debugName "pConstitutiveRule" $ do
myTraceM $ "pConstitutiveRule: matched defWord " ++ show defWord
myTraceM $ "pConstitutiveRule: \"" ++ Text.unpack term ++ "\" " ++ show defWord ++ "..."
(ands,rs) <- withDepth leftX dBoolRules -- (foo AND (bar OR baz), [constitutive and regulative sub-rules])
return $ Constitutive term ands Nothing : rs
return $ Constitutive term ands Nothing Nothing : rs

pRegRule :: Parser [Rule]
pRegRule = debugName "pRegRule" $ try pRegRuleSugary <|> pRegRuleNormal
Expand Down Expand Up @@ -354,7 +354,7 @@ pRegRuleSugary = debugName "pRegRuleSugary" $ do
(rbdeon rulebody)
(rbaction rulebody)
(rbtemporal rulebody)
Nothing Nothing Nothing
Nothing Nothing Nothing Nothing
myTraceM $ "pRegRuleSugary: the specifier is " ++ show who
myTraceM $ "pRegRuleSugary: returning " ++ show toreturn
myTraceM $ "pRegRuleSugary: with appendix brs = " ++ show brs
Expand Down Expand Up @@ -393,6 +393,7 @@ pRegRuleNormal = debugName "pRegRuleNormal" $ do
henceLimb
lestLimb
Nothing -- rule label
Nothing -- legal source
myTraceM $ "pRegRuleNormal: the specifier is " ++ show who
myTraceM $ "pRegRuleNormal: returning " ++ show toreturn
myTraceM $ "pRegRuleNormal: with appendix brs = " ++ show brs
Expand Down
17 changes: 12 additions & 5 deletions mengwong/mp/src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ data Rule = Regulative
, hence :: Maybe [Rule]
, lest :: Maybe [Rule]
, rlabel :: Maybe Text.Text
, lsource :: Maybe Text.Text
}
| Constitutive
{ term :: ConstitutiveTerm
, cond :: Maybe BoolStruct
, rlabel :: Maybe Text.Text
{ term :: ConstitutiveTerm
, cond :: Maybe BoolStruct
, rlabel :: Maybe Text.Text
, lsource :: Maybe Text.Text
}
| DefTermAlias -- inline alias, like some thing ("Thing")
{ term :: ConstitutiveTerm -- "Thing"
, detail :: Text.Text -- "some thing"
, nlhint :: Maybe Text.Text -- "lang=en number=singular"
}
| RegAlias Text.Text -- softlink to a regulative rule label
| ConAlias Text.Text -- softlink to a constitutive rule label
| RegAlias Text.Text -- internal softlink to a regulative rule label
| ConAlias Text.Text -- internal softlink to a constitutive rule label
deriving (Eq, Show)
-- everything is stringly typed at the moment but as this code matures these will become more specialized.
data TemporalConstraint a = TBefore a
Expand Down
9 changes: 9 additions & 0 deletions mengwong/mp/test/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,15 @@ do the individual components work?
| PARTY | King | |
| MAY | AFTER | 20min |
| -> | pay | |
*** party after may time
:PROPERTIES:
:TABLE_EXPORT_FILE: chained-regulatives-part1-alternative-3.csv
:TABLE_EXPORT_FORMAT: orgtbl-to-csv
:END:

| PARTY | King |
| AFTER | 20min |
| MAY | pay |

** simple natural language aliases
:PROPERTIES:
Expand Down
7 changes: 7 additions & 0 deletions mengwong/mp/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defaultReg = Regulative
, hence = Nothing
, lest = Nothing
, rlabel = Nothing
, lsource = Nothing
}

main :: IO ()
Expand Down Expand Up @@ -121,6 +122,7 @@ main = do
{ term = "degustates"
, cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ]
, rlabel = Nothing
, lsource = Nothing
}

it "should parse a simple constitutive rule" $ do
Expand All @@ -143,6 +145,7 @@ main = do
{ term = "degustates"
, cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ]
, rlabel = Nothing
, lsource = Nothing
}
]

Expand Down Expand Up @@ -219,6 +222,10 @@ main = do
mycsv <- BS.readFile "test/chained-regulatives-part1-alternative-2.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` king_pays_singer

it "should parse alternative deadline/action arrangement 3" $ do
mycsv <- BS.readFile "test/chained-regulatives-part1-alternative-3.csv"
parseR (pRule <* eof) "" (exampleStream mycsv) `shouldParse` king_pays_singer

-- upgrade single OR group to bypass the top level AND group


3 changes: 3 additions & 0 deletions mengwong/mp/test/chained-regulatives-part1-alternative-3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PARTY,King
AFTER,20min
MAY,pay

0 comments on commit cfde6dc

Please sign in to comment.