Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60135 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-03-03 18:30:18


Author: danieljames
Date: 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
New Revision: 60135
URL: http://svn.boost.org/trac/boost/changeset/60135

Log:
Rename the grammar files.
Added:
   branches/quickbook-1.5-spirit2/block_grammar.cpp (contents, props changed)
      - copied, changed from r60134, /branches/quickbook-1.5-spirit2/block.cpp
   branches/quickbook-1.5-spirit2/code_snippet_actions.cpp (contents, props changed)
      - copied, changed from r60134, /branches/quickbook-1.5-spirit2/code_snippet.cpp
   branches/quickbook-1.5-spirit2/doc_info_grammar.cpp (contents, props changed)
      - copied, changed from r60134, /branches/quickbook-1.5-spirit2/doc_info.cpp
   branches/quickbook-1.5-spirit2/phrase_grammar.cpp (contents, props changed)
      - copied, changed from r60134, /branches/quickbook-1.5-spirit2/phrase.cpp
   branches/quickbook-1.5-spirit2/syntax_highlight_grammar.cpp (contents, props changed)
      - copied, changed from r60134, /branches/quickbook-1.5-spirit2/syntax_highlight.cpp
Removed:
   branches/quickbook-1.5-spirit2/block.cpp
   branches/quickbook-1.5-spirit2/code_snippet.cpp
   branches/quickbook-1.5-spirit2/doc_info.cpp
   branches/quickbook-1.5-spirit2/phrase.cpp
   branches/quickbook-1.5-spirit2/syntax_highlight.cpp
Text files modified:
   branches/quickbook-1.5-spirit2/Jamfile.v2 | 10 +++++-----
   1 files changed, 5 insertions(+), 5 deletions(-)

Modified: branches/quickbook-1.5-spirit2/Jamfile.v2
==============================================================================
--- branches/quickbook-1.5-spirit2/Jamfile.v2 (original)
+++ branches/quickbook-1.5-spirit2/Jamfile.v2 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
@@ -28,17 +28,17 @@
     post_process.cpp
     collector.cpp
     template.cpp
- phrase.cpp
+ phrase_grammar.cpp
     phrase_actions.cpp
     phrase_image.cpp
- block.cpp
+ block_grammar.cpp
     block_actions.cpp
     block_list.cpp
- doc_info.cpp
+ doc_info_grammar.cpp
     doc_info_actions.cpp
- code_snippet.cpp
+ code_snippet_actions.cpp
     code_snippet_grammar.cpp
- syntax_highlight.cpp
+ syntax_highlight_grammar.cpp
     boostbook.cpp
     html.cpp
     encoder_impl.cpp

