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 --- src/boost/libs/metaparse/README.md | 8 + src/boost/libs/metaparse/example/Jamfile.v2 | 14 + .../metaparse/example/binary_number/Jamfile.v2 | 1 + .../libs/metaparse/example/binary_number/README | 1 + .../libs/metaparse/example/binary_number/main.cpp | 85 +++++ .../libs/metaparse/example/calculator/Jamfile.v2 | 6 + src/boost/libs/metaparse/example/calculator/README | 1 + .../libs/metaparse/example/calculator/main.cpp | 157 ++++++++ .../example/calculator_with_parens/Jamfile.v2 | 1 + .../example/calculator_with_parens/README | 2 + .../example/calculator_with_parens/main.cpp | 163 ++++++++ .../Jamfile.v2 | 1 + .../calculator_with_parens_and_unary_ops/README | 2 + .../calculator_with_parens_and_unary_ops/main.cpp | 192 ++++++++++ .../example/compile_to_native_code/Jamfile.v2 | 1 + .../example/compile_to_native_code/README | 1 + .../example/compile_to_native_code/main.cpp | 252 +++++++++++++ .../metaparse/example/constexpr_parser/Jamfile.v2 | 1 + .../libs/metaparse/example/constexpr_parser/README | 12 + .../metaparse/example/constexpr_parser/main.cpp | 318 ++++++++++++++++ .../libs/metaparse/example/getting_started/1.hpp | 9 + .../libs/metaparse/example/getting_started/10.hpp | 42 +++ .../libs/metaparse/example/getting_started/11.hpp | 62 +++ .../metaparse/example/getting_started/11_1.hpp | 14 + .../metaparse/example/getting_started/11_2.hpp | 12 + .../metaparse/example/getting_started/11_3.hpp | 49 +++ .../metaparse/example/getting_started/11_3_1.hpp | 38 ++ .../metaparse/example/getting_started/11_3_2.hpp | 25 ++ .../libs/metaparse/example/getting_started/12.hpp | 46 +++ .../libs/metaparse/example/getting_started/1_1.hpp | 12 + .../libs/metaparse/example/getting_started/1_2.hpp | 12 + .../metaparse/example/getting_started/1_2_1.hpp | 12 + .../metaparse/example/getting_started/1_2_2.hpp | 12 + .../libs/metaparse/example/getting_started/2.hpp | 12 + .../libs/metaparse/example/getting_started/3.hpp | 19 + .../libs/metaparse/example/getting_started/3_1.hpp | 22 ++ .../libs/metaparse/example/getting_started/3_2.hpp | 14 + .../libs/metaparse/example/getting_started/3_3.hpp | 24 ++ .../libs/metaparse/example/getting_started/4.hpp | 21 ++ .../libs/metaparse/example/getting_started/4_1.hpp | 27 ++ .../libs/metaparse/example/getting_started/4_2.hpp | 20 + .../libs/metaparse/example/getting_started/5.hpp | 45 +++ .../libs/metaparse/example/getting_started/5_1.hpp | 12 + .../libs/metaparse/example/getting_started/5_2.hpp | 24 ++ .../metaparse/example/getting_started/5_2_1.hpp | 13 + .../metaparse/example/getting_started/5_2_2.hpp | 58 +++ .../metaparse/example/getting_started/5_2_3.hpp | 58 +++ .../metaparse/example/getting_started/5_2_4.hpp | 27 ++ .../libs/metaparse/example/getting_started/6.hpp | 25 ++ .../libs/metaparse/example/getting_started/6_1.hpp | 12 + .../libs/metaparse/example/getting_started/6_2.hpp | 27 ++ .../libs/metaparse/example/getting_started/7.hpp | 49 +++ .../libs/metaparse/example/getting_started/7_1.hpp | 12 + .../libs/metaparse/example/getting_started/7_2.hpp | 35 ++ .../libs/metaparse/example/getting_started/8.hpp | 25 ++ .../libs/metaparse/example/getting_started/8_1.hpp | 36 ++ .../libs/metaparse/example/getting_started/8_2.hpp | 12 + .../libs/metaparse/example/getting_started/9.hpp | 42 +++ .../libs/metaparse/example/getting_started/README | 6 + .../example/grammar_calculator/Jamfile.v2 | 6 + .../metaparse/example/grammar_calculator/README | 2 + .../metaparse/example/grammar_calculator/main.cpp | 160 ++++++++ .../libs/metaparse/example/meta_hs/Jamfile.v2 | 11 + src/boost/libs/metaparse/example/meta_hs/README | 4 + src/boost/libs/metaparse/example/meta_hs/ast.hpp | 43 +++ src/boost/libs/metaparse/example/meta_hs/bind.hpp | 63 ++++ .../libs/metaparse/example/meta_hs/builder.hpp | 80 ++++ src/boost/libs/metaparse/example/meta_hs/curry.hpp | 106 ++++++ .../metaparse/example/meta_hs/double_number.hpp | 18 + .../example/meta_hs/example_handcrafted.hpp | 93 +++++ .../example/meta_hs/example_in_haskell.hpp | 53 +++ .../metaparse/example/meta_hs/except_keywords.hpp | 61 +++ .../libs/metaparse/example/meta_hs/grammar.hpp | 130 +++++++ src/boost/libs/metaparse/example/meta_hs/lazy.hpp | 24 ++ .../metaparse/example/meta_hs/main_handcrafted.cpp | 20 + .../metaparse/example/meta_hs/main_in_haskell.cpp | 20 + .../libs/metaparse/example/meta_hs/meta_hs.hpp | 64 ++++ .../libs/metaparse/example/meta_hs/semantic.hpp | 115 ++++++ src/boost/libs/metaparse/example/meta_hs/token.hpp | 168 +++++++++ .../libs/metaparse/example/meta_lambda/Jamfile.v2 | 1 + .../libs/metaparse/example/meta_lambda/README | 1 + .../libs/metaparse/example/meta_lambda/main.cpp | 265 +++++++++++++ .../metaparse/example/meta_metaparse/Jamfile.v2 | 6 + .../libs/metaparse/example/meta_metaparse/README | 1 + .../libs/metaparse/example/meta_metaparse/main.cpp | 258 +++++++++++++ .../metaparse/example/minimal_rational/Jamfile.v2 | 1 + .../libs/metaparse/example/minimal_rational/README | 3 + .../metaparse/example/minimal_rational/main.cpp | 79 ++++ .../metaparse/example/parsing_error/Jamfile.v2 | 1 + .../libs/metaparse/example/parsing_error/README | 17 + .../libs/metaparse/example/parsing_error/main.cpp | 51 +++ .../libs/metaparse/example/rational/Jamfile.v2 | 1 + src/boost/libs/metaparse/example/rational/README | 1 + src/boost/libs/metaparse/example/rational/main.cpp | 97 +++++ src/boost/libs/metaparse/example/regexp/Jamfile.v2 | 1 + src/boost/libs/metaparse/example/regexp/README | 7 + src/boost/libs/metaparse/example/regexp/main.cpp | 158 ++++++++ src/boost/libs/metaparse/index.html | 13 + src/boost/libs/metaparse/meta/libraries.json | 8 + .../libs/metaparse/test/BOOST_METAPARSE_STRING.cpp | 63 ++++ src/boost/libs/metaparse/test/Jamfile.v2 | 114 ++++++ src/boost/libs/metaparse/test/accept.cpp | 71 ++++ src/boost/libs/metaparse/test/accept_when.cpp | 69 ++++ src/boost/libs/metaparse/test/all_headers.cpp | 8 + src/boost/libs/metaparse/test/alphanum.cpp | 50 +++ src/boost/libs/metaparse/test/always.cpp | 43 +++ src/boost/libs/metaparse/test/always_c.cpp | 41 ++ src/boost/libs/metaparse/test/at_c.cpp | 35 ++ src/boost/libs/metaparse/test/back_inserter.cpp | 26 ++ src/boost/libs/metaparse/test/build_parser.cpp | 7 + .../libs/metaparse/test/change_error_message.cpp | 7 + src/boost/libs/metaparse/test/common.hpp | 110 ++++++ src/boost/libs/metaparse/test/concat.cpp | 48 +++ src/boost/libs/metaparse/test/define_error.cpp | 28 ++ src/boost/libs/metaparse/test/digit.cpp | 55 +++ src/boost/libs/metaparse/test/digit_to_int.cpp | 42 +++ src/boost/libs/metaparse/test/digit_val.cpp | 40 ++ src/boost/libs/metaparse/test/empty.cpp | 39 ++ src/boost/libs/metaparse/test/empty_string.cpp | 27 ++ src/boost/libs/metaparse/test/entire_input.cpp | 57 +++ src/boost/libs/metaparse/test/except.cpp | 56 +++ src/boost/libs/metaparse/test/fail.cpp | 30 ++ .../metaparse/test/fail_at_first_char_expected.cpp | 42 +++ src/boost/libs/metaparse/test/fail_tag.cpp | 41 ++ src/boost/libs/metaparse/test/first_of.cpp | 68 ++++ src/boost/libs/metaparse/test/foldl.cpp | 25 ++ src/boost/libs/metaparse/test/foldl1.cpp | 25 ++ .../metaparse/test/foldl_reject_incomplete.cpp | 27 ++ .../metaparse/test/foldl_reject_incomplete1.cpp | 27 ++ .../foldl_reject_incomplete_start_with_parser.cpp | 97 +++++ .../metaparse/test/foldl_start_with_parser.cpp | 88 +++++ src/boost/libs/metaparse/test/foldr.cpp | 25 ++ src/boost/libs/metaparse/test/foldr1.cpp | 25 ++ .../metaparse/test/foldr_reject_incomplete.cpp | 27 ++ .../metaparse/test/foldr_reject_incomplete1.cpp | 27 ++ .../metaparse/test/foldr_start_with_parser.cpp | 67 ++++ src/boost/libs/metaparse/test/front_inserter.cpp | 26 ++ src/boost/libs/metaparse/test/grammar.cpp | 420 +++++++++++++++++++++ src/boost/libs/metaparse/test/has_type.cpp | 32 ++ src/boost/libs/metaparse/test/if_.cpp | 46 +++ src/boost/libs/metaparse/test/in_range.cpp | 35 ++ src/boost/libs/metaparse/test/in_range_c.cpp | 36 ++ src/boost/libs/metaparse/test/int_.cpp | 53 +++ src/boost/libs/metaparse/test/int_to_digit.cpp | 33 ++ src/boost/libs/metaparse/test/is_char_c.cpp | 25 ++ src/boost/libs/metaparse/test/is_digit.cpp | 30 ++ src/boost/libs/metaparse/test/is_error.cpp | 31 ++ src/boost/libs/metaparse/test/is_lcase_letter.cpp | 29 ++ src/boost/libs/metaparse/test/is_letter.cpp | 32 ++ src/boost/libs/metaparse/test/is_ucase_letter.cpp | 29 ++ src/boost/libs/metaparse/test/is_whitespace.cpp | 32 ++ src/boost/libs/metaparse/test/iterate.cpp | 73 ++++ src/boost/libs/metaparse/test/iterate_c.cpp | 73 ++++ src/boost/libs/metaparse/test/keyword.cpp | 91 +++++ src/boost/libs/metaparse/test/last_of.cpp | 71 ++++ src/boost/libs/metaparse/test/letter.cpp | 41 ++ src/boost/libs/metaparse/test/lit.cpp | 74 ++++ src/boost/libs/metaparse/test/lit_c.cpp | 74 ++++ src/boost/libs/metaparse/test/long_string.cpp | 56 +++ src/boost/libs/metaparse/test/look_ahead.cpp | 60 +++ src/boost/libs/metaparse/test/middle_of.cpp | 81 ++++ src/boost/libs/metaparse/test/next_digit.cpp | 25 ++ src/boost/libs/metaparse/test/nth_of.cpp | 97 +++++ src/boost/libs/metaparse/test/one_char.cpp | 16 + src/boost/libs/metaparse/test/one_char_except.cpp | 19 + .../libs/metaparse/test/one_char_except_c.cpp | 18 + .../libs/metaparse/test/one_char_except_test.hpp | 33 ++ src/boost/libs/metaparse/test/one_char_test.hpp | 103 +++++ src/boost/libs/metaparse/test/one_of.cpp | 158 ++++++++ src/boost/libs/metaparse/test/one_of_c.cpp | 75 ++++ src/boost/libs/metaparse/test/optional.cpp | 55 +++ src/boost/libs/metaparse/test/pop_back.cpp | 38 ++ src/boost/libs/metaparse/test/pop_front.cpp | 38 ++ src/boost/libs/metaparse/test/push_back_c.cpp | 40 ++ src/boost/libs/metaparse/test/push_front_c.cpp | 40 ++ src/boost/libs/metaparse/test/range.cpp | 47 +++ src/boost/libs/metaparse/test/range_c.cpp | 47 +++ src/boost/libs/metaparse/test/reject.cpp | 58 +++ src/boost/libs/metaparse/test/repeated.cpp | 13 + src/boost/libs/metaparse/test/repeated1.cpp | 13 + src/boost/libs/metaparse/test/repeated1_test.hpp | 99 +++++ src/boost/libs/metaparse/test/repeated_one_of.cpp | 106 ++++++ src/boost/libs/metaparse/test/repeated_one_of1.cpp | 100 +++++ .../metaparse/test/repeated_reject_incomplete.cpp | 13 + .../metaparse/test/repeated_reject_incomplete1.cpp | 13 + .../test/repeated_reject_incomplete1_test.hpp | 173 +++++++++ .../test/repeated_reject_incomplete_test.hpp | 176 +++++++++ src/boost/libs/metaparse/test/repeated_test.hpp | 117 ++++++ src/boost/libs/metaparse/test/return_.cpp | 61 +++ src/boost/libs/metaparse/test/returns.cpp | 23 ++ src/boost/libs/metaparse/test/sequence.cpp | 115 ++++++ src/boost/libs/metaparse/test/sequence_apply.cpp | 162 ++++++++ src/boost/libs/metaparse/test/size.cpp | 40 ++ src/boost/libs/metaparse/test/source_position.cpp | 339 +++++++++++++++++ src/boost/libs/metaparse/test/space.cpp | 79 ++++ src/boost/libs/metaparse/test/spaces.cpp | 70 ++++ src/boost/libs/metaparse/test/string.cpp | 166 ++++++++ .../libs/metaparse/test/string_iterator_tag.cpp | 23 ++ src/boost/libs/metaparse/test/string_macros.hpp | 82 ++++ src/boost/libs/metaparse/test/string_tag.cpp | 23 ++ src/boost/libs/metaparse/test/swap.cpp | 52 +++ src/boost/libs/metaparse/test/test_case.hpp | 18 + src/boost/libs/metaparse/test/token.cpp | 74 ++++ src/boost/libs/metaparse/test/too_long_string.cpp | 13 + src/boost/libs/metaparse/test/transform.cpp | 79 ++++ src/boost/libs/metaparse/test/transform_error.cpp | 65 ++++ .../metaparse/test/transform_error_message.cpp | 68 ++++ src/boost/libs/metaparse/test/unless_error.cpp | 40 ++ src/boost/libs/metaparse/test/unpaired.cpp | 36 ++ src/boost/libs/metaparse/test/update_c.cpp | 43 +++ src/boost/libs/metaparse/test/version.cpp | 20 + src/boost/libs/metaparse/tools/benchmark/README.md | 14 + .../libs/metaparse/tools/benchmark/benchmark.py | 354 +++++++++++++++++ .../libs/metaparse/tools/benchmark/char_stat.py | 59 +++ src/boost/libs/metaparse/tools/benchmark/chars.py | 1 + .../libs/metaparse/tools/benchmark/generate.py | 299 +++++++++++++++ .../tools/benchmark/include/benchmark_util.hpp | 281 ++++++++++++++ .../metaparse/tools/benchmark/src/length128.cpp | 18 + .../metaparse/tools/benchmark/src/max_length.cpp | 21 ++ .../libs/metaparse/tools/benchmark/src/number.cpp | 18 + .../libs/metaparse/tools/build_environment.py | 134 +++++++ src/boost/libs/metaparse/tools/deps.json | 60 +++ src/boost/libs/metaparse/tools/generate_all.py | 295 +++++++++++++++ src/boost/libs/metaparse/tools/string_headers.py | 347 +++++++++++++++++ 224 files changed, 13034 insertions(+) create mode 100644 src/boost/libs/metaparse/README.md create mode 100644 src/boost/libs/metaparse/example/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/binary_number/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/binary_number/README create mode 100644 src/boost/libs/metaparse/example/binary_number/main.cpp create mode 100644 src/boost/libs/metaparse/example/calculator/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/calculator/README create mode 100644 src/boost/libs/metaparse/example/calculator/main.cpp create mode 100644 src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/calculator_with_parens/README create mode 100644 src/boost/libs/metaparse/example/calculator_with_parens/main.cpp create mode 100644 src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README create mode 100644 src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp create mode 100644 src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/compile_to_native_code/README create mode 100644 src/boost/libs/metaparse/example/compile_to_native_code/main.cpp create mode 100644 src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/constexpr_parser/README create mode 100644 src/boost/libs/metaparse/example/constexpr_parser/main.cpp create mode 100644 src/boost/libs/metaparse/example/getting_started/1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/10.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/11.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/11_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/11_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/11_3.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/11_3_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/11_3_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/12.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/1_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/1_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/1_2_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/1_2_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/3.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/3_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/3_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/3_3.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/4.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/4_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/4_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5_2_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5_2_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5_2_3.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/5_2_4.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/6.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/6_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/6_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/7.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/7_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/7_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/8.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/8_1.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/8_2.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/9.hpp create mode 100644 src/boost/libs/metaparse/example/getting_started/README create mode 100644 src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/grammar_calculator/README create mode 100644 src/boost/libs/metaparse/example/grammar_calculator/main.cpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/meta_hs/README create mode 100644 src/boost/libs/metaparse/example/meta_hs/ast.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/bind.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/builder.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/curry.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/double_number.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/example_handcrafted.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/example_in_haskell.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/except_keywords.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/grammar.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/lazy.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/main_handcrafted.cpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/main_in_haskell.cpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/meta_hs.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/semantic.hpp create mode 100644 src/boost/libs/metaparse/example/meta_hs/token.hpp create mode 100644 src/boost/libs/metaparse/example/meta_lambda/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/meta_lambda/README create mode 100644 src/boost/libs/metaparse/example/meta_lambda/main.cpp create mode 100644 src/boost/libs/metaparse/example/meta_metaparse/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/meta_metaparse/README create mode 100644 src/boost/libs/metaparse/example/meta_metaparse/main.cpp create mode 100644 src/boost/libs/metaparse/example/minimal_rational/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/minimal_rational/README create mode 100644 src/boost/libs/metaparse/example/minimal_rational/main.cpp create mode 100644 src/boost/libs/metaparse/example/parsing_error/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/parsing_error/README create mode 100644 src/boost/libs/metaparse/example/parsing_error/main.cpp create mode 100644 src/boost/libs/metaparse/example/rational/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/rational/README create mode 100644 src/boost/libs/metaparse/example/rational/main.cpp create mode 100644 src/boost/libs/metaparse/example/regexp/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/regexp/README create mode 100644 src/boost/libs/metaparse/example/regexp/main.cpp create mode 100644 src/boost/libs/metaparse/index.html create mode 100644 src/boost/libs/metaparse/meta/libraries.json create mode 100644 src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp create mode 100644 src/boost/libs/metaparse/test/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/test/accept.cpp create mode 100644 src/boost/libs/metaparse/test/accept_when.cpp create mode 100644 src/boost/libs/metaparse/test/all_headers.cpp create mode 100644 src/boost/libs/metaparse/test/alphanum.cpp create mode 100644 src/boost/libs/metaparse/test/always.cpp create mode 100644 src/boost/libs/metaparse/test/always_c.cpp create mode 100644 src/boost/libs/metaparse/test/at_c.cpp create mode 100644 src/boost/libs/metaparse/test/back_inserter.cpp create mode 100644 src/boost/libs/metaparse/test/build_parser.cpp create mode 100644 src/boost/libs/metaparse/test/change_error_message.cpp create mode 100644 src/boost/libs/metaparse/test/common.hpp create mode 100644 src/boost/libs/metaparse/test/concat.cpp create mode 100644 src/boost/libs/metaparse/test/define_error.cpp create mode 100644 src/boost/libs/metaparse/test/digit.cpp create mode 100644 src/boost/libs/metaparse/test/digit_to_int.cpp create mode 100644 src/boost/libs/metaparse/test/digit_val.cpp create mode 100644 src/boost/libs/metaparse/test/empty.cpp create mode 100644 src/boost/libs/metaparse/test/empty_string.cpp create mode 100644 src/boost/libs/metaparse/test/entire_input.cpp create mode 100644 src/boost/libs/metaparse/test/except.cpp create mode 100644 src/boost/libs/metaparse/test/fail.cpp create mode 100644 src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp create mode 100644 src/boost/libs/metaparse/test/fail_tag.cpp create mode 100644 src/boost/libs/metaparse/test/first_of.cpp create mode 100644 src/boost/libs/metaparse/test/foldl.cpp create mode 100644 src/boost/libs/metaparse/test/foldl1.cpp create mode 100644 src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp create mode 100644 src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp create mode 100644 src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp create mode 100644 src/boost/libs/metaparse/test/foldl_start_with_parser.cpp create mode 100644 src/boost/libs/metaparse/test/foldr.cpp create mode 100644 src/boost/libs/metaparse/test/foldr1.cpp create mode 100644 src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp create mode 100644 src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp create mode 100644 src/boost/libs/metaparse/test/foldr_start_with_parser.cpp create mode 100644 src/boost/libs/metaparse/test/front_inserter.cpp create mode 100644 src/boost/libs/metaparse/test/grammar.cpp create mode 100644 src/boost/libs/metaparse/test/has_type.cpp create mode 100644 src/boost/libs/metaparse/test/if_.cpp create mode 100644 src/boost/libs/metaparse/test/in_range.cpp create mode 100644 src/boost/libs/metaparse/test/in_range_c.cpp create mode 100644 src/boost/libs/metaparse/test/int_.cpp create mode 100644 src/boost/libs/metaparse/test/int_to_digit.cpp create mode 100644 src/boost/libs/metaparse/test/is_char_c.cpp create mode 100644 src/boost/libs/metaparse/test/is_digit.cpp create mode 100644 src/boost/libs/metaparse/test/is_error.cpp create mode 100644 src/boost/libs/metaparse/test/is_lcase_letter.cpp create mode 100644 src/boost/libs/metaparse/test/is_letter.cpp create mode 100644 src/boost/libs/metaparse/test/is_ucase_letter.cpp create mode 100644 src/boost/libs/metaparse/test/is_whitespace.cpp create mode 100644 src/boost/libs/metaparse/test/iterate.cpp create mode 100644 src/boost/libs/metaparse/test/iterate_c.cpp create mode 100644 src/boost/libs/metaparse/test/keyword.cpp create mode 100644 src/boost/libs/metaparse/test/last_of.cpp create mode 100644 src/boost/libs/metaparse/test/letter.cpp create mode 100644 src/boost/libs/metaparse/test/lit.cpp create mode 100644 src/boost/libs/metaparse/test/lit_c.cpp create mode 100644 src/boost/libs/metaparse/test/long_string.cpp create mode 100644 src/boost/libs/metaparse/test/look_ahead.cpp create mode 100644 src/boost/libs/metaparse/test/middle_of.cpp create mode 100644 src/boost/libs/metaparse/test/next_digit.cpp create mode 100644 src/boost/libs/metaparse/test/nth_of.cpp create mode 100644 src/boost/libs/metaparse/test/one_char.cpp create mode 100644 src/boost/libs/metaparse/test/one_char_except.cpp create mode 100644 src/boost/libs/metaparse/test/one_char_except_c.cpp create mode 100644 src/boost/libs/metaparse/test/one_char_except_test.hpp create mode 100644 src/boost/libs/metaparse/test/one_char_test.hpp create mode 100644 src/boost/libs/metaparse/test/one_of.cpp create mode 100644 src/boost/libs/metaparse/test/one_of_c.cpp create mode 100644 src/boost/libs/metaparse/test/optional.cpp create mode 100644 src/boost/libs/metaparse/test/pop_back.cpp create mode 100644 src/boost/libs/metaparse/test/pop_front.cpp create mode 100644 src/boost/libs/metaparse/test/push_back_c.cpp create mode 100644 src/boost/libs/metaparse/test/push_front_c.cpp create mode 100644 src/boost/libs/metaparse/test/range.cpp create mode 100644 src/boost/libs/metaparse/test/range_c.cpp create mode 100644 src/boost/libs/metaparse/test/reject.cpp create mode 100644 src/boost/libs/metaparse/test/repeated.cpp create mode 100644 src/boost/libs/metaparse/test/repeated1.cpp create mode 100644 src/boost/libs/metaparse/test/repeated1_test.hpp create mode 100644 src/boost/libs/metaparse/test/repeated_one_of.cpp create mode 100644 src/boost/libs/metaparse/test/repeated_one_of1.cpp create mode 100644 src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp create mode 100644 src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp create mode 100644 src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp create mode 100644 src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp create mode 100644 src/boost/libs/metaparse/test/repeated_test.hpp create mode 100644 src/boost/libs/metaparse/test/return_.cpp create mode 100644 src/boost/libs/metaparse/test/returns.cpp create mode 100644 src/boost/libs/metaparse/test/sequence.cpp create mode 100644 src/boost/libs/metaparse/test/sequence_apply.cpp create mode 100644 src/boost/libs/metaparse/test/size.cpp create mode 100644 src/boost/libs/metaparse/test/source_position.cpp create mode 100644 src/boost/libs/metaparse/test/space.cpp create mode 100644 src/boost/libs/metaparse/test/spaces.cpp create mode 100644 src/boost/libs/metaparse/test/string.cpp create mode 100644 src/boost/libs/metaparse/test/string_iterator_tag.cpp create mode 100644 src/boost/libs/metaparse/test/string_macros.hpp create mode 100644 src/boost/libs/metaparse/test/string_tag.cpp create mode 100644 src/boost/libs/metaparse/test/swap.cpp create mode 100644 src/boost/libs/metaparse/test/test_case.hpp create mode 100644 src/boost/libs/metaparse/test/token.cpp create mode 100644 src/boost/libs/metaparse/test/too_long_string.cpp create mode 100644 src/boost/libs/metaparse/test/transform.cpp create mode 100644 src/boost/libs/metaparse/test/transform_error.cpp create mode 100644 src/boost/libs/metaparse/test/transform_error_message.cpp create mode 100644 src/boost/libs/metaparse/test/unless_error.cpp create mode 100644 src/boost/libs/metaparse/test/unpaired.cpp create mode 100644 src/boost/libs/metaparse/test/update_c.cpp create mode 100644 src/boost/libs/metaparse/test/version.cpp create mode 100644 src/boost/libs/metaparse/tools/benchmark/README.md create mode 100755 src/boost/libs/metaparse/tools/benchmark/benchmark.py create mode 100755 src/boost/libs/metaparse/tools/benchmark/char_stat.py create mode 100644 src/boost/libs/metaparse/tools/benchmark/chars.py create mode 100755 src/boost/libs/metaparse/tools/benchmark/generate.py create mode 100644 src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp create mode 100644 src/boost/libs/metaparse/tools/benchmark/src/length128.cpp create mode 100644 src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp create mode 100644 src/boost/libs/metaparse/tools/benchmark/src/number.cpp create mode 100755 src/boost/libs/metaparse/tools/build_environment.py create mode 100644 src/boost/libs/metaparse/tools/deps.json create mode 100755 src/boost/libs/metaparse/tools/generate_all.py create mode 100755 src/boost/libs/metaparse/tools/string_headers.py (limited to 'src/boost/libs/metaparse') diff --git a/src/boost/libs/metaparse/README.md b/src/boost/libs/metaparse/README.md new file mode 100644 index 000000000..6a4dd970d --- /dev/null +++ b/src/boost/libs/metaparse/README.md @@ -0,0 +1,8 @@ +# Boost.Metaparse + +[![Build Status](https://secure.travis-ci.org/boostorg/metaparse.svg?branch=master "Build Status")](http://travis-ci.org/boostorg/metaparse) +[![Windows build status](https://ci.appveyor.com/api/projects/status/u7ysxkssmrgr7vau/branch/master?svg=true)](https://ci.appveyor.com/project/sabel83/metaparse-04v04/branch/master) + +Metaparse is parser generator library for template metaprograms. The purpose of +this library is to support the creation of parsers that parse at compile time. + diff --git a/src/boost/libs/metaparse/example/Jamfile.v2 b/src/boost/libs/metaparse/example/Jamfile.v2 new file mode 100644 index 000000000..3b82aec21 --- /dev/null +++ b/src/boost/libs/metaparse/example/Jamfile.v2 @@ -0,0 +1,14 @@ +build-project binary_number ; +build-project calculator ; +build-project calculator_with_parens ; +build-project calculator_with_parens_and_unary_ops ; +build-project compile_to_native_code ; +build-project constexpr_parser ; +build-project grammar_calculator ; +build-project meta_hs ; +build-project meta_lambda ; +build-project meta_metaparse ; +build-project minimal_rational ; +build-project parsing_error ; +build-project rational ; +build-project regexp ; diff --git a/src/boost/libs/metaparse/example/binary_number/Jamfile.v2 b/src/boost/libs/metaparse/example/binary_number/Jamfile.v2 new file mode 100644 index 000000000..9d1bdfdc0 --- /dev/null +++ b/src/boost/libs/metaparse/example/binary_number/Jamfile.v2 @@ -0,0 +1 @@ +exe binary_number : main.cpp ; diff --git a/src/boost/libs/metaparse/example/binary_number/README b/src/boost/libs/metaparse/example/binary_number/README new file mode 100644 index 000000000..580532f48 --- /dev/null +++ b/src/boost/libs/metaparse/example/binary_number/README @@ -0,0 +1 @@ +Parser for binary numbers diff --git a/src/boost/libs/metaparse/example/binary_number/main.cpp b/src/boost/libs/metaparse/example/binary_number/main.cpp new file mode 100644 index 000000000..636245834 --- /dev/null +++ b/src/boost/libs/metaparse/example/binary_number/main.cpp @@ -0,0 +1,85 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// 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 + +using boost::metaparse::foldl1; +using boost::metaparse::build_parser; +using boost::metaparse::transform; +using boost::metaparse::one_of_c; +using boost::metaparse::entire_input; + +using boost::metaparse::util::digit_to_int; + +using boost::mpl::int_; +using boost::mpl::plus; +using boost::mpl::times; + +/* + * The grammar + * + * expression ::= ('1' | '0')* + */ + +struct next_element +{ + template + struct apply : plus >, B> {}; +}; + +typedef + foldl1, digit_to_int<> >, int_<0>, next_element> + S; + +typedef build_parser > binary_parser; + +template +struct binary : binary_parser::apply::type {}; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 + +int main() +{ + using std::cout; + using std::endl; + using boost::metaparse::string; + + cout + << binary >::value << endl + << binary >::value << endl + << binary >::value << endl; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << binary<_STR("100")>::value << endl + << binary<_STR("1011")>::value << endl + << binary<_STR("1")>::value << endl; +} +#endif + + diff --git a/src/boost/libs/metaparse/example/calculator/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator/Jamfile.v2 new file mode 100644 index 000000000..887cff6a8 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/Jamfile.v2 @@ -0,0 +1,6 @@ +project : requirements + gcc:-ftemplate-depth=512 + clang:-ftemplate-depth=512 +; + +exe calculator : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator/README b/src/boost/libs/metaparse/example/calculator/README new file mode 100644 index 000000000..8229ef4b0 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/README @@ -0,0 +1 @@ +Calculator, working at compile-time diff --git a/src/boost/libs/metaparse/example/calculator/main.cpp b/src/boost/libs/metaparse/example/calculator/main.cpp new file mode 100644 index 000000000..fc0dbffa1 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/main.cpp @@ -0,0 +1,157 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) int_token)* + */ + +typedef token > plus_token; +typedef token > minus_token; +typedef token > mult_token; +typedef token > div_token; + +typedef token int_token; + +template +struct is_c : bool_ {}; + +struct eval_plus +{ + template + struct apply : + eval_if< + is_c, '+'>, + plus::type>, + minus::type> + > + {}; +}; + +struct eval_mult +{ + template + struct apply : + eval_if< + is_c, '*'>, + times::type>, + divides::type> + > + {}; +}; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, int_token>, + int_token, + eval_mult + > + prod_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, prod_exp>, + prod_exp, + eval_plus + > + plus_exp; + +typedef last_of, plus_exp> expression; + +typedef build_parser > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + using std::cout; + using std::endl; + using boost::metaparse::string; + + cout + << apply_wrap1 >::type::value << endl + << + apply_wrap1< + calculator_parser, string<' ','1','+',' ','2','*','4','-','6','/','2'> + >::type::value + << endl + ; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + ; +} +#endif + + diff --git a/src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 new file mode 100644 index 000000000..af3cf8796 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 @@ -0,0 +1 @@ +exe calculator_with_parens : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator_with_parens/README b/src/boost/libs/metaparse/example/calculator_with_parens/README new file mode 100644 index 000000000..32bccca45 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens/README @@ -0,0 +1,2 @@ +This is an extended version of the calculator example: it supports parens as +well. diff --git a/src/boost/libs/metaparse/example/calculator_with_parens/main.cpp b/src/boost/libs/metaparse/example/calculator_with_parens/main.cpp new file mode 100644 index 000000000..9a154fc36 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens/main.cpp @@ -0,0 +1,163 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::middle_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) simple_exp)* + * simple_exp ::= int_token | paren_exp + * paren_exp ::= open_paren_token expression close_paren_token + */ + +typedef token > plus_token; +typedef token > minus_token; +typedef token > mult_token; +typedef token > div_token; + +typedef token > open_paren_token; +typedef token > close_paren_token; + +typedef token int_token; + +template +struct is_c : bool_ {}; + +struct eval_plus +{ + template + struct apply : + eval_if< + is_c, '+'>, + plus::type>, + minus::type> + > + {}; +}; + +struct eval_mult +{ + template + struct apply : + eval_if< + is_c, '*'>, + times::type>, + divides::type> + > + {}; +}; + +struct plus_exp; + +typedef middle_of paren_exp; + +typedef one_of simple_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, simple_exp>, + simple_exp, + eval_mult + > + prod_exp; + +struct plus_exp : + foldl_reject_incomplete_start_with_parser< + sequence, prod_exp>, + prod_exp, + eval_plus + > +{}; + +typedef last_of, plus_exp> expression; + +typedef build_parser > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + std::cout << "Please use a compiler that support constexpr" << std::endl; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + ; +} +#endif + diff --git a/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 new file mode 100644 index 000000000..4457aa322 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 @@ -0,0 +1 @@ +exe calculator_with_parens_and_unary_ops : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README new file mode 100644 index 000000000..ed8e33ad4 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README @@ -0,0 +1,2 @@ +This is an extended version of the calculator example: it supports unary +operators (eg. -13) as well. diff --git a/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp new file mode 100644 index 000000000..e9557562d --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp @@ -0,0 +1,192 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::middle_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::foldr_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; +using boost::mpl::negate; +using boost::mpl::char_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) simple_exp)* + * simple_exp ::= (plus_token | minus_token)* (int_token | paren_exp) + * paren_exp ::= open_paren_token expression close_paren_token + */ + +typedef token > plus_token; +typedef token > minus_token; +typedef token > mult_token; +typedef token > div_token; + +typedef token > open_paren_token; +typedef token > close_paren_token; + +typedef token int_token; + +template +struct is_c : bool_ {}; + +struct eval_plus +{ + template + struct apply : + eval_if< + is_c, '+'>, + plus::type>, + minus::type> + > + {}; +}; + +struct eval_mult +{ + template + struct apply : + eval_if< + is_c, '*'>, + times::type>, + divides::type> + > + {}; +}; + +struct eval_unary_plus +{ + template + struct apply : + eval_if< + typename equal_to, typename C::type>::type, + State, // +State is State + negate + > + {}; +}; + +struct plus_exp; + +typedef middle_of paren_exp; + +typedef + foldr_start_with_parser< + one_of, + one_of, + eval_unary_plus + > + simple_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, simple_exp>, + simple_exp, + eval_mult + > + prod_exp; + +struct plus_exp : + foldl_reject_incomplete_start_with_parser< + sequence, prod_exp>, + prod_exp, + eval_plus + > +{}; + +typedef last_of, plus_exp> expression; + +typedef build_parser > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + std::cout << "Please use a compiler that support constexpr" << std::endl; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + ; +} +#endif + diff --git a/src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 b/src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 new file mode 100644 index 000000000..05530b7c8 --- /dev/null +++ b/src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 @@ -0,0 +1 @@ +exe compile_to_native_code : main.cpp ; diff --git a/src/boost/libs/metaparse/example/compile_to_native_code/README b/src/boost/libs/metaparse/example/compile_to_native_code/README new file mode 100644 index 000000000..f41680ff7 --- /dev/null +++ b/src/boost/libs/metaparse/example/compile_to_native_code/README @@ -0,0 +1 @@ +An example on how to compile an EDSL into native executable code. diff --git a/src/boost/libs/metaparse/example/compile_to_native_code/main.cpp b/src/boost/libs/metaparse/example/compile_to_native_code/main.cpp new file mode 100644 index 000000000..e83624b2f --- /dev/null +++ b/src/boost/libs/metaparse/example/compile_to_native_code/main.cpp @@ -0,0 +1,252 @@ +// 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; +using boost::metaparse::transform; +using boost::metaparse::always; + +using boost::mpl::apply_wrap1; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::if_; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= value_exp ((mult_token | div_token) value_exp)* + * value_exp ::= int_token | '_' + */ + +typedef token > plus_token; +typedef token > minus_token; +typedef token > mult_token; +typedef token > div_token; + +typedef token int_token; +typedef token > arg_token; + +template +struct is_c : bool_ {}; + +struct build_plus +{ + template + class _plus + { + public: + typedef _plus type; + + template + T operator()(T t) const + { + return _left(t) + _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template + class _minus + { + public: + typedef _minus type; + + template + T operator()(T t) const + { + return _left(t) - _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template + struct apply : + if_< + typename is_c, '+'>::type, + _plus::type>, + _minus::type> + > + {}; +}; + +struct build_mult +{ + template + class _mult + { + public: + typedef _mult type; + + template + T operator()(T t) const + { + return _left(t) * _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template + class _div + { + public: + typedef _div type; + + template + T operator()(T t) const + { + return _left(t) / _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template + struct apply : + if_< + typename is_c, '*'>::type, + _mult::type>, + _div::type> + > + {}; +}; + +struct build_value +{ + typedef build_value type; + + template + struct apply + { + typedef apply type; + + template + int operator()(T) const + { + return V::type::value; + } + }; +}; + +struct arg +{ + typedef arg type; + + template + T operator()(T t) const + { + return t; + } +}; + +typedef + one_of, always > + value_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, value_exp>, + value_exp, + build_mult + > + prod_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, prod_exp>, + prod_exp, + build_plus + > + plus_exp; + +typedef last_of, plus_exp> expression; + +typedef build_parser > function_parser; + +#if BOOST_METAPARSE_STD < 2011 + +template +struct lambda : apply_wrap1 {}; + +using boost::metaparse::string; + +lambda >::type f1; +lambda >::type f2; +lambda >::type f3; +lambda >::type f4; +lambda >::type f5; + +#else + +#ifdef LAMBDA + #error LAMBDA already defined +#endif +#define LAMBDA(exp) apply_wrap1::type + +LAMBDA(13) f1; +LAMBDA(2 + 3) f2; +LAMBDA(2 * 2) f3; +LAMBDA( 1+ 2*4-6/2) f4; +LAMBDA(2 * _) f5; + +#endif + +int main() +{ + using std::cout; + using std::endl; + + cout + << f1(11) << endl + << f2(11) << endl + << f3(11) << endl + << f4(11) << endl + << f5(11) << endl + << f5(1.1) << endl + ; +} + + diff --git a/src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 b/src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 new file mode 100644 index 000000000..5e1f4246a --- /dev/null +++ b/src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 @@ -0,0 +1 @@ +exe constexpr_parser : main.cpp ; diff --git a/src/boost/libs/metaparse/example/constexpr_parser/README b/src/boost/libs/metaparse/example/constexpr_parser/README new file mode 100644 index 000000000..8b50db0e5 --- /dev/null +++ b/src/boost/libs/metaparse/example/constexpr_parser/README @@ -0,0 +1,12 @@ +Parsers parsing "a* b* a*" and counting the appearance of the characters. +This parser is implemented in three different ways: +- One built with Metaparse +- One implemented using constexpr functions +- One built with Metaparse but parsing a subexpression with a constexpr parser: + - a* at the beginning is parsed using a Metaparse parser + - b* is parsed using a constexpr function + - a* at the end is parsed using a Mataparse parser again + +This example demonstrates how Metaparse can be combined with parsers using +constexpr functions. + diff --git a/src/boost/libs/metaparse/example/constexpr_parser/main.cpp b/src/boost/libs/metaparse/example/constexpr_parser/main.cpp new file mode 100644 index 000000000..4fe291b07 --- /dev/null +++ b/src/boost/libs/metaparse/example/constexpr_parser/main.cpp @@ -0,0 +1,318 @@ +// 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 +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#if BOOST_METAPARSE_STD < 2011 + +int main() +{ + std::cout + << "This example focuses on constexpr, which is not supported" + << std::endl; +} + +#else + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::build_parser; +using boost::metaparse::foldl; +using boost::metaparse::entire_input; +using boost::metaparse::get_result; +using boost::metaparse::start; +using boost::metaparse::last_of; +using boost::metaparse::iterate_c; +using boost::metaparse::one_char; +using boost::metaparse::return_; + +using boost::mpl::apply_wrap1; +using boost::mpl::apply_wrap2; +using boost::mpl::plus; +using boost::mpl::int_; +using boost::mpl::at_c; +using boost::mpl::front; +using boost::mpl::pop_front; +using boost::mpl::size; + +using std::ostream; + +/* + * The grammar + * + * S ::= a* b* a* + */ + +struct parsed +{ + template + constexpr static parsed build() + { + return + parsed( + at_c::type::value, + at_c::type::value, + at_c::type::value + ); + } + + constexpr parsed(int a1, int b, int a2) : + a_count1(a1), + b_count(b), + a_count2(a2) + {}; + + int a_count1; + int b_count; + int a_count2; +}; + +ostream& operator<<(ostream& o, const parsed& p) +{ + return + o << "(" << p.a_count1 << ", " << p.b_count << ", " << p.a_count2 << ")"; +} + +// constexpr parser + +template +struct const_list +{ + T head; + const_list tail; + + constexpr const_list(const T& h, const const_list& t) : + head(h), + tail(t) + {} + + constexpr const_list push_front(const T& t) const + { + return const_list(t, *this); + } + + constexpr T at(int n) const + { + return n == 0 ? head : tail.at(n - 1); + } +}; + +template +struct const_list +{ + constexpr const_list push_front(const T& t) const + { + return const_list(t, *this); + } + + constexpr T at(int) const + { + return T(); + } +}; + +template +struct to_list +{ + static constexpr const_list run(const T (&s)[N]) + { + return const_list(s[from], to_list::run(s)); + } +}; + +template +struct to_list +{ + static constexpr const_list run(const T (&s)[N]) + { + return const_list(); + } +}; + +struct presult +{ + int value; + int remaining_from; + + constexpr presult(int v, int r) : value(v), remaining_from(r) {} + + constexpr presult incr() const { return presult(value + 1, remaining_from); } +}; + +template +constexpr presult parse_cs(const const_list& s, int from) +{ + return + from < N ? + (s.at(from) == C ? parse_cs(s, from + 1).incr() : presult(0, from)) : + presult(0, from); +} + +template +constexpr parsed parse_impl(const const_list& s) +{ + return + parsed( + parse_cs<'a', N>(s, 0).value, + parse_cs<'b', N>(s, parse_cs<'a', N>(s, 0).remaining_from).value, + parse_cs<'a', N>( + s, + parse_cs<'b', N>( + s, + parse_cs<'a', N>(s, 0).remaining_from + ).remaining_from + ).value + ); +} + +template +constexpr parsed parse(const char (&s)[N]) +{ + return parse_impl(to_list::run(s)); +} + +// TMP parser + +struct count +{ + typedef count type; + + template + struct apply : plus, State> {}; +}; + +typedef foldl, int_<0>, count> as; +typedef foldl, int_<0>, count> bs; + +typedef sequence s; + +typedef build_parser > parser; + +#ifdef P + #error P already defined +#endif +#define P(x) \ + parsed::build >() + +// Mixed parser + +template +struct tmp_to_const_list_impl +{ + constexpr static const_list run() + { + return + const_list( + front::type::value, + tmp_to_const_list_impl< + ValueType, + typename pop_front::type, + Len - 1 + >::run() + ); + } +}; + +template +struct tmp_to_const_list_impl +{ + constexpr static const_list run() + { + return const_list(); + } +}; + +template +struct tmp_to_const_list : + tmp_to_const_list_impl::type::value> +{}; + +template +struct parse_with_constexpr +{ + typedef parse_with_constexpr type; + + template + static constexpr presult impl() + { + return + parse_cs::type::value>(tmp_to_const_list::run(), 0); + } + + template + struct apply : + apply_wrap2< + last_of< + iterate_c().remaining_from>, + return_().value> > + >, + S, + Pos + > + {}; +}; + +typedef parse_with_constexpr<'b'> bs_mixed; + +typedef sequence s_mixed; + +typedef build_parser > parser_mixed; + +#ifdef P_MIXED + #error P_MIXED already defined +#endif +#define P_MIXED(x) \ + parsed::build< \ + boost::mpl::apply_wrap1 \ + >() + +int main() +{ + using std::cout; + using std::endl; + + cout + << "TMP only parsers:" << endl + << P(aba) << endl + << P(aaaaaaabbbbaaaa) << endl + << endl + + << "constexpr only parsers:" << endl + << parse("") << endl + << parse("aba") << endl + << parse("aaaaaaabbbbaaaa") << endl + << endl + + << "mixed parsers:" << endl + << P_MIXED(aba) << endl + << P_MIXED(aaaaaaabbbbaaaa) << endl + << endl + ; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1.hpp b/src/boost/libs/metaparse/example/getting_started/1.hpp new file mode 100644 index 000000000..ee00e7a1d --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1.hpp @@ -0,0 +1,9 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_HPP + +// Automatically generated header file + +// Definitions of section + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/10.hpp b/src/boost/libs/metaparse/example/getting_started/10.hpp new file mode 100644 index 000000000..e8ed5f1c3 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/10.hpp @@ -0,0 +1,42 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_10_HPP +#define BOOST_METAPARSE_GETTING_STARTED_10_HPP + +// Automatically generated header file + +// Definitions before section 9 +#include "9.hpp" + +// Definitions of section 9 +#include + +using unary_exp1 = + foldr_start_with_parser< + minus_token, + int_token, + boost::mpl::lambda>::type + >; + +using mult_exp4 = + foldl_start_with_parser< + sequence, unary_exp1>, + unary_exp1, + boost::mpl::quote2 + >; + +using exp_parser18 = + build_parser< + foldl_start_with_parser< + sequence, mult_exp4>, + mult_exp4, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser18::apply::type + +// query: +// exp_parser18::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11.hpp b/src/boost/libs/metaparse/example/getting_started/11.hpp new file mode 100644 index 000000000..3583496a8 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11.hpp @@ -0,0 +1,62 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_HPP + +// Automatically generated header file + +// Definitions before section 10 +#include "10.hpp" + +// Definitions of section 10 +using lparen_token = token>; + +using rparen_token = token>; + +using plus_exp1 = + foldl_start_with_parser< + sequence, mult_exp4>, + mult_exp4, + boost::mpl::quote2 + >; + +using paren_exp1 = sequence; + +#include + +using paren_exp2 = middle_of; + +using primary_exp1 = one_of; + +struct plus_exp2; + +using paren_exp3 = middle_of; + +using primary_exp2 = one_of; + +using unary_exp2 = + foldr_start_with_parser< + minus_token, + primary_exp2, + boost::mpl::lambda>::type + >; + +using mult_exp5 = + foldl_start_with_parser< + sequence, unary_exp2>, + unary_exp2, + boost::mpl::quote2 + >; + +struct plus_exp2 : + foldl_start_with_parser< + sequence, mult_exp5>, + mult_exp5, + boost::mpl::quote2 + > {}; + +using exp_parser19 = build_parser; + +// query: +// exp_parser19::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_1.hpp b/src/boost/libs/metaparse/example/getting_started/11_1.hpp new file mode 100644 index 000000000..be2a2de63 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_1.hpp @@ -0,0 +1,14 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_1_HPP + +// Automatically generated header file + +// Definitions before section 11 +#include "11.hpp" + +// Definitions of section 11 +// query: +// exp_parser19::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_2.hpp b/src/boost/libs/metaparse/example/getting_started/11_2.hpp new file mode 100644 index 000000000..ae36b4e46 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_2_HPP + +// Automatically generated header file + +// Definitions before section 11.1 +#include "11_1.hpp" + +// Definitions of section 11.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_3.hpp b/src/boost/libs/metaparse/example/getting_started/11_3.hpp new file mode 100644 index 000000000..a93c2dc47 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_3.hpp @@ -0,0 +1,49 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_3_HPP + +// Automatically generated header file + +// Definitions before section 11.2 +#include "11_2.hpp" + +// Definitions of section 11.2 +#include + +BOOST_METAPARSE_DEFINE_ERROR(missing_primary_expression, "Missing primary expression"); + +struct plus_exp3; + +using paren_exp4 = middle_of; + +#include + +using primary_exp3 = one_of>; + +using unary_exp3 = + foldr_start_with_parser< + minus_token, + primary_exp3, + boost::mpl::lambda>::type + >; + +using mult_exp6 = + foldl_start_with_parser< + sequence, unary_exp3>, + unary_exp3, + boost::mpl::quote2 + >; + +struct plus_exp3 : + foldl_start_with_parser< + sequence, mult_exp6>, + mult_exp6, + boost::mpl::quote2 + > {}; + +using exp_parser20 = build_parser; + +// query: +// exp_parser20::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_3_1.hpp b/src/boost/libs/metaparse/example/getting_started/11_3_1.hpp new file mode 100644 index 000000000..56da35a82 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_3_1.hpp @@ -0,0 +1,38 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_3_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_3_1_HPP + +// Automatically generated header file + +// Definitions before section 11.3 +#include "11_3.hpp" + +// Definitions of section 11.3 +// query: +// exp_parser20::apply::type + +// query: +// exp_parser20::apply::type + +#include + +#include + +struct plus_exp4 : + first_of< + foldl_start_with_parser< + sequence, mult_exp6>, + mult_exp6, + boost::mpl::quote2 + >, + fail_at_first_char_expected< + sequence, mult_exp6> + > + > {}; + +using exp_parser21 = build_parser; + +// query: +// exp_parser21::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_3_2.hpp b/src/boost/libs/metaparse/example/getting_started/11_3_2.hpp new file mode 100644 index 000000000..bf2e4b457 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_3_2.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_3_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_3_2_HPP + +// Automatically generated header file + +// Definitions before section 11.3.1 +#include "11_3_1.hpp" + +// Definitions of section 11.3.1 +#include + +struct plus_exp5 : + foldl_reject_incomplete_start_with_parser< + sequence, mult_exp6>, + mult_exp6, + boost::mpl::quote2 + > {}; + +using exp_parser22 = build_parser; + +// query: +// exp_parser22::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/12.hpp b/src/boost/libs/metaparse/example/getting_started/12.hpp new file mode 100644 index 000000000..d503539b1 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/12.hpp @@ -0,0 +1,46 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_12_HPP +#define BOOST_METAPARSE_GETTING_STARTED_12_HPP + +// Automatically generated header file + +// Definitions before section 11.3.2 +#include "11_3_2.hpp" + +// Definitions of section 11.3.2 +struct plus_exp6; + +using paren_exp5 = middle_of; + +using primary_exp4 = one_of>; + +using unary_exp4 = + foldr_start_with_parser< + minus_token, + primary_exp4, + boost::mpl::lambda>::type + >; + +using mult_exp7 = + foldl_reject_incomplete_start_with_parser< + sequence, unary_exp4>, + unary_exp4, + boost::mpl::quote2 + >; + +struct plus_exp6 : + foldl_reject_incomplete_start_with_parser< + sequence, mult_exp7>, + mult_exp7, + boost::mpl::quote2 + > {}; + +using exp_parser23 = build_parser; + +// query: +// exp_parser23::apply::type + +// query: +// exp_parser23::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_1.hpp b/src/boost/libs/metaparse/example/getting_started/1_1.hpp new file mode 100644 index 000000000..36fa44660 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_1_HPP + +// Automatically generated header file + +// Definitions before section 1 +#include "1.hpp" + +// Definitions of section 1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_2.hpp b/src/boost/libs/metaparse/example/getting_started/1_2.hpp new file mode 100644 index 000000000..dd19e3ef9 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_2_HPP + +// Automatically generated header file + +// Definitions before section 1.1 +#include "1_1.hpp" + +// Definitions of section 1.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_2_1.hpp b/src/boost/libs/metaparse/example/getting_started/1_2_1.hpp new file mode 100644 index 000000000..db5d3fe53 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_2_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_2_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_2_1_HPP + +// Automatically generated header file + +// Definitions before section 1.2 +#include "1_2.hpp" + +// Definitions of section 1.2 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_2_2.hpp b/src/boost/libs/metaparse/example/getting_started/1_2_2.hpp new file mode 100644 index 000000000..f84edb36c --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_2_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_2_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_2_2_HPP + +// Automatically generated header file + +// Definitions before section 1.2.1 +#include "1_2_1.hpp" + +// Definitions of section 1.2.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/2.hpp b/src/boost/libs/metaparse/example/getting_started/2.hpp new file mode 100644 index 000000000..3c3ecb422 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_2_HPP + +// Automatically generated header file + +// Definitions before section 1.2.2 +#include "1_2_2.hpp" + +// Definitions of section 1.2.2 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3.hpp b/src/boost/libs/metaparse/example/getting_started/3.hpp new file mode 100644 index 000000000..4df3b531d --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3.hpp @@ -0,0 +1,19 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_HPP + +// Automatically generated header file + +// Definitions before section 2 +#include "2.hpp" + +// Definitions of section 2 +#include + +// query: +// boost::metaparse::string<'1', '1', ' ', '+', ' ', '2'> + +// query: +// BOOST_METAPARSE_STRING("11 + 2") + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3_1.hpp b/src/boost/libs/metaparse/example/getting_started/3_1.hpp new file mode 100644 index 000000000..f383508db --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3_1.hpp @@ -0,0 +1,22 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_1_HPP + +// Automatically generated header file + +// Definitions before section 3 +#include "3.hpp" + +// Definitions of section 3 +#include + +#include + +using namespace boost::metaparse; + +using exp_parser1 = build_parser; + +// query: +// exp_parser1::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3_2.hpp b/src/boost/libs/metaparse/example/getting_started/3_2.hpp new file mode 100644 index 000000000..0cc9a48e7 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3_2.hpp @@ -0,0 +1,14 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_2_HPP + +// Automatically generated header file + +// Definitions before section 3.1 +#include "3_1.hpp" + +// Definitions of section 3.1 +// query: +// exp_parser1::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3_3.hpp b/src/boost/libs/metaparse/example/getting_started/3_3.hpp new file mode 100644 index 000000000..cc35183f1 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3_3.hpp @@ -0,0 +1,24 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_3_HPP + +// Automatically generated header file + +// Definitions before section 3.2 +#include "3_2.hpp" + +// Definitions of section 3.2 +// query: +// exp_parser1::apply::type + +#include + +using exp_parser2 = build_parser>; + +// query: +// exp_parser2::apply::type + +// query: +// exp_parser2::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/4.hpp b/src/boost/libs/metaparse/example/getting_started/4.hpp new file mode 100644 index 000000000..6fe2fc8f6 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/4.hpp @@ -0,0 +1,21 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_4_HPP +#define BOOST_METAPARSE_GETTING_STARTED_4_HPP + +// Automatically generated header file + +// Definitions before section 3.3 +#include "3_3.hpp" + +// Definitions of section 3.3 +// query: +// exp_parser2::apply::type + +#include + +using exp_parser3 = build_parser>>; + +// query: +// exp_parser3::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/4_1.hpp b/src/boost/libs/metaparse/example/getting_started/4_1.hpp new file mode 100644 index 000000000..513705947 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/4_1.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_4_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_4_1_HPP + +// Automatically generated header file + +// Definitions before section 4 +#include "4.hpp" + +// Definitions of section 4 +#include + +#include + +using exp_parser4 = build_parser, token>, token>>; + +// query: +// exp_parser4::apply::type + +#ifdef __METASHELL +#include +#endif + +// query: +// exp_parser4::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/4_2.hpp b/src/boost/libs/metaparse/example/getting_started/4_2.hpp new file mode 100644 index 000000000..1663c4686 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/4_2.hpp @@ -0,0 +1,20 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_4_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_4_2_HPP + +// Automatically generated header file + +// Definitions before section 4.1 +#include "4_1.hpp" + +// Definitions of section 4.1 +using int_token = token; + +using plus_token = token>; + +using exp_parser5 = build_parser>; + +// query: +// exp_parser5::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5.hpp b/src/boost/libs/metaparse/example/getting_started/5.hpp new file mode 100644 index 000000000..671b34e9e --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5.hpp @@ -0,0 +1,45 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_HPP + +// Automatically generated header file + +// Definitions before section 4.2 +#include "4_2.hpp" + +// Definitions of section 4.2 +#include + +#include + +#include + +template + struct eval_plus : + boost::mpl::plus< + typename boost::mpl::at_c::type, + typename boost::mpl::at_c::type + > {}; + +// query: +// eval_plus< +// boost::mpl::vector< +// mpl_::integral_c, +// mpl_::char_<'+'>, +// mpl_::integral_c +// >>::type + +#include + +using exp_parser6 = + build_parser< + transform< + sequence, + boost::mpl::quote1 + > + >; + +// query: +// exp_parser6::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_1.hpp b/src/boost/libs/metaparse/example/getting_started/5_1.hpp new file mode 100644 index 000000000..4042182e2 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_1_HPP + +// Automatically generated header file + +// Definitions before section 5 +#include "5.hpp" + +// Definitions of section 5 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2.hpp b/src/boost/libs/metaparse/example/getting_started/5_2.hpp new file mode 100644 index 000000000..ea9a0b18a --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2.hpp @@ -0,0 +1,24 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_HPP + +// Automatically generated header file + +// Definitions before section 5.1 +#include "5_1.hpp" + +// Definitions of section 5.1 +#include + +using exp_parser7 = + build_parser< + sequence< + int_token, /* The first */ + repeated> /* The "+ " elements */ + > + >; + +// query: +// exp_parser7::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_1.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_1.hpp new file mode 100644 index 000000000..f8e9ca219 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_1.hpp @@ -0,0 +1,13 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_1_HPP + +// Automatically generated header file + +// Definitions before section 5.2 +#include "5_2.hpp" + +// Definitions of section 5.2 +using temp_result = exp_parser7::apply::type; + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_2.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_2.hpp new file mode 100644 index 000000000..ea9ecb366 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_2.hpp @@ -0,0 +1,58 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_2_HPP + +// Automatically generated header file + +// Definitions before section 5.2.1 +#include "5_2_1.hpp" + +// Definitions of section 5.2.1 +#include + +using vector_of_numbers = + boost::mpl::vector< + boost::mpl::int_<2>, + boost::mpl::int_<5>, + boost::mpl::int_<6> + >; + +template + struct sum_vector : + boost::mpl::fold< + Vector, + boost::mpl::int_<0>, + boost::mpl::lambda< + boost::mpl::plus + >::type + > + {}; + +// query: +// sum_vector::type + +template + struct sum_items : + boost::mpl::plus< + Sum, + typename boost::mpl::at_c::type + > + {}; + +// query: +// sum_items< +// mpl_::integral_c, +// boost::mpl::vector, mpl_::integral_c> +// >::type + +// query: +// boost::mpl::at_c::type + +// query: +// boost::mpl::fold< +// boost::mpl::at_c::type, /* The vector to summarise */ +// boost::mpl::int_<0>, /* The value to start the sum from */ +// boost::mpl::quote2 /* The function to call in each iteration */ +// >::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_3.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_3.hpp new file mode 100644 index 000000000..b14a0c5e5 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_3.hpp @@ -0,0 +1,58 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_3_HPP + +// Automatically generated header file + +// Definitions before section 5.2.2 +#include "5_2_2.hpp" + +// Definitions of section 5.2.2 +using exp_parser8 = + build_parser< + sequence< + int_token, /* parse the first */ + transform< + repeated>, /* parse the "+ " elements */ + /* lambda expression summarising the "+ " elements using fold */ + boost::mpl::lambda< + /* The folding expression we have just created */ + boost::mpl::fold< + boost::mpl::_1, /* the argument of the lambda expression, the result */ + /* of the repeated<...> parser */ + boost::mpl::int_<0>, + boost::mpl::quote2 + > + >::type + > + > + >; + +// query: +// exp_parser8::apply::type + +using exp_parser9 = + build_parser< + transform< + /* What we had so far */ + sequence< + int_token, + transform< + repeated>, + boost::mpl::lambda< + boost::mpl::fold< + boost::mpl::_1, + boost::mpl::int_<0>, + boost::mpl::quote2 + > + >::type + > + >, + boost::mpl::quote1 /* summarise the vector of numbers */ + > + >; + +// query: +// exp_parser9::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_4.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_4.hpp new file mode 100644 index 000000000..3d4d30210 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_4.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_4_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_4_HPP + +// Automatically generated header file + +// Definitions before section 5.2.3 +#include "5_2_3.hpp" + +// Definitions of section 5.2.3 +#include + +using exp_parser10 = + build_parser< + transform< + sequence< + int_token, + foldl< + sequence, + boost::mpl::int_<0>, + boost::mpl::quote2 + > + >, + boost::mpl::quote1> + >; + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/6.hpp b/src/boost/libs/metaparse/example/getting_started/6.hpp new file mode 100644 index 000000000..906cb04bd --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/6.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_6_HPP +#define BOOST_METAPARSE_GETTING_STARTED_6_HPP + +// Automatically generated header file + +// Definitions before section 5.2.4 +#include "5_2_4.hpp" + +// Definitions of section 5.2.4 +#include + +using exp_parser11 = + build_parser< + foldl_start_with_parser< + sequence, /* apply this parser repeatedly */ + int_token, /* use this parser to get the initial value */ + boost::mpl::quote2 /* use this function to add a new value to the summary */ + > + >; + +// query: +// exp_parser11::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/6_1.hpp b/src/boost/libs/metaparse/example/getting_started/6_1.hpp new file mode 100644 index 000000000..0cc124497 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/6_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_6_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_6_1_HPP + +// Automatically generated header file + +// Definitions before section 6 +#include "6.hpp" + +// Definitions of section 6 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/6_2.hpp b/src/boost/libs/metaparse/example/getting_started/6_2.hpp new file mode 100644 index 000000000..d9f8bad27 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/6_2.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_6_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_6_2_HPP + +// Automatically generated header file + +// Definitions before section 6.1 +#include "6_1.hpp" + +// Definitions of section 6.1 +using minus_token = token>; + +#include + +using exp_parser12 = + build_parser< + foldl_start_with_parser< + sequence, int_token>, + int_token, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser12::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/7.hpp b/src/boost/libs/metaparse/example/getting_started/7.hpp new file mode 100644 index 000000000..fe245b98a --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/7.hpp @@ -0,0 +1,49 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_7_HPP +#define BOOST_METAPARSE_GETTING_STARTED_7_HPP + +// Automatically generated header file + +// Definitions before section 6.2 +#include "6_2.hpp" + +// Definitions of section 6.2 +#include + +template struct eval_binary_op; + +template struct eval_binary_op : boost::mpl::plus::type {}; + +template struct eval_binary_op : boost::mpl::minus::type {}; + +// query: +// eval_binary_op, '+', boost::mpl::int_<2>>::type + +// query: +// eval_binary_op, '-', boost::mpl::int_<2>>::type + +template + struct binary_op : + eval_binary_op< + S, + boost::mpl::at_c::type::value, + typename boost::mpl::at_c::type + > + {}; + +// query: +// binary_op, boost::mpl::vector, boost::mpl::int_<2>>>::type + +using exp_parser13 = + build_parser< + foldl_start_with_parser< + sequence, int_token>, + int_token, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser13::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/7_1.hpp b/src/boost/libs/metaparse/example/getting_started/7_1.hpp new file mode 100644 index 000000000..02b99e7b6 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/7_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_7_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_7_1_HPP + +// Automatically generated header file + +// Definitions before section 7 +#include "7.hpp" + +// Definitions of section 7 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/7_2.hpp b/src/boost/libs/metaparse/example/getting_started/7_2.hpp new file mode 100644 index 000000000..07e1a3583 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/7_2.hpp @@ -0,0 +1,35 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_7_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_7_2_HPP + +// Automatically generated header file + +// Definitions before section 7.1 +#include "7_1.hpp" + +// Definitions of section 7.1 +#include + +template struct eval_binary_op : boost::mpl::times::type {}; + +// query: +// eval_binary_op, '*', boost::mpl::int_<4>>::type + +using times_token = token>; + +using exp_parser14 = + build_parser< + foldl_start_with_parser< + sequence, int_token>, + int_token, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser14::apply::type + +// query: +// exp_parser14::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/8.hpp b/src/boost/libs/metaparse/example/getting_started/8.hpp new file mode 100644 index 000000000..c052f5b83 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/8.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_8_HPP +#define BOOST_METAPARSE_GETTING_STARTED_8_HPP + +// Automatically generated header file + +// Definitions before section 7.2 +#include "7_2.hpp" + +// Definitions of section 7.2 +using mult_exp1 = foldl_start_with_parser, int_token, boost::mpl::quote2>; + +using exp_parser15 = + build_parser< + foldl_start_with_parser< + sequence, mult_exp1>, + mult_exp1, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser15::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/8_1.hpp b/src/boost/libs/metaparse/example/getting_started/8_1.hpp new file mode 100644 index 000000000..aca70e75c --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/8_1.hpp @@ -0,0 +1,36 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_8_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_8_1_HPP + +// Automatically generated header file + +// Definitions before section 8 +#include "8.hpp" + +// Definitions of section 8 +#include + +template struct eval_binary_op : boost::mpl::divides::type {}; + +using divides_token = token>; + +using mult_exp2 = + foldl_start_with_parser< + sequence, int_token>, + int_token, + boost::mpl::quote2 + >; + +using exp_parser16 = + build_parser< + foldl_start_with_parser< + sequence, mult_exp2>, + mult_exp2, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser16::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/8_2.hpp b/src/boost/libs/metaparse/example/getting_started/8_2.hpp new file mode 100644 index 000000000..303c38830 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/8_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_8_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_8_2_HPP + +// Automatically generated header file + +// Definitions before section 8.1 +#include "8_1.hpp" + +// Definitions of section 8.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/9.hpp b/src/boost/libs/metaparse/example/getting_started/9.hpp new file mode 100644 index 000000000..47366b913 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/9.hpp @@ -0,0 +1,42 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_9_HPP +#define BOOST_METAPARSE_GETTING_STARTED_9_HPP + +// Automatically generated header file + +// Definitions before section 8.2 +#include "8_2.hpp" + +// Definitions of section 8.2 +template + struct reverse_binary_op : + eval_binary_op< + typename boost::mpl::at_c::type, + boost::mpl::at_c::type::value, + S + > + {}; + +#include + +using mult_exp3 = + foldr_start_with_parser< + sequence>, /* The parser applied repeatedly */ + int_token, /* The parser parsing the last number */ + boost::mpl::quote2 /* The function called for every result */ + /* of applying the above parser */ + >; + +using exp_parser17 = + build_parser< + foldl_start_with_parser< + sequence, mult_exp3>, + mult_exp3, + boost::mpl::quote2 + > + >; + +// query: +// exp_parser17::apply::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/README b/src/boost/libs/metaparse/example/getting_started/README new file mode 100644 index 000000000..f2c6703b5 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/README @@ -0,0 +1,6 @@ +This example contains the code snippets of Getting Started. These headers are +intended to be used from Metashell. To get all the definitions before section +N. you need to include N.hpp + +The headers can always be re-generated by running tools/generate_all.py + diff --git a/src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 b/src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 new file mode 100644 index 000000000..cc98a4090 --- /dev/null +++ b/src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 @@ -0,0 +1,6 @@ +project : requirements + gcc:-ftemplate-depth=512 + clang:-ftemplate-depth=512 +; + +exe grammar_calculator : main.cpp ; diff --git a/src/boost/libs/metaparse/example/grammar_calculator/README b/src/boost/libs/metaparse/example/grammar_calculator/README new file mode 100644 index 000000000..553170a15 --- /dev/null +++ b/src/boost/libs/metaparse/example/grammar_calculator/README @@ -0,0 +1,2 @@ +Calculator, working at compile-time. This example demonstrates how to build it +with grammars. diff --git a/src/boost/libs/metaparse/example/grammar_calculator/main.cpp b/src/boost/libs/metaparse/example/grammar_calculator/main.cpp new file mode 100644 index 000000000..95ca139c0 --- /dev/null +++ b/src/boost/libs/metaparse/example/grammar_calculator/main.cpp @@ -0,0 +1,160 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// 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 + +#if BOOST_METAPARSE_STD < 2011 +#include + +int main() +{ + std::cout << "Please use a compiler that supports constexpr" << std::endl; +} +#else + +#define BOOST_MPL_LIMIT_STRING_SIZE 64 +#define BOOST_METAPARSE_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::metaparse::build_parser; +using boost::metaparse::entire_input; +using boost::metaparse::token; +using boost::metaparse::grammar; + +using boost::metaparse::util::digit_to_int; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::equal_to; +using boost::mpl::_1; +using boost::mpl::_2; +using boost::mpl::char_; +using boost::mpl::lambda; +using boost::mpl::int_; + +#ifdef _STR + #error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +template +struct lazy_plus : plus {}; + +template +struct lazy_minus : minus {}; + +template +struct lazy_times : times {}; + +template +struct lazy_divides : divides {}; + +template +struct lazy_eval_if : eval_if {}; + +template +struct lazy_equal_to : equal_to {}; + +template +struct lazy_fold : + fold +{}; + +typedef + lazy_fold< + back<_1>, + front<_1>, + lambda< + lazy_eval_if< + lazy_equal_to, char_<'*'>>, + lazy_times<_1, back<_2>>, + lazy_divides<_1, back<_2>> + > + >::type + > + prod_action; + +typedef + lazy_fold< + back<_1>, + front<_1>, + lambda< + lazy_eval_if< + lazy_equal_to, char_<'+'>>, + lazy_plus<_1, back<_2>>, + lazy_minus<_1, back<_2>> + > + >::type + > + plus_action; + +typedef + lambda< + lazy_fold< + _1, + int_<0>, + lambda< + lazy_plus>, apply_wrap1, _2>> + >::type + > + >::type + int_action; + +typedef + grammar<_STR("plus_exp")> + + ::rule<_STR("int ::= ('0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9')+"), int_action>::type + ::rule<_STR("ws ::= (' ' | '\n' | '\r' | '\t')*")>::type + ::rule<_STR("int_token ::= int ws"), front<_1>>::type + ::rule<_STR("plus_token ::= '+' ws"), front<_1>>::type + ::rule<_STR("minus_token ::= '-' ws"), front<_1>>::type + ::rule<_STR("mult_token ::= '*' ws"), front<_1>>::type + ::rule<_STR("div_token ::= '/' ws"), front<_1>>::type + ::rule<_STR("plus_token ::= '+' ws")>::type + ::rule<_STR("plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)*"), plus_action>::type + ::rule<_STR("prod_exp ::= int_token ((mult_token | div_token) int_token)*"), prod_action>::type + expression; + +typedef build_parser> calculator_parser; + +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + ; +} +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 b/src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 new file mode 100644 index 000000000..84d5c3c12 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 @@ -0,0 +1,11 @@ + +project meta_hs : + requirements + . + gcc:-ftemplate-depth=512 + clang:-ftemplate-depth=512 + ; + +exe handcrafted : main_handcrafted.cpp ; +exe in_haskell : main_in_haskell.cpp ; + diff --git a/src/boost/libs/metaparse/example/meta_hs/README b/src/boost/libs/metaparse/example/meta_hs/README new file mode 100644 index 000000000..0afcc4eb8 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/README @@ -0,0 +1,4 @@ +Haskell-like functional EDSL for template metafunctions. +This example contains two programs. Both of them define and execute a few +template metaprograms. One of the do it by using Boost.MPL directly, while the +other one defines the template metaprograms using the EDSL. diff --git a/src/boost/libs/metaparse/example/meta_hs/ast.hpp b/src/boost/libs/metaparse/example/meta_hs/ast.hpp new file mode 100644 index 000000000..68f25eaf9 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/ast.hpp @@ -0,0 +1,43 @@ +#ifndef META_HS_AST_HPP +#define META_HS_AST_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) + +namespace ast +{ + template + struct value + { + typedef value type; + }; + + template + struct ref + { + typedef ref type; + }; + + template + struct application + { + typedef application type; + }; + + template + struct lambda + { + typedef lambda type; + }; + + template + struct top_bound + { + typedef top_bound type; + }; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/bind.hpp b/src/boost/libs/metaparse/example/meta_hs/bind.hpp new file mode 100644 index 000000000..29316084a --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/bind.hpp @@ -0,0 +1,63 @@ +#ifndef META_HS_BIND_HPP +#define META_HS_BIND_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 + +template +struct bind; + +template +struct bind, TopEnv, Env> +{ + typedef lazy::value type; +}; + +template +struct bind, TopEnv, Env> : + bind::type, TopEnv, Env> +{}; + +template +struct bind, TopEnv, Env> +{ + typedef + lazy::application< + typename bind::type, + typename bind::type + > + type; +}; + +template +struct bind, TopEnv, Env> +{ + typedef bind type; + + template + struct apply : + bind< + F, + TopEnv, + typename boost::mpl::insert< + Env, + boost::mpl::pair > + >::type + >::type + {}; +}; + +template +struct bind, TopEnv, Env> : bind {}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/builder.hpp b/src/boost/libs/metaparse/example/meta_hs/builder.hpp new file mode 100644 index 000000000..b49a06a33 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/builder.hpp @@ -0,0 +1,80 @@ +#ifndef META_HS_EXCEPT_BUILDER_HPP +#define META_HS_EXCEPT_BUILDER_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 +#include +#include + +typedef boost::mpl::map<> empty_environment; + +template +struct builder +{ + typedef builder type; + + template + struct import : + builder< + typename boost::mpl::insert< + Env, + boost::mpl::pair > + >::type + > + {}; + +#ifdef IMPORT +# error IMPORT already defined +#endif +#define IMPORT(z, n, unused) \ + template < \ + class Name, \ + template class F \ + > \ + struct BOOST_PP_CAT(import, n) : \ + builder< \ + typename boost::mpl::insert< \ + Env, \ + boost::mpl::pair > > \ + >::type \ + > \ + {}; + +BOOST_PP_REPEAT_FROM_TO(1, CURRY_MAX_ARGUMENT, IMPORT, ~) + +#undef IMPORT + + template + struct define : + builder< + typename boost::mpl::insert< + Env, + typename boost::mpl::apply_wrap1::type + >::type + > + {}; + + template + struct get : + bind::type, Env, Env>::type::type + {}; +}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/curry.hpp b/src/boost/libs/metaparse/example/meta_hs/curry.hpp new file mode 100644 index 000000000..5ca1711d3 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/curry.hpp @@ -0,0 +1,106 @@ +#ifndef BOOST_METAPARSE_META_HS_CURRY_HPP +#define BOOST_METAPARSE_META_HS_CURRY_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// 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 +#include +#include +#include + +#ifndef CURRY_MAX_ARGUMENT +# define CURRY_MAX_ARGUMENT 5 +#endif + +namespace impl +{ + template < + class UnpackedMetafunctionClass, + class ArgumentsLeft, + class ArgumentList + > + struct curry_impl; + + + + template < + class UnpackedMetafunctionClass, + class ArgumentsLeft, + class ArgumentList + > + struct next_currying_step + { + typedef next_currying_step type; + + template + struct apply : + curry_impl< + UnpackedMetafunctionClass, + typename boost::mpl::minus< + ArgumentsLeft, + boost::mpl::int_<1> + >::type, + typename boost::mpl::push_back::type + > + {}; + }; + + + template < + class UnpackedMetafunctionClass, + class ArgumentsLeft, + class ArgumentList + > + struct curry_impl : + boost::mpl::eval_if< + typename boost::mpl::equal_to< + ArgumentsLeft, + boost::mpl::int_<0> + >::type, + boost::mpl::apply, + next_currying_step< + UnpackedMetafunctionClass, + ArgumentsLeft, + ArgumentList + > + > + {}; +} + + +template +struct curry0 : T {}; + +#ifdef CURRY +# error CURRY already defined +#endif +#define CURRY(z, n, unused) \ + template