Module RegExp

A library to defines a structure of regular expressions and a simple match operation for regular expressions. This library is used to translate integrated code in the form of POSIX extended regular expressions into Curry programs. It is based on the bachelor thesis "Foreign Code Integration in Curry" of Jasper Sikorra (March 2014).

Author: Corinna Wambsganz

Version: October 2022

Summary of exported operations:

eps :: [Int] -> [ORegExp a]  Deterministic 
ε
literal :: [Int] -> a -> [ORegExp a]  Deterministic 
a
alt :: [Int] -> [ORegExp a] -> [ORegExp a] -> [ORegExp a]  Deterministic 
α|β
conc :: [Int] -> [ORegExp a] -> [ORegExp a] -> [ORegExp a]  Deterministic 
αβ
rep :: [Int] -> [ORegExp a] -> [ORegExp a]  Deterministic 
α*
pl :: [Int] -> [ORegExp a] -> [ORegExp a]  Deterministic 
α⁺
anyL :: [Int] -> [ORegExp a]  Deterministic 
_
bracket :: [Int] -> [Either a (a,a)] -> [ORegExp a]  Deterministic 
[as]
negBracket :: [Int] -> [Either a (a,a)] -> [ORegExp a]  Deterministic 
[^as]
start :: [Int] -> [ORegExp a] -> Bool -> [ORegExp a]  Deterministic 
end :: [Int] -> [ORegExp a] -> Bool -> [ORegExp a]  Deterministic 
α$
times :: [Int] -> Int -> Int -> [ORegExp a] -> [ORegExp a]  Deterministic 
α{n,m}
captureG :: Int -> [ORegExp a] -> [ORegExp a]  Deterministic 
/(α)/
grepPos :: (Data a, Ord a) => [ORegExp a] -> [a] -> Int  Non-deterministic 
The operation grepPos returns the first starting position of a substring which matches the regular expression.
grep :: (Data a, Ord a) => [ORegExp a] -> [a] -> [Int]  Non-deterministic 
The operation grep returns a list with starting positions of substrings that match the regular expression.
grepShow :: (Data a, Ord a) => [ORegExp a] -> [a] -> [[a]]  Non-deterministic 
The operation grepShow returns a list of substrings that match the regular expression.
grepShowUnique :: (Data a, Ord a) => [ORegExp a] -> [a] -> [[a]]  Non-deterministic 
As grepShow but without duplicated elements.
match :: (Data a, Ord a) => [ORegExp a] -> [a] -> Bool  Non-deterministic 
The match function is used to match lists with regular expressions
capture :: (Data a, Ord a) => [ORegExp a] -> [a] -> [(Int,[[a]])]  Non-deterministic 
The operation capture is used to return capture groups.

Exported datatypes:


RegExp

Data type for regex representation in Curry.

Type synonym: RegExp a = [ORegExp a]


ORegExp

Constructors:

  • Nil :: ORegExp a
  • Literal :: a -> ORegExp a
  • Xor :: (RegExp a) -> (RegExp a) -> ORegExp a
  • Star :: (RegExp a) -> ORegExp a
  • Plus :: (RegExp a) -> ORegExp a
  • AnyLiteral :: ORegExp a
  • Bracket :: [Either a (a,a)] -> ORegExp a
  • NegBracket :: [Either a (a,a)] -> ORegExp a
  • Start :: (RegExp a) -> ORegExp a
  • End :: (RegExp a) -> ORegExp a
  • Times :: (Int,Int) -> (RegExp a) -> ORegExp a
  • Capture :: Int -> (RegExp a) -> ORegExp a

Exported operations:

eps :: [Int] -> [ORegExp a]  Deterministic 

ε

Further infos:
  • solution complete, i.e., able to compute all solutions

literal :: [Int] -> a -> [ORegExp a]  Deterministic 

a

Further infos:
  • solution complete, i.e., able to compute all solutions

alt :: [Int] -> [ORegExp a] -> [ORegExp a] -> [ORegExp a]  Deterministic 

α|β

Further infos:
  • solution complete, i.e., able to compute all solutions

conc :: [Int] -> [ORegExp a] -> [ORegExp a] -> [ORegExp a]  Deterministic 

αβ

Further infos:
  • solution complete, i.e., able to compute all solutions

rep :: [Int] -> [ORegExp a] -> [ORegExp a]  Deterministic 

α*

Further infos:
  • solution complete, i.e., able to compute all solutions

pl :: [Int] -> [ORegExp a] -> [ORegExp a]  Deterministic 

α⁺

Further infos:
  • solution complete, i.e., able to compute all solutions

anyL :: [Int] -> [ORegExp a]  Deterministic 

_

Further infos:
  • solution complete, i.e., able to compute all solutions

bracket :: [Int] -> [Either a (a,a)] -> [ORegExp a]  Deterministic 

[as]

Further infos:
  • solution complete, i.e., able to compute all solutions

negBracket :: [Int] -> [Either a (a,a)] -> [ORegExp a]  Deterministic 

[^as]

Further infos:
  • solution complete, i.e., able to compute all solutions

start :: [Int] -> [ORegExp a] -> Bool -> [ORegExp a]  Deterministic 

Further infos:
  • solution complete, i.e., able to compute all solutions

end :: [Int] -> [ORegExp a] -> Bool -> [ORegExp a]  Deterministic 

α$

Further infos:
  • solution complete, i.e., able to compute all solutions

times :: [Int] -> Int -> Int -> [ORegExp a] -> [ORegExp a]  Deterministic 

α{n,m}

Further infos:
  • solution complete, i.e., able to compute all solutions

captureG :: Int -> [ORegExp a] -> [ORegExp a]  Deterministic 

/(α)/

Further infos:
  • solution complete, i.e., able to compute all solutions

grepPos :: (Data a, Ord a) => [ORegExp a] -> [a] -> Int  Non-deterministic 

The operation grepPos returns the first starting position of a substring which matches the regular expression.

Example call:
(grepPos r s)
Parameters:
  • r : The regular expression
  • s : The input list

grep :: (Data a, Ord a) => [ORegExp a] -> [a] -> [Int]  Non-deterministic 

The operation grep returns a list with starting positions of substrings that match the regular expression.

Example call:
(grep r s)
Parameters:
  • r : The regular expression
  • s : The input list

grepShow :: (Data a, Ord a) => [ORegExp a] -> [a] -> [[a]]  Non-deterministic 

The operation grepShow returns a list of substrings that match the regular expression.

Example call:
(grepShow r s)
Parameters:
  • r : The regular expression
  • s : The input list
Returns:
l - The list of substrings from s that match r

grepShowUnique :: (Data a, Ord a) => [ORegExp a] -> [a] -> [[a]]  Non-deterministic 

As grepShow but without duplicated elements.

match :: (Data a, Ord a) => [ORegExp a] -> [a] -> Bool  Non-deterministic 

The match function is used to match lists with regular expressions

Example call:
(match r s)
Parameters:
  • r : The regular expression
  • s : The input list

capture :: (Data a, Ord a) => [ORegExp a] -> [a] -> [(Int,[[a]])]  Non-deterministic 

The operation capture is used to return capture groups. The capture group with number 0 is always the complete string.

Example call:
(capture r s)
Parameters:
  • r : The regular expression
  • s : The input list