Applied more formatting; added Makefile #4
2 changed files with 275 additions and 273 deletions
|
|
@ -4,7 +4,8 @@ module Lexer (
|
|||
Token (..),
|
||||
lexer,
|
||||
emphasis,
|
||||
) where
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad (mfilter, void)
|
||||
import Data.Functor (($>))
|
||||
|
|
@ -17,6 +18,7 @@ import Text.Parsec qualified as Parsec
|
|||
import Text.Parsec.Pos (updatePosChar)
|
||||
|
||||
type Located a = (SourcePos, a)
|
||||
|
||||
type LocatedToken = (SourcePos, Token)
|
||||
|
||||
type Lexer = Parser [LocatedToken]
|
||||
|
|
@ -173,7 +175,6 @@ anchor = do
|
|||
x <- located $ between "#" "#" (Anchor <$> anyUntil "#")
|
||||
pure [x]
|
||||
|
||||
|
||||
moduleNames :: Parser Text
|
||||
moduleNames = intercalate "." . fmap Text.pack <$> upperId `sepBy1` char '.'
|
||||
|
||||
|
|
@ -228,7 +229,7 @@ labeledLink = do
|
|||
labelRes <- located $ Token <$> anyUntil ">"
|
||||
close <- located $ LabeledLinkClose <$ ">"
|
||||
pure $
|
||||
open : linkRes <> [ labelRes , close ]
|
||||
open : linkRes <> [labelRes, close]
|
||||
|
||||
mathMultiline :: Lexer
|
||||
mathMultiline = delimited "\\[" "\\]" MathMultilineOpen MathMultilineClose
|
||||
|
|
@ -302,6 +303,7 @@ scan ::
|
|||
Parser Text
|
||||
scan f initState = do
|
||||
parserState@State{stateInput = input, statePos = pos} <- Parsec.getParserState
|
||||
|
||||
(remaining, finalPos, ct) <- go input initState pos 0
|
||||
let newState = parserState{stateInput = remaining, statePos = finalPos}
|
||||
Parsec.setParserState newState $> Text.take ct input
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import Types
|
|||
|
||||
import Data.String (IsString (..))
|
||||
import Data.Text (Text)
|
||||
import Text.Parsec.Pos
|
||||
import GHC.Stack
|
||||
import Text.Parsec.Pos
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue