LayeredHaskell-0.1.0.0: A friendly layered implementation of a subset of Haskell.
Copyright(c) Hangil Kim 2026
Kairon Johnson 2026
Leonidas Sallos 2026
Oscar Abelanet 2026
LicenseMIT
Maintainerkimhang@oregonstate.edu
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

LH.Text.Parser.Monad

Description

This module provides the parser monad for Layered Haskell. Consequently, it includes definitions for a custom Alex wrapper and a representation of errors and state.

Synopsis

A wrapper for Alex

data AlexInput Source #

A representation of the current state of the input stream being tokenized.

Constructors

AlexInput 

Fields

alexGetByte :: AlexInput -> Maybe (Word8, AlexInput) Source #

Fetches the next byte from the input and returns an updated input.

alexInputPrevChar :: AlexInput -> Char Source #

Returns the character previously read from the input.

The parser monad

newtype LHsParser a Source #

A parser monad with state (LHsState) and errors (LHsTextError).

Instances

Instances details
Applicative LHsParser Source # 
Instance details

Defined in LH.Text.Parser.Monad

Methods

pure :: a -> LHsParser a #

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

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

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

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

Functor LHsParser Source # 
Instance details

Defined in LH.Text.Parser.Monad

Methods

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

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

Monad LHsParser Source # 
Instance details

Defined in LH.Text.Parser.Monad

Methods

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

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

return :: a -> LHsParser a #

MonadError LHsTextError LHsParser Source # 
Instance details

Defined in LH.Text.Parser.Monad

MonadState LHsState LHsParser Source # 
Instance details

Defined in LH.Text.Parser.Monad

runLHsParser :: LHsParser a -> Text -> Either LHsTextError a Source #

Runs a LHsParser against an input Text.

State

data LHsState Source #

The parser state, which keeps track of the current input and two stacks.

Constructors

LHsState 

Fields

Instances

Instances details
MonadState LHsState LHsParser Source # 
Instance details

Defined in LH.Text.Parser.Monad

getInput :: LHsParser AlexInput Source #

Retrieves the current input.

setInput :: AlexInput -> LHsParser () Source #

Sets the current input.

Startcodes

data LHsStcd Source #

A startcode paired with the position at which it was pushed onto the stack.

Constructors

LHsStcd !Int !LHsPos 

getStcd :: LHsParser Int Source #

Retrieves the current startcode.

pushStcd :: Int -> LHsPos -> LHsParser () Source #

Pushes a startcode onto the stack.

popStcd :: LHsParser () Source #

Pops the current startcode from the stack.

Layout

getInnermostLayout :: LHsParser (Maybe Int) Source #

Retrieves the column of the innermost open layout block, if present.

pushLayout :: Int -> LHsParser () Source #

Pushes a column of an open layout block onto the stack.

popLayout :: LHsParser () Source #

Pops a column of an open layout block from the stack.

Errors

data LHsTextError Source #

A text-related error emitted by the lexer or parser.

Constructors

LexicalError !LHsPos !Text

A lexical error emitted by Alex.

UnclosedComment !LHsPos

An unclosed multi-line comment error emitted by Alex.

ParseError !LHsSpan !LHsToken

A parse error emitted by Happy. The first argument indicates where an unexpected token starts and ends in the source.