From 368e5bc9a0eb923ee2c79d59d7b6cafff3093cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Wed, 24 Sep 2025 20:25:48 +0800 Subject: [PATCH] ref(lexer): simplify anchor --- src/Lexer.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Lexer.hs b/src/Lexer.hs index 31f3ac0..d89ad53 100644 --- a/src/Lexer.hs +++ b/src/Lexer.hs @@ -152,6 +152,9 @@ delimitedSymmetric s t1 t2 = delimited s s t1 t2 eol :: Parser () eol = void "\n" <|> void "\r\n" <|> Parsec.eof +anchorHash :: Parser Text +anchorHash = "#" <|> try "\\#" + header1 :: Lexer header1 = delimitedNoTrailing "= " eol (Header One) @@ -172,15 +175,10 @@ header6 = delimitedNoTrailing "====== " eol (Header Six) -- #anchors# anchors :: Lexer -anchors = do - pos <- getPosition - void $ try anchor' - txt <- anyUntil anchor' - void $ try anchor' - - pure [(pos, Anchor txt)] - where - anchor' = (string "#" <|> string "\\#") +anchors = + tokenise + [ between anchorHash anchorHash (Anchor <$> anyUntil anchorHash) + ] -- "Module.Name" -- "Module.Name#anchor"