ref(lexer): simplify anchor

This commit is contained in:
Primrose 2025-09-24 20:25:48 +08:00
parent 064e253f03
commit c956c97e0c
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -152,6 +152,9 @@ delimitedSymmetric s t1 t2 = delimited s s t1 t2
eol :: Parser () eol :: Parser ()
eol = void "\n" <|> void "\r\n" <|> Parsec.eof eol = void "\n" <|> void "\r\n" <|> Parsec.eof
anchorHash :: Parser Text
anchorHash = "#" <|> try "\\#"
header1 :: Lexer header1 :: Lexer
header1 = delimitedNoTrailing "= " eol (Header One) header1 = delimitedNoTrailing "= " eol (Header One)
@ -172,15 +175,10 @@ header6 = delimitedNoTrailing "====== " eol (Header Six)
-- #anchors# -- #anchors#
anchors :: Lexer anchors :: Lexer
anchors = do anchors =
pos <- getPosition tokenise
void $ try anchor' [ between anchorHash anchorHash (Anchor <$> anyUntil anchorHash)
txt <- anyUntil anchor' ]
void $ try anchor'
pure [(pos, Anchor txt)]
where
anchor' = (string "#" <|> string "\\#")
-- "Module.Name" -- "Module.Name"
-- "Module.Name#anchor" -- "Module.Name#anchor"