Deleted: branches/quickbook-1.5-spirit2/block.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block.cpp 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
+++ (empty file)
@@ -1,581 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002 2004 2006Joel de Guzman
- Copyright (c) 2004 Eric Niebler
- http://spirit.sourceforge.net/
-
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-
-#include <boost/spirit/include/qi_core.hpp>
-#include <boost/spirit/include/qi_eol.hpp>
-#include <boost/spirit/include/qi_eps.hpp>
-#include <boost/spirit/include/qi_attr.hpp>
-#include <boost/spirit/include/qi_attr_cast.hpp>
-#include <boost/spirit/include/qi_repeat.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_fusion.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include "grammars.hpp"
-#include "block.hpp"
-#include "template.hpp"
-#include "actions.hpp"
-#include "parse_utils.hpp"
-#include "code.hpp"
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::paragraph,
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::list_item,
- (quickbook::file_position, position)
- (std::string, indent)
- (char, mark)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::title,
- (quickbook::raw_source, raw)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::begin_section,
- (boost::optional<std::string>, id)
- (quickbook::title, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::end_section,
- (quickbook::file_position, position)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::heading,
- (int, level)
- (quickbook::title, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::def_macro,
- (std::string, macro_identifier)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::define_template,
- (std::string, id)
- (std::vector<std::string>, params)
- (quickbook::template_value, body)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::template_value,
- (quickbook::file_position, position)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::variablelist,
- (std::string, title)
- (std::vector<quickbook::varlistentry>, entries)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::table,
- (boost::optional<std::string>, id)
- (std::string, title)
- (std::vector<quickbook::table_row>, rows)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::xinclude,
- (std::string, path)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::import,
- (std::string, path)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::include,
- (boost::optional<std::string>, id)
- (std::string, path)
-)
-
-namespace quickbook
-{
- namespace qi = boost::spirit::qi;
- namespace ph = boost::phoenix;
-
- struct block_grammar::rules
- {
- rules(quickbook::actions& actions_);
-
- quickbook::actions& actions;
- bool no_eols;
- phrase_grammar common;
-
- qi::rule<iterator> start_, blocks, block_markup;
- qi::rule<iterator, quickbook::begin_section()> begin_section;
- qi::rule<iterator, quickbook::end_section()> end_section;
- qi::rule<iterator, quickbook::heading()> heading;
- qi::symbols<char, int> heading_symbol;
- qi::rule<iterator, quickbook::formatted()> paragraph_block, blockquote, preformatted;
- qi::symbols<char, quickbook::formatted_type> paragraph_blocks;
- qi::rule<iterator, quickbook::def_macro()> def_macro;
- qi::rule<iterator, quickbook::table()> table;
- qi::rule<iterator, quickbook::table_row()> table_row;
- qi::rule<iterator, quickbook::table_cell()> table_cell;
- qi::rule<iterator, quickbook::formatted()> table_cell_body;
- qi::rule<iterator, quickbook::variablelist()> variablelist;
- qi::rule<iterator, quickbook::varlistentry()> varlistentry;
- qi::rule<iterator, quickbook::formatted()>
- varlistterm, varlistterm_body,
- varlistitem, varlistitem_body;
- qi::rule<iterator, quickbook::xinclude()> xinclude;
- qi::rule<iterator, quickbook::include()> include;
- qi::rule<iterator, quickbook::import()> import;
- qi::rule<iterator, quickbook::define_template()> define_template;
- qi::rule<iterator, quickbook::template_value()> template_body;
- qi::rule<iterator> template_body_recurse;
- qi::rule<iterator, quickbook::code()> code;
- qi::rule<iterator> code_line;
- qi::rule<iterator, quickbook::list()> list;
- qi::rule<iterator, quickbook::list_item()> list_item;
- qi::rule<iterator, std::string()> list_item_content;
- qi::rule<iterator, quickbook::hr()> hr;
- qi::rule<iterator, quickbook::paragraph()> paragraph;
- qi::rule<iterator, std::string()> paragraph_content;
- qi::rule<iterator> paragraph_end;
- qi::symbols<> paragraph_end_markups;
- qi::rule<iterator, quickbook::title()> title_phrase;
- qi::rule<iterator, std::string()> inside_paragraph;
- qi::rule<iterator, quickbook::formatted()> inside_paragraph2;
- qi::rule<iterator, std::string()> phrase_attr;
- qi::rule<iterator> phrase_end;
- qi::rule<iterator> comment, dummy_block;
- qi::rule<iterator, boost::optional<std::string>()> element_id;
- qi::rule<iterator, std::string()> element_id_part;
- qi::rule<iterator, std::string()> macro_identifier;
- qi::rule<iterator, std::string()> template_id;
- qi::rule<iterator> hard_space, space, blank, eol;
- qi::rule<iterator, file_position()> position;
- qi::rule<iterator> error;
- };
-
- block_grammar::block_grammar(quickbook::actions& actions_)
- : block_grammar::base_type(start, "block")
- , rules_pimpl(new rules(actions_))
- , start(rules_pimpl->start_) {}
-
- block_grammar::~block_grammar() {}
-
- block_grammar::rules::rules(quickbook::actions& actions_)
- : actions(actions_), no_eols(true), common(actions, no_eols)
- {
- start_ =
- blocks >> blank
- ;
-
- blocks =
- +( block_markup
- | code [actions.process]
- | list [actions.process]
- | hr [actions.process]
- | comment >> *eol
- | paragraph [actions.process]
- | eol
- )
- ;
-
- block_markup =
- '[' >> space
- >> ( begin_section
- | end_section
- | heading
- | paragraph_block
- | blockquote
- | preformatted
- | def_macro
- | table
- | variablelist
- | xinclude
- | include
- | import
- | define_template
- ) [actions.process]
- >> ( (space >> ']' >> +eol)
- | error
- )
- ;
-
- begin_section =
- "section"
- >> hard_space
- >> element_id
- >> title_phrase
- ;
-
- end_section =
- position
- >> "endsect"
- >> qi::attr(nothing())
- ;
-
- heading = heading_symbol >> hard_space >> title_phrase;
-
- heading_symbol.add
- ("h1", 1)
- ("h2", 2)
- ("h3", 3)
- ("h4", 4)
- ("h5", 5)
- ("h6", 6)
- ("heading", -1);
-
- paragraph_block =
- paragraph_blocks >> hard_space >> inside_paragraph
- ;
-
- paragraph_blocks.add
- ("blurb", formatted_type("blurb"))
- ("warning", formatted_type("warning"))
- ("caution", formatted_type("caution"))
- ("important", formatted_type("important"))
- ("note", formatted_type("note"))
- ("tip", formatted_type("tip"))
- ;
-
- blockquote =
- ':'
- >> blank
- >> qi::attr(formatted_type("blockquote"))
- >> inside_paragraph
- ;
-
- preformatted %=
- "pre"
- >> hard_space [ph::ref(no_eols) = false]
- >> -eol
- >> qi::attr(formatted_type("preformatted"))
- >> phrase_attr
- >> qi::eps [ph::ref(no_eols) = true]
- ;
-
- def_macro =
- "def"
- >> hard_space
- >> macro_identifier
- >> blank
- >> phrase_attr
- ;
-
- table =
- "table"
- >> (&(*qi::blank >> qi::eol) | hard_space)
- >> ((qi::eps(qbk_since(105u)) >> element_id) | qi::eps)
- >> (&(*qi::blank >> qi::eol) | space)
- >> *(qi::char_ - eol)
- >> +eol
- >> *table_row
- ;
-
- table_row =
- space
- >> '['
- >> ( *table_cell >> ']' >> space
- | error >> qi::attr(quickbook::table_row())
- )
- ;
-
- table_cell =
- space
- >> '['
- >> ( table_cell_body >> ']' >> space
- | error >> qi::attr(quickbook::table_cell())
- )
- ;
-
- table_cell_body =
- qi::attr(formatted_type("cell"))
- >> inside_paragraph
- ;
-
- variablelist =
- "variablelist"
- >> (&(*qi::blank >> qi::eol) | hard_space)
- >> *(qi::char_ - eol)
- >> +eol
- >> *varlistentry
- ;
-
- varlistentry =
- space
- >> '['
- >> ( varlistterm
- >> +varlistitem
- >> ']'
- >> space
- | error >> qi::attr(quickbook::varlistentry())
- )
- ;
-
- varlistterm =
- space
- >> '['
- >> ( varlistterm_body >> ']' >> space
- | error >> qi::attr(quickbook::formatted())
- )
- ;
-
- varlistterm_body =
- qi::attr(formatted_type("varlistterm"))
- >> phrase_attr
- ;
-
- varlistitem =
- space
- >> '['
- >> ( varlistitem_body >> ']' >> space
- | error >> qi::attr(quickbook::formatted())
- )
- ;
-
- varlistitem_body =
- qi::attr(formatted_type("varlistitem"))
- >> inside_paragraph
- ;
-
- // TODO: Why do these use phrase_end? It doesn't make any sense.
- xinclude =
- "xinclude"
- >> hard_space
- >> *(qi::char_ - phrase_end)
- >> qi::attr(nothing())
- ;
-
- include =
- "include"
- >> hard_space
- >> -(
- ':'
- >> *((qi::alnum | '_') - qi::space)
- >> space
- )
- >> *(qi::char_ - phrase_end)
- ;
-
- import =
- "import"
- >> hard_space
- >> *(qi::char_ - phrase_end)
- >> qi::attr(nothing())
- ;
-
- define_template =
- "template"
- >> hard_space
- >> template_id
- >> -(
- space
- >> '['
- >> *(space >> template_id)
- >> space
- >> ']'
- )
- >> template_body
- ;
-
- template_body =
- position
- >> qi::raw[template_body_recurse]
- ;
-
- template_body_recurse =
- *( ('[' >> template_body_recurse >> ']')
- | (qi::char_ - ']')
- )
- >> space
- >> &qi::lit(']')
- ;
-
- // Blocks indicated by text layout (indentation, leading characters etc.)
-
- code =
- position
- >> qi::raw[
- code_line
- >> *(*eol >> code_line)
- ]
- >> +eol
- >> qi::attr(true)
- ;
-
- code_line =
- qi::char_(" \t")
- >> *(qi::char_ - eol)
- >> eol
- ;
-
- list =
- &qi::char_("*#")
- >> +list_item
- ;
-
- list_item =
- position
- >> *qi::blank
- >> qi::char_("*#")
- >> qi::omit[*qi::blank]
- >> list_item_content
- ;
-
- list_item_content =
- qi::eps[actions.phrase_push] >>
- *( common
- | (qi::char_ -
- ( qi::eol >> *qi::blank >> &(qi::char_('*') | '#')
- | (eol >> eol)
- )
- ) [actions.process]
- )
- >> +eol
- >> qi::eps[actions.phrase_pop]
- ;
-
- hr =
- qi::omit[
- "----"
- >> *(qi::char_ - eol)
- >> +eol
- ] >> qi::attr(quickbook::hr())
- ;
-
- paragraph = paragraph_content >> qi::attr(nothing());
-
- paragraph_content =
- qi::eps [actions.phrase_push]
- >> *( common
- | (qi::char_ - // Make sure we don't go past
- paragraph_end // a single block.
- ) [actions.process]
- )
- >> qi::eps [actions.phrase_pop]
- >> (&qi::lit('[') | +eol)
- ;
-
- paragraph_end =
- '[' >> space >> paragraph_end_markups >> hard_space | eol >> eol
- ;
-
- paragraph_end_markups =
- "section", "endsect", "h1", "h2", "h3", "h4", "h5", "h6",
- "blurb", ":", "pre", "def", "table", "include", "xinclude",
- "variablelist", "import", "template", "warning", "caution",
- "important", "note", "tip", ":"
- ;
-
- // Block contents
-
- // Used when the title is used both to generate the title text and
- // possibly to generate an id (based on the raw source).
- title_phrase =
- qi::raw[
- phrase_attr [ph::at_c<1>(qi::_val) = qi::_1]
- ] [ph::at_c<0>(qi::_val) = qi::_1]
- ;
-
- inside_paragraph =
- qi::eps [actions.phrase_push]
- >> inside_paragraph2 [actions.process]
- >> *( eol
- >> eol
- >> inside_paragraph2 [actions.process]
- )
- >> qi::eps [actions.phrase_pop]
- ;
-
- inside_paragraph2 =
- qi::attr(formatted_type("paragraph"))
- >> phrase_attr;
-
- phrase_attr =
- qi::eps [actions.phrase_push]
- >> *( common
- | comment
- | (qi::char_ - phrase_end) [actions.process]
- )
- >> qi::eps [actions.phrase_pop]
- ;
-
- // Make sure that we don't go past a single block, except when
- // preformatted.
- phrase_end =
- ']' | qi::eps(ph::ref(no_eols)) >> eol >> eol
- ;
-
- comment =
- "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- // Identifiers
-
- element_id =
- ( ':'
- >> -(qi::eps(qbk_since(105u)) >> space)
- >> (
- element_id_part
- | qi::omit[
- qi::raw[qi::eps] [actions.element_id_warning]
- ]
- )
- )
- | qi::eps
- ;
-
- element_id_part = +(qi::alnum | qi::char_('_'));
-
- macro_identifier =
- +(qi::char_ - (qi::space | ']'))
- ;
-
- template_id
- = (qi::alpha | '_') >> *(qi::alnum | '_')
- | qi::repeat(1)[qi::punct - qi::char_("[]")]
- ;
-
- // Used after an identifier that must not be immediately
- // followed by an alpha-numeric character or underscore.
- hard_space =
- !(qi::alnum | '_') >> space
- ;
-
- space =
- *(qi::space | comment)
- ;
-
- blank =
- *(qi::blank | comment)
- ;
-
- eol = blank >> qi::eol
- ;
-
- position =
- qi::raw[qi::eps] [get_position];
-
- error =
- qi::raw[qi::eps] [actions.error];
- }
-}

Copied: branches/quickbook-1.5-spirit2/block_grammar.cpp (from r60134, /branches/quickbook-1.5-spirit2/block.cpp)
==============================================================================

Deleted: branches/quickbook-1.5-spirit2/code_snippet.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/code_snippet.cpp 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
+++ (empty file)
@@ -1,98 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002 2004 2006 Joel de Guzman
- Copyright (c) 2004 Eric Niebler
- Copyright (c) 2005 Thomas Guest
- Copyright (c) 2010 Daniel James
- http://spirit.sourceforge.net/
-
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-
-#include <numeric>
-#include <functional>
-#include <algorithm>
-#include <iterator>
-#include <boost/lexical_cast.hpp>
-#include "utils.hpp"
-#include "grammars.hpp"
-#include "code_snippet_types.hpp"
-#include "template.hpp"
-
-namespace quickbook
-{
- void code_snippet_actions::process_action::operator()(char x, unused_type, unused_type) const
- {
- actions.code += x;
- }
-
- namespace detail
- {
- int callout_id = 0;
- }
-
- void code_snippet_actions::process_action::operator()(callout const& x, unused_type, unused_type) const
- {
- using detail::callout_id;
-
- callout_source item;
- item.identifier = actions.doc_id + boost::lexical_cast<std::string>(callout_id + actions.callouts.size());
- item.body = template_value(x.position, x.content);
-
- actions.code += "``[[callout]";
- actions.code += x.role;
- actions.code += " ";
- actions.code += item.identifier;
- actions.code += "]``";
-
- actions.callouts.push_back(item);
- }
-
- void code_snippet_actions::process_action::operator()(escaped_comment const& x, unused_type, unused_type) const
- {
- if (!actions.code.empty())
- {
- detail::unindent(actions.code); // remove all indents
- if (actions.code.size() != 0)
- {
- actions.snippet += "\n\n";
- actions.snippet += actions.source_type;
- actions.snippet += "``\n" + actions.code + "``\n\n";
- actions.code.clear();
- }
- }
- std::string temp(x.content);
- detail::unindent(temp); // remove all indents
- if (temp.size() != 0)
- {
- actions.snippet += "\n" + temp; // add a linebreak to allow block marskups
- }
- }
-
- void code_snippet_actions::output_action::operator()(code_snippet const& x, unused_type, unused_type) const
- {
- using detail::callout_id;
- if (!actions.code.empty())
- {
- detail::unindent(actions.code); // remove all indents
- if (actions.code.size() != 0)
- {
- actions.snippet += "\n\n";
- actions.snippet += actions.source_type;
- actions.snippet += "```\n" + actions.code + "```\n\n";
- }
- }
-
- std::vector<std::string> empty_params;
- define_template d(x.identifier, empty_params,
- template_value(x.position, actions.snippet));
- d.callouts = actions.callouts;
- actions.storage.push_back(d);
-
- callout_id += actions.callouts.size();
- actions.callouts.clear();
- actions.code.clear();
- actions.snippet.clear();
- }
-}

Copied: branches/quickbook-1.5-spirit2/code_snippet_actions.cpp (from r60134, /branches/quickbook-1.5-spirit2/code_snippet.cpp)
==============================================================================

Deleted: branches/quickbook-1.5-spirit2/doc_info.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/doc_info.cpp 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
+++ (empty file)
@@ -1,205 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002 2004 2006 Joel de Guzman
- Copyright (c) 2004 Eric Niebler
- http://spirit.sourceforge.net/
-
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-
-#include "doc_info.hpp"
-#include "grammars.hpp"
-#include "actions.hpp"
-#include "state.hpp"
-#include "parse_utils.hpp"
-#include <boost/spirit/include/qi_core.hpp>
-#include <boost/spirit/include/qi_uint.hpp>
-#include <boost/spirit/include/qi_eol.hpp>
-#include <boost/spirit/include/qi_eps.hpp>
-#include <boost/spirit/include/qi_attr_cast.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_container.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_fusion.hpp>
-#include <boost/fusion/include/std_pair.hpp>
-#include <boost/fusion/include/reverse_view.hpp>
-
-namespace quickbook
-{
- namespace qi = boost::spirit::qi;
- namespace ph = boost::phoenix;
-
- void set_quickbook_version(boost::optional<std::pair<unsigned, unsigned> > version)
- {
- if (version)
- {
- qbk_major_version = version->first;
- qbk_minor_version = version->second;
- }
- else
- {
- qbk_major_version = 1;
- qbk_minor_version = 1;
-
- // TODO:
- //detail::outwarn(actions.filename.native_file_string(),1)
- // << "Warning: Quickbook version undefined. "
- // "Version 1.1 is assumed" << std::endl;
- }
-
- qbk_version_n = (qbk_major_version * 100) + qbk_minor_version;
- }
-
- struct doc_info_grammar::rules
- {
- rules(quickbook::actions& actions);
-
- quickbook::actions& actions;
- bool unused;
- phrase_grammar common;
- qi::symbols<char> doc_types;
- qi::rule<iterator, doc_info()> doc_info_details;
- qi::rule<iterator> comment, space, hard_space;
- qi::rule<iterator, std::pair<unsigned, unsigned>()> quickbook_version;
- qi::rule<iterator, std::string()> phrase, doc_version, doc_id, doc_dirname, doc_category, doc_last_revision, doc_source_mode, doc_purpose, doc_license;
- qi::rule<iterator, std::pair<std::vector<unsigned int>, std::string>()> doc_copyright;
- qi::rule<iterator, std::vector<std::pair<std::string, std::string> >()> doc_authors;
- qi::rule<iterator, boost::fusion::reverse_view<
- std::pair<std::string, std::string> >()> doc_author;
- };
-
- doc_info_grammar::doc_info_grammar(quickbook::actions& actions)
- : doc_info_grammar::base_type(start)
- , rules_pimpl(new rules(actions))
- , start(rules_pimpl->doc_info_details) {}
-
- doc_info_grammar::~doc_info_grammar() {}
-
-
- doc_info_grammar::rules::rules(quickbook::actions& actions)
- : actions(actions), unused(false), common(actions, unused)
- {
- typedef qi::uint_parser<int, 10, 1, 2> uint2_t;
-
- doc_types =
- "book", "article", "library", "chapter", "part"
- , "appendix", "preface", "qandadiv", "qandaset"
- , "reference", "set"
- ;
-
- doc_info_details =
- space
- >> '[' >> space
- >> qi::raw[doc_types] [member_assign(&doc_info::doc_type)]
- >> hard_space
- >> ( *(qi::char_ -
- (qi::char_('[') | ']' | qi::eol)
- )
- ) [member_assign(&doc_info::doc_title)]
- >> quickbook_version [set_quickbook_version]
- >>
- *(
- space >> '[' >>
- (
- doc_version [member_assign(&doc_info::doc_version)]
- | doc_id [member_assign(&doc_info::doc_id)]
- | doc_dirname [member_assign(&doc_info::doc_dirname)]
- | doc_copyright [ph::push_back(ph::bind(&doc_info::doc_copyrights, qi::_val), qi::_1)]
- | doc_purpose [member_assign(&doc_info::doc_purpose)]
- | doc_category [member_assign(&doc_info::doc_category)]
- | doc_authors [member_assign(&doc_info::doc_authors)]
- | doc_license [member_assign(&doc_info::doc_license)]
- | doc_last_revision [member_assign(&doc_info::doc_last_revision)]
- // This has to be set in actions so that source code in phrases use the
- // correct encoding.
- | doc_source_mode [ph::ref(actions.state_.source_mode) = qi::_1]
- )
- >> space >> ']' >> +qi::eol
- )
- >> space >> ']' >> +qi::eol
- ;
-
- quickbook_version = -(
- space >> '['
- >> "quickbook"
- >> hard_space
- >> qi::uint_
- >> '.'
- >> uint2_t()
- >> space >> ']'
- );
-
- doc_version = "version" >> hard_space >> *(qi::char_ - ']');
- doc_id = "id" >> hard_space >> *(qi::char_ - ']');
- doc_dirname = "dirname" >> hard_space >> *(qi::char_ - ']');
- doc_category="category" >> hard_space >> *(qi::char_ - ']');
- doc_last_revision = "last-revision" >> hard_space >> *(qi::char_ - ']');
-
- doc_copyright =
- "copyright"
- >> hard_space
- >> +(qi::uint_ >> space)
- >> qi::raw[(*(qi::char_ - ']'))]
- ;
-
- doc_purpose =
- "purpose" >> hard_space
- >> (
- qi::eps(qbk_before(103)) >> qi::raw[phrase] |
- qi::eps(qbk_since(103)) >> phrase
- )
- ;
-
- doc_author =
- space
- >> '['
- >> space
- >> (*(qi::char_ - ','))
- >> ',' >> space
- >> (*(qi::char_ - ']'))
- >> ']'
- ;
-
- doc_authors = "authors" >> hard_space >> (doc_author % ',') ;
-
- doc_license =
- "license" >> hard_space
- >> (
- qi::eps(qbk_before(103)) >> qi::raw[phrase] |
- qi::eps(qbk_since(103)) >> phrase
- )
- ;
-
-
- doc_source_mode =
- "source-mode" >> hard_space
- >> (
- qi::string("c++")
- | qi::string("python")
- | qi::string("teletype")
- )
- ;
-
- comment =
- "[/" >> *(qi::char_ - ']') >> ']'
- ;
-
- space =
- *(qi::space | comment)
- ;
-
- hard_space =
- !(qi::alnum | '_') >> space // must not be preceded by
- ; // alpha-numeric or underscore
-
- phrase =
- qi::eps [actions.phrase_push]
- >> *( common
- | comment
- | (qi::char_ - ']') [actions.process]
- )
- >> qi::eps [actions.phrase_pop]
- ;
- }
-}

Copied: branches/quickbook-1.5-spirit2/doc_info_grammar.cpp (from r60134, /branches/quickbook-1.5-spirit2/doc_info.cpp)
==============================================================================

Deleted: branches/quickbook-1.5-spirit2/phrase.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/phrase.cpp 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
+++ (empty file)
@@ -1,527 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002 2004 2006 Joel de Guzman
- Copyright (c) 2004 Eric Niebler
- http://spirit.sourceforge.net/
-
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-
-#include <map>
-#include <boost/spirit/include/qi_core.hpp>
-#include <boost/spirit/include/qi_symbols.hpp>
-#include <boost/spirit/include/qi_attr.hpp>
-#include <boost/spirit/include/qi_eoi.hpp>
-#include <boost/spirit/include/qi_eol.hpp>
-#include <boost/spirit/include/qi_eps.hpp>
-#include <boost/spirit/include/qi_matches.hpp>
-#include <boost/spirit/include/qi_uint.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/fusion/include/std_pair.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include "code.hpp"
-#include "phrase.hpp"
-#include "grammars.hpp"
-#include "actions.hpp"
-#include "template.hpp"
-#include "parse_utils.hpp"
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::anchor,
- (std::string, id)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::link,
- (quickbook::formatted_type, type)
- (std::string, destination)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::simple_markup,
- (char, symbol)
- (std::string, raw_content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::break_,
- (quickbook::file_position, position)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::image,
- (quickbook::file_position, position)
- (std::string, image_filename)
- (quickbook::image::attribute_map, attributes)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::cond_phrase,
- (std::string, macro_id)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::call_template,
- (quickbook::file_position, position)
- (bool, escape)
- (quickbook::template_symbol const*, symbol)
- (std::vector<quickbook::template_value>, args)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::template_value,
- (quickbook::file_position, position)
- (std::string, content)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::callout_link,
- (std::string, role)
- (std::string, identifier)
-)
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::unicode_char,
- (std::string, value)
-)
-
-namespace quickbook
-{
- namespace qi = boost::spirit::qi;
- namespace ph = boost::phoenix;
-
- struct phrase_grammar::rules
- {
- rules(quickbook::actions& actions, bool& no_eols);
-
- quickbook::actions& actions;
- bool& no_eols;
-
- qi::rule<iterator, std::string()> phrase;
- qi::rule<iterator> common;
- qi::rule<iterator> macro;
- qi::rule<iterator> phrase_markup;
- qi::rule<iterator, quickbook::code()> code_block;
- qi::rule<iterator, quickbook::code()> inline_code;
- qi::rule<iterator, quickbook::simple_markup(), qi::locals<char> > simple_format;
- qi::rule<iterator> simple_phrase_end;
- qi::rule<iterator> escape;
- qi::rule<iterator, quickbook::break_()> escape_break;
- qi::rule<iterator, quickbook::formatted()> escape_punct;
- qi::rule<iterator, quickbook::formatted()> escape_markup;
- qi::rule<iterator, quickbook::unicode_char()> escape_unicode;
- qi::rule<iterator> comment;
- qi::rule<iterator> dummy_block;
- qi::rule<iterator, quickbook::callout_link()> callout_link;
- qi::rule<iterator, quickbook::cond_phrase()> cond_phrase;
- qi::rule<iterator, std::string()> macro_identifier;
- qi::rule<iterator, quickbook::image()> image, image_1_4, image_1_5;
- qi::rule<iterator, std::string()> image_filename;
- qi::rule<iterator, quickbook::image::attribute_map()> image_attributes;
- qi::rule<iterator, std::pair<std::string, std::string>()> image_attribute;
- qi::rule<iterator, std::string()> image_attribute_key, image_attribute_value;
- qi::rule<iterator, quickbook::link()> url;
- qi::rule<iterator, quickbook::link()> link;
- qi::symbols<char, formatted_type> link_symbol;
- qi::rule<iterator, quickbook::anchor()> anchor;
- qi::symbols<char, quickbook::source_mode> source_mode;
- qi::rule<iterator, quickbook::formatted()> formatted;
- qi::symbols<char, formatted_type> format_symbol;
- qi::rule<iterator, quickbook::formatted()> footnote;
- qi::rule<iterator, quickbook::call_template()> call_template;
- qi::rule<iterator, std::vector<quickbook::template_value>()> template_args;
- qi::rule<iterator, quickbook::template_value()> template_arg_1_4;
- qi::rule<iterator> brackets_1_4;
- qi::rule<iterator, quickbook::template_value()> template_arg_1_5;
- qi::rule<iterator> brackets_1_5;
- qi::rule<iterator, quickbook::break_()> break_;
- qi::rule<iterator> space, blank, eol, phrase_end, hard_space;
- qi::rule<iterator, file_position()> position;
-
- };
-
- phrase_grammar::phrase_grammar(quickbook::actions& actions, bool& no_eols)
- : phrase_grammar::base_type(start, "phrase")
- , rules_pimpl(new rules(actions, no_eols))
- {
- start = rules_pimpl->common;
- }
-
- phrase_grammar::~phrase_grammar() {}
-
- phrase_grammar::rules::rules(quickbook::actions& actions, bool& no_eols)
- : actions(actions), no_eols(no_eols)
- {
- phrase =
- qi::eps [actions.phrase_push]
- >> *( common
- | comment
- | (qi::char_ - phrase_end) [actions.process]
- )
- >> qi::eps [actions.phrase_pop]
- ;
-
- common =
- macro
- | phrase_markup
- | code_block [actions.process]
- | inline_code [actions.process]
- | simple_format [actions.process]
- | escape
- | comment
- ;
-
- macro =
- ( actions.macro // must not be followed by
- >> !(qi::alpha | '_') // alpha or underscore
- ) [actions.process]
- ;
-
- phrase_markup =
- ( '['
- >> ( callout_link
- | cond_phrase
- | image
- | url
- | link
- | anchor
- | source_mode
- | formatted
- | footnote
- | call_template
- | break_
- )
- >> ']'
- ) [actions.process]
- ;
-
- code_block =
- (
- "```"
- >> position
- >> qi::raw[*(qi::char_ - "```")]
- >> "```"
- >> qi::attr(true)
- )
- | (
- "``"
- >> position
- >> qi::raw[*(qi::char_ - "``")]
- >> "``"
- >> qi::attr(true)
- )
- ;
-
- inline_code =
- '`'
- >> position
- >> qi::raw
- [ *( qi::char_ -
- ( '`'
- | (eol >> eol) // Make sure that we don't go
- ) // past a single block
- )
- >> &qi::lit('`')
- ]
- >> '`'
- >> qi::attr(false)
- ;
-
- simple_format %=
- qi::char_("*/_=") [qi::_a = qi::_1]
- >> qi::raw
- [ ( ( qi::graph // A single char. e.g. *c*
- >> &( qi::char_(qi::_a)
- >> (qi::space | qi::punct | qi::eoi)
- )
- )
- |
- ( qi::graph // qi::graph must follow qi::lit(qi::_r1)
- >> *( qi::char_ -
- ( (qi::graph >> qi::lit(qi::_a))
- | simple_phrase_end // Make sure that we don't go
- ) // past a single block
- )
- >> qi::graph // qi::graph must precede qi::lit(qi::_r1)
- >> &( qi::char_(qi::_a)
- >> (qi::space | qi::punct | qi::eoi)
- )
- )
- )
- ]
- >> qi::omit[qi::char_(qi::_a)]
- ;
-
- simple_phrase_end = '[' | phrase_end;
-
- escape =
- ( escape_break
- | "\\ " // ignore an escaped char
- | escape_punct
- | escape_unicode
- | escape_markup
- ) [actions.process]
- ;
-
- escape_break =
- position
- >> "\\n"
- >> qi::attr(nothing())
- ;
-
- escape_punct =
- qi::attr(formatted_type(""))
- >> '\\'
- >> qi::repeat(1)[qi::punct]
- ;
-
- escape_markup =
- ("'''" >> -eol)
- >> qi::attr("escape")
- >> *(qi::char_ - "'''")
- >> "'''"
- ;
-
- escape_unicode =
- "\\u"
- >> qi::raw[qi::repeat(1,4)[qi::hex]]
- >> qi::attr(nothing())
- ;
-
- comment =
- "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- // Don't use this, it's meant to be private.
- callout_link =
- "[callout]"
- >> *~qi::char_(' ')
- >> ' '
- >> *~qi::char_(']')
- >> qi::attr(nothing())
- ;
-
- cond_phrase =
- '?'
- >> blank
- >> macro_identifier
- >> -phrase
- ;
-
- macro_identifier =
- +(qi::char_ - (qi::space | ']'))
- ;
-
- image =
- (qi::eps(qbk_since(105u)) >> image_1_5) |
- (qi::eps(qbk_before(105u)) >> image_1_4);
-
- image_1_4 =
- position
- >> '$'
- >> blank
- >> *(qi::char_ - phrase_end)
- >> &qi::lit(']')
- ;
-
- image_1_5 =
- position
- >> '$'
- >> blank
- >> image_filename
- >> hard_space
- >> image_attributes
- >> &qi::lit(']')
- ;
-
- image_filename = qi::raw[
- +(qi::char_ - (qi::space | phrase_end | '['))
- >> *(
- +qi::space
- >> +(qi::char_ - (qi::space | phrase_end | '['))
- )];
-
- image_attributes = *(image_attribute >> space);
-
- image_attribute =
- '['
- >> image_attribute_key
- >> space
- >> image_attribute_value
- >> ']'
- ;
-
- image_attribute_key = *(qi::alnum | '_');
- image_attribute_value = *(qi::char_ - (phrase_end | '['));
-
- url =
- '@'
- >> qi::attr("url")
- >> *(qi::char_ - (']' | qi::space))
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- )
- ;
-
- link =
- link_symbol
- >> hard_space
- >> *(qi::char_ - (']' | qi::space))
- >> ( &qi::lit(']')
- | (hard_space >> phrase)
- )
- ;
-
- link_symbol.add
- ("link", formatted_type("link"))
- ("funcref", formatted_type("funcref"))
- ("classref", formatted_type("classref"))
- ("memberref", formatted_type("memberref"))
- ("enumref", formatted_type("enumref"))
- ("macroref", formatted_type("macroref"))
- ("headerref", formatted_type("headerref"))
- ("conceptref", formatted_type("conceptref"))
- ("globalref", formatted_type("globalref"))
- ;
-
- anchor =
- '#'
- >> blank
- >> *(qi::char_ - phrase_end)
- >> qi::attr(nothing())
- ;
-
- source_mode.add
- ("c++", quickbook::source_mode("c++"))
- ("python", quickbook::source_mode("python"))
- ("teletype", quickbook::source_mode("teletype"))
- ;
-
- formatted = format_symbol >> blank >> phrase;
-
- format_symbol.add
- ("*", "bold")
- ("'", "italic")
- ("_", "underline")
- ("^", "teletype")
- ("-", "strikethrough")
- ("\"", "quote")
- ("~", "replaceable")
- ;
-
- footnote =
- "footnote"
- >> qi::attr("footnote")
- >> blank
- >> phrase
- ;
-
- // Template call
-
- call_template =
- position
- >> qi::matches['`']
- >> ( // Lookup the template name
- (&qi::punct >> actions.templates.scope)
- | (actions.templates.scope >> hard_space)
- )
- >> template_args
- >> &qi::lit(']')
- ;
-
- template_args =
- qi::eps(qbk_before(105u)) >> -(template_arg_1_4 % "..") |
- qi::eps(qbk_since(105u)) >> -(template_arg_1_5 % "..");
-
- template_arg_1_4 =
- position >>
- qi::raw[+(brackets_1_4 | ~qi::char_(']') - "..")]
- ;
-
- brackets_1_4 =
- '[' >> +(brackets_1_4 | ~qi::char_(']') - "..") >> ']'
- ;
-
- template_arg_1_5 =
- position >>
- qi::raw[+(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]") - "..")]
- ;
-
- brackets_1_5 =
- '[' >> +(brackets_1_5 | '\\' >> qi::char_ | ~qi::char_("[]")) >> ']'
- ;
-
- break_ =
- position
- >> "br"
- >> qi::attr(nothing())
- ;
-
- space =
- *(qi::space | comment)
- ;
-
- blank =
- *(qi::blank | comment)
- ;
-
- eol = blank >> qi::eol
- ;
-
- phrase_end =
- ']' |
- qi::eps(ph::ref(no_eols)) >>
- eol >> eol // Make sure that we don't go
- ; // past a single block, except
- // when preformatted.
-
- hard_space =
- !(qi::alnum | '_') >> space
- ; // must not be preceded by
- // alpha-numeric or underscore
- position = qi::raw[qi::eps] [get_position];
- }
-
- struct simple_phrase_grammar::rules
- {
- rules(quickbook::actions& actions);
-
- quickbook::actions& actions;
- bool unused;
- phrase_grammar common;
- qi::rule<iterator> phrase, comment, dummy_block;
- };
-
- simple_phrase_grammar::simple_phrase_grammar(quickbook::actions& actions)
- : simple_phrase_grammar::base_type(start, "simple_phrase")
- , rules_pimpl(new rules(actions))
- , start(rules_pimpl->phrase) {}
-
- simple_phrase_grammar::~simple_phrase_grammar() {}
-
- simple_phrase_grammar::rules::rules(quickbook::actions& actions)
- : actions(actions), unused(false), common(actions, unused)
- {
- phrase =
- *( common
- | comment
- | (qi::char_ - ']') [actions.process]
- )
- ;
-
- comment =
- "[/" >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
-
- dummy_block =
- '[' >> *(dummy_block | (qi::char_ - ']')) >> ']'
- ;
- }
-}

