From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../libs/metaparse/example/meta_hs/grammar.hpp | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/boost/libs/metaparse/example/meta_hs/grammar.hpp (limited to 'src/boost/libs/metaparse/example/meta_hs/grammar.hpp') diff --git a/src/boost/libs/metaparse/example/meta_hs/grammar.hpp b/src/boost/libs/metaparse/example/meta_hs/grammar.hpp new file mode 100644 index 000000000..e4bcf0b63 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/grammar.hpp @@ -0,0 +1,130 @@ +#ifndef META_HS_GRAMMAR_HPP +#define META_HS_GRAMMAR_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under 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 +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace grammar +{ + /* + * The grammar + * + * definition ::= token::name+ token::define expression + * expression ::= cmp_exp + * cmp_exp ::= plus_exp (token::cmp plus_exp)* + * plus_exp ::= mult_exp ((token::plus | token::minus) mult_exp)* + * mult_exp ::= application ((token::mult | token::div) application)* + * application ::= single_exp+ + * single_exp ::= if_exp | token::name | token::int_ | bracket_exp + * if_exp ::= token::if_ expression token::then expression token::else_ expression + * bracket_exp ::= token::open_bracket expression token::close_bracket + */ + + struct expression; + + typedef + boost::metaparse::middle_of< + token::open_bracket, + expression, + token::close_bracket + > + bracket_exp; + + typedef + boost::metaparse::transform< + boost::metaparse::sequence< + boost::metaparse::last_of, + boost::metaparse::last_of, + boost::metaparse::last_of + >, + semantic::if_ + > + if_exp; + + typedef + boost::metaparse::one_of< + if_exp, + boost::metaparse::transform, + boost::metaparse::transform, + bracket_exp + > + single_exp; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + single_exp, + single_exp, + semantic::application + > + application; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::sequence< + boost::metaparse::one_of, + application + >, + application, + semantic::binary_op + > + mult_exp; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::sequence< + boost::metaparse::one_of, + mult_exp + >, + mult_exp, + semantic::binary_op + > + plus_exp; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::sequence, + plus_exp, + semantic::binary_op + > + cmp_exp; + + struct expression : cmp_exp {}; + + typedef + boost::metaparse::transform< + boost::metaparse::sequence< + token::name, + boost::metaparse::foldr_start_with_parser< + token::name, + boost::metaparse::last_of, + semantic::lambda + > + >, + semantic::pair + > + definition; + + typedef + boost::metaparse::build_parser< + boost::metaparse::entire_input + > + def_parser; +} + +#endif + -- cgit v1.2.3