From 0e05000b7d412d763b7e9114e6667d0c850f6eac Mon Sep 17 00:00:00 2001 From: c2h4ie Date: Tue, 15 Oct 2024 19:48:16 +0200 Subject: [PATCH] first commit --- .clang-format | 66 + .gitignore | 3 + .gitmodules | 3 + CMakeLists.txt | 22 + external/ctre/.conan/build.py | 24 + .../ctre/.conan/test_package/CMakeLists.txt | 11 + .../ctre/.conan/test_package/conanfile.py | 20 + .../ctre/.conan/test_package/test_package.cpp | 32 + external/ctre/.github/workflows/tests.yml | 81 + external/ctre/.gitignore | 22 + external/ctre/.gitmodules | 0 external/ctre/.tm_properties | 3 + external/ctre/.travis.yml | 113 + external/ctre/CMakeLists.txt | 196 + external/ctre/LICENSE | 218 + external/ctre/Makefile | 92 + external/ctre/NOTES.md | 24 + external/ctre/README.md | 295 + external/ctre/clang-bench.txt | 20 + external/ctre/conanfile.py | 27 + external/ctre/ctre.cppm | 26 + external/ctre/docs/api.rst | 100 + external/ctre/docs/conf.py | 54 + external/ctre/docs/examples.rst | 77 + external/ctre/docs/index.rst | 66 + external/ctre/docs/regex_syntax.rst | 18 + external/ctre/future.cpp | 15 + external/ctre/gcc-bench.txt | 20 + external/ctre/include/ctll.hpp | 6 + external/ctre/include/ctll/actions.hpp | 29 + external/ctre/include/ctll/fixed_string.hpp | 223 + external/ctre/include/ctll/grammars.hpp | 123 + external/ctre/include/ctll/list.hpp | 93 + external/ctre/include/ctll/parser.hpp | 192 + external/ctre/include/ctll/utilities.hpp | 67 + external/ctre/include/ctre-unicode.hpp | 7 + external/ctre/include/ctre.hpp | 10 + .../ctre/include/ctre/actions/asserts.inc.hpp | 29 + .../include/ctre/actions/atomic_group.inc.hpp | 19 + .../ctre/actions/backreference.inc.hpp | 30 + .../include/ctre/actions/boundaries.inc.hpp | 14 + .../ctre/include/ctre/actions/capture.inc.hpp | 40 + .../include/ctre/actions/characters.inc.hpp | 41 + .../ctre/include/ctre/actions/class.inc.hpp | 51 + .../ctre/include/ctre/actions/fusion.inc.hpp | 70 + .../ctre/include/ctre/actions/hexdec.inc.hpp | 29 + .../ctre/include/ctre/actions/look.inc.hpp | 68 + .../ctre/include/ctre/actions/mode.inc.hpp | 32 + .../include/ctre/actions/named_class.inc.hpp | 61 + .../ctre/include/ctre/actions/options.inc.hpp | 55 + .../include/ctre/actions/properties.inc.hpp | 73 + .../ctre/include/ctre/actions/repeat.inc.hpp | 90 + .../include/ctre/actions/sequence.inc.hpp | 32 + .../ctre/include/ctre/actions/set.inc.hpp | 66 + external/ctre/include/ctre/atoms.hpp | 80 + .../ctre/include/ctre/atoms_characters.hpp | 139 + external/ctre/include/ctre/atoms_unicode.hpp | 157 + external/ctre/include/ctre/evaluation.hpp | 567 + external/ctre/include/ctre/find_captures.hpp | 125 + external/ctre/include/ctre/first.hpp | 554 + .../ctre/include/ctre/flags_and_modes.hpp | 97 + external/ctre/include/ctre/functions.hpp | 48 + external/ctre/include/ctre/id.hpp | 25 + external/ctre/include/ctre/iterators.hpp | 196 + external/ctre/include/ctre/literals.hpp | 140 + external/ctre/include/ctre/operators.hpp | 12 + external/ctre/include/ctre/pcre.gram | 189 + external/ctre/include/ctre/pcre.hpp | 466 + external/ctre/include/ctre/pcre_actions.hpp | 61 + external/ctre/include/ctre/range.hpp | 151 + external/ctre/include/ctre/return_type.hpp | 574 + external/ctre/include/ctre/rotate.hpp | 99 + .../ctre/include/ctre/starts_with_anchor.hpp | 87 + external/ctre/include/ctre/utf8.hpp | 252 + external/ctre/include/ctre/utility.hpp | 45 + external/ctre/include/ctre/wrapper.hpp | 350 + external/ctre/include/unicode-db.hpp | 7 + .../ctre/include/unicode-db/unicode-db.hpp | 9535 +++ .../include/unicode-db/unicode_interface.hpp | 100 + external/ctre/packaging/pkgconfig.pc.in | 7 + external/ctre/single-header/ctre-unicode.hpp | 15525 +++++ external/ctre/single-header/ctre.hpp | 5979 ++ external/ctre/single-header/unicode-db.hpp | 9535 +++ external/ctre/tests/CMakeLists.txt | 15 + external/ctre/tests/__utf8.cpp | 43 + external/ctre/tests/_bad_cycle.cpp | 21 + external/ctre/tests/_fixed-string.cpp | 36 + external/ctre/tests/_unicode.cpp | 136 + external/ctre/tests/benchmark-exec/.gitignore | 3 + .../ctre/tests/benchmark-exec/.tm_properties | 2 + external/ctre/tests/benchmark-exec/Makefile | 76 + .../ctre/tests/benchmark-exec/baseline.cpp | 8 + external/ctre/tests/benchmark-exec/boost.cpp | 10 + external/ctre/tests/benchmark-exec/common.hpp | 136 + external/ctre/tests/benchmark-exec/ctre.cpp | 11 + external/ctre/tests/benchmark-exec/jsc.js | 60 + external/ctre/tests/benchmark-exec/node-v8.js | 44 + .../ctre/tests/benchmark-exec/pcre-jit.cpp | 29 + external/ctre/tests/benchmark-exec/pcre.cpp | 25 + external/ctre/tests/benchmark-exec/re2.cpp | 10 + external/ctre/tests/benchmark-exec/srell.cpp | 10 + external/ctre/tests/benchmark-exec/std.cpp | 10 + .../ctre/tests/benchmark-exec/xpressive.cpp | 11 + .../ctre/tests/benchmark-range/load-file.hpp | 29 + .../tests/benchmark-range/measurement.cpp | 210 + .../benchmark/many-of-different-ctll.cpp | 104 + .../benchmark/many-of-different-x5-ctll.cpp | 508 + .../tests/benchmark/many-of-same-ctll.cpp | 54002 ++++++++++++++++ .../tests/benchmark/many-of-same-proto.cpp | 3002 + external/ctre/tests/benchmark/same.cpp | 4105 ++ external/ctre/tests/benchmark/unique.cpp | 262 + external/ctre/tests/ci.cpp | 40 + external/ctre/tests/cnttp.cpp | 22 + external/ctre/tests/correct-conversion.cpp | 13 + external/ctre/tests/gcc8.cpp | 11 + external/ctre/tests/generating.cpp | 274 + external/ctre/tests/gets.cpp | 19 + external/ctre/tests/is_prime.cpp | 23 + external/ctre/tests/many-of-same-proto.cpp | 3019 + external/ctre/tests/matching.cpp | 190 + external/ctre/tests/matching2-msvc-greedy.cpp | 281 + external/ctre/tests/matching2.cpp | 310 + external/ctre/tests/matching3.cpp | 236 + external/ctre/tests/mode.cpp | 46 + external/ctre/tests/msvc.cpp | 41 + external/ctre/tests/parsing.cpp | 174 + external/ctre/tests/range.cpp | 34 + external/ctre/tests/results.cpp | 39 + external/ctre/tests/string.cpp | 16 + external/ctre/tests/trampoline.cpp | 13 + external/ctre/tests/wide-pattern.cpp | 11 + external/ctre/tests/z_matching.cpp | 33 + src/ArgParser.hpp | 98 + src/Helpers/Utility.cpp | 21 + src/Helpers/Utility.hpp | 8 + src/Helpers/WolframAlpha.cpp | 60 + src/Helpers/WolframAlpha.hpp | 21 + src/main.cpp | 30 + 138 files changed, 116301 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100755 external/ctre/.conan/build.py create mode 100644 external/ctre/.conan/test_package/CMakeLists.txt create mode 100644 external/ctre/.conan/test_package/conanfile.py create mode 100644 external/ctre/.conan/test_package/test_package.cpp create mode 100644 external/ctre/.github/workflows/tests.yml create mode 100644 external/ctre/.gitignore create mode 100644 external/ctre/.gitmodules create mode 100644 external/ctre/.tm_properties create mode 100644 external/ctre/.travis.yml create mode 100644 external/ctre/CMakeLists.txt create mode 100644 external/ctre/LICENSE create mode 100644 external/ctre/Makefile create mode 100644 external/ctre/NOTES.md create mode 100644 external/ctre/README.md create mode 100644 external/ctre/clang-bench.txt create mode 100755 external/ctre/conanfile.py create mode 100644 external/ctre/ctre.cppm create mode 100644 external/ctre/docs/api.rst create mode 100644 external/ctre/docs/conf.py create mode 100644 external/ctre/docs/examples.rst create mode 100644 external/ctre/docs/index.rst create mode 100644 external/ctre/docs/regex_syntax.rst create mode 100644 external/ctre/future.cpp create mode 100644 external/ctre/gcc-bench.txt create mode 100644 external/ctre/include/ctll.hpp create mode 100644 external/ctre/include/ctll/actions.hpp create mode 100644 external/ctre/include/ctll/fixed_string.hpp create mode 100644 external/ctre/include/ctll/grammars.hpp create mode 100644 external/ctre/include/ctll/list.hpp create mode 100644 external/ctre/include/ctll/parser.hpp create mode 100644 external/ctre/include/ctll/utilities.hpp create mode 100644 external/ctre/include/ctre-unicode.hpp create mode 100644 external/ctre/include/ctre.hpp create mode 100644 external/ctre/include/ctre/actions/asserts.inc.hpp create mode 100644 external/ctre/include/ctre/actions/atomic_group.inc.hpp create mode 100644 external/ctre/include/ctre/actions/backreference.inc.hpp create mode 100644 external/ctre/include/ctre/actions/boundaries.inc.hpp create mode 100644 external/ctre/include/ctre/actions/capture.inc.hpp create mode 100644 external/ctre/include/ctre/actions/characters.inc.hpp create mode 100644 external/ctre/include/ctre/actions/class.inc.hpp create mode 100644 external/ctre/include/ctre/actions/fusion.inc.hpp create mode 100644 external/ctre/include/ctre/actions/hexdec.inc.hpp create mode 100644 external/ctre/include/ctre/actions/look.inc.hpp create mode 100644 external/ctre/include/ctre/actions/mode.inc.hpp create mode 100644 external/ctre/include/ctre/actions/named_class.inc.hpp create mode 100644 external/ctre/include/ctre/actions/options.inc.hpp create mode 100644 external/ctre/include/ctre/actions/properties.inc.hpp create mode 100644 external/ctre/include/ctre/actions/repeat.inc.hpp create mode 100644 external/ctre/include/ctre/actions/sequence.inc.hpp create mode 100644 external/ctre/include/ctre/actions/set.inc.hpp create mode 100644 external/ctre/include/ctre/atoms.hpp create mode 100644 external/ctre/include/ctre/atoms_characters.hpp create mode 100644 external/ctre/include/ctre/atoms_unicode.hpp create mode 100644 external/ctre/include/ctre/evaluation.hpp create mode 100644 external/ctre/include/ctre/find_captures.hpp create mode 100644 external/ctre/include/ctre/first.hpp create mode 100644 external/ctre/include/ctre/flags_and_modes.hpp create mode 100644 external/ctre/include/ctre/functions.hpp create mode 100644 external/ctre/include/ctre/id.hpp create mode 100644 external/ctre/include/ctre/iterators.hpp create mode 100644 external/ctre/include/ctre/literals.hpp create mode 100644 external/ctre/include/ctre/operators.hpp create mode 100644 external/ctre/include/ctre/pcre.gram create mode 100644 external/ctre/include/ctre/pcre.hpp create mode 100644 external/ctre/include/ctre/pcre_actions.hpp create mode 100644 external/ctre/include/ctre/range.hpp create mode 100644 external/ctre/include/ctre/return_type.hpp create mode 100644 external/ctre/include/ctre/rotate.hpp create mode 100644 external/ctre/include/ctre/starts_with_anchor.hpp create mode 100644 external/ctre/include/ctre/utf8.hpp create mode 100644 external/ctre/include/ctre/utility.hpp create mode 100644 external/ctre/include/ctre/wrapper.hpp create mode 100644 external/ctre/include/unicode-db.hpp create mode 100644 external/ctre/include/unicode-db/unicode-db.hpp create mode 100644 external/ctre/include/unicode-db/unicode_interface.hpp create mode 100644 external/ctre/packaging/pkgconfig.pc.in create mode 100644 external/ctre/single-header/ctre-unicode.hpp create mode 100644 external/ctre/single-header/ctre.hpp create mode 100644 external/ctre/single-header/unicode-db.hpp create mode 100644 external/ctre/tests/CMakeLists.txt create mode 100644 external/ctre/tests/__utf8.cpp create mode 100644 external/ctre/tests/_bad_cycle.cpp create mode 100644 external/ctre/tests/_fixed-string.cpp create mode 100644 external/ctre/tests/_unicode.cpp create mode 100644 external/ctre/tests/benchmark-exec/.gitignore create mode 100644 external/ctre/tests/benchmark-exec/.tm_properties create mode 100644 external/ctre/tests/benchmark-exec/Makefile create mode 100644 external/ctre/tests/benchmark-exec/baseline.cpp create mode 100644 external/ctre/tests/benchmark-exec/boost.cpp create mode 100644 external/ctre/tests/benchmark-exec/common.hpp create mode 100644 external/ctre/tests/benchmark-exec/ctre.cpp create mode 100644 external/ctre/tests/benchmark-exec/jsc.js create mode 100644 external/ctre/tests/benchmark-exec/node-v8.js create mode 100644 external/ctre/tests/benchmark-exec/pcre-jit.cpp create mode 100644 external/ctre/tests/benchmark-exec/pcre.cpp create mode 100644 external/ctre/tests/benchmark-exec/re2.cpp create mode 100644 external/ctre/tests/benchmark-exec/srell.cpp create mode 100644 external/ctre/tests/benchmark-exec/std.cpp create mode 100644 external/ctre/tests/benchmark-exec/xpressive.cpp create mode 100644 external/ctre/tests/benchmark-range/load-file.hpp create mode 100644 external/ctre/tests/benchmark-range/measurement.cpp create mode 100644 external/ctre/tests/benchmark/many-of-different-ctll.cpp create mode 100644 external/ctre/tests/benchmark/many-of-different-x5-ctll.cpp create mode 100644 external/ctre/tests/benchmark/many-of-same-ctll.cpp create mode 100644 external/ctre/tests/benchmark/many-of-same-proto.cpp create mode 100644 external/ctre/tests/benchmark/same.cpp create mode 100644 external/ctre/tests/benchmark/unique.cpp create mode 100644 external/ctre/tests/ci.cpp create mode 100644 external/ctre/tests/cnttp.cpp create mode 100644 external/ctre/tests/correct-conversion.cpp create mode 100644 external/ctre/tests/gcc8.cpp create mode 100644 external/ctre/tests/generating.cpp create mode 100644 external/ctre/tests/gets.cpp create mode 100644 external/ctre/tests/is_prime.cpp create mode 100644 external/ctre/tests/many-of-same-proto.cpp create mode 100644 external/ctre/tests/matching.cpp create mode 100644 external/ctre/tests/matching2-msvc-greedy.cpp create mode 100644 external/ctre/tests/matching2.cpp create mode 100644 external/ctre/tests/matching3.cpp create mode 100644 external/ctre/tests/mode.cpp create mode 100644 external/ctre/tests/msvc.cpp create mode 100644 external/ctre/tests/parsing.cpp create mode 100644 external/ctre/tests/range.cpp create mode 100644 external/ctre/tests/results.cpp create mode 100644 external/ctre/tests/string.cpp create mode 100644 external/ctre/tests/trampoline.cpp create mode 100644 external/ctre/tests/wide-pattern.cpp create mode 100644 external/ctre/tests/z_matching.cpp create mode 100644 src/ArgParser.hpp create mode 100644 src/Helpers/Utility.cpp create mode 100644 src/Helpers/Utility.hpp create mode 100644 src/Helpers/WolframAlpha.cpp create mode 100644 src/Helpers/WolframAlpha.hpp create mode 100644 src/main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b48ce2b --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +--- +Language: Cpp +BasedOnStyle: LLVM + +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: true +AlignConsecutiveAssignments: true +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +ColumnLimit: 180 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +IncludeBlocks: Preserve +IndentCaseLabels: true +IndentWidth: 2 +PointerAlignment: Left +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 2 +UseTab: Never + +AllowShortEnumsOnASingleLine: false + +BraceWrapping: + AfterEnum: false + +AlignConsecutiveDeclarations: AcrossEmptyLines + +NamespaceIndentation: All + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..436c580 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cmake-build* + +.idea \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..46c24d6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/ctre"] + path = external/ctre + url = https://github.com/hanickadot/compile-time-regular-expressions.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2881d3e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.30) +project(nutri) + +set(CMAKE_CXX_STANDARD 26) + +find_package(fmt REQUIRED) +find_package(cpr REQUIRED) +find_package(nlohmann_json REQUIRED) + +include_directories(${CMAKE_SOURCE_DIR}/external/ctre/include) +add_subdirectory(external/ctre/) + +add_executable( + nutri + src/main.cpp + src/ArgParser.hpp + src/Helpers/Utility.cpp + src/Helpers/Utility.hpp + src/Helpers/WolframAlpha.hpp + src/Helpers/WolframAlpha.cpp) + +target_link_libraries(nutri PRIVATE cpr::cpr nlohmann_json::nlohmann_json ctre::ctre) diff --git a/external/ctre/.conan/build.py b/external/ctre/.conan/build.py new file mode 100755 index 0000000..c53daf4 --- /dev/null +++ b/external/ctre/.conan/build.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import os +from cpt.packager import ConanMultiPackager + + +def get_travis_branch(): + return os.getenv("TRAVIS_BRANCH") + + +def get_reference(): + return "CTRE/{}".format(get_travis_branch()) + + +if __name__ == "__main__": + builder = ConanMultiPackager( + reference=get_reference(), + username="ctre", + upload="https://api.bintray.com/conan/hanickadot/ctre", + upload_only_when_stable=True, + stable_branch_pattern="v?\d+\.\d+.*", + test_folder=os.path.join(".conan", "test_package")) + builder.add_common_builds() + builder.run() diff --git a/external/ctre/.conan/test_package/CMakeLists.txt b/external/ctre/.conan/test_package/CMakeLists.txt new file mode 100644 index 0000000..c64b54d --- /dev/null +++ b/external/ctre/.conan/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +project(test_package CXX) +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) + +set(CMAKE_VERBOSE_MAKEFILE TRUE) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/external/ctre/.conan/test_package/conanfile.py b/external/ctre/.conan/test_package/conanfile.py new file mode 100644 index 0000000..d4a5266 --- /dev/null +++ b/external/ctre/.conan/test_package/conanfile.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from conans import ConanFile, CMake, tools, RunEnvironment +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + assert os.path.exists(os.path.join(self.deps_cpp_info["CTRE"].rootpath, "licenses", "LICENSE")) + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/external/ctre/.conan/test_package/test_package.cpp b/external/ctre/.conan/test_package/test_package.cpp new file mode 100644 index 0000000..b1af18f --- /dev/null +++ b/external/ctre/.conan/test_package/test_package.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +#include + +using namespace std::string_view_literals; +using namespace ctre::literals; + +struct date { std::string_view year; std::string_view month; std::string_view day; }; + +static constexpr ctll::fixed_string pattern = "^([0-9]{4})/([0-9]{1,2}+)/([0-9]{1,2}+)$"; + +constexpr std::optional extract_date(std::string_view s) noexcept { + if (auto [whole, year, month, day] = ctre::match(s); whole + ) { + return date{year.to_view(), month.to_view(), day.to_view()}; + } else { + return std::nullopt; + } +} + +int main() { + + assert(extract_date("2018/08/27"sv).has_value()); + assert(extract_date("2018/08/27"sv)->year == "2018"sv); + assert(extract_date("2018/08/27"sv)->month == "08"sv); + assert(extract_date("2018/08/27"sv)->day == "27"sv); + + return EXIT_SUCCESS; +} diff --git a/external/ctre/.github/workflows/tests.yml b/external/ctre/.github/workflows/tests.yml new file mode 100644 index 0000000..08bd127 --- /dev/null +++ b/external/ctre/.github/workflows/tests.yml @@ -0,0 +1,81 @@ +name: Tests +on: [push, pull_request] +jobs: + appleclang: + strategy: + matrix: + macos: [12, 13] + standard: [17, 20] + fail-fast: false + name: "AppleClang (MacOS ${{ matrix.macos }}, C++${{ matrix.standard }})" + runs-on: macos-${{ matrix.macos }} + steps: + - uses: actions/checkout@v2 + - run: c++ -v + - run: make CXX=c++ CXX_STANDARD=2a + if: ${{ matrix.standard == '20' }} + - run: make CXX=c++ CXX_STANDARD=17 + if: ${{ matrix.standard == '17' }} + gcc: + strategy: + matrix: + gcc: [8, 9, 10, 11, 13] + standard: [17, 20] + fail-fast: false + name: "GCC ${{ matrix.gcc }} (C++${{ matrix.standard }})" + runs-on: ubuntu-20.04 + steps: + - name: "Install GCC" + uses: egor-tensin/setup-gcc@v1 + with: + version: ${{ matrix.gcc }} + - uses: actions/checkout@v2 + - run: c++ -v + - run: make CXX=c++ CXX_STANDARD=2a + if: ${{ matrix.standard == '20' }} + - run: make CXX=c++ CXX_STANDARD=17 + if: ${{ matrix.gcc < '9' && matrix.standard == '17' }} + - run: make CXX=c++ CXX_STANDARD=17 CXXFLAGS=-DCTRE_ENABLE_LITERALS PEDANTIC="" + if: ${{ matrix.gcc >= '9' && matrix.standard == '17' }} + clang: + strategy: + matrix: + clang: [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] + stdlib: ["libc++", "libstdc++"] + standard: [17, 20] + fail-fast: false + name: "Clang ${{ matrix.clang }} (C++${{ matrix.standard }}, ${{ matrix.stdlib }})" + runs-on: ubuntu-20.04 + steps: + - name: "Install Clang" + uses: egor-tensin/setup-clang@v1 + with: + version: ${{ matrix.clang }} + - name: "Install libc++" + if: ${{ matrix.stdlib == 'libc++' }} + run: sudo apt-get install libc++abi-${{ matrix.clang }}-dev libc++1-${{ matrix.clang }} libc++-${{ matrix.clang }}-dev + - uses: actions/checkout@v2 + - run: c++ -v + - run: make CXX=c++ CXX_STANDARD=2a CXXFLAGS=-stdlib=${{ matrix.stdlib }} + if: ${{ matrix.standard == '20' }} + - run: make CXX=c++ CXX_STANDARD=17 CXXFLAGS=-stdlib=${{ matrix.stdlib }} + if: ${{ matrix.standard == '17' }} + msvc: + strategy: + matrix: + version: [14.29, ""] + fail-fast: false + name: "MSVC ${{ matrix.version }} (C++20)" + runs-on: windows-2022 + steps: + - name: Add MSVC ${{ matrix.version }} to PATH + uses: ilammy/msvc-dev-cmd@v1 + with: + toolset: ${{ matrix.version }} + - name: "Install Ninja & CMake" + run: choco install ninja cmake + - uses: actions/checkout@v2 + - name: "Configure" + run: cmake . -G Ninja -B build -DCTRE_BUILD_TESTS=ON -DCTRE_CXX_STANDARD=20 + - name: "Build" + run: cmake --build build --target ctre-test --verbose diff --git a/external/ctre/.gitignore b/external/ctre/.gitignore new file mode 100644 index 0000000..a644be0 --- /dev/null +++ b/external/ctre/.gitignore @@ -0,0 +1,22 @@ +*.o +*.d +**/*.tmp +test +result +tests/benchmark-exec/* +!tests/benchmark-exec/Makefile +!tests/benchmark-exec/.gitignore +!tests/benchmark-exec/.tm_properties +!tests/benchmark-exec/*.cpp +!tests/benchmark-exec/*.hpp +!tests/benchmark-exec/*.js +*.pyc +.conan/test_package/build +mtent12.txt +*.zip +tests/benchmark-range/* +!tests/benchmark-range/*.cpp +!tests/benchmark-range/*.hpp +build +cmake-build-*/* +.idea/* \ No newline at end of file diff --git a/external/ctre/.gitmodules b/external/ctre/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/external/ctre/.tm_properties b/external/ctre/.tm_properties new file mode 100644 index 0000000..b08b62a --- /dev/null +++ b/external/ctre/.tm_properties @@ -0,0 +1,3 @@ +exclude = "{$exclude,**/*.dSYM,**/*.d,**/*.o,test,*.tmp}" +include = "{$include,.gitignore,.github,.travis*,.conan}" +excludeInFolderSearch = "{$excludeInFolderSearch,./ctre.hpp}" diff --git a/external/ctre/.travis.yml b/external/ctre/.travis.yml new file mode 100644 index 0000000..3c28067 --- /dev/null +++ b/external/ctre/.travis.yml @@ -0,0 +1,113 @@ +language: cpp +dist: focal +os: linux + +jobs: + include: + - os: linux + language: python + python: "3.6" + services: + - docker + env: + - COMPILER=g++-8 + - CONAN_GCC_VERSIONS=8 + - CONAN_DOCKER_IMAGE=lasote/conangcc8 + install: + - pip install -U conan conan-package-tools + script: + - python .conan/build.py + + - os: linux + compiler: gcc + env: + - COMPILER=g++-8 + - CXX_STANDARD=17 + addons: + apt: + packages: ['g++-8'] + + - os: linux + compiler: gcc + env: + - COMPILER=g++-8 + - CXX_STANDARD=2a + addons: + apt: + packages: ['g++-8'] + + - os: linux + compiler: clang + env: + - COMPILER=clang++-6.0 + - CXX_STANDARD=17 + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0'] + packages: ['g++-8', 'clang-6.0'] + + - os: linux + compiler: clang + env: + - COMPILER=clang++-6.0 + - CXX_STANDARD=2a + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0'] + packages: ['g++-8', 'clang-6.0'] + +# FIXME: don't use GCC10 in 17 mode for tests as they are depending on operator"" +# - os: linux +# compiler: gcc +# env: +# - COMPILER=g++-10 +# - CXX_STANDARD=17 +# addons: +# apt: +# packages: ['g++-10'] + + - os: linux + compiler: gcc + env: + - COMPILER=g++-10 + - CXX_STANDARD=20 + addons: + apt: + packages: ['g++-10'] + + - os: osx + osx_image: xcode10 + env: + - CXX_STANDARD=17 + + - os: osx + osx_image: xcode10 + env: + - CXX_STANDARD=2a + + - os: osx + osx_image: xcode11 + env: + - CXX_STANDARD=17 + + - os: osx + osx_image: xcode11 + env: + - CXX_STANDARD=2a + + - os: osx + osx_image: xcode12 + env: + - CXX_STANDARD=17 + + - os: osx + osx_image: xcode12 + env: + - CXX_STANDARD=2a + +install: + - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi + - uname -a + - $CXX --version +script: + - make CXX_STANDARD=$CXX_STANDARD diff --git a/external/ctre/CMakeLists.txt b/external/ctre/CMakeLists.txt new file mode 100644 index 0000000..9e5a80e --- /dev/null +++ b/external/ctre/CMakeLists.txt @@ -0,0 +1,196 @@ +cmake_minimum_required(VERSION 3.14...3.29) + +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.29.20240416") + set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + set(CMAKE_CXX_MODULE_STD 1) +endif() + +# When updating to a newer version of CMake, see if we can use the following +project(ctre + HOMEPAGE_URL "https://compile-time.re" + VERSION 3.9.0 + LANGUAGES CXX) +set(PROJECT_DESCRIPTION "Fast compile-time regular expressions with support for matching/searching/capturing during compile-time or runtime.") + +include(CMakePackageConfigHelpers) +include(CMakeDependentOption) +include(GNUInstallDirs) +include(CTest) + +find_program(CTRE_DPKG_BUILDPACKAGE_FOUND dpkg-buildpackage) +find_program(CTRE_RPMBUILD_FOUND rpmbuild) + +cmake_dependent_option(CTRE_BUILD_TESTS "Build ctre Tests" ON + "BUILD_TESTING;CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) +cmake_dependent_option(CTRE_BUILD_PACKAGE "Build ctre Packages" ON + "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF) +cmake_dependent_option(CTRE_BUILD_PACKAGE_DEB + "Create DEB Package (${PROJECT_NAME})" ON + "CTRE_BUILD_PACKAGE;CTRE_DPKG_BUILDPACKAGE_FOUND" OFF) +cmake_dependent_option(CTRE_BUILD_PACKAGE_RPM + "Create RPM Package (${PROJECT_NAME})" ON + "CTRE_BUILD_PACKAGE;CTRE_RPMBUILD_FOUND" OFF) + +option(CTRE_MODULE "build C++ module" OFF) + +if(CTRE_MODULE) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.29.20240416") + add_library(${PROJECT_NAME}) + + target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES TYPE CXX_MODULES FILES ctre.cppm) + target_sources(${PROJECT_NAME} PUBLIC FILE_SET HEADERS TYPE HEADERS + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}/include" + FILES + include/ctll.hpp + include/ctre/functions.hpp + include/ctre/utility.hpp + include/ctre/utf8.hpp + include/ctre/evaluation.hpp + include/ctre/starts_with_anchor.hpp + include/ctre/pcre_actions.hpp + include/ctre/rotate.hpp + include/ctre/iterators.hpp + include/ctre/literals.hpp + include/ctre/return_type.hpp + include/ctre/find_captures.hpp + include/ctre/id.hpp + include/ctre/atoms_characters.hpp + include/ctre/actions/mode.inc.hpp + include/ctre/actions/characters.inc.hpp + include/ctre/actions/class.inc.hpp + include/ctre/actions/look.inc.hpp + include/ctre/actions/sequence.inc.hpp + include/ctre/actions/fusion.inc.hpp + include/ctre/actions/asserts.inc.hpp + include/ctre/actions/capture.inc.hpp + include/ctre/actions/named_class.inc.hpp + include/ctre/actions/backreference.inc.hpp + include/ctre/actions/options.inc.hpp + include/ctre/actions/atomic_group.inc.hpp + include/ctre/actions/set.inc.hpp + include/ctre/actions/hexdec.inc.hpp + include/ctre/actions/repeat.inc.hpp + include/ctre/actions/properties.inc.hpp + include/ctre/actions/boundaries.inc.hpp + include/ctre/operators.hpp + include/ctre/pcre.hpp + include/ctre/atoms_unicode.hpp + include/ctre/range.hpp + include/ctre/wrapper.hpp + include/ctre/first.hpp + include/ctre/flags_and_modes.hpp + include/ctre/atoms.hpp + include/unicode-db.hpp + include/unicode-db/unicode_interface.hpp + include/unicode-db/unicode-db.hpp + include/ctll/parser.hpp + include/ctll/actions.hpp + include/ctll/fixed_string.hpp + include/ctll/list.hpp + include/ctll/utilities.hpp + include/ctll/grammars.hpp + include/ctre.hpp + include/ctre-unicode.hpp + ) + + # we are using `import std;` + if (NOT DEFINED CTRE_CXX_STANDARD OR CTRE_CXX_STANDARD LESS 23) + set(CTRE_CXX_STANDARD 23) + endif() + + target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_${CTRE_CXX_STANDARD}) + + install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets + FILE_SET CXX_MODULES DESTINATION "${CMAKE_INSTALL_LIBDIR}/cxx/${PROJECT_NAME}" + FILE_SET HEADERS DESTINATION "include") + else() + message(FATAL_ERROR "unsupported cmake for c++ modules") + endif() +else() + add_library(${PROJECT_NAME} INTERFACE) + + target_include_directories(${PROJECT_NAME} INTERFACE + $ + $) + + if (NOT CTRE_CXX_STANDARD) + set(CTRE_CXX_STANDARD 20) + endif() + + target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_${CTRE_CXX_STANDARD}) + set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_SCAN_FOR_MODULES 0) + + install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets) + install(DIRECTORY include/ DESTINATION include + FILES_MATCHING PATTERN *.hpp) +endif() + +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + +if (NOT EXISTS "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in") + file(WRITE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in [[ + @PACKAGE_INIT@ + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") + ]]) +endif() + +configure_package_config_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO) + +write_basic_package_version_file(ctre-config-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + +install(EXPORT ${PROJECT_NAME}-targets + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + NAMESPACE ${PROJECT_NAME}::) +install( + FILES + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +if(CTRE_BUILD_TESTS) + add_subdirectory(tests) +endif() + +if (NOT CTRE_BUILD_PACKAGE) + return() +endif() + +list(APPEND source-generators TBZ2 TGZ TXZ ZIP) + +if (CTRE_BUILD_PACKAGE_DEB) + list(APPEND binary-generators "DEB") +endif() + +if (CTRE_BUILD_PACKAGE_RPM) + list(APPEND binary-generators "RPM") +endif() + +set(CPACK_SOURCE_GENERATOR ${source-generators}) +set(CPACK_GENERATOR ${binary-generators}) + +set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}") + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Hana Dusíková") +set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") +set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev") + +set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel") + +set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/packaging/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY) +install(FILES "${PKG_CONFIG_FILE_NAME}" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" +) + +list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store) + +include(CPack) diff --git a/external/ctre/LICENSE b/external/ctre/LICENSE new file mode 100644 index 0000000..bd8b243 --- /dev/null +++ b/external/ctre/LICENSE @@ -0,0 +1,218 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +--- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. diff --git a/external/ctre/Makefile b/external/ctre/Makefile new file mode 100644 index 0000000..a48a30a --- /dev/null +++ b/external/ctre/Makefile @@ -0,0 +1,92 @@ +.PHONY: default all clean grammar compare single-header single-header/ctre.hpp single-header/ctre-unicode.hpp single-header/unicode-db.hpp + +default: all + +TARGETS := $(wildcard tests/benchmark-exec/*.cpp) +IGNORE := $(wildcard tests/benchmark/*.cpp) $(wildcard tests/benchmark-exec/*.cpp) + +DESATOMAT := /bin/false + +CXX_STANDARD := 20 + +PYTHON := python3.9 + +PEDANTIC:=-pedantic + +override CXXFLAGS := $(CXXFLAGS) -std=c++$(CXX_STANDARD) -Iinclude -O3 $(PEDANTIC) -Wall -Wextra -Werror -Wconversion +LDFLAGS := + +TESTS := $(wildcard tests/*.cpp) $(wildcard tests/benchmark/*.cpp) +TRUE_TARGETS := $(TARGETS:%.cpp=%) +override TRUE_TARGETS := $(filter-out $(IGNORE:%.cpp=%), $(TRUE_TARGETS)) +OBJECTS := $(TARGETS:%.cpp=%.o) $(TESTS:%.cpp=%.o) +override OBJECTS := $(filter-out $(IGNORE:%.cpp=%.o),$(OBJECTS)) +DEPEDENCY_FILES := $(OBJECTS:%.o=%.d) + +all: $(TRUE_TARGETS) $(OBJECTS) + +list: + echo $(SUPPORTED_CPP20) + +$(TRUE_TARGETS): %: %.o + $(CXX) $< $(LDFLAGS) -o $@ + +$(OBJECTS): %.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -c $< -o $@ + +-include $(DEPEDENCY_FILES) + +benchmark: + @$(MAKE) clean + @$(MAKE) IGNORE="" + +benchmark-clean: + @$(MAKE) IGNORE="" clean + +clean: + rm -f $(TRUE_TARGETS) $(OBJECTS) $(DEPEDENCY_FILES) mtent12.txt mtent12.zip + +grammar: include/ctre/pcre.hpp + +regrammar: + @rm -f include/ctre/pcre.hpp + @$(MAKE) grammar + +include/ctre/pcre.hpp: include/ctre/pcre.gram + @echo "LL1q $<" + @$(DESATOMAT) --ll --q --input=include/ctre/pcre.gram --output=include/ctre/ --generator=cpp_ctll_v2 --cfg:fname=pcre.hpp --cfg:namespace=ctre --cfg:guard=CTRE__PCRE__HPP --cfg:grammar_name=pcre + +mtent12.zip: + curl -s http://www.gutenberg.org/files/3200/old/mtent12.zip -o mtent12.zip + +mtent12.txt: mtent12.zip + unzip -o mtent12.zip + touch mtent12.txt + +single-header: single-header/ctre.hpp single-header/ctre-unicode.hpp single-header/unicode-db.hpp + +single-header/unicode-db.hpp: include/unicode-db/unicode-db.hpp + cp $+ $@ + +single-header/ctre.hpp: + ${PYTHON} -m quom include/ctre.hpp ctre.hpp.tmp + echo "/*" > single-header/ctre.hpp + cat LICENSE >> single-header/ctre.hpp + echo "*/" >> single-header/ctre.hpp + cat ctre.hpp.tmp >> single-header/ctre.hpp + rm ctre.hpp.tmp + +single-header/ctre-unicode.hpp: + ${PYTHON} -m quom include/ctre-unicode.hpp ctre-unicode.hpp.tmp + echo "/*" > single-header/ctre-unicode.hpp + cat LICENSE >> single-header/ctre-unicode.hpp + echo "*/" >> single-header/ctre-unicode.hpp + cat ctre-unicode.hpp.tmp >> single-header/ctre-unicode.hpp + rm ctre-unicode.hpp.tmp + +REPEAT:=10 + +compare: mtent12.txt + $(CXX) $(CXXFLAGS) -MMD -march=native -DPATTERN="\"(${PATTERN})\"" -c tests/benchmark-range/measurement.cpp -o tests/benchmark-range/measurement.o + $(CXX) tests/benchmark-range/measurement.o -lboost_regex -lpcre2-8 -lre2 -o tests/benchmark-range/measurement + tests/benchmark-range/measurement all mtent12.txt ${REPEAT} diff --git a/external/ctre/NOTES.md b/external/ctre/NOTES.md new file mode 100644 index 0000000..b01a62c --- /dev/null +++ b/external/ctre/NOTES.md @@ -0,0 +1,24 @@ +# Unsupported PCRE constructs + +* `\0dd` `\ddd` `\0{dd...}` octal numbers +* `\Q...\E` quoting +* `\cx` control characters +* `\C` data unit +* `\h` `\H` horizontal character classes +* `\v` `\V` vertical character classes +* `\p{xx}` `\P{xx}` character properties +* `\X` unicode grapheme cluster +* boundaries other than `^$` +* atomic groups +* comments +* options/modes +* subroutines +* conditional patterns +* callouts +* match point reset `\K` + + +# Other unsupported "things" +* `[[.hyphen.]]` named characters +* `[[=M=]]` whatever this is + diff --git a/external/ctre/README.md b/external/ctre/README.md new file mode 100644 index 0000000..e609ef9 --- /dev/null +++ b/external/ctre/README.md @@ -0,0 +1,295 @@ +# Compile time regular expressions v3 + +[![Build Status](https://travis-ci.org/hanickadot/compile-time-regular-expressions.svg?branch=master)](https://travis-ci.org/hanickadot/compile-time-regular-expressions) + +Fast compile-time regular expressions with support for matching/searching/capturing during compile-time or runtime. + +You can use the single header version from directory `single-header`. This header can be regenerated with `make single-header`. If you are using cmake, you can add this directory as subdirectory and link to target `ctre`. + +More info at [compile-time.re](https://compile-time.re/) + +## What this library can do + +```c++ +ctre::match<"REGEX">(subject); // C++20 +"REGEX"_ctre.match(subject); // C++17 + N3599 extension +``` + +* Matching +* Searching (`search` or `starts_with`) +* Capturing content (named captures are supported too, but only with syntax `(?...)`) +* Back-Reference (\g{N} syntax, and \1...\9 syntax too) +* Multiline support (with `multi_`) functions +* Unicode properties and UTF-8 support + +The library is implementing most of the PCRE syntax with a few exceptions: + +* callouts +* comments +* conditional patterns +* control characters (`\cX`) +* match point reset (`\K`) +* named characters +* octal numbers +* options / modes +* subroutines +* unicode grapheme cluster (`\X`) + +More documentation on [pcre.org](https://www.pcre.org/current/doc/html/pcre2syntax.html). + +### Unknown character escape behaviour + +Not all escaped characters are automatically inserted as self, behaviour of the library is escaped characters are with special meaning, unknown escaped character is a syntax error. + +Explicitly allowed character escapes which insert only the character are: + +```\-\"\<\>``` + +## Basic API + +This is approximated API specification from a user perspective (omitting `constexpr` and `noexcept` which are everywhere, and using C++20 syntax even the API is C++17 compatible): +```c++ +// look if whole input matches the regex: +template auto ctre::match(auto Range &&) -> regex_results; +template auto ctre::match(auto First &&, auto Last &&) -> regex_results; + +// look if input contains match somewhere inside of itself: +template auto ctre::search(auto Range &&) -> regex_results; +template auto ctre::search(auto First &&, auto Last &&) -> regex_results; + +// check if input starts with match (but doesn't need to match everything): +template auto ctre::starts_with(auto Range &&) -> regex_results; +template auto ctre::starts_with(auto First &&, auto Last &&) -> regex_results; + +// result type is deconstructible into a structured bindings +template <...> struct regex_results { + operator bool() const; // if it's a match + auto to_view() const -> std::string_view; // also view() + auto to_string() const -> std::string; // also str() + operator std::string_view() const; // also supports all char variants + explicit operator std::string() const; + + // also size(), begin(), end(), data() + + size_t count() const; // number of captures + template const captured_content & get() const; // provide specific capture, whole regex_results is implicit capture 0 +}; +``` + +### Range outputing API + +```c++ +// search for regex in input and return each occurence, ignoring rest: +template auto ctre::range(auto Range &&) -> range of regex_result; +template auto ctre::range(auto First &&, auto Last &&) -> range of regex_result; + +// return range of each match, stopping at something which can't be matched +template auto ctre::tokenize(auto Range &&) -> range of regex_result; +template auto ctre::tokenize(auto First &&, auto Last &&) -> range of regex_result; + +// return parts of the input splited by the regex, returning it as part of content of the implicit zero capture (other captures are not changed, you can use it to access how the values were splitted): +template auto ctre::split(auto Range &&) -> regex_result; +template auto ctre::split(auto First &&, auto Last &&) -> range of regex_result; +``` + +### Functors + +All the functions (`ctre::match`, `ctre::search`, `ctre::starts_with`, `ctre::range`, `ctre::tokenize`, `ctre::split`) are functors and can be used without parenthesis: + +```c++ +auto matcher = ctre::match<"regex">; +if (matcher(input)) ... +``` + +### Possible subjects (inputs) + +* `std::string`-like objects (`std::string_view` or your own string if it's providing `begin`/`end` functions with forward iterators) +* pairs of forward iterators + +### Unicode support + +To enable you need to include: +* `` +* or `` and `` + +Otherwise you will get missing symbols if you try to use the unicode support without enabling it. + +## Supported compilers + +* clang 7.0+ (template UDL, C++17 syntax) +* xcode clang 10.0+ (template UDL, C++17 syntax) +* clang 12.0+ (C++17 syntax, C++20 cNTTP syntax) +* gcc 8.0+ (template UDL, C++17 syntax) +* gcc 9.0+ (C++17 & C++20 cNTTP syntax) +* MSVC 14.29+ (Visual Studio 16.11+) (C++20) + +### Template UDL syntax + +The compiler must support extension N3599, for example as GNU extension in gcc (not in GCC 9.1+) and clang. + +```c++ +constexpr auto match(std::string_view sv) noexcept { + using namespace ctre::literals; + return "h.*"_ctre.match(sv); +} +``` + +If you need extension N3599 in GCC 9.1+, you can't use -pedantic. Also, you need to define macro `CTRE_ENABLE_LITERALS`. + +### C++17 syntax + +You can provide a pattern as a `constexpr ctll::fixed_string` variable. + +```c++ +static constexpr auto pattern = ctll::fixed_string{ "h.*" }; + +constexpr auto match(std::string_view sv) noexcept { + return ctre::match(sv); +} +``` + +(this is tested in MSVC 15.8.8) + +### C++20 syntax + +Currently, the only compiler which supports cNTTP syntax `ctre::match(subject)` is GCC 9+. + +```c++ +constexpr auto match(std::string_view sv) noexcept { + return ctre::match<"h.*">(sv); +} +``` + +## Examples + +### Extracting number from input + +```c++ +std::optional extract_number(std::string_view s) noexcept { + if (auto m = ctre::match<"[a-z]+([0-9]+)">(s)) { + return m.get<1>().to_view(); + } else { + return std::nullopt; + } +} +``` + +[link to compiler explorer](https://gcc.godbolt.org/z/5U67_e) + +### Extracting values from date + +```c++ +struct date { std::string_view year; std::string_view month; std::string_view day; }; + +std::optional extract_date(std::string_view s) noexcept { + using namespace ctre::literals; + if (auto [whole, year, month, day] = ctre::match<"(\\d{4})/(\\d{1,2})/(\\d{1,2})">(s); whole) { + return date{year, month, day}; + } else { + return std::nullopt; + } +} + +//static_assert(extract_date("2018/08/27"sv).has_value()); +//static_assert((*extract_date("2018/08/27"sv)).year == "2018"sv); +//static_assert((*extract_date("2018/08/27"sv)).month == "08"sv); +//static_assert((*extract_date("2018/08/27"sv)).day == "27"sv); +``` + +[link to compiler explorer](https://gcc.godbolt.org/z/x64CVp) + +### Using captures + +```c++ +auto result = ctre::match<"(?\\d{4})/(?\\d{1,2})/(?\\d{1,2})">(s); +return date{result.get<"year">(), result.get<"month">, result.get<"day">}; + +// or in C++ emulation, but the object must have a linkage +static constexpr ctll::fixed_string year = "year"; +static constexpr ctll::fixed_string month = "month"; +static constexpr ctll::fixed_string day = "day"; +return date{result.get(), result.get, result.get}; + +// or use numbered access +// capture 0 is the whole match +return date{result.get<1>(), result.get<2>, result.get<3>}; +``` + +### Lexer + +```c++ +enum class type { + unknown, identifier, number +}; + +struct lex_item { + type t; + std::string_view c; +}; + +std::optional lexer(std::string_view v) noexcept { + if (auto [m,id,num] = ctre::match<"([a-z]+)|([0-9]+)">(v); m) { + if (id) { + return lex_item{type::identifier, id}; + } else if (num) { + return lex_item{type::number, num}; + } + } + return std::nullopt; +} +``` + +[link to compiler explorer](https://gcc.godbolt.org/z/PKTiCC) + +### Range over input + +This support is preliminary, probably the API will be changed. + +```c++ +auto input = "123,456,768"sv; + +for (auto match: ctre::range<"([0-9]+),?">(input)) { + std::cout << std::string_view{match.get<0>()} << "\n"; +} +``` + +### Unicode + +```c++ +#include +#include +// needed if you want to output to the terminal +std::string_view cast_from_unicode(std::u8string_view input) noexcept { + return std::string_view(reinterpret_cast(input.data()), input.size()); +} +int main() +{ + using namespace std::literals; + std::u8string_view original = u8"Tu es un génie"sv; + + for (auto match : ctre::range<"\\p{Letter}+">(original)) + std::cout << cast_from_unicode(match) << std::endl; + return 0; +} +``` + +[link to compiler explorer](https://godbolt.org/z/erTshe6sz) + + +## Installing ctre using vcpkg + +You can download and install ctre using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager: + +```bash +git clone https://github.com/Microsoft/vcpkg.git +cd vcpkg +./bootstrap-vcpkg.sh +./vcpkg integrate install +./vcpkg install ctre +``` + +The ctre port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. + +## Running tests (for developers) + +Just run `make` in root of this project. diff --git a/external/ctre/clang-bench.txt b/external/ctre/clang-bench.txt new file mode 100644 index 0000000..264827a --- /dev/null +++ b/external/ctre/clang-bench.txt @@ -0,0 +1,20 @@ +//--------- ABCD|DEFGH|EFGHI|A{4,} +egrep 0m49.353s +CTRE 0m10.093s +PCRE 0m12.515s +std::regex 21m9.309s +//--------- [0-9a-fA-F]{8,16} +egrep 0m32.256s +CTRE 0m14.197s +PCRE 0m17.832s +std::regex 2m34.505s +//--------- ^([0-9]{4,16})?[aA] +egrep 0m12.880s +CTRE 0m7.596s +PCRE 0m6.590s +std::regex 7m54.793s +//--------- ([aAbB]{4,}|[xXyY]{4,}|[1234]{4,})0 +egrep 1m56.412s +CTRE 0m59.864s +PCRE 0m43.486s +std::regex 27m35.004s diff --git a/external/ctre/conanfile.py b/external/ctre/conanfile.py new file mode 100755 index 0000000..9edf262 --- /dev/null +++ b/external/ctre/conanfile.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from conans import ConanFile + + +class CtreConan(ConanFile): + name = "CTRE" + license = "Apache 2.0 with LLVM Exception" + url = "https://github.com/hanickadot/compile-time-regular-expressions" + author = "Hana Dusíková (ctre@hanicka.net)" + description = "Compile Time Regular Expression for C++17/20" + homepage = "https://github.com/hanickadot/compile-time-regular-expressions" + no_copy_source = True + scm = { + "type": "git", + "url": "auto", + "revision": "auto" + } + + def package(self): + self.copy("LICENSE", "licenses") + self.copy("*.hpp") + + def package_id(self): + self.info.header_only() + diff --git a/external/ctre/ctre.cppm b/external/ctre/ctre.cppm new file mode 100644 index 0000000..6526e50 --- /dev/null +++ b/external/ctre/ctre.cppm @@ -0,0 +1,26 @@ +module; + +#ifdef _MSVC_LANG +#pragma warning( disable : 5202 ) +#endif + +import std; + +export module ctre; + +#define CTRE_IN_A_MODULE +#define CTLL_IN_A_MODULE +#define UNICODE_DB_IN_A_MODULE + +using std::int16_t; +using std::int32_t; +using std::int64_t; +using std::int8_t; +using std::size_t; +using std::uint16_t; +using std::uint32_t; +using std::uint64_t; +using std::uint8_t; + +#include "ctre.hpp" +#include "unicode-db.hpp" diff --git a/external/ctre/docs/api.rst b/external/ctre/docs/api.rst new file mode 100644 index 0000000..8dbecc9 --- /dev/null +++ b/external/ctre/docs/api.rst @@ -0,0 +1,100 @@ +API +=== + +.. class:: ctll::fixed_string + + A compile-time fixed string. + + Example: :: + + static constexpr auto pattern = ctll::fixed_string{ "h.*" }; + + constexpr auto match(std::string_view sv) noexcept { + return ctre::match(sv); + } + +.. class:: template ctre::regex_results + + .. type:: char_type = typename std::iterator_traits::value_type + + The character type used by the ``Iterator``. + + .. function:: template constexpr captured_content::storage get() + template constexpr captured_content::storage get() + template constexpr captured_content::storage get() + + Returns the capture specified by ``Id`` or ``Name``. ID ``0`` is the full match, ID ``1`` is the first capture group, ID ``2`` is the second, etc. + Named groups are specified using ``(?)``. + + Example: :: + + if (auto m = ctre::match<"(?[a-z]+)([0-9]+)">("abc123")) { + m.get<"chars">(); //abc + m.get<2>(); //123 + } + + .. function:: constexpr size_t size() + + Returns the number of captures in this result object. + + .. function:: constexpr operator bool() const noexcept + + Returns whether the match was successful. + + .. function:: constexpr operator std::basic_string_view() const noexcept + constexpr std::basic_string_view to_view() const noexcept + constexpr std::basic_string_view view() const noexcept + + Converts the match to a string view. + + .. function:: constexpr explicit operator std::basic_string() const noexcept + constexpr std::basic_string to_string() const noexcept + constexpr std::basic_string str() const noexcept + + Converts the match to a string view. + +.. class:: template captured_content + + .. class:: template storage + + .. function:: constexpr auto begin() const noexcept + constexpr auto end() const noexcept + + Returns the begin or end iterator for the captured content. + + .. function:: constexpr operator bool() const noexcept + + Returns whether the match was successful. + + .. function:: constexpr auto size() const noexcept + + Returns the number of characters in the capture. + + .. function:: constexpr operator std::basic_string_view() const noexcept + constexpr std::basic_string_view to_view() const noexcept + constexpr std::basic_string_view view() const noexcept + + Converts the capture to a string view. + + .. function:: constexpr explicit operator std::basic_string() const noexcept + constexpr std::basic_string to_string() const noexcept + constexpr std::basic_string str() const noexcept + + Converts the capture to a string view. + + .. function:: constexpr static size_t get_id() noexcept + + Returns ``Id`` + +.. function:: template constexpr ctre::regex_results match(Args&&... args) + template constexpr ctre::regex_results match(Args&&... args) + + Matches ``RE`` against the whole input. + ``Args...`` must be either a string-like object with ``begin`` and ``end`` member functions, or a pair of forward iterators. + +.. function:: template constexpr ctre::regex_results search(Args&&... args) + template constexpr ctre::regex_results search(Args&&... args) + + Searches for a match somewhere within the input. + ``Args...`` must be either a string-like object with ``begin`` and ``end`` member functions, or a pair of forward iterators. + diff --git a/external/ctre/docs/conf.py b/external/ctre/docs/conf.py new file mode 100644 index 0000000..b9bbc25 --- /dev/null +++ b/external/ctre/docs/conf.py @@ -0,0 +1,54 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# http://www.sphinx-doc.org/en/master/config + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'ctre' +copyright = '2019, Hana Dusikova' +author = 'Hana Dusikova' +master_doc = 'index' +primary_domain = 'cpp' +highlight_language = 'cpp' + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] diff --git a/external/ctre/docs/examples.rst b/external/ctre/docs/examples.rst new file mode 100644 index 0000000..5281beb --- /dev/null +++ b/external/ctre/docs/examples.rst @@ -0,0 +1,77 @@ +Examples +======== + +Extracting a number from input +------------------------------ +:: + + std::optional extract_number(std::string_view s) noexcept { + if (auto m = ctre::match<"[a-z]+([0-9]+)">(s)) { + return m.get<1>().to_view(); + } else { + return std::nullopt; + } + } + +`link to compiler explorer `_ + +Extracting values from date +--------------------------- +:: + + + struct date { std::string_view year; std::string_view month; std::string_view day; }; + std::optional extract_date(std::string_view s) noexcept { + using namespace ctre::literals; + if (auto [whole, year, month, day] = ctre::match<"(\\d{4})/(\\d{1,2})/(\\d{1,2})">(s); whole) { + return date{year, month, day}; + } else { + return std::nullopt; + } + } + + //static_assert(extract_date("2018/08/27"sv).has_value()); + //static_assert((*extract_date("2018/08/27"sv)).year == "2018"sv); + //static_assert((*extract_date("2018/08/27"sv)).month == "08"sv); + //static_assert((*extract_date("2018/08/27"sv)).day == "27"sv); + +`link to compiler explorer `_ + +Lexer +----- +:: + + enum class type { + unknown, identifier, number + }; + + struct lex_item { + type t; + std::string_view c; + }; + + std::optional lexer(std::string_view v) noexcept { + if (auto [m,id,num] = ctre::match<"([a-z]+)|([0-9]+)">(v); m) { + if (id) { + return lex_item{type::identifier, id}; + } else if (num) { + return lex_item{type::number, num}; + } + } + return std::nullopt; + } + +`link to compiler explorer `_ + +Range over input +---------------- + +This support is preliminary and probably the API will be changed. + +:: + + auto input = "123,456,768"sv; + + for (auto match: ctre::range<"([0-9]+),?">(input)) { + std::cout << std::string_view{match.get<0>()} << "\n"; + } \ No newline at end of file diff --git a/external/ctre/docs/index.rst b/external/ctre/docs/index.rst new file mode 100644 index 0000000..67c7b3e --- /dev/null +++ b/external/ctre/docs/index.rst @@ -0,0 +1,66 @@ +ctre +==== + +A compile-time (almost) PCRE-compatible regular expression matcher for C++. + +Overview +======== + +Fast compile-time regular expressions with support for matching/searching/capturing at compile-time or runtime. :: + + ctre::match<"REGEX">(subject); // C++20 + "REGEX"_ctre.match(subject); // C++17 + N3599 extension + +.. toctree:: + :maxdepth: 2 + + api + examples + regex_syntax + +Supported compilers +=================== + +- clang 6.0+ (template UDL, C++17 syntax) +- xcode clang 10.0+ (template UDL, C++17 syntax) +- gcc 7.4+ (template UDL, C++17 syntax) +- gcc 9.0+ (C++17 & C++20 cNTTP syntax) +- MSVC 15.8.8+ (C++17 syntax only) + +Basic Usage +=========== + +Template UDL syntax +------------------- + +Compiler must support N3599 extension, as GNU extension in gcc (not in GCC 9.1+) and clang. :: + + constexpr auto match(std::string_view sv) noexcept { + using namespace ctre::literals; + return "h.*"_ctre.match(sv); + } + +If you need N3599 extension in GCC 9.1+ you can't use -pedantic mode and define the macro ``CTRE_ENABLE_LITERALS``. + +C++17 syntax +------------ + +You can provide pattern as a constexpr ``ctll::fixed_string variable``. :: + + static constexpr auto pattern = ctll::fixed_string{ "h.*" }; + + constexpr auto match(std::string_view sv) noexcept { + return ctre::match(sv); + } + +(this is tested in MSVC 15.8.8) + +C++20 syntax +------------ + +Currently only compiler which supports cNTTP syntax ``ctre::match(subject)`` is GCC 9+. :: + + constexpr auto match(std::string_view sv) noexcept { + return ctre::match<"h.*">(sv); + } + diff --git a/external/ctre/docs/regex_syntax.rst b/external/ctre/docs/regex_syntax.rst new file mode 100644 index 0000000..9af97ad --- /dev/null +++ b/external/ctre/docs/regex_syntax.rst @@ -0,0 +1,18 @@ +Regex Syntax +============ + +The library supports most of the `PCRE `_ syntax with a few exceptions: + +- callouts +- comments +- conditional patterns +- control characters (\\cX) +- horizontal / vertical character classes (\\h\\H\\v\\V) +- match point reset (\\K) +- named characters +- octal numbers +- options / modes +- subroutines +- unicode grapheme cluster (\\X) + +TODO more detailed regex information \ No newline at end of file diff --git a/external/ctre/future.cpp b/external/ctre/future.cpp new file mode 100644 index 0000000..07931f6 --- /dev/null +++ b/external/ctre/future.cpp @@ -0,0 +1,15 @@ +#include +#include +#include + +std::string match(std::string_view sv) { + if (auto match = ctre::match<"[a-z]+">(sv); match) { + return match.to_string(); + } else { + return "not_match"; + } +} + +int main() { + std::cout << match("hello") << "\n"; +} \ No newline at end of file diff --git a/external/ctre/gcc-bench.txt b/external/ctre/gcc-bench.txt new file mode 100644 index 0000000..a943b97 --- /dev/null +++ b/external/ctre/gcc-bench.txt @@ -0,0 +1,20 @@ +//--------- ABCD|DEFGH|EFGHI|A{4,} +egrep 0m50.036s +CTRE 0m3.982s +PCRE 0m8.621s +std::regex 0m55.058s +//--------- [0-9a-fA-F]{8,16} +egrep 0m32.361s +CTRE 0m4.291s +PCRE 0m13.958s +std::regex 0m18.179s +//--------- ^([0-9]{4,16})?[aA] +egrep 0m12.819s +CTRE 0m2.844s +PCRE 0m2.614s +std::regex 0m22.876s +//--------- ([aAbB]{4,}|[xXyY]{4,}|[1234]{4,})0 +egrep 1m45.696s +CTRE 0m7.623s +PCRE 0m39.808s +std::regex 1m2.799s diff --git a/external/ctre/include/ctll.hpp b/external/ctre/include/ctll.hpp new file mode 100644 index 0000000..2fe40e3 --- /dev/null +++ b/external/ctre/include/ctll.hpp @@ -0,0 +1,6 @@ +#ifndef CTRE_V2__CTLL__HPP +#define CTRE_V2__CTLL__HPP + +#include "ctll/parser.hpp" + +#endif diff --git a/external/ctre/include/ctll/actions.hpp b/external/ctre/include/ctll/actions.hpp new file mode 100644 index 0000000..a6a569d --- /dev/null +++ b/external/ctre/include/ctll/actions.hpp @@ -0,0 +1,29 @@ +#ifndef CTLL__ACTIONS__HPP +#define CTLL__ACTIONS__HPP + +namespace ctll { + struct empty_subject { }; + + struct empty_actions { + // dummy operator so using Actions::operator() later will not give error + template static constexpr auto apply(Action, InputSymbol, Subject subject) { + return subject; + } + }; + + template struct identity: public Actions { + using Actions::apply; + // allow empty_subject to exists + template constexpr static auto apply(Action, term, empty_subject) -> empty_subject { return {}; } + template constexpr static auto apply(Action, epsilon, empty_subject) -> empty_subject { return {}; } + }; + + template struct ignore_unknown: public Actions { + using Actions::apply; + // allow flow thru unknown actions + template constexpr static auto apply(Action, term, Subject) -> Subject { return {}; } + template constexpr static auto apply(Action, epsilon, Subject) -> Subject { return {}; } + }; +} + +#endif diff --git a/external/ctre/include/ctll/fixed_string.hpp b/external/ctre/include/ctll/fixed_string.hpp new file mode 100644 index 0000000..5c7666b --- /dev/null +++ b/external/ctre/include/ctll/fixed_string.hpp @@ -0,0 +1,223 @@ +#ifndef CTLL__FIXED_STRING__GPP +#define CTLL__FIXED_STRING__GPP + +#ifndef CTLL_IN_A_MODULE +#include +#include +#include +#include +#include +#endif + +#include "utilities.hpp" + +namespace ctll { + +struct length_value_t { + uint32_t value; + uint8_t length; +}; + +constexpr length_value_t length_and_value_of_utf8_code_point(uint8_t first_unit) noexcept { + if ((first_unit & 0b1000'0000) == 0b0000'0000) return {static_cast(first_unit), 1}; + else if ((first_unit & 0b1110'0000) == 0b1100'0000) return {static_cast(first_unit & 0b0001'1111), 2}; + else if ((first_unit & 0b1111'0000) == 0b1110'0000) return {static_cast(first_unit & 0b0000'1111), 3}; + else if ((first_unit & 0b1111'1000) == 0b1111'0000) return {static_cast(first_unit & 0b0000'0111), 4}; + else if ((first_unit & 0b1111'1100) == 0b1111'1000) return {static_cast(first_unit & 0b0000'0011), 5}; + else if ((first_unit & 0b1111'1100) == 0b1111'1100) return {static_cast(first_unit & 0b0000'0001), 6}; + else return {0, 0}; +} + +constexpr char32_t value_of_trailing_utf8_code_point(uint8_t unit, bool & correct) noexcept { + if ((unit & 0b1100'0000) == 0b1000'0000) return unit & 0b0011'1111; + else { + correct = false; + return 0; + } +} + +constexpr length_value_t length_and_value_of_utf16_code_point(uint16_t first_unit) noexcept { + if ((first_unit & 0b1111110000000000) == 0b1101'1000'0000'0000) return {static_cast(first_unit & 0b0000001111111111), 2}; + else return {first_unit, 1}; +} + +struct construct_from_pointer_t { }; + +constexpr auto construct_from_pointer = construct_from_pointer_t{}; + +CTLL_EXPORT template struct fixed_string { + char32_t content[N] = {}; + size_t real_size{0}; + bool correct_flag{true}; + + template constexpr fixed_string(construct_from_pointer_t, const T * input) noexcept { + if constexpr (std::is_same_v) { + #ifdef CTRE_STRING_IS_UTF8 + size_t out{0}; + for (size_t i{0}; i < N; ++i) { + length_value_t info = length_and_value_of_utf8_code_point(input[i]); + switch (info.length) { + case 6: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 5: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 4: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 3: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 2: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 1: + content[out++] = static_cast(info.value); + real_size++; + break; + default: + correct_flag = false; + return; + } + } + #else + for (size_t i{0}; i < N; ++i) { + content[i] = static_cast(input[i]); + real_size++; + } + #endif + #if __cpp_char8_t + } else if constexpr (std::is_same_v) { + size_t out{0}; + for (size_t i{0}; i < N; ++i) { + length_value_t info = length_and_value_of_utf8_code_point(input[i]); + switch (info.length) { + case 6: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 5: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 4: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 3: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 2: + if (++i < N) info.value = (info.value << 6) | value_of_trailing_utf8_code_point(input[i], correct_flag); + [[fallthrough]]; + case 1: + content[out++] = static_cast(info.value); + real_size++; + break; + default: + correct_flag = false; + return; + } + } + #endif + } else if constexpr (std::is_same_v) { + size_t out{0}; + for (size_t i{0}; i < N; ++i) { + length_value_t info = length_and_value_of_utf16_code_point(input[i]); + if (info.length == 2) { + if (++i < N) { + if ((input[i] & 0b1111'1100'0000'0000) == 0b1101'1100'0000'0000) { + content[out++] = ((info.value << 10) | (input[i] & 0b0000'0011'1111'1111)) + 0x10000; + } else { + correct_flag = false; + break; + } + } + } else { + content[out++] = info.value; + } + } + real_size = out; + } else if constexpr (std::is_same_v || std::is_same_v) { + for (size_t i{0}; i < N; ++i) { + content[i] = static_cast(input[i]); + real_size++; + } + } + } + + template constexpr fixed_string(const std::array & in) noexcept: fixed_string{construct_from_pointer, in.data()} { } + template constexpr fixed_string(const T (&input)[N+1]) noexcept: fixed_string{construct_from_pointer, input} { } + + constexpr fixed_string(const fixed_string & other) noexcept { + for (size_t i{0}; i < N; ++i) { + content[i] = other.content[i]; + } + real_size = other.real_size; + correct_flag = other.correct_flag; + } + constexpr bool correct() const noexcept { + return correct_flag; + } + constexpr size_t size() const noexcept { + return real_size; + } + constexpr const char32_t * begin() const noexcept { + return content; + } + constexpr const char32_t * end() const noexcept { + return content + size(); + } + constexpr char32_t operator[](size_t i) const noexcept { + return content[i]; + } + template constexpr bool is_same_as(const fixed_string & rhs) const noexcept { + if (real_size != rhs.size()) return false; + for (size_t i{0}; i != real_size; ++i) { + if (content[i] != rhs[i]) return false; + } + return true; + } + constexpr operator std::basic_string_view() const noexcept { + return std::basic_string_view{content, size()}; + } +}; + +template <> class fixed_string<0> { + static constexpr char32_t empty[1] = {0}; +public: + template constexpr fixed_string(const T *) noexcept { + + } + constexpr fixed_string(std::initializer_list) noexcept { + + } + constexpr fixed_string(const fixed_string &) noexcept { + + } + constexpr bool correct() const noexcept { + return true; + } + constexpr size_t size() const noexcept { + return 0; + } + constexpr const char32_t * begin() const noexcept { + return empty; + } + constexpr const char32_t * end() const noexcept { + return empty + size(); + } + constexpr char32_t operator[](size_t) const noexcept { + return 0; + } + constexpr operator std::basic_string_view() const noexcept { + return std::basic_string_view{empty, 0}; + } +}; + +template fixed_string(const CharT (&)[N]) -> fixed_string; +template fixed_string(const std::array &) -> fixed_string; + +template fixed_string(fixed_string) -> fixed_string; + +} + +#endif diff --git a/external/ctre/include/ctll/grammars.hpp b/external/ctre/include/ctll/grammars.hpp new file mode 100644 index 0000000..fd5184c --- /dev/null +++ b/external/ctre/include/ctll/grammars.hpp @@ -0,0 +1,123 @@ +#ifndef CTLL__GRAMMARS__HPP +#define CTLL__GRAMMARS__HPP + +namespace ctll { + +// terminal type representing symbol / character of any type +template struct term { + static constexpr auto value = v; +}; + +// epsilon = nothing on input tape +// also used as an command for parsing means "do nothing" +struct epsilon { + static constexpr auto value = '-'; +}; + +// empty_stack_symbol = nothing on stack +struct empty_stack_symbol {}; + +// push is alias to list +template using push = list; + +// accept/reject type for controlling output of LL1 machine +struct accept { constexpr explicit operator bool() noexcept { return true; } }; +struct reject { constexpr explicit operator bool() noexcept { return false; } }; + +// action type, every action item in grammar must inherit from +struct action { + struct action_tag { }; +}; + +// move one character forward and pop it from stack command +struct pop_input { + struct pop_input_tag { }; +}; + +// additional overloads for type list +template constexpr auto push_front(pop_input, list) -> list { return {}; } + +template constexpr auto push_front(epsilon, list) -> list { return {}; } + +template constexpr auto push_front(list, list) -> list { return {}; } + +template constexpr auto pop_front_and_push_front(T item, list l) { + return push_front(item, pop_front(l)); +} + +// SPECIAL matching types for nicer grammars + +// match any term +struct anything { + constexpr inline anything() noexcept { } + template constexpr anything(term) noexcept; +}; + +// match range of term A-B +template struct range { + constexpr inline range() noexcept { } + //template constexpr range(term) noexcept requires (A <= V) && (V <= B); + template > constexpr range(term) noexcept; +}; + +#ifdef __EDG__ +template struct contains { + static constexpr bool value = ((Set == V) || ... || false); +}; +#endif + +// match terms defined in set +template struct set { + constexpr inline set() noexcept { } + #ifdef __EDG__ + template ::value>> constexpr set(term) noexcept; + #else + template > constexpr set(term) noexcept; + #endif +}; + +// match terms not defined in set +template struct neg_set { + constexpr inline neg_set() noexcept { } + + #ifdef __EDG__ + template ::value>> constexpr neg_set(term) noexcept; + #else + template > constexpr neg_set(term) noexcept; + #endif +}; + +// AUGMENTED grammar which completes user-defined grammar for all other cases +template struct augment_grammar: public Grammar { + // start nonterminal is defined in parent type + using typename Grammar::_start; + + // grammar rules are inherited from Grammar parent type + using Grammar::rule; + + // term on stack and on input means pop_input; + template static constexpr auto rule(term, term) -> ctll::pop_input; + + // if the type on stack (range, set, neg_set, anything) is constructible from the terminal => pop_input + template static constexpr auto rule(Expected, term) -> std::enable_if_t>, ctll::pop_input>; + + // empty stack and empty input means we are accepting + static constexpr auto rule(empty_stack_symbol, epsilon) -> ctll::accept; + + // not matching anything else => reject + static constexpr auto rule(...) -> ctll::reject; + + // start stack is just a list; + using start_stack = list; +}; + + + +} + + + + + +#endif + diff --git a/external/ctre/include/ctll/list.hpp b/external/ctre/include/ctll/list.hpp new file mode 100644 index 0000000..a04ed51 --- /dev/null +++ b/external/ctre/include/ctll/list.hpp @@ -0,0 +1,93 @@ +#ifndef CTLL__TYPE_STACK__HPP +#define CTLL__TYPE_STACK__HPP + +#include "utilities.hpp" + +namespace ctll { + +template struct list { }; + +struct _nothing { }; + +using empty_list = list<>; + +// calculate size of list content +template constexpr auto size(list) noexcept { return sizeof...(Ts); } + + +// check if the list is empty +template constexpr bool empty(list) noexcept { return false; } +constexpr bool empty(empty_list) { return true; } + + +// concat two lists together left to right +template constexpr auto concat(list, list) noexcept -> list { return {}; } + + +// push something to the front of a list +template constexpr auto push_front(T, list) noexcept -> list { return {}; } + + +// pop element from the front of a list +template constexpr auto pop_front(list) noexcept -> list { return {}; } +constexpr auto pop_front(empty_list) -> empty_list; + +// pop element from the front of a list and return new typelist too +template struct list_pop_pair { + Front front{}; + List list{}; + constexpr list_pop_pair() = default; +}; + +template constexpr auto pop_and_get_front(list, T = T()) noexcept -> list_pop_pair> { return {}; } +template constexpr auto pop_and_get_front(empty_list, T = T()) noexcept -> list_pop_pair { return {}; } + + +// return front of the list +template constexpr auto front(list, T = T()) noexcept -> Head { return {}; } +template constexpr auto front(empty_list, T = T()) noexcept -> T { return {}; } + +// rotate list +template struct rotate_item { + template friend constexpr auto operator+(list, rotate_item) noexcept -> list { return {}; } +}; + +template constexpr auto rotate(list) -> decltype((list<>{} + ... + rotate_item{})) { + return {}; +} + +// set operations +template struct item_matcher { + struct not_selected { + template friend constexpr auto operator+(list, not_selected) -> list; + }; + template struct wrapper { + template friend constexpr auto operator+(list, wrapper) -> list; + }; + + static constexpr auto check(T) { return std::true_type{}; } + static constexpr auto check(...) { return std::false_type{}; } + static constexpr auto select(T) { return not_selected{}; } + template static constexpr auto select(Y) { return wrapper{}; } +}; + +template constexpr bool exists_in(T, list) noexcept { + return (item_matcher::check(Ts{}) || ... || false); +} + +template constexpr auto add_item(T item, list l) noexcept { + if constexpr (exists_in(item, l)) { + return l; + } else { + return list{}; + } +} + +template constexpr auto remove_item(T, list) noexcept { + item_matcher matcher; + return decltype((list<>{} + ... + matcher.select(Ts{}))){}; +} + +} + +#endif diff --git a/external/ctre/include/ctll/parser.hpp b/external/ctre/include/ctll/parser.hpp new file mode 100644 index 0000000..d3751f9 --- /dev/null +++ b/external/ctre/include/ctll/parser.hpp @@ -0,0 +1,192 @@ +#ifndef CTLL__PARSER__HPP +#define CTLL__PARSER__HPP + +#include "fixed_string.hpp" +#include "list.hpp" +#include "grammars.hpp" +#include "actions.hpp" + +#ifndef CTLL_IN_A_MODULE +#include +#endif + +namespace ctll { + + +enum class decision { + reject, + accept, + undecided +}; + +struct placeholder { }; + +template using index_placeholder = placeholder; + +#if CTLL_CNTTP_COMPILER_CHECK +template struct parser { // in c++20 +#else +template struct parser { +#endif + + #ifdef __GNUC__ // workaround to GCC bug + #if CTLL_CNTTP_COMPILER_CHECK + static constexpr auto _input = input; // c++20 mode + #else + static constexpr auto & _input = input; // c++17 mode + #endif + #else + static constexpr auto _input = input; // everyone else + #endif + + using Actions = ctll::conditional, identity>; + using grammar = augment_grammar; + + template struct results { + + static constexpr bool is_correct = Decision == decision::accept; + + constexpr inline CTLL_FORCE_INLINE operator bool() const noexcept { + return is_correct; + } + + #ifdef __GNUC__ // workaround to GCC bug + #if CTLL_CNTTP_COMPILER_CHECK + static constexpr auto _input = input; // c++20 mode + #else + static constexpr auto & _input = input; // c++17 mode + #endif + #else + static constexpr auto _input = input; // everyone else + #endif + + using output_type = Subject; + static constexpr size_t position = Pos; + + constexpr auto operator+(placeholder) const noexcept { + if constexpr (Decision == decision::undecided) { + // parse for current char (RPos) with previous stack and subject :) + return parser::template decide({}, {}); + } else { + // if there is decision already => just push it to the end of fold expression + return *this; + } + } + }; + + template static constexpr auto get_current_term() noexcept { + if constexpr (Pos < input.size()) { + constexpr auto value = input[Pos]; + if constexpr (value <= static_cast((std::numeric_limits::max)())) { + return term(value)>{}; + } else { + return term{}; + } + + } else { + // return epsilon if we are past the input + return epsilon{}; + } + } + template static constexpr auto get_previous_term() noexcept { + if constexpr (Pos == 0) { + // there is no previous character on input if we are on start + return epsilon{}; + } else if constexpr ((Pos-1) < input.size()) { + constexpr auto value = input[Pos-1]; + if constexpr (value <= static_cast((std::numeric_limits::max)())) { + return term(value)>{}; + } else { + return term{}; + } + } else { + return epsilon{}; + } + } + // if rule is accept => return true and subject + template + static constexpr auto move(ctll::accept, Terminal, Stack, Subject) noexcept { + return typename parser::template results(); + } + // if rule is reject => return false and subject + template + static constexpr auto move(ctll::reject, Terminal, Stack, Subject) noexcept { + return typename parser::template results(); + } + // if rule is pop_input => move to next character + template + static constexpr auto move(ctll::pop_input, Terminal, Stack, Subject) noexcept { + return typename parser::template results(); + } + // if rule is string => push it to the front of stack + template + static constexpr auto move(push string, Terminal, Stack stack, Subject subject) noexcept { + return decide(push_front(string, stack), subject); + } + // if rule is epsilon (empty string) => continue + template + static constexpr auto move(epsilon, Terminal, Stack stack, Subject subject) noexcept { + return decide(stack, subject); + } + // if rule is string with current character at the beginning (term) => move to next character + // and push string without the character (quick LL(1)) + template + static constexpr auto move(push, Content...>, term, Stack stack, Subject) noexcept { + constexpr auto local_input = input; + return typename parser::template results(), stack)), Subject, decision::undecided>(); + } + // if rule is string with any character at the beginning (compatible with current term) => move to next character + // and push string without the character (quick LL(1)) + template + static constexpr auto move(push, term, Stack stack, Subject) noexcept { + constexpr auto local_input = input; + return typename parser::template results(), stack)), Subject, decision::undecided>(); + } + // decide if we need to take action or move + template static constexpr auto decide(Stack previous_stack, Subject previous_subject) noexcept { + // each call means we pop something from stack + auto top_symbol = decltype(ctll::front(previous_stack, empty_stack_symbol()))(); + // gcc pedantic warning + [[maybe_unused]] auto stack = decltype(ctll::pop_front(previous_stack))(); + + // in case top_symbol is action type (apply it on previous subject and get new one) + if constexpr (std::is_base_of_v) { + auto subject = Actions::apply(top_symbol, get_previous_term(), previous_subject); + + // in case that semantic action is error => reject input + if constexpr (std::is_same_v) { + return typename parser::template results(); + } else { + return decide(stack, subject); + } + } else { + // all other cases are ordinary for LL(1) parser + auto current_term = get_current_term(); + auto rule = decltype(grammar::rule(top_symbol,current_term))(); + return move(rule, current_term, stack, previous_subject); + } + } + + // trampolines with folded expression + template static constexpr auto trampoline_decide(Subject, std::index_sequence) noexcept { + // parse everything for first char and than for next and next ... + // Pos+1 is needed as we want to finish calculation with epsilons on stack + auto v = (decide<0, typename grammar::start_stack, Subject>({}, {}) + ... + index_placeholder()); + return v; + } + + template static constexpr auto trampoline_decide(Subject subject = {}) noexcept { + // there will be no recursion, just sequence long as the input + return trampoline_decide(subject, std::make_index_sequence()); + } + + template using output = decltype(trampoline_decide()); + template static inline constexpr bool correct_with = trampoline_decide(); + +}; + +} // end of ctll namespace + + +#endif + diff --git a/external/ctre/include/ctll/utilities.hpp b/external/ctre/include/ctll/utilities.hpp new file mode 100644 index 0000000..808e2ff --- /dev/null +++ b/external/ctre/include/ctll/utilities.hpp @@ -0,0 +1,67 @@ +#ifndef CTLL__UTILITIES__HPP +#define CTLL__UTILITIES__HPP + +#ifndef CTLL_IN_A_MODULE +#include +#endif + +#ifdef CTLL_IN_A_MODULE +#define CTLL_EXPORT export +#else +#define CTLL_EXPORT +#endif + +#if defined __cpp_nontype_template_parameter_class + #define CTLL_CNTTP_COMPILER_CHECK 1 +#elif defined __cpp_nontype_template_args +// compiler which defines correctly feature test macro (not you clang) + #if __cpp_nontype_template_args >= 201911L + #define CTLL_CNTTP_COMPILER_CHECK 1 + #elif __cpp_nontype_template_args >= 201411L +// appleclang 13+ + #if defined __apple_build_version__ + #if defined __clang_major__ && __clang_major__ >= 13 +// but only in c++20 and more + #if __cplusplus > 201703L + #define CTLL_CNTTP_COMPILER_CHECK 1 + #endif + #endif + #else +// clang 12+ + #if defined __clang_major__ && __clang_major__ >= 12 +// but only in c++20 and more + #if __cplusplus > 201703L + #define CTLL_CNTTP_COMPILER_CHECK 1 + #endif + #endif + #endif + #endif +#endif + +#ifndef CTLL_CNTTP_COMPILER_CHECK + #define CTLL_CNTTP_COMPILER_CHECK 0 +#endif + +#ifdef _MSC_VER +#define CTLL_FORCE_INLINE __forceinline +#else +#define CTLL_FORCE_INLINE __attribute__((always_inline)) +#endif + +namespace ctll { + +template struct conditional_helper; + +template <> struct conditional_helper { + template using type = A; +}; + +template <> struct conditional_helper { + template using type = B; +}; + +template using conditional = typename conditional_helper::template type; + +} + +#endif diff --git a/external/ctre/include/ctre-unicode.hpp b/external/ctre/include/ctre-unicode.hpp new file mode 100644 index 0000000..5c8ac17 --- /dev/null +++ b/external/ctre/include/ctre-unicode.hpp @@ -0,0 +1,7 @@ +#ifndef CTRE_V2__CTRE_UNICODE__HPP +#define CTRE_V2__CTRE_UNICODE__HPP + +#include "ctre.hpp" +#include "unicode-db.hpp" + +#endif diff --git a/external/ctre/include/ctre.hpp b/external/ctre/include/ctre.hpp new file mode 100644 index 0000000..fcc4b0d --- /dev/null +++ b/external/ctre/include/ctre.hpp @@ -0,0 +1,10 @@ +#ifndef CTRE_V2__CTRE__HPP +#define CTRE_V2__CTRE__HPP + +#include "ctre/literals.hpp" +#include "ctre/functions.hpp" +#include "ctre/iterators.hpp" +#include "ctre/range.hpp" +#include "ctre/operators.hpp" + +#endif diff --git a/external/ctre/include/ctre/actions/asserts.inc.hpp b/external/ctre/include/ctre/actions/asserts.inc.hpp new file mode 100644 index 0000000..8b8077c --- /dev/null +++ b/external/ctre/include/ctre/actions/asserts.inc.hpp @@ -0,0 +1,29 @@ +#ifndef CTRE__ACTIONS__ASSERTS__HPP +#define CTRE__ACTIONS__ASSERTS__HPP + +// push_assert_begin +template static constexpr auto apply(pcre::push_assert_begin, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(assert_line_begin(), subject.stack), subject.parameters}; +} + +// push_assert_end +template static constexpr auto apply(pcre::push_assert_end, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(assert_line_end(), subject.stack), subject.parameters}; +} + +// push_assert_begin +template static constexpr auto apply(pcre::push_assert_subject_begin, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(assert_subject_begin(), subject.stack), subject.parameters}; +} + +// push_assert_subject_end +template static constexpr auto apply(pcre::push_assert_subject_end, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(assert_subject_end(), subject.stack), subject.parameters}; +} + +// push_assert_subject_end_with_lineend +template static constexpr auto apply(pcre::push_assert_subject_end_with_lineend, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(assert_subject_end_line(), subject.stack), subject.parameters}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/atomic_group.inc.hpp b/external/ctre/include/ctre/actions/atomic_group.inc.hpp new file mode 100644 index 0000000..f615c8a --- /dev/null +++ b/external/ctre/include/ctre/actions/atomic_group.inc.hpp @@ -0,0 +1,19 @@ +#ifndef CTRE__ACTIONS__ATOMIC_GROUP__HPP +#define CTRE__ACTIONS__ATOMIC_GROUP__HPP + +// atomic start +template static constexpr auto apply(pcre::start_atomic, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::list(), pcre_parameters()}; +} + +// atomic +template static constexpr auto apply(pcre::make_atomic, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// atomic sequence +template static constexpr auto apply(pcre::make_atomic, ctll::term, pcre_context, atomic_start, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/backreference.inc.hpp b/external/ctre/include/ctre/actions/backreference.inc.hpp new file mode 100644 index 0000000..2a7de4d --- /dev/null +++ b/external/ctre/include/ctre/actions/backreference.inc.hpp @@ -0,0 +1,30 @@ +#ifndef CTRE__ACTIONS__BACKREFERENCE__HPP +#define CTRE__ACTIONS__BACKREFERENCE__HPP + +// backreference with name +template static constexpr auto apply(pcre::make_back_reference, ctll::term, pcre_context, Ts...>, pcre_parameters>) { + return pcre_context{ctll::push_front(back_reference_with_name>(), ctll::list()), pcre_parameters()}; +} + +// with just a number +template static constexpr auto apply(pcre::make_back_reference, ctll::term, pcre_context, Ts...>, pcre_parameters>) { + // if we are looking outside of existing list of Ids ... reject input during parsing + if constexpr (Counter < Id) { + return ctll::reject{}; + } else { + return pcre_context{ctll::push_front(back_reference(), ctll::list()), pcre_parameters()}; + } +} + +// relative backreference +template static constexpr auto apply(pcre::make_relative_back_reference, ctll::term, [[maybe_unused]] pcre_context, Ts...>, pcre_parameters>) { + // if we are looking outside of existing list of Ids ... reject input during parsing + if constexpr (Counter < Id) { + return ctll::reject{}; + } else { + constexpr size_t absolute_id = (Counter + 1) - Id; + return pcre_context{ctll::push_front(back_reference(), ctll::list()), pcre_parameters()}; + } +} + +#endif diff --git a/external/ctre/include/ctre/actions/boundaries.inc.hpp b/external/ctre/include/ctre/actions/boundaries.inc.hpp new file mode 100644 index 0000000..097bc9d --- /dev/null +++ b/external/ctre/include/ctre/actions/boundaries.inc.hpp @@ -0,0 +1,14 @@ +#ifndef CTRE__ACTIONS__BOUNDARIES__HPP +#define CTRE__ACTIONS__BOUNDARIES__HPP + +// push_word_boundary +template static constexpr auto apply(pcre::push_word_boundary, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(boundary(), subject.stack), subject.parameters}; +} + +// push_not_word_boundary +template static constexpr auto apply(pcre::push_not_word_boundary, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(boundary>(), subject.stack), subject.parameters}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/capture.inc.hpp b/external/ctre/include/ctre/actions/capture.inc.hpp new file mode 100644 index 0000000..ebf5437 --- /dev/null +++ b/external/ctre/include/ctre/actions/capture.inc.hpp @@ -0,0 +1,40 @@ +#ifndef CTRE__ACTIONS__CAPTURE__HPP +#define CTRE__ACTIONS__CAPTURE__HPP + +// prepare_capture +template static constexpr auto apply(pcre::prepare_capture, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::push_front(capture_id(), ctll::list()), pcre_parameters()}; +} + +// reset_capture +template static constexpr auto apply(pcre::reset_capture, ctll::term, pcre_context, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list(), pcre_parameters()}; +} + +// capture +template static constexpr auto apply(pcre::make_capture, ctll::term, pcre_context, Ts...>, pcre_parameters>) { + return pcre_context{ctll::push_front(capture(), ctll::list()), pcre_parameters()}; +} +// capture (sequence) +template static constexpr auto apply(pcre::make_capture, ctll::term, pcre_context, capture_id, Ts...>, pcre_parameters>) { + return pcre_context{ctll::push_front(capture(), ctll::list()), pcre_parameters()}; +} +// push_name +template static constexpr auto apply(pcre::push_name, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(id(), subject.stack), subject.parameters}; +} +// push_name (concat) +template static constexpr auto apply(pcre::push_name, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(id(), ctll::list()), subject.parameters}; +} +// capture with name +template static constexpr auto apply(pcre::make_capture_with_name, ctll::term, pcre_context, capture_id, Ts...>, pcre_parameters>) { + return pcre_context{ctll::push_front(capture_with_name, A>(), ctll::list()), pcre_parameters()}; +} +// capture with name (sequence) +template static constexpr auto apply(pcre::make_capture_with_name, ctll::term, pcre_context, id, capture_id, Ts...>, pcre_parameters>) { + return pcre_context{ctll::push_front(capture_with_name, Content...>(), ctll::list()), pcre_parameters()}; +} + + +#endif diff --git a/external/ctre/include/ctre/actions/characters.inc.hpp b/external/ctre/include/ctre/actions/characters.inc.hpp new file mode 100644 index 0000000..4aa7ffd --- /dev/null +++ b/external/ctre/include/ctre/actions/characters.inc.hpp @@ -0,0 +1,41 @@ +#ifndef CTRE__ACTIONS__CHARACTERS__HPP +#define CTRE__ACTIONS__CHARACTERS__HPP + +// push character +template static constexpr auto apply(pcre::push_character, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character(), subject.stack), subject.parameters}; +} +// push_any_character +template static constexpr auto apply(pcre::push_character_anything, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(any(), subject.stack), subject.parameters}; +} +// character_alarm +template static constexpr auto apply(pcre::push_character_alarm, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\x07'>(), subject.stack), subject.parameters}; +} +// character_escape +template static constexpr auto apply(pcre::push_character_escape, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\x14'>(), subject.stack), subject.parameters}; +} +// character_formfeed +template static constexpr auto apply(pcre::push_character_formfeed, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\x0C'>(), subject.stack), subject.parameters}; +} +// push_character_newline +template static constexpr auto apply(pcre::push_character_newline, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\x0A'>(), subject.stack), subject.parameters}; +} +// push_character_null +template static constexpr auto apply(pcre::push_character_null, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\0'>(), subject.stack), subject.parameters}; +} +// push_character_return_carriage +template static constexpr auto apply(pcre::push_character_return_carriage, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\x0D'>(), subject.stack), subject.parameters}; +} +// push_character_tab +template static constexpr auto apply(pcre::push_character_tab, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(character<'\x09'>(), subject.stack), subject.parameters}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/class.inc.hpp b/external/ctre/include/ctre/actions/class.inc.hpp new file mode 100644 index 0000000..c52c550 --- /dev/null +++ b/external/ctre/include/ctre/actions/class.inc.hpp @@ -0,0 +1,51 @@ +#ifndef CTRE__ACTIONS__CLASS__HPP +#define CTRE__ACTIONS__CLASS__HPP + +// class_digit +template static constexpr auto apply(pcre::class_digit, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::set(), subject.stack), subject.parameters}; +} +// class_non_digit +template static constexpr auto apply(pcre::class_nondigit, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::negative_set(), subject.stack), subject.parameters}; +} +// class_space +template static constexpr auto apply(pcre::class_space, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::set(), subject.stack), subject.parameters}; +} +// class_nonspace +template static constexpr auto apply(pcre::class_nonspace, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::negative_set(), subject.stack), subject.parameters}; +} + +// class_horizontal_space +template static constexpr auto apply(pcre::class_horizontal_space, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::set(), subject.stack), subject.parameters}; +} +// class_horizontal_nonspace +template static constexpr auto apply(pcre::class_non_horizontal_space, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::negative_set(), subject.stack), subject.parameters}; +} +// class_vertical_space +template static constexpr auto apply(pcre::class_vertical_space, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::set(), subject.stack), subject.parameters}; +} +// class_vertical_nonspace +template static constexpr auto apply(pcre::class_non_vertical_space, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::negative_set(), subject.stack), subject.parameters}; +} + +// class_word +template static constexpr auto apply(pcre::class_word, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::set(), subject.stack), subject.parameters}; +} +// class_nonword +template static constexpr auto apply(pcre::class_nonword, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::negative_set(), subject.stack), subject.parameters}; +} +// class_nonnewline +template static constexpr auto apply(pcre::class_nonnewline, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::negative_set>(), subject.stack), subject.parameters}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/fusion.inc.hpp b/external/ctre/include/ctre/actions/fusion.inc.hpp new file mode 100644 index 0000000..bccb20b --- /dev/null +++ b/external/ctre/include/ctre/actions/fusion.inc.hpp @@ -0,0 +1,70 @@ +#ifndef CTRE__ACTIONS__FUSION__HPP +#define CTRE__ACTIONS__FUSION__HPP + +static constexpr size_t combine_max_repeat_length(size_t A, size_t B) { + if (A && B) return A+B; + else return 0; +} + +template static constexpr auto combine_repeat(repeat, repeat) { + return repeat(); +} + +template static constexpr auto combine_repeat(lazy_repeat, lazy_repeat) { + return lazy_repeat(); +} + +template static constexpr auto combine_repeat(possessive_repeat, possessive_repeat) { + [[maybe_unused]] constexpr bool first_is_unbounded = (MaxA == 0); + [[maybe_unused]] constexpr bool second_is_nonempty = (MinB > 0); + [[maybe_unused]] constexpr bool second_can_be_empty = (MinB == 0); + + if constexpr (first_is_unbounded && second_is_nonempty) { + // will always reject, but I keep the content, so I have some amount of captures + return sequence(); + } else if constexpr (first_is_unbounded) { + return possessive_repeat(); + } else if constexpr (second_can_be_empty) { + return possessive_repeat(); + } else { + return possessive_repeat(); + } +} + +// concat repeat sequences +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, repeat, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(combine_repeat(repeat(), repeat()), ctll::list()), subject.parameters}; +} + +// concat lazy repeat sequences +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, lazy_repeat, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(combine_repeat(lazy_repeat(), lazy_repeat()), ctll::list()), subject.parameters}; +} + +// concat possessive repeat seqeunces +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, possessive_repeat, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(combine_repeat(possessive_repeat(), possessive_repeat()), ctll::list()), subject.parameters}; +} + +// concat repeat sequences into sequence +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, As...>,repeat,Ts...>, Parameters> subject) { + using result = decltype(combine_repeat(repeat(), repeat())); + + return pcre_context{ctll::push_front(sequence(), ctll::list()), subject.parameters}; +} + +// concat lazy repeat sequences into sequence +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, As...>,lazy_repeat,Ts...>, Parameters> subject) { + using result = decltype(combine_repeat(lazy_repeat(), lazy_repeat())); + + return pcre_context{ctll::push_front(sequence(), ctll::list()), subject.parameters}; +} + +// concat possessive repeat sequences into sequence +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, As...>,possessive_repeat,Ts...>, Parameters> subject) { + using result = decltype(combine_repeat(possessive_repeat(), possessive_repeat())); + + return pcre_context{ctll::push_front(sequence(), ctll::list()), subject.parameters}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/hexdec.inc.hpp b/external/ctre/include/ctre/actions/hexdec.inc.hpp new file mode 100644 index 0000000..ae30b6e --- /dev/null +++ b/external/ctre/include/ctre/actions/hexdec.inc.hpp @@ -0,0 +1,29 @@ +#ifndef CTRE__ACTIONS__HEXDEC__HPP +#define CTRE__ACTIONS__HEXDEC__HPP + +// hexdec character support (seed) +template static constexpr auto apply(pcre::create_hexdec, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(number<0ull>(), subject.stack), subject.parameters}; +} +// hexdec character support (push value) +template static constexpr auto apply(pcre::push_hexdec, ctll::term, pcre_context, Ts...>, Parameters> subject) { + constexpr auto previous = N << 4ull; + if constexpr (V >= 'a' && V <= 'f') { + return pcre_context{ctll::push_front(number<(previous + (V - 'a' + 10))>(), ctll::list()), subject.parameters}; + } else if constexpr (V >= 'A' && V <= 'F') { + return pcre_context{ctll::push_front(number<(previous + (V - 'A' + 10))>(), ctll::list()), subject.parameters}; + } else { + return pcre_context{ctll::push_front(number<(previous + (V - '0'))>(), ctll::list()), subject.parameters}; + } +} +// hexdec character support (convert to character) +template static constexpr auto apply(pcre::finish_hexdec, ctll::term, pcre_context, Ts...>, Parameters> subject) { + constexpr size_t max_char = (std::numeric_limits::max)(); + if constexpr (N <= max_char) { + return pcre_context{ctll::push_front(character(), ctll::list()), subject.parameters}; + } else { + return pcre_context{ctll::push_front(character(), ctll::list()), subject.parameters}; + } +} + +#endif diff --git a/external/ctre/include/ctre/actions/look.inc.hpp b/external/ctre/include/ctre/actions/look.inc.hpp new file mode 100644 index 0000000..8786a77 --- /dev/null +++ b/external/ctre/include/ctre/actions/look.inc.hpp @@ -0,0 +1,68 @@ +#ifndef CTRE__ACTIONS__LOOKAHEAD__HPP +#define CTRE__ACTIONS__LOOKAHEAD__HPP + +// lookahead positive start +template static constexpr auto apply(pcre::start_lookahead_positive, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::list>, Ts...>(), pcre_parameters()}; +} + +// lookahead positive end +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context>, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// lookahead positive end (sequence) +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context, look_start>, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// lookahead negative start +template static constexpr auto apply(pcre::start_lookahead_negative, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::list>, Ts...>(), pcre_parameters()}; +} + +// lookahead negative end +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context>, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// lookahead negative end (sequence) +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context, look_start>, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// LOOKBEHIND + +// lookbehind positive start +template static constexpr auto apply(pcre::start_lookbehind_positive, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::list>, Ts...>(), pcre_parameters()}; +} + +// lookbehind positive end +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context>, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// lookbehind positive end (sequence) +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context, look_start>, Ts...>, pcre_parameters>) { + using my_lookbehind = decltype(ctre::convert_to_basic_list(ctll::rotate(ctll::list{}))); + return pcre_context{ctll::list(), pcre_parameters()}; +} + +// lookbehind negative start +template static constexpr auto apply(pcre::start_lookbehind_negative, ctll::term, pcre_context, pcre_parameters>) { + return pcre_context{ctll::list>, Ts...>(), pcre_parameters()}; +} + +// lookbehind negative end +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context>, Ts...>, pcre_parameters>) { + return pcre_context{ctll::list, Ts...>(), pcre_parameters()}; +} + +// lookbehind negative end (sequence) +template static constexpr auto apply(pcre::look_finish, ctll::term, pcre_context, look_start>, Ts...>, pcre_parameters>) { + using my_lookbehind = decltype(ctre::convert_to_basic_list(ctll::rotate(ctll::list{}))); + return pcre_context{ctll::list(), pcre_parameters()}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/mode.inc.hpp b/external/ctre/include/ctre/actions/mode.inc.hpp new file mode 100644 index 0000000..d4e612b --- /dev/null +++ b/external/ctre/include/ctre/actions/mode.inc.hpp @@ -0,0 +1,32 @@ +#ifndef CTRE__ACTIONS__MODE__HPP +#define CTRE__ACTIONS__MODE__HPP + +// we need to reset counter and wrap Mode into mode_switch +template static constexpr auto apply_mode(Mode, ctll::list, Parameters) { + return pcre_context, Ts...>, Parameters>{}; +} + +template static constexpr auto apply_mode(Mode, ctll::list, Ts...>, pcre_parameters) { + return pcre_context, Ts...>, pcre_parameters>{}; +} + +// catch a semantic action into mode +template static constexpr auto apply(pcre::mode_case_insensitive mode, ctll::term,pcre_context, Parameters>) { + return apply_mode(mode, ctll::list{}, Parameters{}); +} + +template static constexpr auto apply(pcre::mode_case_sensitive mode, ctll::term,pcre_context, Parameters>) { + return apply_mode(mode, ctll::list{}, Parameters{}); +} + +template static constexpr auto apply(pcre::mode_singleline mode, ctll::term,pcre_context, Parameters>) { + return apply_mode(mode, ctll::list{}, Parameters{}); +} + +template static constexpr auto apply(pcre::mode_multiline mode, ctll::term,pcre_context, Parameters>) { + return apply_mode(mode, ctll::list{}, Parameters{}); +} + +// to properly reset capture + +#endif diff --git a/external/ctre/include/ctre/actions/named_class.inc.hpp b/external/ctre/include/ctre/actions/named_class.inc.hpp new file mode 100644 index 0000000..0be2710 --- /dev/null +++ b/external/ctre/include/ctre/actions/named_class.inc.hpp @@ -0,0 +1,61 @@ +#ifndef CTRE__ACTIONS__NAMED_CLASS__HPP +#define CTRE__ACTIONS__NAMED_CLASS__HPP + +// class_named_alnum +template static constexpr auto apply(pcre::class_named_alnum, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::alphanum_chars(), subject.stack), subject.parameters}; +} +// class_named_alpha +template static constexpr auto apply(pcre::class_named_alpha, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::alpha_chars(), subject.stack), subject.parameters}; +} +// class_named_digit +template static constexpr auto apply(pcre::class_named_digit, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::digit_chars(), subject.stack), subject.parameters}; +} +// class_named_ascii +template static constexpr auto apply(pcre::class_named_ascii, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::ascii_chars(), subject.stack), subject.parameters}; +} +// class_named_blank +template static constexpr auto apply(pcre::class_named_blank, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::enumeration<' ','\t'>(), subject.stack), subject.parameters}; +} +// class_named_cntrl +template static constexpr auto apply(pcre::class_named_cntrl, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::set, ctre::character<'\x7F'>>(), subject.stack), subject.parameters}; +} +// class_named_graph +template static constexpr auto apply(pcre::class_named_graph, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::char_range<'\x21','\x7E'>(), subject.stack), subject.parameters}; +} +// class_named_lower +template static constexpr auto apply(pcre::class_named_lower, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::char_range<'a','z'>(), subject.stack), subject.parameters}; +} +// class_named_upper +template static constexpr auto apply(pcre::class_named_upper, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::char_range<'A','Z'>(), subject.stack), subject.parameters}; +} +// class_named_print +template static constexpr auto apply(pcre::class_named_print, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(ctre::char_range<'\x20','\x7E'>(), subject.stack), subject.parameters}; +} +// class_named_space +template static constexpr auto apply(pcre::class_named_space, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(space_chars(), subject.stack), subject.parameters}; +} +// class_named_word +template static constexpr auto apply(pcre::class_named_word, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(word_chars(), subject.stack), subject.parameters}; +} +// class_named_punct +template static constexpr auto apply(pcre::class_named_punct, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(punct_chars(), subject.stack), subject.parameters}; +} +// class_named_xdigit +template static constexpr auto apply(pcre::class_named_xdigit, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(xdigit_chars(), subject.stack), subject.parameters}; +} + +#endif diff --git a/external/ctre/include/ctre/actions/options.inc.hpp b/external/ctre/include/ctre/actions/options.inc.hpp new file mode 100644 index 0000000..93ef48a --- /dev/null +++ b/external/ctre/include/ctre/actions/options.inc.hpp @@ -0,0 +1,55 @@ +#ifndef CTRE__ACTIONS__OPTIONS__HPP +#define CTRE__ACTIONS__OPTIONS__HPP + +// empty option for alternate +template static constexpr auto apply(pcre::push_empty, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(empty(), subject.stack), subject.parameters}; +} + +// empty option for empty regex +template static constexpr auto apply(pcre::push_empty, ctll::epsilon, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(empty(), subject.stack), subject.parameters}; +} + +// make_alternate (A|B) +template static constexpr auto apply(pcre::make_alternate, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(select(), ctll::list()), subject.parameters}; +} +// make_alternate (As..)|B => (As..|B) +template static constexpr auto apply(pcre::make_alternate, ctll::term, pcre_context, A, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(select(), ctll::list()), subject.parameters}; +} + + +// make_optional +template static constexpr auto apply(pcre::make_optional, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(optional(), ctll::list()), subject.parameters}; +} + +template static constexpr auto apply(pcre::make_optional, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(optional(), ctll::list()), subject.parameters}; +} + +// prevent from creating wrapped optionals +template static constexpr auto apply(pcre::make_optional, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(optional(), ctll::list()), subject.parameters}; +} + +// in case inner optional is lazy, result should be lazy too +template static constexpr auto apply(pcre::make_optional, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(lazy_optional(), ctll::list()), subject.parameters}; +} + +// make_lazy (optional) +template static constexpr auto apply(pcre::make_lazy, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(lazy_optional(), ctll::list()), subject.parameters}; +} + +// if you already got a lazy optional, make_lazy is no-op +template static constexpr auto apply(pcre::make_lazy, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(lazy_optional(), ctll::list()), subject.parameters}; +} + + + +#endif diff --git a/external/ctre/include/ctre/actions/properties.inc.hpp b/external/ctre/include/ctre/actions/properties.inc.hpp new file mode 100644 index 0000000..05f7e80 --- /dev/null +++ b/external/ctre/include/ctre/actions/properties.inc.hpp @@ -0,0 +1,73 @@ +#ifndef CTRE__ACTIONS__PROPERTIES__HPP +#define CTRE__ACTIONS__PROPERTIES__HPP + +// push_property_name +template static constexpr auto apply(pcre::push_property_name, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(property_name(), subject.stack), subject.parameters}; +} +// push_property_name (concat) +template static constexpr auto apply(pcre::push_property_name, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(property_name(), ctll::list()), subject.parameters}; +} + +// push_property_value +template static constexpr auto apply(pcre::push_property_value, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(property_value(), subject.stack), subject.parameters}; +} +// push_property_value (concat) +template static constexpr auto apply(pcre::push_property_value, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(property_value(), ctll::list()), subject.parameters}; +} + +// make_property +template static constexpr auto apply(pcre::make_property, ctll::term, [[maybe_unused]] pcre_context, Ts...>, Parameters> subject) { + //return ctll::reject{}; + constexpr char name[sizeof...(Name)]{static_cast(Name)...}; + constexpr auto p = uni::detail::binary_prop_from_string(get_string_view(name)); + + if constexpr (uni::detail::is_unknown(p)) { + return ctll::reject{}; + } else { + return pcre_context{ctll::push_front(make_binary_property

