1 | [section Preface] |
---|
2 | |
---|
3 | [:['Wife:] It's a floor wax!\n |
---|
4 | ['Husband:] No, it's a dessert topping!\n |
---|
5 | ['Announcer:] Stop! You're both right. It's a floor wax ['and] a dessert topping!] |
---|
6 | [:[*['-- Saturday Night Live]]] |
---|
7 | |
---|
8 | [h2 Description] |
---|
9 | |
---|
10 | xpressive is an advanced, object-oriented regular expression template library for C++. |
---|
11 | Regular expressions can be written as strings that are parsed at run-time, or as expression |
---|
12 | templates that are parsed at compile-time. Regular expressions can refer to each other and |
---|
13 | to themselves recursively, allowing you to build arbitrarily complicated grammars out of |
---|
14 | them. |
---|
15 | |
---|
16 | [h2 Motivation] |
---|
17 | |
---|
18 | If you need to manipulate text in C++, you have typically had two disjoint options: a regular |
---|
19 | expression engine or a parser generator. Regular expression engines (like _regexpp_) are powerful |
---|
20 | and flexible; patterns are represented as strings which can be specified at runtime. However, |
---|
21 | that means that syntax errors are likewise not detected until runtime. Also, regular expressions |
---|
22 | are ill-suited to advanced text processing tasks such as matching balanced, nested tags. Those |
---|
23 | tasks have traditionally been handled by parser generators (like the _spirit_fx_). These |
---|
24 | beasts are more powerful but less flexible. They generally don't allow you to arbitrarily modify |
---|
25 | your grammar rules on the fly. In addition, they don't have the exhaustive backtracking semantics |
---|
26 | of regular expressions, which can make it more challenging to author some types of patterns. |
---|
27 | |
---|
28 | xpressive brings these two approaches seamlessly together and occupies a unique niche in the |
---|
29 | world of C++ text processing. With xpressive, you can choose to use it much as you would use |
---|
30 | _regexpp_, representing regular expressions as strings. Or you can use it as you would use _spirit_, |
---|
31 | writing your regexes as C++ expressions, enjoying all the benefits of an embedded language |
---|
32 | dedicated to text manipulation. What's more, you can mix the two to get the benefits of |
---|
33 | both, writing regular expression ['grammars] in which some of the regular expressions are |
---|
34 | statically bound -- hard-coded and syntax\-checked by the compiler \-- and others are dynamically |
---|
35 | bound and specified at runtime. These regular expressions can refer to each other recursively, |
---|
36 | matching patterns in strings that ordinary regular expressions cannot. |
---|
37 | |
---|
38 | [h2 Influences and Related Work] |
---|
39 | |
---|
40 | The design of xpressive's interface has been strongly influenced by John Maddock's |
---|
41 | _regexpp_ library and his _proposal_ |
---|
42 | to add regular expressions to the Standard Library. I also drew a great deal of |
---|
43 | inspiration from Joel de Guzman's _spirit_fx_, which served as the model |
---|
44 | for static xpressive. Other sources of inspiration are the _perl6_ redesign and _greta_. |
---|
45 | (You can read a summary of the changes Perl 6 will bring to regex culture |
---|
46 | [@http://dev.perl.org/perl6/doc/design/syn/S05.html here].) |
---|
47 | |
---|
48 | [endsect] |
---|