refactor lexer #2

Merged
primrose merged 13 commits from primrose/haddock2:leana8959 into dev 2025-09-26 14:44:47 +00:00
2 changed files with 7 additions and 7 deletions
Showing only changes of commit c4d59d3236 - Show all commits

View file

@ -53,8 +53,8 @@ data Token
| BracketClose
| MathInlineOpen
| MathInlineClose
| MathsBracketOpen
| MathsBracketClose
| MathMultilineOpen
| MathMultilineClose
| NumericEntity Int
| Module Text
| QuoteOpen
@ -85,7 +85,7 @@ lexText = go
toks <-
choice $
Parsec.try
<$> [ mathsBracket
<$> [ mathMultiline
, mathInline
, escape -- maths go before escape to avoid mismatch
, headers
@ -242,8 +242,8 @@ labeledLink = do
, (pos8, LabeledLinkClose)
]
mathsBracket :: Lexer
mathsBracket = delimited "\\[" "\\]" MathsBracketOpen MathsBracketClose
mathMultiline :: Lexer
mathMultiline = delimited "\\[" "\\]" MathMultilineOpen MathMultilineClose
mathInline :: Lexer
mathInline = delimited "\\(" "\\)" MathInlineOpen MathInlineClose

❤️

❤️

View file

@ -93,9 +93,9 @@ anchors =
maths :: IO ()
maths = do
"\\[some math\\]"
`shouldLexTo` [ (1, 1, MathsBracketOpen)
`shouldLexTo` [ (1, 1, MathMultilineOpen)
, (1, 3, Token "some math")
, (1, 12, MathsBracketClose)
, (1, 12, MathMultilineClose)
]
"\\(other maths\\)"
`shouldLexTo` [ (1, 1, MathInlineOpen)