(), ctll::list()), subject.parameters}; + } +} + +// make_property +template static constexpr auto apply(pcre::make_property, ctll::term, [[maybe_unused]] pcre_context, property_name, Ts...>, Parameters> subject) { + //return ctll::reject{}; + constexpr auto prop = property_builder::template get(); + + if constexpr (std::is_same_v) { + return ctll::reject{}; + } else { + return pcre_context{ctll::push_front(prop, ctll::list()), subject.parameters}; + } +} + + +// make_property_negative +template static constexpr auto apply(pcre::make_property_negative, ctll::term, [[maybe_unused]] pcre_context, Ts...>, Parameters> subject) { + //return ctll::reject{}; + constexpr char name[sizeof...(Name)]{static_cast(Name)...}; + constexpr auto p = uni::detail::binary_prop_from_string(get_string_view(name)); + + if constexpr (uni::detail::is_unknown(p)) { + return ctll::reject{}; + } else { + return pcre_context{ctll::push_front(negate>(), ctll::list()), subject.parameters}; + } +} + +// make_property_negative +template static constexpr auto apply(pcre::make_property_negative, ctll::term, [[maybe_unused]] pcre_context, property_name, Ts...>, Parameters> subject) { + //return ctll::reject{}; + constexpr auto prop = property_builder::template get(); + + if constexpr (std::is_same_v) { + return ctll::reject{}; + } else { + return pcre_context{ctll::push_front(negate(), ctll::list()), subject.parameters}; + } +} + +#endif diff --git a/external/ctre/include/ctre/actions/repeat.inc.hpp b/external/ctre/include/ctre/actions/repeat.inc.hpp new file mode 100644 index 0000000..98c2e0b --- /dev/null +++ b/external/ctre/include/ctre/actions/repeat.inc.hpp @@ -0,0 +1,90 @@ +#ifndef CTRE__ACTIONS__REPEAT__HPP +#define CTRE__ACTIONS__REPEAT__HPP + +// repeat 1..N +template static constexpr auto apply(pcre::repeat_plus, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(plus(), ctll::list()), subject.parameters}; +} +// repeat 1..N (sequence) +template static constexpr auto apply(pcre::repeat_plus, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(plus(), ctll::list()), subject.parameters}; +} + +// repeat 0..N +template static constexpr auto apply(pcre::repeat_star, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(star(), ctll::list()), subject.parameters}; +} +// repeat 0..N (sequence) +template static constexpr auto apply(pcre::repeat_star, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(star(), ctll::list()), subject.parameters}; +} + +// create_number (seed) +template static constexpr auto apply(pcre::create_number, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(number(V - '0')>(), subject.stack), subject.parameters}; +} +// push_number +template static constexpr auto apply(pcre::push_number, ctll::term, pcre_context, Ts...>, Parameters> subject) { + constexpr size_t previous = N * 10ull; + return pcre_context{ctll::push_front(number<(previous + (V - '0'))>(), ctll::list()), subject.parameters}; +} + +// repeat A..B +template static constexpr auto apply(pcre::repeat_ab, ctll::term, pcre_context, number, Subject, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(repeat(), ctll::list()), subject.parameters}; +} +// repeat A..B (sequence) +template static constexpr auto apply(pcre::repeat_ab, ctll::term, pcre_context, number, sequence, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(repeat(), ctll::list()), subject.parameters}; +} + +// repeat_exactly +template static constexpr auto apply(pcre::repeat_exactly, ctll::term, pcre_context, Subject, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(repeat(), ctll::list()), subject.parameters}; +} +// repeat_exactly A..B (sequence) +template static constexpr auto apply(pcre::repeat_exactly, ctll::term, pcre_context, sequence, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(repeat(), ctll::list()), subject.parameters}; +} + +// repeat_at_least (A+) +template static constexpr auto apply(pcre::repeat_at_least, ctll::term, pcre_context, Subject, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(repeat(), ctll::list()), subject.parameters}; +} +// repeat_at_least (A+) (sequence) +template static constexpr auto apply(pcre::repeat_at_least, ctll::term, pcre_context, sequence, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(repeat(), ctll::list()), subject.parameters}; +} + +// make_lazy (plus) +template static constexpr auto apply(pcre::make_lazy, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(lazy_plus(), ctll::list()), subject.parameters}; +} + +// make_lazy (star) +template static constexpr auto apply(pcre::make_lazy, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(lazy_star(), ctll::list()), subject.parameters}; +} + +// make_lazy (repeat) +template static constexpr auto apply(pcre::make_lazy, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(lazy_repeat(), ctll::list()), subject.parameters}; +} + +// make_possessive (plus) +template static constexpr auto apply(pcre::make_possessive, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(possessive_plus(), ctll::list()), subject.parameters}; +} + +// make_possessive (star) +template static constexpr auto apply(pcre::make_possessive, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(possessive_star(), ctll::list()), subject.parameters}; +} + +// make_possessive (repeat) +template static constexpr auto apply(pcre::make_possessive, ctll::term, pcre_context, Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(possessive_repeat(), ctll::list()), subject.parameters}; +} + + +#endif diff --git a/external/ctre/include/ctre/actions/sequence.inc.hpp b/external/ctre/include/ctre/actions/sequence.inc.hpp new file mode 100644 index 0000000..f590432 --- /dev/null +++ b/external/ctre/include/ctre/actions/sequence.inc.hpp @@ -0,0 +1,32 @@ +#ifndef CTRE__ACTIONS__SEQUENCE__HPP +#define CTRE__ACTIONS__SEQUENCE__HPP + +// make_sequence +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context, Parameters> subject) { + return pcre_context{ctll::push_front(sequence(), ctll::list()), subject.parameters}; +} +// make_sequence (concat) +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context,A,Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(sequence(), ctll::list()), subject.parameters}; +} + +// make_sequence (make string) +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context,character,Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(string(), ctll::list()), subject.parameters}; +} +// make_sequence (concat string) +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context,character,Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(string(), ctll::list()), subject.parameters}; +} + +// make_sequence (make string in front of different items) +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context,Sq...>,character,Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(sequence,Sq...>(), ctll::list()), subject.parameters}; +} +// make_sequence (concat string in front of different items) +template static constexpr auto apply(pcre::make_sequence, ctll::term, pcre_context,Sq...>,character,Ts...>, Parameters> subject) { + return pcre_context{ctll::push_front(sequence,Sq...>(), ctll::list()), subject.parameters}; +} + + +#endif diff --git a/external/ctre/include/ctre/actions/set.inc.hpp b/external/ctre/include/ctre/actions/set.inc.hpp new file mode 100644 index 0000000..a5a08d1 --- /dev/null +++ b/external/ctre/include/ctre/actions/set.inc.hpp @@ -0,0 +1,66 @@ +#ifndef CTRE__ACTIONS__SET__HPP +#define CTRE__ACTIONS__SET__HPP + +// UTILITY +// add into set if not exists +template