preface.qbk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  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. [:['["Examples of designs that meet most of the criteria for
  9. "goodness" (easy to understand, flexible, efficient) are a
  10. recursive-descent parser, which is traditional procedural
  11. code. Another example is the STL, which is a generic library of
  12. containers and algorithms depending crucially on both traditional
  13. procedural code and on parametric polymorphism.]] [*--Bjarne
  14. Stroustrup]]
  15. [heading History]
  16. [heading /80s/]
  17. In the mid-80s, Joel wrote his first calculator in Pascal. Such an
  18. unforgettable coding experience, he was amazed at how a mutually
  19. recursive set of functions can model a grammar specification. In time,
  20. the skills he acquired from that academic experience became very
  21. practical as he was tasked to do some parsing. For instance, whenever he
  22. needed to perform any form of binary or text I/O, he tried to approach
  23. each task somewhat formally by writing a grammar using Pascal-like
  24. syntax diagrams and then a corresponding recursive-descent parser. This
  25. process worked very well.
  26. [heading /90s/]
  27. The arrival of the Internet and the World Wide Web magnified the need
  28. for parsing a thousand-fold. At one point Joel had to write an HTML
  29. parser for a Web browser project. Using the W3C formal specifications,
  30. he easily wrote a recursive-descent HTML parser. With the influence of
  31. the Internet, RFC specifications were abundent. SGML, HTML, XML, email
  32. addresses and even those seemingly trivial URLs were all formally
  33. specified using small EBNF-style grammar specifications. Joel had more
  34. parsing to do, and he wished for a tool similar to larger parser
  35. generators such as YACC and ANTLR, where a parser is built automatically
  36. from a grammar specification.
  37. This ideal tool would be able to parse anything from email addresses and
  38. command lines, to XML and scripting languages. Scalability was a primary
  39. goal. The tool would be able to do this without incurring a heavy
  40. development load, which was not possible with the above mentioned parser
  41. generators. The result was Spirit.
  42. Spirit was a personal project that was conceived when Joel was involved
  43. in R&D in Japan. Inspired by the GoF's composite and interpreter
  44. patterns, he realized that he can model a recursive-descent parser with
  45. hierarchical-object composition of primitives (terminals) and composites
  46. (productions). The original version was implemented with run-time
  47. polymorphic classes. A parser was generated at run time by feeding in
  48. production rule strings such as:
  49. "prod ::= {'A' | 'B'} 'C';"
  50. A compile function compiled the parser, dynamically creating a hierarchy
  51. of objects and linking semantic actions on the fly. A very early text
  52. can be found here: __early_spirit__.
  53. [heading /2001 to 2006/]
  54. Version 1.0 to 1.8 was a complete rewrite of the original Spirit parser
  55. using expression templates and static polymorphism, inspired by the
  56. works of Todd Veldhuizen (__exprtemplates__, C++ Report, June
  57. 1995). Initially, the static-Spirit version was meant only to replace
  58. the core of the original dynamic-Spirit. Dynamic-Spirit needed a parser
  59. to implement itself anyway. The original employed a hand-coded
  60. recursive-descent parser to parse the input grammar specification
  61. strings. It was at this time when Hartmut Kaiser joined the Spirit
  62. development.
  63. After its initial "open-source" debut in May 2001, static-Spirit became
  64. a success. At around November 2001, the Spirit website had an activity
  65. percentile of 98%, making it the number one parser tool at Source Forge
  66. at the time. Not bad for a niche project like a parser library. The
  67. "static" portion of Spirit was forgotten and static-Spirit simply became
  68. Spirit. The library soon evolved to acquire more dynamic features.
  69. Spirit was formally accepted into __boost__ in October 2002. Boost is a
  70. peer-reviewed, open collaborative development effort around a collection
  71. of free Open Source C++ libraries covering a wide range of domains. The
  72. Boost Libraries have become widely known as an industry standard for
  73. design and implementation quality, robustness, and reusability.
  74. [heading /2007/]
  75. Over the years, especially after Spirit was accepted into Boost, Spirit
  76. has served its purpose quite admirably. [*/Classic-Spirit/] (versions
  77. prior to 2.0) focused on transduction parsing, where the input string is
  78. merely translated to an output string. Many parsers fall into the
  79. transduction type. When the time came to add attributes to the parser
  80. library, it was done in a rather ad-hoc manner, with the goal being 100%
  81. backward compatible with Classic Spirit. As a result, some parsers have
  82. attributes, some don't.
  83. Spirit V2 is another major rewrite. Spirit V2 grammars are fully
  84. attributed (see __attr_grammar__) which means that all parser components
  85. have attributes. To do this efficiently and elegantly, we had to use a
  86. couple of infrastructure libraries. Some did not exist, some were quite
  87. new when Spirit debuted, and some needed work. __mpl__ is an important
  88. infrastructure library, yet is not sufficient to implement Spirit V2.
  89. Another library had to be written: __fusion__. Fusion sits between MPL
  90. and STL --between compile time and runtime -- mapping types to values.
  91. Fusion is a direct descendant of both MPL and __boost_tuples__. Fusion
  92. is now a full-fledged __boost__ library. __phoenix__ also had to be
  93. beefed up to support Spirit V2. The result is __phoenix__. Last
  94. but not least, Spirit V2 uses an __exprtemplates__ library called
  95. __boost_proto__.
  96. Even though it has evolved and matured to become a multi-module library,
  97. Spirit is still used for micro-parsing tasks as well as scripting
  98. languages. Like C++, you only pay for features that you need. The power
  99. of Spirit comes from its modularity and extensibility. Instead of giving
  100. you a sledgehammer, it gives you the right ingredients to easily create
  101. a sledgehammer.
  102. [heading New Ideas: Spirit V2]
  103. Just before the development of Spirit V2 began, Hartmut came across the
  104. __string_template__ library that is a part of the ANTLR parser
  105. framework. [footnote Quote from http://www.stringtemplate.org/: It is a
  106. Java template engine (with ports for C# and Python) for generating
  107. source code, web pages, emails, or any other formatted text output.]
  108. The concepts presented in that library lead Hartmut to
  109. the next step in the evolution of Spirit. Parsing and generation are
  110. tightly connected to a formal notation, or a grammar. The grammar
  111. describes both input and output, and therefore, a parser library should
  112. have a grammar driven output. This duality is expressed in Spirit by the
  113. parser library __qi__ and the generator library __karma__ using the same
  114. component infrastructure.
  115. The idea of creating a lexer library well integrated with the Spirit
  116. parsers is not new. This has been discussed almost since Classic-Spirit
  117. (pre V2) initially debuted. Several attempts to integrate existing lexer
  118. libraries and frameworks with Spirit have been made and served as a
  119. proof of concept and usability (for example see __wave__: The Boost
  120. C/C++ Preprocessor Library, and __slex__: a fully dynamic C++ lexer
  121. implemented with Spirit). Based on these experiences we added __lex__: a
  122. fully integrated lexer library to the mix, allowing the user to take
  123. advantage of the power of regular expressions for token matching,
  124. removing pressure from the parser components, simplifying parser
  125. grammars. Again, Spirit's modular structure allowed us to reuse the same
  126. underlying component library as for the parser and generator libraries.
  127. [heading How to use this manual]
  128. Each major section (there are 3: __sec_qi__, __sec_karma__, and
  129. __sec_lex__) is roughly divided into 3 parts:
  130. # Tutorials: A step by step guide with heavily annotated code. These
  131. are meant to get the user acquainted with the library as quickly as
  132. possible. The objective is to build the confidence of the user in
  133. using the library through abundant examples and detailed
  134. instructions. Examples speak volumes and we have volumes of
  135. examples!
  136. # Abstracts: A high level summary of key topics. The objective is to
  137. give the user a high level view of the library, the key concepts,
  138. background and theories.
  139. # Reference: Detailed formal technical reference. We start with a quick
  140. reference -- an easy to use table that maps into the reference proper.
  141. The reference proper starts with C++ concepts followed by
  142. models of the concepts.
  143. Some icons are used to mark certain topics indicative of their relevance.
  144. These icons precede some text to indicate:
  145. [table Icons
  146. [[Icon] [Name] [Meaning]]
  147. [[__note__] [Note] [Generally useful information (an aside that
  148. doesn't fit in the flow of the text)]]
  149. [[__tip__] [Tip] [Suggestion on how to do something
  150. (especially something that is not obvious)]]
  151. [[__important__] [Important] [Important note on something to take
  152. particular notice of]]
  153. [[__caution__] [Caution] [Take special care with this - it may
  154. not be what you expect and may cause bad
  155. results]]
  156. [[__danger__] [Danger] [This is likely to cause serious
  157. trouble if ignored]]
  158. ]
  159. This documentation is automatically generated by Boost QuickBook
  160. documentation tool. QuickBook can be found in the __boost_tools__.
  161. [heading Support]
  162. Please direct all questions to Spirit's mailing list. You can subscribe
  163. to the __spirit_list__. The mailing list has a searchable archive. A
  164. search link to this archive is provided in __spirit__'s home page. You
  165. may also read and post messages to the mailing list through
  166. __spirit_general__ (thanks to __gmane__). The news group mirrors the
  167. mailing list. Here is a link to the archives: __mlist_archive__.
  168. [endsect] [/ Preface]