hxt-9.3.1.1: A collection of tools for processing XML with Haskell.

Portabilityportable
Stabilityexperimental
MaintainerUwe Schmidt (uwe@fh-wedel.de)
Safe HaskellSafe-Inferred

Text.XML.HXT.DTDValidation.RE

Description

A module for regular expression matching based on derivatives of regular expressions.

The code was taken from Joe English (http://www.flightlab.com/~joe/sgml/validate.html). Tested and extended by Martin Schmidt.

Further references for the algorithm:

Janusz A. Brzozowski.

Derivatives of Regular Expressions. Journal of the ACM, Volume 11, Issue 4, 1964.

Mark Hopkins.

Regular Expression Package. Posted to comp.compilers, 1994. Available per FTP at ftp://iecc.com/pub/file/regex.tar.gz.

Synopsis

Documentation

data RE a Source

Data type for regular expressions.

Constructors

RE_ZERO String 
RE_UNIT 
RE_SYM a 
RE_DOT 
RE_REP (RE a) 
RE_PLUS (RE a) 
RE_OPT (RE a) 
RE_SEQ (RE a) (RE a) 
RE_ALT (RE a) (RE a) 

Instances

Eq a => Eq (RE a) 
Show a => Show (RE a) 

re_unit :: RE aSource

Constructs a regular expression for an empty sequence.

  • returns : regular expression for an empty sequence

re_zero :: String -> RE aSource

Constructs a regular expression for an empty set.

  • 1.parameter errMsg : error message
  • returns : regular expression for an empty set

re_sym :: a -> RE aSource

Constructs a regular expression for accepting a symbol

  • 1.parameter sym : the symbol to be accepted
  • returns : regular expression for accepting a symbol

re_rep :: RE a -> RE aSource

Constructs an optional repetition (*) of a regular expression

  • 1.parameter re_a : regular expression to be repeted
  • returns : new regular expression

re_plus :: RE a -> RE aSource

Constructs a repetition (+) of a regular expression

  • 1.parameter re_a : regular expression to be repeted
  • returns : new regular expression

re_opt :: RE a -> RE aSource

Constructs an option (?) of a regular expression

  • 1.parameter re_a : regular expression to be optional
  • returns : new regular expression

re_seq :: RE a -> RE a -> RE aSource

Constructs a sequence (,) of two regular expressions

  • 1.parameter re_a : first regular expression in sequence
  • 2.parameter re_b : second regular expression in sequence
  • returns : new regular expression

re_alt :: RE a -> RE a -> RE aSource

Constructs an alternative (|) of two regular expressions

  • 1.parameter re_a : first regular expression of alternative
  • 2.parameter re_b : second regular expression of alternative
  • returns : new regular expression

re_dot :: RE aSource

Constructs a regular expression for accepting any singel symbol

  • returns : regular expression for accepting any singel symbol

checkRE :: Show a => RE a -> StringSource

Checks if an input matched a regular expression. The function should be called after matches.

Was the sentence used in matches in the language of the regular expression? -> matches e s == s `in` L(e)?

  • 1.parameter re : the derived regular expression
  • returns : empty String if input matched the regular expression, otherwise an error message is returned

matches :: (Eq a, Show a) => RE a -> [a] -> RE aSource

Derives a regular expression with respect to a sentence.

  • 1.parameter re : regular expression
  • 2.parameter s : sentence to which the regular expression is applied
  • returns : the derived regular expression

nullable :: Show a => RE a -> BoolSource

Checks if a regular expression matches the empty sequence.

nullable e == [] `in` L(e)

This check indicates if a regular expression fits to a sentence or not.

  • 1.parameter re : regular expression to be checked
  • returns : true if regular expression matches the empty sequence, otherwise false

printRE :: Show a => RE a -> StringSource

Constructs a string representation of a regular expression.

  • 1.parameter re : a regular expression
  • returns : the string representation of the regular expression