Skip to content

Commit

Permalink
improve previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Oct 20, 2021
1 parent 4e80aaf commit f8ab21e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mengwong/mp/src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import qualified Data.Vector as V
import Generic.Data (Generic)
import Data.Vector ((!), (!?))
import Data.Maybe (fromMaybe, catMaybes)
import Text.Pretty.Simple (pPrint, pShow)
import Text.Pretty.Simple (pPrint)
import Control.Monad (guard, when, forM_)
import qualified AnyAll as AA
import qualified Text.PrettyPrint.Boxes as Box
Expand Down Expand Up @@ -329,8 +329,8 @@ pRule = withDepth 1 $ do
pConstitutiveRule :: Parser [Rule]
pConstitutiveRule = debugName "pConstitutiveRule" $ do
leftY <- lookAhead pYLocation
(term,termalias) <- pTermParens
checkDepth
(term,termalias) <- pTermParens
leftX <- lookAhead pXLocation -- this is the column where we expect IF/AND/OR etc.
defWord <- pToken Means <|> pToken Is <|> pToken Includes
myTraceM $ "pConstitutiveRule: matched defWord " ++ show defWord
Expand Down Expand Up @@ -389,7 +389,7 @@ pRegRuleNormal :: Parser [Rule]
pRegRuleNormal = debugName "pRegRuleNormal" $ do
leftX <- lookAhead pXLocation -- this is the column where we expect IF/AND/OR etc.
checkDepth
(_party_every, entitytype, _entityalias, defalias) <- pActor Party <|> pActor Every
(_party_every, entitytype, _entityalias, defalias) <- try (pActor Party) <|> pActor Every
-- (Who, (BoolStruct,[Rule]))
whoBool <- optional (withDepth leftX (preambleBoolRules [Who]))
-- the below are going to be permutables
Expand Down Expand Up @@ -446,20 +446,22 @@ pTemporal = ( do
-- "PARTY Bob (the "Seller")
-- "EVERY Seller"
pActor :: MyToken -> Parser (MyToken, Text.Text, Maybe Text.Text, [Rule])
pActor party = do
pActor party = debugName ("pActor " ++ show party) $ do
leftY <- lookAhead pYLocation
leftX <- lookAhead pXLocation -- this is the column where we expect IF/AND/OR etc.
-- add pConstitutiveRule here -- we could have "MEANS"
(entitytype, entityalias) <- lookAhead (pToken party *> pTermParens)
omgARule <- pConstitutiveRule <|> ([] <$ (pToken party *> pTermParens))
_ <- pToken party
(entitytype, entityalias) <- lookAhead pTermParens
omgARule <- try pConstitutiveRule <|> ([] <$ pTermParens)
myTraceM $ "pActor: omgARule = " ++ show omgARule
srcurl <- asks sourceURL
let srcref = SrcRef srcurl srcurl leftX leftY Nothing
let defalias = maybe [] (\t -> pure (DefTermAlias t entitytype Nothing (Just srcref))) entityalias
return (party, entitytype, entityalias, defalias ++ omgARule)

-- two tokens of the form | some thing | ("A Thing") | ; |
pTermParens :: Parser (Text.Text, Maybe Text.Text)
pTermParens = do
pTermParens = debugName "pTermParens" $ do
entitytype <- pOtherVal
entityalias <- optional pOtherVal -- TODO: add test here to see if the pOtherVal has the form ("xxx")
_ <- dnl
Expand Down
12 changes: 12 additions & 0 deletions mengwong/mp/test/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ do the individual components work?
| IF | the King wishes | | |
| -> | sing | | |

** qualifying person
:PROPERTIES:
:TABLE_EXPORT_FILE: qualifying-person.csv
:TABLE_EXPORT_FORMAT: orgtbl-to-csv
:END:

| EVERY | Qualifying Person | ("QP") | |
| | MEANS | walks | |
| | AND | eats | |
| MUST | | | |
| -> | sing | | |

** legislative source citations
:PROPERTIES:
:TABLE_EXPORT_FILE: source-citations.csv
Expand Down

0 comments on commit f8ab21e

Please sign in to comment.