Copied: branches/quickbook-1.5-spirit2/phrase_grammar.cpp (from r60134, /branches/quickbook-1.5-spirit2/phrase.cpp)
==============================================================================

Deleted: branches/quickbook-1.5-spirit2/syntax_highlight.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/syntax_highlight.cpp 2010-03-03 18:30:16 EST (Wed, 03 Mar 2010)
+++ (empty file)
@@ -1,401 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002 2004 2006 Joel de Guzman
- Copyright (c) 2004 Eric Niebler
- http://spirit.sourceforge.net/
-
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-
-#include <boost/spirit/include/qi_core.hpp>
-#include <boost/spirit/include/qi_auxiliary.hpp>
-#include <boost/spirit/include/qi_string.hpp>
-#include <boost/spirit/include/qi_directive.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include "actions.hpp"
-#include "grammars.hpp"
-#include "phrase.hpp"
-#include "utils.hpp"
-#include "syntax_highlight.hpp"
-
-BOOST_FUSION_ADAPT_STRUCT(
- quickbook::code_token,
- (std::string, text)
- (char const*, type)
-)
-
-namespace quickbook
-{
- namespace qi = boost::spirit::qi;
- using boost::spirit::unused_type;
-
- struct parse_escaped_impl
- {
- parse_escaped_impl(quickbook::actions& actions)
- : actions(actions) {}
-
- void operator()(boost::iterator_range<iterator> escaped, unused_type, unused_type) const {
- bool unused;
- phrase_grammar common(actions, unused);
- iterator first = escaped.begin(), last = escaped.end();
- while(first != last) {
- if(!qi::parse(first, last, common)) {
- actions.process(*first);
- ++first;
- }
- }
- }
-
- quickbook::actions& actions;
- };
-
- // Grammar for C++ highlighting
- struct cpp_highlight : public qi::grammar<iterator>
- {
- cpp_highlight(quickbook::actions& actions)
- : cpp_highlight::base_type(program), actions(actions)
- , parse_escaped(actions)
- {
- program
- =
- *( space
- | macro
- | escape
- | preprocessor
- | comment
- | keyword
- | identifier
- | special
- | string_
- | char_
- | number
- | unexpected
- ) [actions.process]
- ;
-
- macro =
- ( actions.macro // must not be followed by
- >> !(qi::alpha | '_') // alpha or underscore
- )
- ;
-
- escape =
- "``" >> (
- (qi::raw[+(qi::char_ - "``")] >> "``")
- [parse_escaped]
- | qi::raw[*qi::char_] [actions.error]
- )
- ;
-
- space
- = qi::raw[+qi::space]
- >> qi::attr("space");
-
- preprocessor
- = qi::raw[
- '#' >> *qi::space
- >> ((qi::alpha | '_') >> *(qi::alnum | '_'))
- ]
- >> qi::attr("preprocessor")
- ;
-
- comment
- = qi::raw[
- qi::lit("//") >> *(qi::char_ - qi::eol) >> -qi::eol
- | qi::lit("/*") >> *(qi::char_ - "*/") >> -qi::lit("*/")
- ]
- >> qi::attr("comment")
- ;
-
- keyword
- = qi::raw[keyword_ >> !(qi::alnum | '_')]
- >> qi::attr("keyword")
- ; // make sure we recognize whole words only
-
- keyword_
- = "and_eq", "and", "asm", "auto", "bitand", "bitor",
- "bool", "break", "case", "catch", "char", "class",
- "compl", "const_cast", "const", "continue", "default",
- "delete", "do", "double", "dynamic_cast", "else",
- "enum", "explicit", "export", "extern", "false",
- "float", "for", "friend", "goto", "if", "inline",
- "int", "long", "mutable", "namespace", "new", "not_eq",
- "not", "operator", "or_eq", "or", "private",
- "protected", "public", "register", "reinterpret_cast",
- "return", "short", "signed", "sizeof", "static",
- "static_cast", "struct", "switch", "template", "this",
- "throw", "true", "try", "typedef", "typeid",
- "typename", "union", "unsigned", "using", "virtual",
- "void", "volatile", "wchar_t", "while", "xor_eq", "xor"
- ;
-
- special
- = +qi::char_("~!%^&*()+={[}]:;,<.>?/|\\-")
- >> qi::attr("special")
- ;
-
- string_char = ('\\' >> qi::char_) | (qi::char_ - '\\');
-
- string_
- = qi::raw[
- -qi::no_case['l']
- >> '"' >> *(string_char - '"') >> -qi::lit('"')
- ]
- >> qi::attr("string")
- ;
-
- char_ =
- qi::raw[
- -qi::no_case['l']
- >> '\'' >> *(string_char - '\'') >> -qi::lit('\'')
- ]
- >> qi::attr("char")
- ;
-
- number
- = qi::raw
- [
- (
- qi::no_case["0x"] >> qi::hex
- | '0' >> qi::oct
- | qi::long_double
- )
- >> *qi::no_case[qi::char_("ldfu")]
- ]
- >> qi::attr("number")
- ;
-
- identifier
- = qi::raw[(qi::alpha | '_') >> *(qi::alnum | '_')]
- >> qi::attr("identifier")
- ;
-
- // TODO: warn user?
- unexpected
- = qi::raw[qi::char_]
- >> qi::attr("error")
- ;
- }
-
- qi::rule<iterator> program, escape, string_char;
- qi::rule<iterator, quickbook::macro()> macro;
- qi::rule<iterator, code_token()>
- space, preprocessor, comment, special, string_,
- char_, number, identifier, keyword, unexpected;
-
- quickbook::actions& actions;
-
- qi::symbols<> keyword_;
- parse_escaped_impl parse_escaped;
- std::string save;
- };
-
- // Grammar for Python highlighting
- // See also: The Python Reference Manual
- // http://docs.python.org/ref/ref.html
- struct python_highlight : public qi::grammar<iterator>
- {
- python_highlight(quickbook::actions& actions)
- : python_highlight::base_type(program), actions(actions)
- , parse_escaped(actions)
- {
- program
- =
- *( space
- | macro
- | escape
- | comment
- | keyword
- | identifier
- | special
- | string_
- | number
- | unexpected
- ) [actions.process]
- ;
-
- macro =
- ( actions.macro // must not be followed by
- >> !(qi::alpha | '_') // alpha or underscore
- )
- ;
-
- escape =
- "``" >> (
- (qi::raw[+(qi::char_ - "``")] >> "``")
- [parse_escaped]
- | qi::raw[*qi::char_] [actions.error]
- )
- ;
-
- space
- = qi::raw[+qi::space]
- >> qi::attr("space");
-
- comment
- = qi::raw[
- '#' >> *(qi::char_ - qi::eol) >> -qi::eol
- ]
- >> qi::attr("comment")
- ;
-
- keyword
- = qi::raw[keyword_ >> !(qi::alnum | '_')]
- >> qi::attr("keyword")
- ; // make sure we recognize whole words only
-
- keyword_
- =
- "and", "del", "for", "is", "raise",
- "assert", "elif", "from", "lambda", "return",
- "break", "else", "global", "not", "try",
- "class", "except", "if", "or", "while",
- "continue", "exec", "import", "pass", "yield",
- "def", "finally", "in", "print",
-
- // Technically "as" and "None" are not yet keywords (at Python
- // 2.4). They are destined to become keywords, and we treat them
- // as such for syntax highlighting purposes.
-
- "as", "None"
- ;
-
- special
- = +qi::char_("~!%^&*()+={[}]:;,<.>/|\\-")
- >> qi::attr("special")
- ;
-
- string_prefix
- = qi::no_case[qi::string("u") >> - qi::string("r")]
- ;
-
- string_
- = qi::raw[
- -string_prefix
- >> (long_string | short_string)
- ]
- >> qi::attr("string")
- ;
-
- string_char = ('\\' >> qi::char_) | (qi::char_ - '\\');
-
- short_string
- = qi::lit('\'') >> *(string_char - '\'') >> -qi::lit('\'') |
- qi::lit('"') >> *(string_char - '"') >> -qi::lit('"')
- ;
-
- long_string
- = qi::lit("'''") >> *(string_char - "'''") >> -qi::lit("'''") |
- qi::lit("\"\"\"") >> *(string_char - "\"\"\"") >> -qi::lit("\"\"\"")
- ;
-
- number
- = qi::raw[
- (
- qi::no_case["0x"] >> qi::hex
- | '0' >> qi::oct
- | qi::long_double
- )
- >> *qi::no_case[qi::char_("lj")]
- ]
- >> qi::attr("number")
- ;
-
- identifier
- = qi::raw[(qi::alpha | '_') >> *(qi::alnum | '_')]
- >> qi::attr("identifier")
- ;
-
- // TODO: warn user?
- unexpected
- = qi::raw[qi::char_]
- >> qi::attr("error")
- ;
- }
-
- qi::rule<iterator>
- program, string_prefix, short_string, long_string,
- escape, string_char;
- qi::rule<iterator, quickbook::macro()> macro;
- qi::rule<iterator, code_token()>
- space, comment, special, string_,
- number, identifier, keyword, unexpected;
-
- quickbook::actions& actions;
-
- qi::symbols<> keyword_;
- parse_escaped_impl parse_escaped;
- std::string save;
- };
-
- // Grammar for plain text (no actual highlighting)
- struct teletype_highlight : public qi::grammar<iterator>
- {
- teletype_highlight(quickbook::actions& actions)
- : teletype_highlight::base_type(program), actions(actions)
- , parse_escaped(actions)
- {
- program
- =
- *( macro [actions.process]
- | escape
- | qi::char_ [actions.process]
- )
- ;
-
- macro =
- ( actions.macro // must not be followed by
- >> !(qi::alpha | '_') // alpha or underscore
- )
- ;
-
- escape =
- "``" >> (
- (qi::raw[+(qi::char_ - "``")] >> "``")
- [parse_escaped]
- | qi::raw[*qi::char_] [actions.error]
- )
- ;
- }
-
- qi::rule<iterator> program, escape;
- qi::rule<iterator, quickbook::macro()> macro;
-
- quickbook::actions& actions;
-
- parse_escaped_impl parse_escaped;
- std::string save;
- };
-
- std::string syntax_highlight(
- iterator first, iterator last,
- actions& escape_actions,
- std::string& source_mode)
- {
- escape_actions.phrase_push();
-
- // print the code with syntax coloring
- if (source_mode == "c++")
- {
- cpp_highlight cpp_p(escape_actions);
- parse(first, last, cpp_p);
- }
- else if (source_mode == "python")
- {
- python_highlight python_p(escape_actions);
- parse(first, last, python_p);
- }
- else if (source_mode == "teletype")
- {
- teletype_highlight teletype_p(escape_actions);
- parse(first, last, teletype_p);
- }
- else
- {
- BOOST_ASSERT(0);
- }
-
- return escape_actions.phrase_pop();
- }
-}

Copied: branches/quickbook-1.5-spirit2/syntax_highlight_grammar.cpp (from r60134, /branches/quickbook-1.5-spirit2/syntax_highlight.cpp)
==============================================================================


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk