parsley-core-2.3.0.0: A fast parser combinator library backed by Typed Template Haskell
LicenseBSD-3-Clause
MaintainerJamie Willis
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Parsley.Internal.Core.CharPred

Description

This module contains CharPred, a specialised defunctionalising for Char -> Bool functions. This can be used to efficiently query for character class membership.

Since: 2.1.0.0

Synopsis

Documentation

data CharPred where Source #

Represents Char -> Bool functions, potentially in a more inspectable way.

Since: 2.1.0.0

Constructors

UserPred :: (Char -> Bool) -> Lam (Char -> Bool) -> CharPred

This is a raw user-defined predicate, with little inspectability other than membership.

Ranges :: RangeSet Char -> CharPred

This accounts for a character-class, implemented using a RangeSet for efficient querying and space.

Instances

Instances details
Show CharPred Source # 
Instance details

Defined in Parsley.Internal.Core.CharPred

pattern Item :: CharPred Source #

Represents const True.

Since: 2.1.0.0

pattern Specific :: Char -> CharPred Source #

Represents (== c) for some specific c.

Since: 2.1.0.0

apply :: CharPred -> Char -> Bool Source #

Tests whether a given character falls within the predicate.

Since: 2.1.0.0

andPred :: CharPred -> CharPred -> CharPred Source #

Merges two predicates by creating one which only returns true when a character is in both original predicates.

Since: 2.1.0.0

orPred :: CharPred -> CharPred -> CharPred Source #

Merges two predicates by creating one which only returns true when a character is in either of the original predicates.

Since: 2.1.0.0

diffPred :: CharPred -> CharPred -> CharPred Source #

Merges two predicates by creating one which only returns true when a character is in the first but not the second predicate.

Since: 2.1.0.0

optimisePredGiven Source #

Arguments

:: CharPred

A predicate to be optimised with previous given knowledge.

-> CharPred

A predicate that is known to already be true.

-> CharPred 

Occasionally, characters can pass through a predicate only to pass through another at a later point. This given information can be used to optimise the new predicate the character is fed through.

This works as follows:

  • If the given knowledge is a subset of the new predicate, then we know that any character check will have passed, because it already passed a stricter check. The predicate can, therefore, be optimised to Item.
  • Otherwise, the character can only pass through both predicates if it can pass through their intersection. If the intersection is smaller (in terms of the number of checks required to establish membership), then it should be used as it generates smaller code.
  • If neither of the above conditions are true, then the original predicate remains the most efficient for future tests.

Since: 2.1.0.0

members :: CharPred -> [Char] Source #

Given a predicate, returns the full range of characters it returns True for.

Since: 2.1.0.0

nonMembers :: CharPred -> [Char] Source #

Given a predicate, returns the full range of characters it returns False for.

Since: 2.1.0.0

lamTerm :: CharPred -> Lam (Char -> Bool) Source #

Converts this predicate into a Lam term represention. This representation can be optimised.

Since: 2.1.0.0