forked from elland/haddock2
Add located combinator; improved anchor matches with tests
This commit is contained in:
parent
8887476626
commit
7ae868932d
2 changed files with 18 additions and 9 deletions
22
src/Lexer.hs
22
src/Lexer.hs
|
|
@ -175,22 +175,26 @@ anchors = do
|
||||||
where
|
where
|
||||||
anchor' = (string "#" <|> string "\\#")
|
anchor' = (string "#" <|> string "\\#")
|
||||||
|
|
||||||
|
located :: Parser a -> Parser (SourcePos, a)
|
||||||
|
located p = (,) <$> getPosition <*> p
|
||||||
|
|
||||||
|
startPosition :: Parser a -> Parser SourcePos
|
||||||
|
startPosition = fmap fst . located
|
||||||
|
|
||||||
-- "Module.Name"
|
-- "Module.Name"
|
||||||
-- "Module.Name#anchor"
|
-- "Module.Name#anchor"
|
||||||
|
-- "Module.Name\#anchor" -- this has been deprecated for 9 years, thanks Ben
|
||||||
modules :: Lexer
|
modules :: Lexer
|
||||||
modules = do
|
modules = do
|
||||||
pos <- getPosition
|
startPos <- startPosition $ char '"'
|
||||||
void $ char '"'
|
(modPos, modName) <- located modId
|
||||||
pos' <- getPosition
|
|
||||||
modName <- modId
|
|
||||||
anch <- option [] do
|
anch <- option [] do
|
||||||
pos'' <- getPosition
|
anchPos <- startPosition (string "#" <|> string' "\\#")
|
||||||
void $ try (string "#" <|> string "\\#")
|
txt <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
||||||
a <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
pure [(anchPos, Anchor txt)]
|
||||||
pure [(pos'', Anchor a)]
|
|
||||||
|
|
||||||
void $ char '"'
|
void $ char '"'
|
||||||
pure $ [(pos, Module), (pos', Token modName)] <> anch
|
pure $ [(startPos, Module), (modPos, Token modName)] <> anch
|
||||||
where
|
where
|
||||||
modId = intercalate "." <$> (fmap Text.pack <$> (conId `sepBy1` (char '.')))
|
modId = intercalate "." <$> (fmap Text.pack <$> (conId `sepBy1` (char '.')))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,11 @@ modules = do
|
||||||
, (1, 18, Anchor "myAnchor")
|
, (1, 18, Anchor "myAnchor")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
"\"OtherModule.Name\\#myAnchor\""
|
||||||
|
`shouldLexTo` [ (1, 1, Module)
|
||||||
|
, (1, 2, Token "OtherModule.Name")
|
||||||
|
, (1, 18, Anchor "myAnchor")
|
||||||
|
]
|
||||||
link :: Expectation
|
link :: Expectation
|
||||||
link =
|
link =
|
||||||
"[link to](http://some.website)"
|
"[link to](http://some.website)"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue