curry-base-1.1.1: Functions for manipulating Curry programs

Copyright(c) 1999 - 2004 Wolfgang Lux
2012 - 2013 Björn Peemöller
2016 Jan Tikovsky
LicenseBSD-3-clause
Maintainerbjp@informatik.uni-kiel.de
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Curry.Base.LexComb

Contents

Description

This module provides the basic types and combinators to implement the lexers. The combinators use continuation passing code in a monadic style.

The first argument of the continuation function is the current span, and the second is the string to be parsed. The third argument is a flag which signals the lexer that it is lexing the beginning of a line and therefore has to check for layout tokens. The fourth argument is a stack of indentations that is used to handle nested layout groups.

Synopsis

Types

class (Ord s, Show s) => Symbol s where Source #

Type class for symbols

Methods

isEOF :: s -> Bool Source #

Does the Symbol represent the end of the input?

dist :: Int -> s -> Distance Source #

Compute the distance of a Symbol

Instances
Symbol Token Source # 
Instance details

Defined in Curry.Syntax.Lexer

type Indent = Int Source #

Type for indentations, necessary for the layout rule

type Context = [Indent] Source #

Type of context for representing layout grouping

type P a Source #

Arguments

 = Span

Current source code span

-> String

String to be parsed

-> Bool

Flag whether the beginning of a line should be parsed, which requires layout checking

-> Context

context as a stack of Indents

-> CYM a 

Basic lexer function

type CYM a = CYT Identity a Source #

Pure Curry compiler monad

type SuccessP s a = Span -> s -> P a Source #

success continuation

type FailP a = Span -> String -> P a Source #

failure continuation

type Lexer s a = SuccessP s a -> FailP a -> P a Source #

A CPS lexer

Monadic functions

parse :: P a -> FilePath -> String -> CYM a Source #

Apply a lexer on a String to lex the content. The second parameter requires a FilePath to use in the Span

applyLexer :: Symbol s => Lexer s [(Span, s)] -> P [(Span, s)] Source #

Apply a lexer

returnP :: a -> P a Source #

Lift a value into the lexer type

thenP :: P a -> (a -> P b) -> P b infixl 1 Source #

Apply the first lexer and then apply the second one, based on the result of the first lexer.

thenP_ :: P a -> P b -> P b infixl 1 Source #

Apply the first lexer and then apply the second one, ignoring the first result.

failP :: Span -> String -> P a Source #

Fail to lex on a Span, given an error message

warnP :: Span -> String -> P a -> P a Source #

Warn on a Span, given a warning message

liftP :: (a -> b) -> P a -> P b Source #

Apply a pure function to the lexers result

closeP0 :: P a -> P (P a) Source #

Lift a lexer into the P monad, returning the lexer when evaluated.

closeP1 :: (a -> P b) -> P (a -> P b) Source #

Lift a lexer-generating function into the P monad, returning the function when evaluated.

Combinators for layout handling

pushContext :: Indent -> P a -> P a Source #

Push an Indent to the context, increasing the levels of indentation

popContext :: P a -> P a Source #

Pop an Indent from the context, decreasing the levels of indentation

Conversion of numbers

convertSignedIntegral :: Num a => a -> String -> a Source #

Convert a String into a signed intergral using a given base

convertSignedFloating :: Fractional a => String -> String -> Int -> a Source #

Convert a mantissa, a fraction part and an exponent into a signed floating value

convertIntegral :: Num a => a -> String -> a Source #

Convert a String into an unsigned intergral using a given base

convertFloating :: Fractional a => String -> String -> Int -> a Source #

Convert a mantissa, a fraction part and an exponent into an unsigned floating value