flex-tasks-0.0.0
Safe HaskellNone
LanguageHaskell2010

FlexTask.Generic.Parse

Description

Generic Parsing interface for submission types.

Synopsis

Documentation

class Parse a where Source #

Class for generic parsing of types. Bodyless instances can be declared for any type instancing Generic. Exception: Types with multiple constructors. Use utility functions for those or provide your own instance.

Minimal complete definition

Nothing

Methods

formParser :: Parser a Source #

default formParser :: (Generic a, GParse (Rep a)) => Parser a Source #

Instances

Instances details
Parse MultipleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse SingleChoiceSelection Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse Text Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse Textarea Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser Textarea Source #

Parse String Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse Integer Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse Bool Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse Double Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse Int Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Text) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Textarea) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList String) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Integer) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Bool) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Double) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse (SingleInputList Int) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse a => Parse (Maybe a) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Parse [String] Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

(TypeError ('Text "Parse instances for nested lists are not supported." ':$$: 'Text "Please use a newtype or custom datatype instead.") :: Constraint) => Parse [[a]] Source # 
Instance details

Defined in FlexTask.Generic.Parse

Methods

formParser :: Parser [[a]] Source #

Parse a => Parse [a] Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser [a] Source #

(Parse a, Parse b) => Parse (a, b) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser (a, b) Source #

(Parse a, Parse b, Parse c) => Parse (a, b, c) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser (a, b, c) Source #

(Parse a, Parse b, Parse c, Parse d) => Parse (a, b, c, d) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser (a, b, c, d) Source #

(Parse a, Parse b, Parse c, Parse d, Parse e) => Parse (a, b, c, d, e) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser (a, b, c, d, e) Source #

(Parse a, Parse b, Parse c, Parse d, Parse e, Parse f) => Parse (a, b, c, d, e, f) Source # 
Instance details

Defined in FlexTask.Generic.ParseInternal

Methods

formParser :: Parser (a, b, c, d, e, f) Source #

parseInstanceSingleChoice :: (Bounded a, Enum a, Eq a) => Parser a Source #

Parser for single choice answer of Enum types. Use as implementation of formParser for manual Parse instances. Intended for use with types such as

data MyType = One | Two | Three deriving (Bounded, Enum, Eq)

that can not use a bodyless Parse instance.

parseInstanceMultiChoice :: (Bounded a, Enum a, Eq a) => Parser [a] Source #

Same as parseInstanceSingleChoice, but for parsing a List of the given type, i.e. a multiple choice version.

parseInstanceSingleInputList :: Parser a -> Parser (SingleInputList a) Source #

Parser for a list of values inside a single input field. Takes a parser for individual list values. Please note that it must not use the escape function found in this module. Use as implementation of formParser for manual Parse instances. These instances are already provided for standard types as is.

escaped :: Parser a -> Parser a Source #

Parses FlexTask answer escape characters enclosing the input. Use this to wrap preexisting parsers that are used to parse a student solution. Otherwise your parser will fail on the escape characters. Parsers generated by Parse already consider the escaping and do not need to be wrapped.

parseWithOrReport :: forall (m :: Type -> Type) o a. (Monad m, OutputCapable (ReportT o m)) => Parser a -> (String -> ParseError -> LangM (ReportT o m)) -> String -> LangM' (ReportT o m) a Source #

Parses a String with the given parser and embeds the result into the OutputCapable interface. No value will be embedded in case of a ParseError. Instead, an error report is given then. That report is built using the second function argument. The report will automatically abort after displaying. It is therefore not necessary to include a refuse, but it is not harmful either. Adding a refuse will display text and cut off any following output as usual. This can be useful for giving better error messages.

reportWithFieldNumber :: forall (m :: Type -> Type). OutputCapable m => String -> ParseError -> LangM m Source #

Provide error report with positional information relative to an input form.

parseInfallibly :: Applicative m => Parser a -> String -> m a Source #

Parses a String with the given parser and embeds the result into the OutputCapable interface. Use when you know that there will be no error (e.g., when the parser used is formParser and the input form is "infallible" since only constructed from String text fields, single, multiple choice).

parseWithFallback Source #

Arguments

:: forall (m :: Type -> Type) o a. (Monad m, OutputCapable (ReportT o m)) 
=> Parser a

Parser to use initially

-> (String -> Maybe ParseError -> ParseError -> LangM (ReportT o m))

How to produce an error report based on: ^ 1. The input string ^ 2. The possible parse error of the fallback parser ^ 3. The original parse error

-> Parser ()

The secondary parser to use in case of a parse error. ^ Only used for generating possible further errors, thus does not return a value.

-> String

The input

-> LangM' (ReportT o m) a

The finished error report or embedded value

Parses a String with the given parser. Allows for further processing of a possible parse error. A second parser is used as a fallback in case of an error. The result of both parsers is then used to construct the report. Comments on refuse's behaviour for parseWithOrReport also apply for this function. This can be useful for giving more specific error messages, e.g. checking a term for bracket consistency even if the parser failed early on.

displayInputAnd :: forall (m :: Type -> Type) a. OutputCapable m => (Maybe a -> ParseError -> LangM m) -> String -> Maybe a -> ParseError -> LangM m Source #

Orphan instances

(TypeError ('Text "Parse instances for nested lists are not supported." ':$$: 'Text "Please use a newtype or custom datatype instead.") :: Constraint) => Parse [[a]] Source # 
Instance details

Methods

formParser :: Parser [[a]] Source #