removed debug log and handled list newlines correctly, this was concerningly easy

This commit is contained in:
Pagwin 2025-12-13 16:11:16 -05:00
parent bdb14c3535
commit 132496cdca
No known key found for this signature in database
GPG key ID: 81137023740CA260
2 changed files with 26 additions and 3 deletions

View file

@ -63,7 +63,6 @@ element =
try htmlBlock <?> "HTML Block", try htmlBlock <?> "HTML Block",
paragraphBlock <?> "Paragarph" paragraphBlock <?> "Paragarph"
] ]
<* logDebug "element end"
<* blockEnding <* blockEnding
lineEnding :: (Logger m, Characters s, HasCallStack) => Parser s m () lineEnding :: (Logger m, Characters s, HasCallStack) => Parser s m ()
@ -162,12 +161,14 @@ listBlock list_type prefix child_parser_factory nest_level = do
pure $ List $ L {list_type, items} pure $ List $ L {list_type, items}
where where
listItem = do listItem = do
-- TODO
error "Need to handle newlines and not consuming blockEndings here due to nesting"
count nest_level ((try $ void $ char '\t') <|> (void $ (count 4 $ char ' '))) count nest_level ((try $ void $ char '\t') <|> (void $ (count 4 $ char ' ')))
prefix prefix
content <- many ((notFollowedBy lineEnding) *> inlineText' lineEnding) content <- many ((notFollowedBy lineEnding) *> inlineText' lineEnding)
optional ((notFollowedBy blockEnding) *> lineEnding)
child <- optional $ child_parser_factory $ nest_level + 1 child <- optional $ child_parser_factory $ nest_level + 1
pure $ LI {content, child} pure $ LI {content, child}
unorderedListBlock :: (Logger m, Characters s) => Int -> Parser s m Element unorderedListBlock :: (Logger m, Characters s) => Int -> Parser s m Element

View file

@ -40,6 +40,7 @@ main = do
("ordered_list", ordered_list), ("ordered_list", ordered_list),
("multiple_ordered_lists", multiple_ordered_lists), ("multiple_ordered_lists", multiple_ordered_lists),
("header_then_ordered_list", header_then_ordered_list), ("header_then_ordered_list", header_then_ordered_list),
("simple_nested_ordered_list", simple_nested_ordered_list),
("nested_unordered_list", nested_unordered_list) ("nested_unordered_list", nested_unordered_list)
-- ("",), -- ("",),
] ]
@ -222,6 +223,27 @@ multiple_ordered_lists = property $ do
(Just (Right tree)) -> fail $ "Incorrect syntax tree: " <> show tree (Just (Right tree)) -> fail $ "Incorrect syntax tree: " <> show tree
(Just (Left e)) -> fail $ errorBundlePretty e (Just (Left e)) -> fail $ errorBundlePretty e
simple_nested_ordered_list :: Property
simple_nested_ordered_list = property $ do
let text_gen = forAll $ Gen.text (Range.linear 1 10) Gen.alpha
item_1 <- text_gen
item_2 <- text_gen
let input = "1) " <> item_1 <> "\n 1) " <> item_2
parsed <- generic_parse input
case parsed of
Nothing -> fail $ "Hit Timeout"
( Just
( Right
( Doc
[ List (L {list_type = Ordered, items = [LI {content = [Text item_1], child = Just (L {list_type = Ordered, items = [LI {content = [Text item_2], child = Nothing}]})}]})
]
)
)
) -> success
(Just (Right tree)) -> fail $ "Incorrect syntax tree: " <> show tree
(Just (Left e)) -> fail $ errorBundlePretty e
-- - a -- - a
-- - a -- - a
-- - b -- - b