Skip to content

Commit

Permalink
some bugfixes around gluing chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
mengwong committed Oct 20, 2021
1 parent 381de0f commit b3b4b4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 6 additions & 5 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)
import Text.Pretty.Simple (pPrint, pShow)
import Control.Monad (guard, when, forM_)
import qualified AnyAll as AA
import qualified Text.PrettyPrint.Boxes as Box
Expand Down Expand Up @@ -151,7 +151,7 @@ getStanzas esa = do
rs <- esa
let chunks = getChunks $ Location rs (0,0) ((0,0),(V.length (rs ! (V.length rs - 1)) - 1, V.length rs - 1))
toreturn = extractRange <$> glueChunks chunks
-- traceM ("getStanzas: extracted range " ++ show toreturn)
traceM ("getStanzas: extracted range " ++ (Text.unpack $ pShow toreturn))
return toreturn

-- because sometimes a chunk followed by another chunk is really part of the same chunk.
Expand All @@ -176,9 +176,9 @@ getChunks loc@(Location rs (_cx,_cy) ((_lx,_ly),(_rx,ry))) =
, any (\row ->
V.any (\w -> w `elem` Text.words "EVERY PARTY MUST MAY WHEN INCLUDES MEANS IS IF UNLESS")
(rs ! row)
||
V.all Text.null (rs ! row)
)
) rows
||
all (\row -> V.all Text.null (rs ! row))
rows
]
toreturn = setRange loc <$> wantedChunks
Expand Down Expand Up @@ -322,6 +322,7 @@ pRule = withDepth 1 $ do
_ <- optional dnl
try (pRegRule <?> "regulative rule")
<|> (pConstitutiveRule <?> "constitutive rule")
<|> (eof >> return [])

pConstitutiveRule :: Parser [Rule]
pConstitutiveRule = debugName "pConstitutiveRule" $ do
Expand Down
20 changes: 12 additions & 8 deletions mengwong/mp/test/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,18 @@ do the individual components work?
:TABLE_EXPORT_FORMAT: orgtbl-to-csv
:END:

| EVERY | person | ("singer") | |
| WHO | walks | | |
| AND | eats | | |
| MUST | | | |
| | | | |
| | | | |
| IF | the King wishes | | |
| -> | sing | | |
| | | | |
| A paragraph with irrelevant text should be ignored. | | Like so. | |
| | | | |
| | | | |
| EVERY | person | ("singer") | |
| WHO | walks | | |
| AND | eats | | |
| MUST | | | |
| | | | |
| | | | |
| IF | the King wishes | | |
| -> | sing | | |

** legislative source citations
:PROPERTIES:
Expand Down
4 changes: 4 additions & 0 deletions mengwong/mp/test/blank-lines.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
,,,
A paragraph with irrelevant text should be ignored.,,Like so.,
,,,
,,,
EVERY,person,"(""singer"")",
WHO,walks,,
AND,eats,,
Expand Down

0 comments on commit b3b4b4f

Please sign in to comment.