preface.qbk 3.2 KB

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