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
|
data Token
|
||||||
= Token Text
|
= Token Text
|
||||||
| Anchor Text
|
| Anchor
|
||||||
| BirdTrack
|
| BirdTrack
|
||||||
| BoldOpen
|
| BoldOpen
|
||||||
| BoldClose
|
| BoldClose
|
||||||
|
|
@ -54,7 +54,6 @@ data Token
|
||||||
| MathsParenClose
|
| MathsParenClose
|
||||||
| MathsBracketOpen
|
| MathsBracketOpen
|
||||||
| MathsBracketClose
|
| MathsBracketClose
|
||||||
| NumericEntity Int
|
|
||||||
| Module
|
| Module
|
||||||
| QuoteOpen
|
| QuoteOpen
|
||||||
| QuoteClose
|
| QuoteClose
|
||||||
|
|
@ -168,33 +167,37 @@ anchors :: Lexer
|
||||||
anchors = do
|
anchors = do
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
void $ try anchor'
|
void $ try anchor'
|
||||||
|
pos' <- getPosition
|
||||||
txt <- anyUntil anchor'
|
txt <- anyUntil anchor'
|
||||||
|
pos'' <- getPosition
|
||||||
void $ try anchor'
|
void $ try anchor'
|
||||||
|
|
||||||
pure [(pos, Anchor txt)]
|
pure
|
||||||
|
[ (pos, Anchor)
|
||||||
|
, (pos', Token txt)
|
||||||
|
, (pos'', Anchor)
|
||||||
|
]
|
||||||
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
|
-- "Module.Name#anchor"
|
||||||
modules :: Lexer
|
modules :: Lexer
|
||||||
modules = do
|
modules = do
|
||||||
startPos <- startPosition $ char '"'
|
pos <- getPosition
|
||||||
(modPos, modName) <- located modId
|
void $ char '"'
|
||||||
|
pos' <- getPosition
|
||||||
|
modName <- modId
|
||||||
anch <- option [] do
|
anch <- option [] do
|
||||||
anchPos <- startPosition (string "#" <|> string' "\\#")
|
pos'' <- getPosition
|
||||||
txt <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
void $ try (string "#" <|> string "\\#")
|
||||||
pure [(anchPos, Anchor txt)]
|
pos''' <- getPosition
|
||||||
|
a <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
||||||
|
pure [(pos'', Anchor), (pos''', Token a)]
|
||||||
|
|
||||||
void $ char '"'
|
void $ char '"'
|
||||||
pure $ [(startPos, Module), (modPos, Token modName)] <> anch
|
pure $ [(pos, Module), (pos', Token modName)] <> anch
|
||||||
where
|
where
|
||||||
modId = intercalate "." <$> (fmap Text.pack <$> (conId `sepBy1` (char '.')))
|
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\""
|
"\"OtherModule.Name#myAnchor\""
|
||||||
`shouldLexTo` [ (1, 1, Module)
|
`shouldLexTo` [ (1, 1, Module)
|
||||||
, (1, 2, Token "OtherModule.Name")
|
, (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 :: Expectation
|
||||||
link =
|
link =
|
||||||
"[link to](http://some.website)"
|
"[link to](http://some.website)"
|
||||||
|
|
@ -89,7 +85,9 @@ labeledLink =
|
||||||
anchors :: Expectation
|
anchors :: Expectation
|
||||||
anchors =
|
anchors =
|
||||||
"#myAnchor#"
|
"#myAnchor#"
|
||||||
`shouldLexTo` [ (1, 1, Anchor "myAnchor")
|
`shouldLexTo` [ (1, 1, Anchor)
|
||||||
|
, (1, 2, Token "myAnchor")
|
||||||
|
, (1, 10, Anchor)
|
||||||
]
|
]
|
||||||
|
|
||||||
maths :: IO ()
|
maths :: IO ()
|
||||||
|
|
|
||||||
|
|
@ -27,16 +27,8 @@ ftp\://example.com
|
||||||
|
|
||||||

|

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