Version 1.0.2 created by Frank Hein and the mxc-commons team.
MxcQitoo provides some additional parser components for the Boost-Spirit-Qi (currently v2.5.2) parser library. Boost Spirit Qi documentation can be found here.
MxcQitoo is part of the maxence Open Source initiative by maxence business consulting gmbh, Germany.
Spirit is a set of C++ libraries for parsing and output generation implemented as Domain Specific Embedded Languages (DSEL) using Expression templates and Template Meta-Programming. The Spirit libraries enable a target grammar to be written exclusively in C++. Inline grammar specifications can mix freely with other C++ code and, thanks to the generative power of C++ templates, are immediately executable.
Spirit is part of Boost C++ Libraries, a peer-reviewed, open collaborative development effort.
- Boost C++ Libraries (latest)
The parser components are tested with Boost 1.6.0 and 1.6.1, but should work even on older boost installations.
- Ease the use of parsers for the implementors in some situations
- Simplification of rules
As spirit::qi qitoo is a header only collection of parsers.
- Clone this project to a location you want.
- Add the
mxc
directory to your include path. - Directory organisation just like Boost directory organisation
-
MxcQitoo parser objects live in the namespace
mxc::qitoo
(reads qi, too ;). Use like#include <mxc/qitoo/qitoo.hpp> namespace qitoo=mxc::qitoo; namespace qi = boost::spirit::qi; // just to show qi::rule<iterator_type, result_type(), skipper_type> rule = qi::raw["X"] >> qitoo::probe[id];
-
Spirit::Qi headers get included by qitoo.hpp automatically.
-
Please have a look at the provided examples which supplement this small documentation.
Provided are the directives:
-
expect -
qitoo::expect
works similar to the qi expect operator >. See documentation here here. Other than the qi operator the qitoo expect directive throws an exception even if the first operand fails. Usage:qitoo::expect[parser-expression]
Note: With Boost::Spirit v2.5.4 the expect directive was integrated into qi (see boostorg/spirit#196).
-
probe -
qitoo::probe
works exactly asqi::hold
. See documentation here here.O ther thanqi::hold
doesqitoo::probe
not require to implement swap for the ast containers. This convenience gets payed for with runtime and possibly increased buffering requirements, becauseprobe
does lookahead parsing to work. Usage:qitoo::probe[parser-expression]
Note: One important design goal of
spirit::qi
is speed. Keep in mind, thatprobe
parses twice if successful, so take care not to apply it to parser-expressions if it can consume MB of input. An advantage of 'qitoo::probe' overqi::hold
is that it can be applied to temporaries, soparser-expression >> qitoo::probe[parser-expression] >> ...
will work as expected without having taking care about that 'temporaray' type and how to swap it..
-
operator / - This operator acts like the
qi::operator %
, [see documentation here] (http://www.boost.org/doc/libs/1_61_0/libs/spirit/doc/html/spirit/qi/reference/operator/list.html) but the right hand side operand contributes to the attribute vector also.qi::operator %
discards the rhs operand's attribute.id % char_(';,')]
does the same asid / qi::omit[char_(';,')]
Note:
qitoo::operator /
needs to lookahead both operands to detect if the list continues and to make sure, that the returned attribute is not polluted with temporary results. Consider runtime effects and increased buffering requirements. For tasks like the following this is not relevant, but if you take a serious long string of thousands of chars it would be.id = (qi::alpha | qi::char_('_')) >> *(qi::alnum | qi::char_('_')); qualified_id = id / qi::string("::");
Given an input of ident1::ident2
qualified_id matches providing the result ident1::ident2
.
Given an input of ident1
qualified_id matches providing the result ident1
.
MxcQitoo supports named n-ary operators. These operators use a function style syntax op(p1, ...)
, where op
is the named operator, and p1, ...
are parser expressions.
- function if_: This implements a ternary conditional operator (thus taking 3 arguments). Syntax is
if_(condition, if, else)
wherecondition
,if
andelse
are parser expressions. Attribute type ofif_
is a boost::variant ofif
andelse
attributes. Thecondition
parser does not contribute to the attribute. See if.cpp in the test directory for examples on how to use it.
MxcQitoo is distributed under the Boost Software License, Version 1.0. (See link or accompanying file LICENSE.txt).
This work relies on Boost Spirit, which lives because of the tremendous amount of time and effort spent by Joel de Guzman, Hartmut Kaiser and many other developers who made Spirit happen.