From cfde6dcb285a0566238c21018caa2164e96509d6 Mon Sep 17 00:00:00 2001 From: Wong Meng Weng Date: Wed, 20 Oct 2021 22:07:28 +0800 Subject: [PATCH] preparing for inline aliases ("Aliases") --- mengwong/mp/src/Lib.hs | 5 +++-- mengwong/mp/src/Types.hs | 17 ++++++++++++----- mengwong/mp/test/README.org | 9 +++++++++ mengwong/mp/test/Spec.hs | 7 +++++++ .../chained-regulatives-part1-alternative-3.csv | 3 +++ 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 mengwong/mp/test/chained-regulatives-part1-alternative-3.csv diff --git a/mengwong/mp/src/Lib.hs b/mengwong/mp/src/Lib.hs index 1447f276..6f361bf0 100644 --- a/mengwong/mp/src/Lib.hs +++ b/mengwong/mp/src/Lib.hs @@ -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 @@ -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 @@ -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 diff --git a/mengwong/mp/src/Types.hs b/mengwong/mp/src/Types.hs index f6fe5cfd..258530b1 100644 --- a/mengwong/mp/src/Types.hs +++ b/mengwong/mp/src/Types.hs @@ -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 diff --git a/mengwong/mp/test/README.org b/mengwong/mp/test/README.org index b37ab13d..681d25f8 100644 --- a/mengwong/mp/test/README.org +++ b/mengwong/mp/test/README.org @@ -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: diff --git a/mengwong/mp/test/Spec.hs b/mengwong/mp/test/Spec.hs index 994882e0..1d2a39da 100644 --- a/mengwong/mp/test/Spec.hs +++ b/mengwong/mp/test/Spec.hs @@ -48,6 +48,7 @@ defaultReg = Regulative , hence = Nothing , lest = Nothing , rlabel = Nothing + , lsource = Nothing } main :: IO () @@ -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 @@ -143,6 +145,7 @@ main = do { term = "degustates" , cond = Just $ Any ( Pre "any of:" ) [ Leaf "eats", Leaf "drinks" ] , rlabel = Nothing + , lsource = Nothing } ] @@ -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 diff --git a/mengwong/mp/test/chained-regulatives-part1-alternative-3.csv b/mengwong/mp/test/chained-regulatives-part1-alternative-3.csv new file mode 100644 index 00000000..b0dae2fc --- /dev/null +++ b/mengwong/mp/test/chained-regulatives-part1-alternative-3.csv @@ -0,0 +1,3 @@ +PARTY,King +AFTER,20min +MAY,pay