Compare commits
No commits in common. "7ae868932d5aa11df631a04b86e9293010610cec" and "82e1c76fe7f08baceda8a4e8283892c8ce03c3b8" have entirely different histories.
7ae868932d
...
82e1c76fe7
3 changed files with 313 additions and 320 deletions
35
src/Lexer.hs
35
src/Lexer.hs
|
|
@ -31,7 +31,7 @@ data Level
|
|||
|
||||
data Token
|
||||
= Token Text
|
||||
| Anchor Text
|
||||
| Anchor
|
||||
| BirdTrack
|
||||
| BoldOpen
|
||||
| BoldClose
|
||||
|
|
@ -54,7 +54,6 @@ data Token
|
|||
| MathsParenClose
|
||||
| MathsBracketOpen
|
||||
| MathsBracketClose
|
||||
| NumericEntity Int
|
||||
| Module
|
||||
| QuoteOpen
|
||||
| QuoteClose
|
||||
|
|
@ -168,33 +167,37 @@ anchors :: Lexer
|
|||
anchors = do
|
||||
pos <- getPosition
|
||||
void $ try anchor'
|
||||
pos' <- getPosition
|
||||
txt <- anyUntil anchor'
|
||||
pos'' <- getPosition
|
||||
void $ try anchor'
|
||||
|
||||
pure [(pos, Anchor txt)]
|
||||
pure
|
||||
[ (pos, Anchor)
|
||||
, (pos', Token txt)
|
||||
, (pos'', Anchor)
|
||||
]
|
||||
where
|
||||
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#anchor"
|
||||
-- "Module.Name\#anchor" -- this has been deprecated for 9 years, thanks Ben
|
||||
-- "Module.Name#anchor"
|
||||
modules :: Lexer
|
||||
modules = do
|
||||
startPos <- startPosition $ char '"'
|
||||
(modPos, modName) <- located modId
|
||||
pos <- getPosition
|
||||
void $ char '"'
|
||||
pos' <- getPosition
|
||||
modName <- modId
|
||||
anch <- option [] do
|
||||
anchPos <- startPosition (string "#" <|> string' "\\#")
|
||||
txt <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
||||
pure [(anchPos, Anchor txt)]
|
||||
pos'' <- getPosition
|
||||
void $ try (string "#" <|> string "\\#")
|
||||
pos''' <- getPosition
|
||||
a <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
||||
pure [(pos'', Anchor), (pos''', Token a)]
|
||||
|
||||
void $ char '"'
|
||||
pure $ [(startPos, Module), (modPos, Token modName)] <> anch
|
||||
pure $ [(pos, Module), (pos', Token modName)] <> anch
|
||||
where
|
||||
modId = intercalate "." <$> (fmap Text.pack <$> (conId `sepBy1` (char '.')))
|
||||
|
||||
|
|
|
|||
12
test/Spec.hs
12
test/Spec.hs
|
|
@ -51,14 +51,10 @@ modules = do
|
|||
"\"OtherModule.Name#myAnchor\""
|
||||
`shouldLexTo` [ (1, 1, Module)
|
||||
, (1, 2, Token "OtherModule.Name")
|
||||
, (1, 18, Anchor "myAnchor")
|
||||
, (1, 18, Anchor)
|
||||
, (1, 19, Token "myAnchor")
|
||||
]
|
||||
|
||||
"\"OtherModule.Name\\#myAnchor\""
|
||||
`shouldLexTo` [ (1, 1, Module)
|
||||
, (1, 2, Token "OtherModule.Name")
|
||||
, (1, 18, Anchor "myAnchor")
|
||||
]
|
||||
link :: Expectation
|
||||
link =
|
||||
"[link to](http://some.website)"
|
||||
|
|
@ -89,7 +85,9 @@ labeledLink =
|
|||
anchors :: Expectation
|
||||
anchors =
|
||||
"#myAnchor#"
|
||||
`shouldLexTo` [ (1, 1, Anchor "myAnchor")
|
||||
`shouldLexTo` [ (1, 1, Anchor)
|
||||
, (1, 2, Token "myAnchor")
|
||||
, (1, 10, Anchor)
|
||||
]
|
||||
|
||||
maths :: IO ()
|
||||
|
|
|
|||
|
|
@ -27,16 +27,8 @@ ftp\://example.com
|
|||
|
||||

|
||||
|
||||
\(mathematical 1+3 expression\)
|
||||
|
||||
\[mathematical
|
||||
expression
|
||||
accross lines with + addition and such
|
||||
\]
|
||||
|
||||
{
|
||||
e
|
||||
¥
|
||||
\(mathematical expression\)
|
||||
\[mathematical expression\]
|
||||
|
||||
@
|
||||
code block content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue