Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63624 - branches/quickbook-1.5-spirit2
From: daniel_james_at_[hidden]
Date: 2010-07-04 14:58:40


Author: danieljames
Date: 2010-07-04 14:58:39 EDT (Sun, 04 Jul 2010)
New Revision: 63624
URL: http://svn.boost.org/trac/boost/changeset/63624

Log:
Use the expectation operator for tables.

I think this makes the error handling a little better. Although it does
bail out after the first error, some per-rule custom error handling
might be smarter.
Text files modified:
   branches/quickbook-1.5-spirit2/block_table_grammar.cpp | 120 ++++++++++++++++++---------------------
   branches/quickbook-1.5-spirit2/grammar.cpp | 46 +++++++++++++++
   2 files changed, 100 insertions(+), 66 deletions(-)

Modified: branches/quickbook-1.5-spirit2/block_table_grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/block_table_grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/block_table_grammar.cpp 2010-07-04 14:58:39 EDT (Sun, 04 Jul 2010)
@@ -9,11 +9,8 @@
 =============================================================================*/
 
 #include <boost/spirit/include/qi_core.hpp>
-#include <boost/spirit/include/qi_attr.hpp>
 #include <boost/spirit/include/qi_eps.hpp>
 #include <boost/spirit/include/qi_eol.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
 #include "grammar_impl.hpp"
 #include "block.hpp"
 #include "actions.hpp"
@@ -30,100 +27,93 @@
         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::block_formatted()> table_cell_body;
         qi::rule<iterator, quickbook::variablelist()> variablelist;
         qi::rule<iterator, quickbook::varlistentry()> varlistentry;
         qi::rule<iterator, quickbook::block_formatted()> varlistterm;
- qi::rule<iterator, quickbook::block_formatted()> varlistterm_body;
         qi::rule<iterator, quickbook::block_formatted()> varlistitem;
- qi::rule<iterator, quickbook::block_formatted()> varlistitem_body;
+
+ qi::rule<iterator> nested_cell_check;
     };
 
     void quickbook_grammar::impl::init_block_table()
     {
         block_table_grammar_local& local = store_.create();
 
+ // Error checking
+
+ local.nested_cell_check = &qi::char_("[]");
+ local.nested_cell_check.name("nested cell");
+
         // Table
         
         block_keyword_rules.add("table", local.table[actions.process]);
 
         local.table =
                 (&(*qi::blank >> qi::eol) | space)
- >> ((
- qi::eps(qbk_since(105u))
+ > -( qi::eps(qbk_since(105u))
>> element_id [member_assign(&quickbook::table::id)]
- ) | qi::eps)
- >> (&(*qi::blank >> qi::eol) | space)
- >> qi::raw[*(qi::char_ - eol)] [member_assign(&quickbook::table::title)]
- >> +eol
- >> (*local.table_row) [member_assign(&quickbook::table::rows)]
- ;
-
- local.table_row =
- space
- >> '['
- >> ( *local.table_cell >> ']' >> space
- | error >> qi::attr(quickbook::table_row())
                 )
- ;
-
- local.table_cell =
- space
- >> '['
- >> ( local.table_cell_body >> ']' >> space
- | error >> qi::attr(quickbook::table_cell())
- )
- ;
-
- local.table_cell_body =
- inside_paragraph [member_assign(&quickbook::block_formatted::content)]
+ > (&(*qi::blank >> qi::eol) | space)
+ > qi::raw[*(qi::char_ - eol)] [member_assign(&quickbook::table::title)]
+ > eol
+ > space
+ > (*local.table_row) [member_assign(&quickbook::table::rows)]
+ ;
+
+ local.table_row
+ = '['
+ > space
+ > local.nested_cell_check
+ > *local.table_cell
+ > ']'
+ > space
+ ;
+
+ local.table_cell
+ = '['
+ > inside_paragraph [member_assign(&quickbook::block_formatted::content)]
                                                     [member_assign(&quickbook::block_formatted::type, "cell")]
+ > ']'
+ > space
             ;
 
+ local.table.name("table");
+ local.table_row.name("table_row");
+ local.table_cell.name("table_cell");
+
         block_keyword_rules.add("variablelist", local.variablelist[actions.process]);
 
         local.variablelist =
                 (&(*qi::blank >> qi::eol) | space)
- >> qi::raw[*(qi::char_ - eol)] [member_assign(&quickbook::variablelist::title)]
- >> +eol
- >> (*local.varlistentry) [member_assign(&quickbook::variablelist::entries)]
+ > qi::raw[*(qi::char_ - eol)] [member_assign(&quickbook::variablelist::title)]
+ > eol
+ > space
+ > (*local.varlistentry) [member_assign(&quickbook::variablelist::entries)]
             ;
             
- local.varlistentry =
- space
- >> '['
- >> ( local.varlistterm
- >> +local.varlistitem
- >> ']'
- >> space
- | error >> qi::attr(quickbook::varlistentry())
- )
+ local.varlistentry
+ = '['
+ > space
+ > local.varlistterm
+ > +local.varlistitem
+ > ']'
+ > space
             ;
 
- local.varlistterm =
- space
- >> '['
- >> ( local.varlistterm_body >> ']' >> space
- | error >> qi::attr(quickbook::block_formatted())
- )
- ;
-
- local.varlistterm_body =
- phrase [member_assign(&quickbook::block_formatted::content)]
+ local.varlistterm
+ = '['
+ > phrase [member_assign(&quickbook::block_formatted::content)]
                                                     [member_assign(&quickbook::block_formatted::type, "varlistterm")]
+ > ']'
+ > space
             ;
 
- local.varlistitem =
- space
- >> '['
- >> ( local.varlistitem_body >> ']' >> space
- | error >> qi::attr(quickbook::block_formatted())
- )
- ;
-
- local.varlistitem_body =
- inside_paragraph [member_assign(&quickbook::block_formatted::content)]
+ local.varlistitem
+ = '['
+ > inside_paragraph [member_assign(&quickbook::block_formatted::content)]
                                                     [member_assign(&quickbook::block_formatted::type, "varlistitem")]
+ > ']'
+ > space
             ;
     }
-}
\ No newline at end of file
+}

Modified: branches/quickbook-1.5-spirit2/grammar.cpp
==============================================================================
--- branches/quickbook-1.5-spirit2/grammar.cpp (original)
+++ branches/quickbook-1.5-spirit2/grammar.cpp 2010-07-04 14:58:39 EDT (Sun, 04 Jul 2010)
@@ -10,10 +10,53 @@
 =============================================================================*/
 
 #include "grammar_impl.hpp"
+#include "utils.hpp"
+#include "actions.hpp"
+#include "state.hpp"
+#include <boost/spirit/include/qi_nonterminal.hpp>
 
 namespace quickbook
 {
- quickbook_grammar::quickbook_grammar(quickbook::actions& a)
+ struct error_handler
+ {
+ error_handler(quickbook::actions& a)
+ : actions_(a) {}
+
+ void operator()(
+ boost::fusion::vector<
+ iterator&,
+ iterator const&,
+ iterator const&,
+ boost::spirit::info const&> args,
+ boost::spirit::unused_type,
+ qi::error_handler_result& r) const
+ {
+ iterator& first = boost::fusion::at_c<0>(args);
+ iterator end = boost::fusion::at_c<1>(args);
+ iterator pos = boost::fusion::at_c<2>(args);
+ boost::spirit::info const& error = boost::fusion::at_c<3>(args);
+
+ detail::outerr(pos.get_position().file, pos.get_position().line)
+ << "Syntax error near column "
+ << pos.get_position().column
+ << ". Expecting "
+ << error
+ << "."
+ << std::endl;
+
+ ++actions_.state_.error_count;
+
+ // Pretend we've successfully parsed the whole content since we've
+ // already complained about the parse error and don't want to
+ // complain again.
+ r = qi::accept;
+ first = end;
+ }
+
+ quickbook::actions& actions_;
+ };
+
+ quickbook_grammar::quickbook_grammar(quickbook::actions& a)
         : impl_(new impl(a))
         , command_line_macro(impl_->command_line_macro, "command_line_macro")
         , phrase(impl_->common, "phrase")
@@ -21,6 +64,7 @@
         , block(impl_->block_start, "block")
         , doc_info(impl_->doc_info_details, "doc_info")
     {
+ qi::on_error(impl_->block_start, error_handler(a));
     }
     
     quickbook_grammar::~quickbook_grammar()


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