-
Notifications
You must be signed in to change notification settings - Fork 7
/
pcre.doc
67 lines (52 loc) · 2.08 KB
/
pcre.doc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
\documentclass[11pt]{article}
\usepackage{times}
\usepackage{pl}
\usepackage{html}
\sloppy
\makeindex
\onefile
\htmloutput{.} % Output directory
\htmlmainfile{pcre} % Main document file
\bodycolor{white} % Page colour
\begin{document}
\title{SWI-Prolog Regular Expression library}
\author{Jan Wielemaker and Peter Ludemann \\
VU University Amsterdam \\
The Netherlands \\
E-mail: \email{[email protected]}}
\maketitle
\begin{abstract}
The library \pllib{pcre} provides access to Perl Compatible Regular
Expressions.
\end{abstract}
\pagebreak
\tableofcontents
\vfill
\vfill
\newpage
\section{Motivation}
\label{sec:pcre-motivation}
The core facility for string matching in Prolog is provided by DCG
(\jargon{Definite Clause Grammars}). Using DCGs is typically more
verbose but gives reuse, modularity, readability and mixing with
arbitrary Prolog code in return. Supporting regular expressions has some
advantages: (1) in simple cases, the terse specification of a regular
expression is more comfortable; (2) many programmers are familar with
them; and (3) regular expressions are part of domain specific languages
one may wish to implement in Prolog, e.g., SPARQL.
There are roughly three options for adding regular expressions to
Prolog. One is to simply interpret them in Prolog. Given Prolog's
unification and backtracking facilities this is remarkable simple and
performs quite reasonably. Still, implementing all facilities of
modern regular expression engines requires significant effort.
Alternatively, we can \jargon{compile} them into DCGs. This brings terse
expressions to DCGs while staying in the same framework. The
disadvantage is that regular expressions become programs that are hard
to work with, making this approach less attractive for applications that
potentially execute many different regular expressions. The final option
is to wrap an existing regular expression engine. This provides access
to a robust implementation for which we only have to document the Prolog
binding. That is the option taken by library \pllib{pcre}.
\input{pcre4pl.tex}
\printindex
\end{document}