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