miso
Copyright(C) 2016-2025 David M. Johnson (@dmjio)
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Util.Lexer

Description

 
Synopsis

Types

newtype Lexer token Source #

A Lexer is a state monad with optional failure the abides by the maximal munch rule in its Alternative instance.

Constructors

Lexer 

Fields

Instances

Instances details
Alternative Lexer Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

empty :: Lexer a #

(<|>) :: Lexer a -> Lexer a -> Lexer a #

some :: Lexer a -> Lexer [a] #

many :: Lexer a -> Lexer [a] #

Applicative Lexer Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

pure :: a -> Lexer a #

(<*>) :: Lexer (a -> b) -> Lexer a -> Lexer b #

liftA2 :: (a -> b -> c) -> Lexer a -> Lexer b -> Lexer c #

(*>) :: Lexer a -> Lexer b -> Lexer b #

(<*) :: Lexer a -> Lexer b -> Lexer a #

Functor Lexer Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

fmap :: (a -> b) -> Lexer a -> Lexer b #

(<$) :: a -> Lexer b -> Lexer a #

Monad Lexer Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

(>>=) :: Lexer a -> (a -> Lexer b) -> Lexer b #

(>>) :: Lexer a -> Lexer b -> Lexer b #

return :: a -> Lexer a #

MonadPlus Lexer Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

mzero :: Lexer a #

mplus :: Lexer a -> Lexer a -> Lexer a #

data Stream Source #

A Stream of text used as input to lexing

Constructors

Stream 

Fields

Instances

Instances details
Eq Stream Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

(==) :: Stream -> Stream -> Bool #

(/=) :: Stream -> Stream -> Bool #

data Located token Source #

A Located token holds the lexed output the Location at which the successful lex occurred.

Constructors

Located 

Fields

Instances

Instances details
Show token => Show (Located token) Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

showsPrec :: Int -> Located token -> ShowS #

show :: Located token -> String #

showList :: [Located token] -> ShowS #

Eq token => Eq (Located token) Source # 
Instance details

Defined in Miso.Util.Lexer

Methods

(==) :: Located token -> Located token -> Bool #

(/=) :: Located token -> Located token -> Bool #

data Location Source #

Type to hold the location (line and column) of a Token

Constructors

Location 

Fields

Instances

Instances details
Show Location Source # 
Instance details

Defined in Miso.Util.Lexer

Eq Location Source # 
Instance details

Defined in Miso.Util.Lexer

data LexerError Source #

Potential errors during lexing

Instances

Instances details
Show LexerError Source # 
Instance details

Defined in Miso.Util.Lexer

Eq LexerError Source # 
Instance details

Defined in Miso.Util.Lexer

Combinators

getStartColumn :: Location -> Int Source #

Helper for extracting column from Location

mkStream :: MisoString -> Stream Source #

Smart constructor for Stream

oops :: Lexer token Source #

Combinator that always fails to lex

streamError :: Stream -> LexerError Source #

Smart constructor for LexerError

string :: MisoString -> Lexer MisoString Source #

Lexer combinator for matching a MisoString

string' :: String -> Lexer String Source #

Lexer combinator for matching a String

char :: Char -> Lexer Char Source #

Lexer combinator for matching a Char

satisfy :: (Char -> Bool) -> Lexer Char Source #

Predicate combinator that consumes matching input

peek :: Lexer (Maybe Char) Source #

Fetches the first character in the Stream, does not consume input

getInput :: Lexer Stream Source #

Retrieves current input from Lexer

putInput :: Stream -> Lexer () Source #

Overrides current Stream in Lexer to user-specified Stream.

getLocation :: Lexer Location Source #

Retrieves the current Stream Location

setLocation :: Location -> Lexer () Source #

Sets the current Stream Location

modifyInput :: (Stream -> Stream) -> Lexer () Source #

Modifies a Stream

withLocation :: ToMisoString token => Lexer token -> Lexer (Located token) Source #

Lexer combinator for executing a Lexer with annotated Location information