diff --git a/packages/PEGTL/.appveyor.yml b/packages/PEGTL/.appveyor.yml deleted file mode 100644 index 02289836c6090f6ceccf750a79ed6a2e875082c5..0000000000000000000000000000000000000000 --- a/packages/PEGTL/.appveyor.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: '{branch}-{build}' - -skip_commits: - files: - - README.md - - doc/**/* - -os: - - Visual Studio 2017 - -platform: - - x86 - - x64 - -configuration: - - Debug - - Release - -environment: - matrix: - - GENERATOR: Visual Studio 15 2017 - - - GENERATOR: Visual Studio 15 2017 Win64 - - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 - GENERATOR: Visual Studio 16 2019 - -init: [] - -before_build: -- if defined BINDIR (set "PATH=%BINDIR%;%PATH:C:\Program Files\Git\usr\bin;=%") -- md build -- cd build -- cmake -Wno-dev --config "%CONFIGURATION%" -G "%GENERATOR%" .. - -build_script: -- cmake --build . --config "%CONFIGURATION%" - -test_script: -- ctest -C "%CONFIGURATION%" --output-on-failure diff --git a/packages/PEGTL/.clang-tidy b/packages/PEGTL/.clang-tidy index 2af75f8edbfac208c7fef1dfcbbcb1da1093f367..cad3a9f3fc344995216d51ad6ae3df9821f03a0f 100644 --- a/packages/PEGTL/.clang-tidy +++ b/packages/PEGTL/.clang-tidy @@ -10,6 +10,7 @@ Checks: >- llvm-*, -llvm-namespace-comment, misc-*, + -misc-no-recursion, -misc-non-private-member-variables-in-classes, -misc-unused-alias-decls, modernize-*, diff --git a/packages/PEGTL/cmake/dummy-config.cmake.in b/packages/PEGTL/.cmake/pegtl-config.cmake.in similarity index 63% rename from packages/PEGTL/cmake/dummy-config.cmake.in rename to packages/PEGTL/.cmake/pegtl-config.cmake.in index 3374d615f1e0c65342f79b402943957a8d307afe..99779763a8e0cba6ce9fcbeec7eda2f19a446c4e 100644 --- a/packages/PEGTL/cmake/dummy-config.cmake.in +++ b/packages/PEGTL/.cmake/pegtl-config.cmake.in @@ -1,5 +1,4 @@ -# Dummy config file # When a dependency is added with add_subdirectory, but searched with find_package # Redirect to the directory added with add_subdirectory -add_subdirectory(@PROJECT_SOURCE_DIR@ @PROJECT_BINARY_DIR@) +add_subdirectory("@PROJECT_SOURCE_DIR@" "@PROJECT_BINARY_DIR@") diff --git a/packages/PEGTL/.cmake/test_filesystem.cpp.in b/packages/PEGTL/.cmake/test_filesystem.cpp.in new file mode 100644 index 0000000000000000000000000000000000000000..587e5f320233411d374142e423abed98742eda86 --- /dev/null +++ b/packages/PEGTL/.cmake/test_filesystem.cpp.in @@ -0,0 +1,22 @@ +// This is a dummy program that just needs to compile and link to tell us if +// the C++17 std::filesystem API is available. Use CMake's configure_file +// command to replace the FILESYSTEM_HEADER and FILESYSTEM_NAMESPACE tokens +// for each combination of headers and namespaces which we want to pass to the +// CMake try_compile command. + +#include <@FILESYSTEM_HEADER@> + +// clang-format off +int main() +{ +#if defined( __cpp_exceptions ) + try { + throw @FILESYSTEM_NAMESPACE@::filesystem_error( "instantiate one to make sure it links", std::make_error_code( std::errc::function_not_supported ) ); + } + catch( const @FILESYSTEM_NAMESPACE@::filesystem_error& error ) { + return -1; + } +#endif + + return !@FILESYSTEM_NAMESPACE@::temp_directory_path().is_absolute(); +} diff --git a/packages/PEGTL/.codecov.yml b/packages/PEGTL/.codecov.yml new file mode 100644 index 0000000000000000000000000000000000000000..7f976a215c02c6a479bcc34e0e2a79a1adfdb121 --- /dev/null +++ b/packages/PEGTL/.codecov.yml @@ -0,0 +1,2 @@ +ignore: + - src/example/**/* diff --git a/packages/PEGTL/.github/workflows/android.yml b/packages/PEGTL/.github/workflows/android.yml new file mode 100644 index 0000000000000000000000000000000000000000..8cf72544ebb4990caf3a62379218b524d5450c1b --- /dev/null +++ b/packages/PEGTL/.github/workflows/android.yml @@ -0,0 +1,31 @@ +name: Android + +on: [push, pull_request] + +jobs: + android: + strategy: + fail-fast: false + matrix: + image: + - r22 + platform: + - android-27 + - android-29 + abi: + - armeabi-v7a + - arm64-v8a + build_type: [Debug, Release] + + runs-on: ubuntu-latest + + container: + image: bojoe/cpp-android-ndk-build-env-ubuntu:${{ matrix.image }} + options: --user root + + steps: + - uses: actions/checkout@v2 + + - run: cmake -H$GITHUB_WORKSPACE -B/home/developer/build -GNinja -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DANDROID_ABI=${{ matrix.abi }} -DANDROID_PLATFORM=${{ matrix.platform }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + + - run: cmake --build /home/developer/build diff --git a/packages/PEGTL/.github/workflows/clang-analyze.yml b/packages/PEGTL/.github/workflows/clang-analyze.yml new file mode 100644 index 0000000000000000000000000000000000000000..2226ea7b00338b26996a6ea8bc19d93eb10e4a8e --- /dev/null +++ b/packages/PEGTL/.github/workflows/clang-analyze.yml @@ -0,0 +1,20 @@ +name: clang-analyze + +on: [push, pull_request] + +jobs: + clang-analyze: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - run: sudo apt-get install -yq clang-tools + + - run: scan-build cmake -E make_directory build + + - working-directory: build/ + run: scan-build cmake $GITHUB_WORKSPACE + + - working-directory: build/ + run: scan-build cmake --build . diff --git a/packages/PEGTL/.github/workflows/clang-format.yml b/packages/PEGTL/.github/workflows/clang-format.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac69e2ed6d003d15f1acf8a883c88e38b7c1d9bb --- /dev/null +++ b/packages/PEGTL/.github/workflows/clang-format.yml @@ -0,0 +1,14 @@ +name: clang-format + +on: [push, pull_request] + +jobs: + clang-format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.11 + with: + extensions: 'hpp,cpp' + clangFormatVersion: 11 diff --git a/packages/PEGTL/.github/workflows/clang-tidy.yml b/packages/PEGTL/.github/workflows/clang-tidy.yml new file mode 100644 index 0000000000000000000000000000000000000000..41e1003c48514127943e3f2da59e119b7c75e670 --- /dev/null +++ b/packages/PEGTL/.github/workflows/clang-tidy.yml @@ -0,0 +1,16 @@ +name: clang-tidy + +on: [push, pull_request] + +jobs: + clang-tidy: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - run: sudo apt-get install -yq clang-tidy + + - run: find include/ -name '*.hpp' | grep -vF file_mapper_win32.hpp | grep -vF endian_win.hpp | xargs -I '{}' clang-tidy --quiet '{}' -- --std=c++17 -Iinclude + + - run: find src/ -name '*.cpp' | xargs -I '{}' clang-tidy --quiet '{}' -- --std=c++17 -Iinclude diff --git a/packages/PEGTL/.github/workflows/code-coverage.yml b/packages/PEGTL/.github/workflows/code-coverage.yml new file mode 100644 index 0000000000000000000000000000000000000000..320e77d8c8545ef8dfe2e7c1d5a153e2615ed76c --- /dev/null +++ b/packages/PEGTL/.github/workflows/code-coverage.yml @@ -0,0 +1,24 @@ +name: Code Coverage + +on: [push, pull_request] + +jobs: + code-coverage: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DPEGTL_BUILD_EXAMPLES=OFF -DCMAKE_CXX_FLAGS="-coverage" + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure + + - working-directory: build/ + run: bash <(curl -s https://codecov.io/bash) diff --git a/packages/PEGTL/.github/workflows/codeql-analysis.yml b/packages/PEGTL/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000000000000000000000000000000000000..a2d930ad89209daf36ed8b234c83a3bb3e6fb87e --- /dev/null +++ b/packages/PEGTL/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '31 6 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # âšī¸ Command-line programs to run using the OS shell. + # đ https://git.io/JvXDl + + # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/packages/PEGTL/.github/workflows/linux.yml b/packages/PEGTL/.github/workflows/linux.yml new file mode 100644 index 0000000000000000000000000000000000000000..ba30d3d98d9b4753649bd71fc5bdfa984c05971e --- /dev/null +++ b/packages/PEGTL/.github/workflows/linux.yml @@ -0,0 +1,119 @@ +name: Linux + +on: [push, pull_request] + +jobs: + linux: + strategy: + fail-fast: false + matrix: + compiler: + - g++-7 + - g++-8 + - g++-9 + - g++-10 + - clang++-8 + - clang++-9 + - clang++-10 + build_type: [Debug, Release] + + runs-on: ubuntu-20.04 + + env: + CXX: ${{ matrix.compiler }} + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure + + linux-gcc-extra: + strategy: + fail-fast: false + matrix: + flags: ["-fno-rtti"] + build_type: [Debug, Release] + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.flags }}" + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure + + linux-clang-extra: + strategy: + fail-fast: false + matrix: + flags: ["-fno-rtti", "-fms-extensions"] + build_type: [Debug, Release] + + runs-on: ubuntu-20.04 + + env: + CXX: clang++ + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.flags }}" + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure + + clang-conanio: + strategy: + fail-fast: false + matrix: + image: + # List: https://github.com/conan-io/conan-docker-tools + - clang50 + - clang60 + - clang7 + - clang9-x86 + - clang11 + build_type: [Debug, Release] + + container: + image: conanio/${{ matrix.image }} + options: --user root + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure diff --git a/packages/PEGTL/.github/workflows/macos.yml b/packages/PEGTL/.github/workflows/macos.yml new file mode 100644 index 0000000000000000000000000000000000000000..78c479511c47895ea6eb44b452d31b343036eacc --- /dev/null +++ b/packages/PEGTL/.github/workflows/macos.yml @@ -0,0 +1,31 @@ +name: macOS + +on: [push, pull_request] + +jobs: + xcode: + strategy: + fail-fast: false + matrix: + xcode: ['11', '12'] + build_type: [Debug, Release] + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: ${{ matrix.xcode }} + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE + + - working-directory: build/ + run: cmake --build . --config ${{ matrix.build_type }} + + - working-directory: build/ + run: ctest --config ${{ matrix.build_type }} --output-on-failure diff --git a/packages/PEGTL/.github/workflows/no-exceptions.yml b/packages/PEGTL/.github/workflows/no-exceptions.yml new file mode 100644 index 0000000000000000000000000000000000000000..3dd3d74b835d02a9b06dfa404b44793ac44900a3 --- /dev/null +++ b/packages/PEGTL/.github/workflows/no-exceptions.yml @@ -0,0 +1,30 @@ +name: No-Exceptions + +on: [push, pull_request] + +jobs: + no-exceptions: + strategy: + fail-fast: false + matrix: + compiler: [g++-10, clang++-10] + build_type: [Debug, Release] + + runs-on: ubuntu-20.04 + + env: + CXX: ${{ matrix.compiler }} + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="-fno-exceptions" + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure diff --git a/packages/PEGTL/.github/workflows/sanitizer.yml b/packages/PEGTL/.github/workflows/sanitizer.yml new file mode 100644 index 0000000000000000000000000000000000000000..1f478cb067072b19416fde873c39725e1a3f03d9 --- /dev/null +++ b/packages/PEGTL/.github/workflows/sanitizer.yml @@ -0,0 +1,30 @@ +name: Sanitizer + +on: [push, pull_request] + +jobs: + sanitizer: + strategy: + fail-fast: false + matrix: + cxx: [g++, clang++] + sanitizer: [address, undefined] + + runs-on: ubuntu-20.04 + + env: + CXX: ${{ matrix.cxx }} + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - working-directory: build/ + run: cmake $GITHUB_WORKSPACE -DPEGTL_BUILD_EXAMPLES=OFF -DCMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizer }}" + + - working-directory: build/ + run: cmake --build . + + - working-directory: build/ + run: ctest --output-on-failure diff --git a/packages/PEGTL/.github/workflows/windows.yml b/packages/PEGTL/.github/workflows/windows.yml new file mode 100644 index 0000000000000000000000000000000000000000..760efb9c85eaa444ba67299f1936ec5422ccb6c2 --- /dev/null +++ b/packages/PEGTL/.github/workflows/windows.yml @@ -0,0 +1,76 @@ +name: Windows + +on: [push, pull_request] + +jobs: + vs2019: + strategy: + fail-fast: false + matrix: + build_type: [Debug, Release] + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - shell: bash + working-directory: build/ + run: cmake $GITHUB_WORKSPACE -G "Visual Studio 16 2019" + + - working-directory: build/ + run: cmake --build . --config ${{ matrix.build_type }} + + - working-directory: build/ + run: ctest -C ${{ matrix.build_type }} --output-on-failure + + vs2019-clang: + strategy: + fail-fast: false + matrix: + build_type: [Debug, Release] + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - shell: bash + working-directory: build/ + run: cmake $GITHUB_WORKSPACE -G "Visual Studio 16 2019" -T ClangCL + + - working-directory: build/ + run: cmake --build . --config ${{ matrix.build_type }} + + - working-directory: build/ + run: ctest -C ${{ matrix.build_type }} --output-on-failure + + vs2017: + strategy: + fail-fast: false + matrix: + visual_studio: + - 'Visual Studio 15 2017' + - 'Visual Studio 15 2017 Win64' + build_type: [Debug, Release] + + runs-on: windows-2016 + + steps: + - uses: actions/checkout@v2 + + - run: cmake -E make_directory build + + - shell: bash + working-directory: build/ + run: cmake $GITHUB_WORKSPACE -G "${{ matrix.visual_studio }}" + + - working-directory: build/ + run: cmake --build . --config ${{ matrix.build_type }} + + - working-directory: build/ + run: ctest -C ${{ matrix.build_type }} --output-on-failure diff --git a/packages/PEGTL/.gitignore b/packages/PEGTL/.gitignore index 90173b58d947cdff1175a16b8c2a9e67ec4ca0bf..da92b797d9a088c1565721bad71c5a4f22b94574 100644 --- a/packages/PEGTL/.gitignore +++ b/packages/PEGTL/.gitignore @@ -2,3 +2,4 @@ build private /.vs +/.vscode diff --git a/packages/PEGTL/.gitrepo b/packages/PEGTL/.gitrepo index 00b4dcf367034ec66b746e464a2f7bb9ffdcf080..393af709f67ffe786ffbcab99ba7af6772acfce4 100644 --- a/packages/PEGTL/.gitrepo +++ b/packages/PEGTL/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = git@github.com:taocpp/PEGTL.git branch = master - commit = 3d4fee2837decb5ecff9543276c4aa922b280972 + commit = 57f8ebe0045d7e35cbb251536146a57bc0cf9db5 parent = 0a259f7e3e4fe2364b8d45b641c7f48ff3bc7341 - cmdver = 0.4.1 + cmdver = 0.4.3 method = merge diff --git a/packages/PEGTL/.travis.yml b/packages/PEGTL/.travis.yml deleted file mode 100644 index 8d81bb3ce3272882de4fc246274b13ea56acfb72..0000000000000000000000000000000000000000 --- a/packages/PEGTL/.travis.yml +++ /dev/null @@ -1,237 +0,0 @@ -language: generic -os: linux -dist: xenial - -jobs: - include: - - compiler: gcc - addons: - apt: - sources: [ ubuntu-toolchain-r-test ] - packages: [ g++-8 ] - env: - - CXX=g++-8 - - LDFLAGS="-lstdc++fs" - - - compiler: gcc - addons: - apt: - sources: [ ubuntu-toolchain-r-test ] - packages: [ g++-9 ] - env: - - CXX=g++-9 - - - &gcc-10 - dist: bionic - compiler: gcc - addons: - apt: - sources: [ ubuntu-toolchain-r-test ] - packages: [ g++-10 ] - env: - - CXX=g++-10 - - - <<: *gcc-10 - env: - - CXX=g++-10 - - CXXSTD="-std=c++20" - - - <<: *gcc-10 - env: - - CXX=g++-10 - - CPPFLAGS="-fno-rtti" - - - compiler: clang - addons: - apt: - sources: [ ubuntu-toolchain-r-test, llvm-toolchain-xenial-5 ] - packages: [ clang-5.0, g++-9 ] - env: - - CXX=clang++-5.0 - - - compiler: clang - addons: - apt: - sources: [ ubuntu-toolchain-r-test, llvm-toolchain-xenial-6 ] - packages: [ clang-6.0, g++-9 ] - env: - - CXX=clang++-6.0 - - - compiler: clang - addons: - apt: - sources: [ ubuntu-toolchain-r-test, llvm-toolchain-xenial-7 ] - packages: [ clang-7, g++-9 ] - env: - - CXX=clang++-7 - - - compiler: clang - addons: - apt: - sources: [ ubuntu-toolchain-r-test, llvm-toolchain-xenial-8 ] - packages: [ clang-8, g++-9 ] - env: - - CXX=clang++-8 - - - compiler: clang - addons: - apt: - sources: - - ubuntu-toolchain-r-test - - sourceline: deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main - key_url: https://apt.llvm.org/llvm-snapshot.gpg.key - packages: [ clang-9, g++-9 ] - env: - - CXX=clang++-9 - - - &clang-10 - dist: bionic - compiler: clang - addons: - apt: - sources: &clang-10-sources - - ubuntu-toolchain-r-test - - sourceline: deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main - key_url: https://apt.llvm.org/llvm-snapshot.gpg.key - packages: [ clang-10, g++-10 ] - env: - - CXX=clang++-10 - - - <<: *clang-10 - env: - - CXX=clang++-10 - - CXXSTD="-std=c++20" - - - <<: *clang-10 - env: - - CXX=clang++-10 - - CPPFLAGS="-fms-extensions" - - - <<: *clang-10 - env: - - CXX=clang++-10 - - CPPFLAGS="-fno-rtti" - - - os: osx - osx_image: xcode11.4 - compiler: clang - env: - - CXX=clang++ - - - &android - compiler: clang - addons: - apt: - packages: - - openjdk-8-jdk - before_install: - - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 - - wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip - - unzip -qq sdk-tools-linux-4333796.zip -d /opt/android-sdk - - rm sdk-tools-linux-4333796.zip - - echo "y" | /opt/android-sdk/tools/bin/sdkmanager "platform-tools" "system-images;android-24;default;${ANDROID_ABI}" "platforms;android-24" "emulator" "ndk-bundle" "cmake;3.10.2.4988404" > /dev/null - before_script: - - export TERM=dumb - - export _NO_CHECK_SIGNATURE=true - - export ANDROID_SDK_ROOT=/opt/android-sdk - - echo no | /opt/android-sdk/tools/bin/avdmanager create avd -n test -k "system-images;android-24;default;${ANDROID_ABI}" - - /opt/android-sdk/emulator/emulator -avd test -no-audio -no-window -dns-server 8.8.8.8 & - #- android-wait-for-emulator || android-wait-for-emulator - - /opt/android-sdk/platform-tools/adb shell input keyevent 82 & - script: - # Using the ninja build command. Is much faster then make build command. - - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake -H. -Bcmake-build -GNinja -DANDROID_ABI=${ANDROID_ABI} -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=${ANDROID_PLATFORM} -DCMAKE_MAKE_PROGRAM=/opt/android-sdk/cmake/3.10.2.4988404/bin/ninja -DPEGTL_BUILD_EXAMPLES=OFF - - /opt/android-sdk/cmake/3.10.2.4988404/bin/cmake --build cmake-build --target all - # FIXME android emulator stuck sometimes - cd cmake-build && /opt/android-sdk/cmake/3.10.2.4988404/bin/ctest --output-on-failure - env: - - ANDROID_ABI=armeabi-v7a - - ANDROID_PLATFORM=android-22 - - - <<: *android - env: - - ANDROID_ABI=armeabi-v7a - - ANDROID_PLATFORM=android-24 - - - <<: *android - env: - - ANDROID_ABI=arm64-v8a - - ANDROID_PLATFORM=android-24 - - - <<: *gcc-10 - env: - - CXX=g++-10 - - CPPFLAGS="-fsanitize=undefined -fuse-ld=gold" - - - <<: *gcc-10 - env: - - CXX=g++-10 - - CPPFLAGS="-fsanitize=address -fuse-ld=gold" - - - <<: *clang-10 - env: - - CXX=clang++-10 - - CPPFLAGS="-fsanitize=undefined" - - - <<: *clang-10 - env: - - CXX=clang++-10 - - CPPFLAGS="-fsanitize=address" - - - dist: bionic - compiler: clang - addons: - apt: - sources: *clang-10-sources - packages: [ clang-10, clang-tidy-10, g++-10 ] - env: - - CXX=clang++-10 - - CLANG_TIDY=clang-tidy-10 - script: - - make -kj3 clang-tidy - - - dist: bionic - compiler: clang - addons: - apt: - sources: *clang-10-sources - packages: [ clang-tools-10, g++-10 ] - script: - - scan-build-10 --use-c++=clang++-10 --status-bugs make -kj3 - - - dist: bionic - compiler: gcc - addons: - apt: - sources: [ ubuntu-toolchain-r-test ] - packages: [ g++-10, valgrind ] - env: - - CXX=g++-10 - - SPECIAL=valgrind - script: - - make -kj3 valgrind - - - <<: *gcc-10 - env: - - CXX=g++-10 - - CXXFLAGS="-O0 --coverage" - before_script: - - pip install --user cpp-coveralls - script: - - make -kj3 check - - coveralls --gcov gcov-10 --gcov-options '\-lp' --exclude src - - - dist: bionic - compiler: clang - addons: - apt: - sources: *clang-10-sources - packages: [ clang-format-10, g++-10 ] - script: - - clang-format-10 -i -style=file $(find . -name '[^.]*.[hc]pp') - - git diff --exit-code - -script: - - $CXX --version - - make -j3 build/src/test/pegtl/tester - - build/src/test/pegtl/tester - - make -kj3 diff --git a/packages/PEGTL/CMakeLists.txt b/packages/PEGTL/CMakeLists.txt index 0fe7e8e7a5d93ffa969b7129b84ee9b71de03270..c2ee336f31b4c18f309adfa94c77db6f99978936 100644 --- a/packages/PEGTL/CMakeLists.txt +++ b/packages/PEGTL/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.8...3.19) # Read version from version.hpp file(READ "${CMAKE_CURRENT_LIST_DIR}/include/tao/pegtl/version.hpp" version_hpp_data) @@ -7,7 +7,12 @@ set(PEGTL_VERSION "${CMAKE_MATCH_1}") project(pegtl VERSION ${PEGTL_VERSION} LANGUAGES CXX) -if(${PROJECT_NAME}_FOUND) +set(PEGTL_IS_MAIN_PROJECT OFF) +if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(PEGTL_IS_MAIN_PROJECT ON) +endif() + +if(PEGTL_HAS_PARENT) # Multiple versions of PEGTL can't co-exist if(NOT ${PROJECT_NAME}_VERSION STREQUAL ${PROJECT_VERSION}) message(FATAL_ERROR "Multiple mismatched PEGTL versions") @@ -44,21 +49,85 @@ target_include_directories(pegtl INTERFACE # require C++17 target_compile_features(pegtl INTERFACE cxx_std_17) +option(PEGTL_USE_BOOST_FILESYSTEM "Override the auto-detection of std::filesystem and use Boost.Filesystem" OFF) + +# Try compiling a test program with std::filesystem or one of its alternatives +function(check_filesystem_impl FILESYSTEM_HEADER FILESYSTEM_NAMESPACE OPTIONAL_LIBS OUT_RESULT) + set(TEST_FILE "test_${OUT_RESULT}.cpp") + configure_file(.cmake/test_filesystem.cpp.in ${TEST_FILE} @ONLY) + + try_compile(TEST_RESULT + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE} + CXX_STANDARD 17) + + if(NOT TEST_RESULT) + # Retry with each of the optional libraries + foreach(OPTIONAL_LIB IN LISTS OPTIONAL_LIBS) + try_compile(TEST_RESULT + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE} + LINK_LIBRARIES ${OPTIONAL_LIB} + CXX_STANDARD 17) + + if(TEST_RESULT) + # Looks like the optional library was required, go ahead and add it to the link options. + message(STATUS "Adding ${OPTIONAL_LIB} to the PEGTL to build with ${FILESYSTEM_NAMESPACE}.") + target_link_libraries(${PROJECT_NAME} INTERFACE ${OPTIONAL_LIB}) + break() + endif() + endforeach() + endif() + + set(${OUT_RESULT} ${TEST_RESULT} PARENT_SCOPE) +endfunction() + +if(PEGTL_USE_BOOST_FILESYSTEM) + # Force the use of Boost.Filesystem: #include <boost/filesystem.hpp> // boost::filesystem + find_package(Boost REQUIRED COMPONENTS filesystem) + target_link_libraries(${PROJECT_NAME} INTERFACE Boost::filesystem) + target_compile_definitions(${PROJECT_NAME} INTERFACE TAO_PEGTL_BOOST_FILESYSTEM) +else() + # Try compiling a minimal program with each header/namespace, in order of preference: + # C++17: #include <filesystem> // std::filesystem + # Experimental C++17: #include <experimental/filesystem> // std::experimental::filesystem + # Boost.Filesystem: #include <boost/filesystem.hpp> // boost::filesystem + check_filesystem_impl("filesystem" "std::filesystem" "stdc++fs;c++fs" STD_FILESYSTEM) + if(STD_FILESYSTEM) + message(STATUS "Using std::filesystem") + else() + check_filesystem_impl("experimental/filesystem" "std::experimental::filesystem" "stdc++fs;c++fs" STD_EXPERIMENTAL_FILESYSTEM) + if(STD_EXPERIMENTAL_FILESYSTEM) + target_compile_definitions(${PROJECT_NAME} INTERFACE TAO_PEGTL_STD_EXPERIMENTAL_FILESYSTEM) + message(WARNING "Using std::experimental::filesystem as a fallback") + else() + find_package(Boost COMPONENTS filesystem) + check_filesystem_impl("boost/filesystem.hpp" "boost::filesystem" Boost::filesystem BOOST_FILESYSTEM) + if(BOOST_FILESYSTEM) + target_compile_definitions(${PROJECT_NAME} INTERFACE TAO_PEGTL_BOOST_FILESYSTEM) + message(WARNING "Using Boost.Filesystem as a fallback") + else() + message(FATAL_ERROR "PEGTL requires C++17, including an implementation of std::filesystem, which your compiler toolchain does not seem to support. You can try installing Boost.Filesystem as a temporary workaround, but there's no guarantee the PEGTL will keep working with your project. Consider upgrading your compiler toolchain or downgrading the PEGTL to the previous version.") + endif() + endif() + endif() +endif() + # testing -enable_testing() -option(PEGTL_BUILD_TESTS "Build test programs" ON) +option(PEGTL_BUILD_TESTS "Build test programs" ${PEGTL_IS_MAIN_PROJECT}) if(PEGTL_BUILD_TESTS) + enable_testing() add_subdirectory(src/test/pegtl) endif() # examples -option(PEGTL_BUILD_EXAMPLES "Build example programs" ON) +option(PEGTL_BUILD_EXAMPLES "Build example programs" ${PEGTL_IS_MAIN_PROJECT}) if(PEGTL_BUILD_EXAMPLES) add_subdirectory(src/example/pegtl) endif() # Make package findable -configure_file(cmake/dummy-config.cmake.in pegtl-config.cmake @ONLY) +configure_file(.cmake/pegtl-config.cmake.in pegtl-config.cmake @ONLY) # Ignore pointer width differences since this is a header-only library unset(CMAKE_SIZEOF_VOID_P) @@ -79,3 +148,8 @@ install(EXPORT pegtl-targets install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pegtl-config-version.cmake DESTINATION ${PEGTL_INSTALL_CMAKE_DIR}) install(DIRECTORY include/ DESTINATION ${PEGTL_INSTALL_INCLUDE_DIR}) install(FILES LICENSE DESTINATION ${PEGTL_INSTALL_DOC_DIR}) + +export(EXPORT pegtl-targets + FILE ${pegtl_BINARY_DIR}/pegtl-targets.cmake + NAMESPACE taocpp:: +) diff --git a/packages/PEGTL/LICENSE b/packages/PEGTL/LICENSE index 17d3ad29c2972cdcc8a5ae536d6811352cfb4a3f..c981590829a1ee30e859ac04a31844398be0ae8e 100644 --- a/packages/PEGTL/LICENSE +++ b/packages/PEGTL/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2007-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2007-2021 Dr. Colin Hirsch and Daniel Frey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/packages/PEGTL/Makefile b/packages/PEGTL/Makefile index 3f47845535131816144829cf7cbecf1724fbe640..3ecca070e2264b4af4542b275f0872bf2c2a32a8 100644 --- a/packages/PEGTL/Makefile +++ b/packages/PEGTL/Makefile @@ -1,5 +1,5 @@ # The Art of C++ -# Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +# Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey # Please see LICENSE for license or visit https://github.com/taocpp/PEGTL .SUFFIXES: @@ -32,15 +32,11 @@ endif CPPFLAGS ?= -pedantic CXXFLAGS ?= -Wall -Wextra -Wshadow -Werror -O3 $(MINGW_CXXFLAGS) -CLANG_TIDY ?= clang-tidy - HEADERS := $(shell find include -name '*.hpp') SOURCES := $(shell find src -name '*.cpp') DEPENDS := $(SOURCES:%.cpp=build/%.d) BINARIES := $(SOURCES:%.cpp=build/%) -CLANG_TIDY_HEADERS := $(filter-out include/tao/pegtl/internal/file_mapper_win32.hpp include/tao/pegtl/contrib/internal/endian_win.hpp,$(HEADERS)) - UNIT_TESTS := $(filter build/src/test/%,$(BINARIES)) .PHONY: all @@ -53,23 +49,6 @@ compile: $(BINARIES) check: $(UNIT_TESTS) @set -e; for T in $(UNIT_TESTS); do echo $$T; $$T > /dev/null; done -build/%.valgrind: build/% - valgrind --error-exitcode=1 --leak-check=full $< - @touch $@ - -.PHONY: valgrind -valgrind: $(UNIT_TESTS:%=%.valgrind) - @echo "All $(words $(UNIT_TESTS)) valgrind tests passed." - -build/%.clang-tidy: % .clang-tidy - $(CLANG_TIDY) -quiet $< -- $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) 2>/dev/null - @mkdir -p $(@D) - @touch $@ - -.PHONY: clang-tidy -clang-tidy: $(CLANG_TIDY_HEADERS:%=build/%.clang-tidy) $(SOURCES:%=build/%.clang-tidy) - @echo "All $(words $(CLANG_TIDY_HEADERS) $(SOURCES)) clang-tidy tests passed." - .PHONY: clean clean: @rm -rf build/* diff --git a/packages/PEGTL/README.md b/packages/PEGTL/README.md index c11b0c8822e7f67f8280f0a17529ed6344b6b498..64d090c994d932cb813415879576ff82443506ed 100644 --- a/packages/PEGTL/README.md +++ b/packages/PEGTL/README.md @@ -1,13 +1,31 @@ # Welcome to the PEGTL +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3AWindows) +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3AmacOS) +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3ALinux) +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3AAndroid) +<br> +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3Aclang-analyze) +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3Aclang-tidy) +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3ASanitizer) +[](https://github.com/taocpp/PEGTL/actions?query=workflow%3ACodeQL) +[](https://codecov.io/gh/taocpp/PEGTL) + The Parsing Expression Grammar Template Library (PEGTL) is a zero-dependency C++ header-only parser combinator library for creating parsers according to a [Parsing Expression Grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (PEG). ## Documentation +* [Changelog](doc/Changelog.md) * [Version 3.x](doc/README.md) (requires C++17) * [Version 2.x](https://github.com/taocpp/PEGTL/blob/2.x/doc/README.md) (requires C++11) * [Version 1.x](https://github.com/taocpp/PEGTL/blob/1.x/doc/README.md) (requires C++11) +## Contact + +<a href="https://discord.gg/VQYkppcgqN"><img align="right" src="https://discordapp.com/api/guilds/790164930083028993/embed.png?style=banner2" alt="Join us on Discord"></a> + +For questions and suggestions regarding the PEGTL, success or failure stories, and any other kind of feedback, please feel free to join our [Discord](https://discord.gg/VQYkppcgqN) server, open a [discussion](https://github.com/taocpp/PEGTL/discussions), an [issue](https://github.com/taocpp/PEGTL/issues) or a [pull request](https://github.com/taocpp/PEGTL/pulls) on GitHub or contact the authors at `taocpp(at)icemx.net`. + ## Introduction Grammars are written as regular C++ code, created with template programming (not template meta programming), i.e. nested template instantiations that naturally correspond to the inductive definition of PEGs (and other parser-combinator approaches). @@ -38,7 +56,8 @@ The included [grammar analysis](doc/Grammar-Analysis.md) finds several typical e The PEGTL is designed to be "lean and mean", the core library consists of approximately 6000 lines of code. Emphasis is on simplicity and efficiency, preferring a well-tuned simple approach over complicated optimisations. -The PEGTL is mostly concerned with parsing combinators and grammar rules, and with giving the user of the library (the possibility of) full control over all other aspects of a parsing run. Whether/which actions are taken, and whether/which data structures are created during a parsing run, is entirely up to the user. +The PEGTL is mostly concerned with parsing combinators and grammar rules, and with giving the user of the library (the possibility of) full control over all other aspects of a parsing run. +Whether/which actions are taken, and whether/which data structures are created during a parsing run, is entirely up to the user. Included are some [examples](doc/Contrib-and-Examples.md#examples) for typical situation like unescaping escape sequences in strings, building a generic [JSON](http://www.json.org/) data structure, and on-the-fly evaluation of arithmetic expressions. @@ -49,61 +68,28 @@ The rules are expressed in C++ as template instantiations, and it is the compile ## Status -[](https://travis-ci.org/taocpp/PEGTL) -[](https://ci.appveyor.com/project/taocpp/PEGTL) - Each commit is automatically tested with multiple architectures, operating systems, compilers, and versions thereof. -* Windows - - * Visual Studio 2017 (x86, x64) - * Visual Studio 2019 (x86, x64) - -* macOS (using libc++) - - * macOS 10.15, Xcode 11.4 - -* Ubuntu 16.04 LTS (using libstdc++) - - * GCC 8.x, 9.x - * Clang 5.x, 6.x, 7.x, 8.x, 9.x - -* Ubuntu 18.04 LTS (using libstdc++) - - * GCC 10.x - * Clang 10.x - -### Code Quality - -[](https://lgtm.com/projects/g/taocpp/PEGTL/context:cpp) - -Each commit is checked with Clang's [Static Analyzer](https://clang-analyzer.llvm.org/), GCC's and Clang's [sanitizers](https://github.com/google/sanitizers), [`clang-tidy`](http://clang.llvm.org/extra/clang-tidy/), and [`valgrind`](http://valgrind.org/). -Additionally, we use [LGTM](https://lgtm.com/) to scan for (security) issues. -Note that [LGTM](https://lgtm.com/) sometimes generate false positives, hence the above badge may not show an accurate grade. - -### Code Coverage - -[](https://coveralls.io/github/taocpp/PEGTL) +Each commit is checked with GCC's and Clang's [sanitizers](https://github.com/google/sanitizers), Clang's [Static Analyzer](https://clang-analyzer.llvm.org/), and [`clang-tidy`](http://clang.llvm.org/extra/clang-tidy/). +Additionally, we use [CodeQL](https://securitylab.github.com/tools/codeql) to scan for (security) issues. Code coverage is automatically measured and the unit tests cover 100% of the core library code (for releases). -Note that the infrastructure is partially broken, hence the above badge may not show 100%. - -### Versioning - -[](https://github.com/taocpp/PEGTL/releases/latest) [Releases](https://github.com/taocpp/PEGTL/releases) are done in accordance with [Semantic Versioning](http://semver.org/). Incompatible API changes are *only* allowed to occur between major versions. -For details see the [changelog](doc/Changelog.md). ## Thank You In appreciation of all contributions here are the people that have [directly contributed](https://github.com/taocpp/PEGTL/graphs/contributors) to the PEGTL and/or its development. +[<img alt="amphaal" src="https://avatars.githubusercontent.com/u/13903151" width="120">](https://github.com/amphaal) +[<img alt="anand-bala" src="https://avatars.githubusercontent.com/u/7420072" width="120">](https://github.com/anand-bala) [<img alt="andoma" src="https://avatars.githubusercontent.com/u/216384" width="120">](https://github.com/andoma) +[<img alt="barbieri" src="https://avatars.githubusercontent.com/u/1838" width="120">](https://github.com/barbieri) [<img alt="bjoe" src="https://avatars.githubusercontent.com/u/727911" width="120">](https://github.com/bjoe) [<img alt="bwagner" src="https://avatars.githubusercontent.com/u/447049" width="120">](https://github.com/bwagner) [<img alt="cdiggins" src="https://avatars.githubusercontent.com/u/1759994" width="120">](https://github.com/cdiggins) +[<img alt="clausklein" src="https://avatars.githubusercontent.com/u/1833050" width="120">](https://github.com/clausklein) [<img alt="delpinux" src="https://avatars.githubusercontent.com/u/35096584" width="120">](https://github.com/delpinux) [<img alt="dkopecek" src="https://avatars.githubusercontent.com/u/1353140" width="120">](https://github.com/dkopecek) [<img alt="gene-hightower" src="https://avatars.githubusercontent.com/u/3957811" width="120">](https://github.com/gene-hightower) @@ -112,6 +98,8 @@ In appreciation of all contributions here are the people that have [directly con [<img alt="joelfrederico" src="https://avatars.githubusercontent.com/u/458871" width="120">](https://github.com/joelfrederico) [<img alt="johelegp" src="https://avatars.githubusercontent.com/u/21071787" width="120">](https://github.com/johelegp) [<img alt="jovermann" src="https://avatars.githubusercontent.com/u/6087443" width="120">](https://github.com/jovermann) +[<img alt="jubnzv" src="https://avatars.githubusercontent.com/u/12023585" width="120">](https://github.com/jubnzv) +[<img alt="kelvinhammond" src="https://avatars.githubusercontent.com/u/1824682" width="120">](https://github.com/kelvinhammond) [<img alt="kneth" src="https://avatars.githubusercontent.com/u/1225363" width="120">](https://github.com/kneth) [<img alt="kuzmas" src="https://avatars.githubusercontent.com/u/1858553" width="120">](https://github.com/kuzmas) [<img alt="lambdafu" src="https://avatars.githubusercontent.com/u/1138455" width="120">](https://github.com/lambdafu) @@ -124,6 +112,8 @@ In appreciation of all contributions here are the people that have [directly con [<img alt="pauloscustodio" src="https://avatars.githubusercontent.com/u/70773" width="120">](https://github.com/pauloscustodio) [<img alt="pleroux0" src="https://avatars.githubusercontent.com/u/39619854" width="120">](https://github.com/pleroux0) [<img alt="quadfault" src="https://avatars.githubusercontent.com/u/30195320" width="120">](https://github.com/quadfault) +[<img alt="ras0219" src="https://avatars.githubusercontent.com/u/533828" width="120">](https://github.com/ras0219) +[<img alt="redmercury" src="https://avatars.githubusercontent.com/u/4424222" width="120">](https://github.com/redmercury) [<img alt="robertcampion" src="https://avatars.githubusercontent.com/u/4220569" width="120">](https://github.com/robertcampion) [<img alt="samhocevar" src="https://avatars.githubusercontent.com/u/245089" width="120">](https://github.com/samhocevar) [<img alt="sanssecours" src="https://avatars.githubusercontent.com/u/691989" width="120">](https://github.com/sanssecours) @@ -143,15 +133,15 @@ The PEGTL is part of [The Art of C++](https://taocpp.github.io/). [<img alt="d-frey" src="https://avatars.githubusercontent.com/u/3956325" width="120">](https://github.com/d-frey) [<img alt="uilianries" src="https://avatars.githubusercontent.com/u/4870173" width="120">](https://github.com/uilianries) -## Contact - -For questions and suggestions regarding the PEGTL, success or failure stories, and any other kind of feedback, please feel free to open an issue or a PR on GitHub or contact the authors at `taocpp(at)icemx.net`. - ## License -The PEGTL is certified [Open Source](http://www.opensource.org/docs/definition.html) software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.html) reproduced here. +<a href="https://opensource.org/licenses/MIT"><img align="right" src="https://opensource.org/files/OSIApproved.png" width="150" hspace="20" alt="Open Source Initiative"></a> + +The PEGTL is certified [Open Source](http://www.opensource.org/docs/definition.html) software. +It may be used for any purpose, including commercial purposes, at absolutely no cost. +It is distributed under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.html) reproduced here. -> Copyright (c) 2007-2020 Dr. Colin Hirsch and Daniel Frey +> Copyright (c) 2007-2021 Dr. Colin Hirsch and Daniel Frey > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: > diff --git a/packages/PEGTL/doc/Actions-and-States.md b/packages/PEGTL/doc/Actions-and-States.md index 480df8140fae8188ddad1c9f2271b99ce21225f0..951720b7d7fcb073b47a94ac797e4b5c684a26d6 100644 --- a/packages/PEGTL/doc/Actions-and-States.md +++ b/packages/PEGTL/doc/Actions-and-States.md @@ -538,4 +538,4 @@ Note that deriving from `require_apply` or `require_apply0` is optional and usua See the [section on legacy-style action rules](Rule-Reference.md#action-rules). -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Changelog.md b/packages/PEGTL/doc/Changelog.md index a6290b6b79212f37de6db731df3879cf0646d58e..d1b57f131b5aa72f8221d024e3a2c705ed8bc77d 100644 --- a/packages/PEGTL/doc/Changelog.md +++ b/packages/PEGTL/doc/Changelog.md @@ -1,8 +1,31 @@ # Changelog +## 3.2.0 + +Released 2021-01-15 + +* Added support for disabling exceptions with [`-fno-exceptions`](Installing-and-Using.md#disabling-exceptions). +* Improved efficiency of parse tree nodes. +* Fixed namespace issue with `tao::pegtl::demangle<T>()` (was: `tao::demangle<T>()`). + +## 3.1.0 + +Released 2020-12-17 + +* Made `analyze()` more verbose by default to aid finding the rule cycles. +* Added `parse_nested()` overload that accepts a `position` as first argument. +* Added some experimental and undocumented `contrib` features and their infrastructure. +* Improved CMake support for [`<filesystem>`](Installing-and-Using.md#filesystem) fallbacks and alternatives. + * Re-enabled support for GCC 7. + * Automatically link with `libstdc++fs` or `libc++fs` as needed. + * Added automatic fallback from `std::filesystem` to `std::experimental::filesystem`. + * Added manual fallback from `std::filesystem` to `boost::filesystem`. + * Thank you [Beman Dawes](https://isocpp.org/blog/2020/12/remembering-beman-dawes)! +* Converted continuous integration infrastructure to GitHub Actions. + ## 3.0.0 -**Not yet released** +Released 2020-11-28 * Use the [**migration guide**](Migration-Guide.md#version-300) when updating. * Infrastructure @@ -36,6 +59,7 @@ * Demoted UTF-16 and UTF-32 support to contrib. * Demoted UINT-8, UINT-16, UINT-32 and UINT-64 support to contrib. * Folded `contrib/counter.hpp` into `json_count.cpp`, count is superceded by coverage. + * Removed right padding from `contrib/json.hpp`'s `value`. * Cleanup * Removed option of [state](Rule-Reference.md#state-s-r-)'s `S::success()` to have an extended signature to get access to the current `apply_mode`, `rewind_mode`, *action*- and *control* class (template). * Removed compatibility macros starting with `TAOCPP_PEGTL_`. @@ -595,4 +619,4 @@ Released 2008 Development of the PEGTL started in November 2007 as an experiment in C++0x. It is based on ideas from the YARD library by Christopher Diggins. -Copyright (c) 2007-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2007-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Contrib-and-Examples.md b/packages/PEGTL/doc/Contrib-and-Examples.md index c4292ae83ed82089782a279c56bbef373c19080a..92c4032a29465e010f310ef1b40112e6273c5617 100644 --- a/packages/PEGTL/doc/Contrib-and-Examples.md +++ b/packages/PEGTL/doc/Contrib-and-Examples.md @@ -31,36 +31,6 @@ For all questions and remarks contact us at **taocpp(at)icemx.net**. * Ready for production use. * Superceeded by `TAO_PEGTL_STRING()`. -###### `<tao/pegtl/contrib/change_action.hpp>` - -* Changes the action class template. -* Ready for production use. - -###### `<tao/pegtl/contrib/change_action_and_state.hpp>` - -* Changes the action class template and the state. -* Ready for production use but might be changed in the future. - -###### `<tao/pegtl/contrib/change_control.hpp>` - -* Changes the control class template. -* Ready for production use. - -###### `<tao/pegtl/contrib/change_state.hpp>` - -* Changes the state. -* Ready for production use but might be changed in the future. - -###### `<tao/pegtl/contrib/disable_action.hpp>` - -* Disables actions. -* Ready for production use. - -###### `<tao/pegtl/contrib/enable_action.hpp>` - -* Enables actions. -* Ready for production use. - ###### `<tao/pegtl/contrib/http.hpp>` * HTTP 1.1 grammar according to [RFC 7230](https://tools.ietf.org/html/rfc7230). @@ -98,12 +68,9 @@ For all questions and remarks contact us at **taocpp(at)icemx.net**. Utility function `to_string<>()` that converts template classes with arbitrary sequences of characters as template arguments into a `std::string` that contains these characters. -###### `<tao/pegtl/contrib/tracer.hpp>` +###### `<tao/pegtl/contrib/trace.hpp>` -* Control class that prints a line of information to `std::cerr` - 1. when and where a rule is attempted to match, - 2. when and where a rule succeeded to match, - 3. when and where a rule failed to match. +* See [Tracer](Getting-Started.md#tracer). ###### `<tao/pegtl/contrib/unescape.hpp>` @@ -234,4 +201,4 @@ Uses the building blocks from `<tao/pegtl/contrib/unescape.hpp>` to show how to Shows how to use the included [tracer control](#taopegtlcontribtracerhpp), here together with the URI grammar from `<tao/pegtl/contrib/uri.hpp>`. Invoked with one or more URIs as command line arguments will attempt to parse the URIs while printing trace information to `std::cerr`. -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Control-and-Debug.md b/packages/PEGTL/doc/Control-and-Debug.md index 7d801ef358f8822937251303bf3991abdac4b9ee..3ff6a88787a36b34de2397690b6cfca147edd9f0 100644 --- a/packages/PEGTL/doc/Control-and-Debug.md +++ b/packages/PEGTL/doc/Control-and-Debug.md @@ -114,7 +114,7 @@ If either produce a (local) failure then `C< R >::failure()` is called. In all cases where an action is called, the success or failure hooks are invoked after the action returns. -The included class `tao::pegtl::tracer` in `<tao/pegtl/contrib/tracer.hpp>` gives a practical example that can be used as control class to debug grammars. +The included `<tao/pegtl/contrib/trace.hpp>` gives a practical example that shows how the control class can be used to debug grammars. ## Exception Throwing @@ -144,4 +144,4 @@ Just like the action class template, a custom control class template can be used The latter requires the use of a [custom action](Actions-and-States.md). Deriving the specialisation of the custom action for `my_rule` from `tao::pegtl::change_control< my_control >` will switch the current control to `my_control` before attempting to match `my_rule`. -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Errors-and-Exceptions.md b/packages/PEGTL/doc/Errors-and-Exceptions.md index 10408129978e2abd86bfced826725a9e9a519714..f080c0917885c1f9b1793e81acaf4222f89dee3d 100644 --- a/packages/PEGTL/doc/Errors-and-Exceptions.md +++ b/packages/PEGTL/doc/Errors-and-Exceptions.md @@ -214,4 +214,4 @@ struct error It is advisable to choose the error points in the grammar with prudence. This choice becoming particularly cumbersome and/or resulting in a large number of error points might be an indication of the grammar needing some kind of simplification or restructuring. -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Getting-Started.md b/packages/PEGTL/doc/Getting-Started.md index 50674bd2af263fd471050316fc5f84dbc31f25d1..1deceba9f37ab81a91448682e0f39dcdbe1d8943 100644 --- a/packages/PEGTL/doc/Getting-Started.md +++ b/packages/PEGTL/doc/Getting-Started.md @@ -60,18 +60,19 @@ namespace hello int main( int argc, char* argv[] ) { - if( argc > 1 ) { - // Start a parsing run of argv[1] with the string - // variable 'name' as additional argument to the - // action; then print what the action put there. + if( argc != 2 ) return 1; - std::string name; + // Start a parsing run of argv[1] with the string + // variable 'name' as additional argument to the + // action; then print what the action put there. - pegtl::argv_input in( argv, 1 ); - pegtl::parse< hello::grammar, hello::action >( in, name ); + std::string name; - std::cout << "Good bye, " << name << "!" << std::endl; - } + pegtl::argv_input in( argv, 1 ); + pegtl::parse< hello::grammar, hello::action >( in, name ); + + std::cout << "Good bye, " << name << "!" << std::endl; + return 0; } ``` @@ -102,16 +103,32 @@ Note, however, that all examples shown in this document will lack proper error h Frequently an application will include `try-catch` blocks to handle the exceptions. The correct way of handling errors is shown at the last paragraph of this page. +## Parsing Expression Grammars + +The PEGTL creates parsers according to a [Parsing Expression Grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (PEG). +The table below shows how the PEG combinators map to PEGTL [rule classes](Rule-Reference.md#combinators) (strictly speaking: class templates). +Beyond these standard combinators the PEGTL contains a [large number of additional combinators](Rule-Reference.md) as well as the possibility of [creating custom rules](Rules-and-Grammars.md#creating-new-rules). + +| PEG | `tao::pegtl::` | +| --- | --- | +| &*e* | [`at< R... >`](Rule-Reference.md#at-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | +| !*e* | [`not_at< R... >`](Rule-Reference.md#not_at-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | +| *e*? | [`opt< R... >`](Rule-Reference.md#opt-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | +| *e*+ | [`plus< R... >`](Rule-Reference.md#plus-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | +| *e*<sub>1</sub>*e*<sub>2</sub> | [`seq< R... >`](Rule-Reference.md#seq-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | +| *e*<sub>1</sub> / *e*<sub>2</sub> | [`sor< R... >`](Rule-Reference.md#sor-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | +| *e** | [`star< R... >`](Rule-Reference.md#star-r-) <sup>[(combinators)](Rule-Reference.md#combinators)</sup> | + +The PEGTL also contains a [large number of atomic rules](Rule-Reference.md) for matching ASCII and Unicode characters, strings, ranges and similar, beginning-of-file or end-of-line and similar, and more... + ## Grammar Analysis -Every grammar must be free of cycles that make no progress, i.e. the cycle does not consume any input. -This is a common problem in parsing called [left recursion](https://en.wikipedia.org/wiki/Left_recursion). -Especially with the PEG formalism, it results in an infinite loop and, eventually, in a stack overflow. +Every grammar must be free of cycles that make no progress, i.e. it must not contain unbounded recursive or iterative rules that do not consume any input, as such grammar might enter an infinite loop. +One common pattern for these kinds of problematic grammars is the so-called [left recursion](https://en.wikipedia.org/wiki/Left_recursion) that, while not a problem for less deterministic formalisms like CFGs, must be avoided with PEGs in order to prevent aforementioned infinite loops. -The PEGTL provides a [grammar analysis](Grammar-Analysis.md) with which a grammar can be verified. -Note that this is done at runtime as a pure compile-time analysis would lead to insupportable compile-times. -The analysis, however, is only based on the grammar itself and not on a specific input. -Additionally, the analysis is typically written as a separate program to keep any overhead from your normal applications. +The PEGTL provides a [grammar analysis](Grammar-Analysis.md) which analyses a grammar for cycles that make no progress. +While it could be implemented with compile-time meta-programming, to prevent the compiler from exploding the analysis is done at run-time. +It is best practice to create a separate dedicated program that does nothing else but run the grammar analysis, thus keeping this development and debug aid out of the main application. ```c++ #include <tao/pegtl.hpp> @@ -134,11 +151,12 @@ int main() return 0; } ``` +For more information see [Grammar Analysis](Grammar-Analysis.md). ## Tracer -One of the most basic tools when developing a grammar is a tracer that prints every step of a parsing run. -The PEGTL provides a tracer that will print to stderr, as well as allowing users to write their own tracers to output other formats. +A fundamental tool used when developing a grammar is a tracer that prints every step of a parsing run, thereby showing exactly which rule was attempted to match where, and what the result was. +The PEGTL provides a tracer that will print to `stderr`, and of course allows users to write their own tracers with custom output formats. ```c++ #include <tao/pegtl.hpp> @@ -155,27 +173,25 @@ int main( int argc, char** argv ) { if( argc != 2 ) return 1; - pegtl::argv_input in( argv, i ); - pegtl::standard_tracer tr( in ); - tr.parse< grammar >( in ); + pegtl::argv_input in( argv, 1 ); + pegtl::standard_trace< grammar >( in ); return 0; } ``` -In the above each command line parameter is parsed as a JSON string. -As the output gets long quickly, we will not show it here, please have a look at the [Tracer](Tracer.md) documentation. +In the above each command line parameter is parsed as a JSON string and a trace is given to understand how the grammar matches the input. -TODO: Write `Tracer.md`. +For more information see `tao/pegtl/contrib/trace.hpp`. ## Parse Tree / AST -When developing grammars, a common goal is to generate a [parse tree](https://en.wikipedia.org/wiki/Parse_tree) or an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). +When developing parsers, a common goal after creating the grammar is to generate a [parse tree](https://en.wikipedia.org/wiki/Parse_tree) or an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). The PEGTL provides a [Parse Tree](Parse-Tree.md) builder that can filter and/or transform tree nodes on-the-fly. -Additionally, a helper is provided to print out the resulting data structure in the [DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) format, suitable for creating a graphical representation of the parse tree. +Additionally, a helper is provided to print out the resulting data structure in [DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) format, suitable for creating a graphical representation of the parse tree. -The following example uses a selector to filter the parse tree nodes, as otherwise the graphical representation may become confusing quite quickly. +The following example uses a selector to choose which rules generate parse tree nodes, as the graphical representation will usually be too large and confusing when not using a filter and generating nodes for *all* rules. ```c++ #include <tao/pegtl.hpp> @@ -207,7 +223,7 @@ int main( int argc, char** argv ) { if( argc != 2 ) return 1; - pegtl::argv_input in( argv, i ); + pegtl::argv_input in( argv, 1 ); const auto root = parse_tree::parse< grammar, selector >( in ); if( root ) { parse_tree::print_dot( std::cout, *root ); @@ -227,10 +243,12 @@ The above will generate an SVG file with a graphical representation of the parse  +For more information see [Parse Tree](Parse-Tree.md). + ## Error Handling -Although the PEGTL could be used without exceptions, most programs will use input classes or grammars that might throw exceptions. -Typically, the following pattern helps to print the exceptions properly: +Although the PEGTL could be used without exceptions, most programs will use input classes, grammars and/or actions that can throw exceptions. +Typically, the following pattern helps to print the exceptions in a human friendly way: ```c++ // The surrounding try/catch for normal exceptions. @@ -265,4 +283,4 @@ Typically, the following pattern helps to print the exceptions properly: For more information see [Errors and Exceptions](Errors-and-Exceptions.md). -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Grammar-Analysis.md b/packages/PEGTL/doc/Grammar-Analysis.md index fa5e17230df1130fe8b4415473588507057fe683..964adb9c19e27963a9ec98202208e98b086e7894 100644 --- a/packages/PEGTL/doc/Grammar-Analysis.md +++ b/packages/PEGTL/doc/Grammar-Analysis.md @@ -21,7 +21,7 @@ const std::size_t issues = tao::pegtl::analyze< my_grammar >(); ``` The `analyze()` function prints some information about the found issues to `std::cout` and returns the total number of issues found. -The output can be suppressed by passing `false` as sole function argument. +The output can be suppressed by passing `-1` as sole function argument, or be extended to give some information about the issues when called with `1`. Analysing a grammar is usually only done while developing and debugging a grammar, or after changing it. @@ -124,4 +124,4 @@ In practice it appears to catch all cases of left-recursion that are typical for False positives are a theoretical problem in that, while relatively easy to trigger, they are not usually encountered when dealing with real world grammars. -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Inputs-and-Parsing.md b/packages/PEGTL/doc/Inputs-and-Parsing.md index 2f00c8661cb61e5cdbbbb96f1446d2b7d9899d7d..b2bb15f44672010dd71792fbc9e4ee06e0c33d00 100644 --- a/packages/PEGTL/doc/Inputs-and-Parsing.md +++ b/packages/PEGTL/doc/Inputs-and-Parsing.md @@ -312,7 +312,7 @@ Nested parsing refers to an (inner) parsing run that is performed "in the middle The difference to the regular `tao::pegtl::parse()` function is that `tao::pegtl::parse_nested()` takes care of adding to the `std::vector` of `tao::pegtl::position` objects in the exception class `tao::pegtl::parse_error`. This allows generating error messages of the form "error in file F1 line L1 included from file F2 line L2...". -Calling `parse_nested()` requires one additional argument compared to `parse()`, the input from the outer parsing run as first argument. +Compared to `parse()`, calling `parse_nested()` requires either the input from the outer parsing run or the position as additional first argument. Everything else remains the same. ```c++ @@ -327,6 +327,18 @@ template< typename Rule, bool parse_nested( const OuterInput& oi, ParseInput& in, States&&... st ); + +template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + apply_mode A = apply_mode::action, + rewind_mode M = rewind_mode::required, + typename OuterInput, + typename ParseInput, + typename... States > +bool parse_nested( position op, + ParseInput& in, + States&&... st ); ``` ## Incremental Input @@ -542,4 +554,4 @@ Trying to call any of those functions on `buffer_input<>`-based instances will l All input classes support [deduction guides](https://en.cppreference.com/w/cpp/language/class_template_argument_deduction), e.g. instead of `file_input<> in( "filename.txt" )` one can use `file_input in( "filename.txt" )`. -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Installing-and-Using.md b/packages/PEGTL/doc/Installing-and-Using.md index 91fc2efec9a772708ab72d1c8aaa3b27193016a1..e235edfbaea9ccfade76f0587cddeaa227358a73 100644 --- a/packages/PEGTL/doc/Installing-and-Using.md +++ b/packages/PEGTL/doc/Installing-and-Using.md @@ -3,7 +3,11 @@ ## Contents * [Requirements](#requirements) +* [Filesystem](#filesystem) +* [Disabling Exceptions](#disabling-exceptions) +* [Disabling RTTI](#disabling-rtti) * [Installation Packages](#installation-packages) +* [Using Vcpkg](#using-vcpkg) * [Using Conan](#using-conan) * [Using CMake](#using-cmake) * [CMake Installation](#cmake-installation) @@ -21,15 +25,10 @@ The PEGTL requires a C++17-capable compiler, e.g. one of -* GCC 8 +* GCC 7 * Clang 5 * Visual Studio 2017 -with (on Unix) - -* libstdc++ 8 -* libc++ 7 - on either * Linux @@ -39,8 +38,6 @@ on either It requires C++17, e.g. using the `--std=c++17` compiler switch. Using newer versions of the C++ standard is supported. -Note that using libstdc++ 8 requires linking with `-lstdc++fs`. - Larger projects will frequently require the `/bigobj` option when compiling with Visual Studio on Windows. It should also work with other C++17 compilers on other Unix systems (or any sufficiently compatible platform). @@ -48,12 +45,73 @@ It should also work with other C++17 compilers on other Unix systems (or any suf The PEGTL is written with an emphasis on clean code and is compatible with the `-pedantic`, `-Wall`, `-Wextra` and `-Werror` compiler switches. +## Filesystem + +By default the PEGTL uses `std::filesystem` facilities for filenames, however when using older compilers, or preferring the Boost filesystem library, manual intervention might be required. + +GCC supports for `std::experimental::filesystem` in `libstdc++fs` since version 7, support for `std::filesystem` in `libstdc++fs` since version 8, and support for `std::filesystem` in regular `libstdc++` since version 9. + +Clang [supports](https://libcxx.llvm.org/docs/UsingLibcxx.html) `std::experimental::filesystem` in `libc++experimental` since version 5, `std::filesystem` in `libc++fs` since version 7, and `std::filesystem` in regular `libc++` since version 9. + +Some Linux distributions have Clang packages without `libc++` and instead configure Clang to use the `libstdc++` from the default GCC. +In such cases it is necessary to use e.g. `libstdc++fs` and include `<experimental/filesystem>` when a Clang 8 it used on a system with GCC 7 default compiler. + +When building with CMake, the appropriate `std::filesystem` or `std::experimental::filesystem` and matching available C++ standard library are chosen automatically. +Alternatively `-DPEGTL_BOOST_FILESYSTEM=ON` can be passed to CMake to use `boost::filesystem` and matching Boost library instead. + +When building with Make, appropriate flags for `include/tao/pegtl/internal/filesystem.hpp` and the linker need to be set manually or by changing the included `Makefile`. +Using `-DTAO_PEGTL_BOOST_FILESYSTEM=1` and setting up the compiler and linker to find the Boost headers and libraries and link against `boost_filesystem` can also be set up manually with Make. + +## Disabling Exceptions + +The PEGTL is compatible with `-fno-exceptions`, however, when disabling exceptions: + +* The following rules are unavailable: + * `raise<>`. + * `try_catch<>`. + * `try_catch_type<>`. + * `must<>`. + * `if_must<>`. + * `if_must_else<>`. + * `list_must<>`. + * `opt_must<>`. + * `star_must<>`. +* The following headers are unavailable: + * `tao/pegtl/contrib/http.hpp`. + * `tao/pegtl/contrib/integer.hpp`. + * `tao/pegtl/contrib/uri.hpp`. +* The error control class template `must_if<>` is unavailable. +* Some of our tests and examples are disabled or limited (via `#if`). + +## Disabling RTTI + +The PEGTL is compatible with `-fno-rtti` on GCC, Clang, and MSVC. +An exception are GCC 9.1 and GCC 9.2, see [bug #91155](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91155). +On unknown compilers, we use RTTI by default (for demangling), please report any such compiler and it might be possible to extend support for disabling RTTI for those compilers as well. + ## Installation Packages +<a href="https://repology.org/metapackage/pegtl"><img align="right" hspace="20" src="https://repology.org/badge/vertical-allrepos/pegtl.svg" alt="Packaging status"></a> + Installation packages are available from several package managers. Note that some of the listed packages are not updated regularly. -[](https://repology.org/metapackage/pegtl) +## Using Vcpkg + +[](https://repology.org/project/pegtl/versions) + +You can download and install the PEGTL using the [Vcpkg] package manager: + +```bash +vcpkg install pegtl:x64-linux pegtl:x64-osx pegtl:x64-windows +``` + +The `pegtl` package in Vcpkg is kept up to date by the Vcpkg 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. + +For more options and ways to use Vcpkg, please refer to the [Vcpkg documentation]. ## Using Conan @@ -107,7 +165,7 @@ find_package(pegtl) ``` This exports the `taocpp::pegtl` target which can be linked against any other -target. Linking against `taocpp:pegtl` automatically sets the include +target. Linking against `taocpp::pegtl` automatically sets the include directories and required flags for C++17 or later. For example: ```cmake @@ -258,8 +316,10 @@ The above will generate a `build/amalgamated/pegtl.hpp` which will consist of the headers `tao/pegtl.hpp`, their dependencies, and all headers in `tao/pegtl/contrib/` except for the headers in `tao/pegtl/contrib/icu/`. -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey +[Vcpkg]: https://github.com/Microsoft/vcpkg +[Vcpkg documentation]: https://github.com/Microsoft/vcpkg/tree/master/docs/index.md [Conan]: https://conan.io/ [Conan documentation]: https://docs.conan.io/ [CMake]: https://cmake.org/ diff --git a/packages/PEGTL/doc/Meta-Data-and-Visit.md b/packages/PEGTL/doc/Meta-Data-and-Visit.md index 3f8207553087b91920fc06f03f7fe54b15da718e..74f8672ca0d25e8d571b9dab9ff746b0c6034371 100644 --- a/packages/PEGTL/doc/Meta-Data-and-Visit.md +++ b/packages/PEGTL/doc/Meta-Data-and-Visit.md @@ -147,4 +147,4 @@ struct coverage_result As usual, unless otherwise indicated, all functions and data structure are in the namespace `tao::pegtl`. -Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Migration-Guide.md b/packages/PEGTL/doc/Migration-Guide.md index 2ef77f806dae469b588eb033c3b01e8671ee849a..91171f3b46050727eb42df083621ef46dc891c4c 100644 --- a/packages/PEGTL/doc/Migration-Guide.md +++ b/packages/PEGTL/doc/Migration-Guide.md @@ -56,4 +56,4 @@ Please contact the authors at `taocpp(at)icemx.net` for any further questions wh There were [many important changes](Changelog.md#100) leading up to version 1.0.0. Please contact the authors at `taocpp(at)icemx.net` for any further questions when updating the PEGTL. -Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Parse-Tree.md b/packages/PEGTL/doc/Parse-Tree.md index f4a7f7c971296d87d00d18fde2ca18a1c46a4428..039208294c18c3a201492e6f8c9da75affcc5bd5 100644 --- a/packages/PEGTL/doc/Parse-Tree.md +++ b/packages/PEGTL/doc/Parse-Tree.md @@ -145,7 +145,7 @@ An example of using some of the transformers can be found in `src/example/pegtl/ This is the interface of the node class used by `tao::pegtl::parse_tree::parse` when no custom node class is specified. ```c++ -template< typename T > +template< typename T, typename Source = std::string_view > struct basic_node { using node_t = T; @@ -153,7 +153,7 @@ struct basic_node children_t children; std::string_view type; - std::string source; + Source source; bool is_root() const noexcept; @@ -235,4 +235,4 @@ struct my_node }; ``` -Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Performance-Notes.md b/packages/PEGTL/doc/Performance-Notes.md index 97cdfd8a5b9cc21e0bda87ed2b88d9734b25db6f..6acf14257286df470492ddb8f2ee20093c121217 100644 --- a/packages/PEGTL/doc/Performance-Notes.md +++ b/packages/PEGTL/doc/Performance-Notes.md @@ -42,4 +42,4 @@ However with `-O0`, the optimised `at_one< '"' >` was faster by 5-10% in a [JSON We still need to test whether the compiler manages to perform the same optimisation in more complex cases. -Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/README.md b/packages/PEGTL/doc/README.md index 2fb1681fc3020828f0158ab0390b1c03415f77ba..09b6fbcf15a32a3202faaa073dd9c96f1fbde813 100644 --- a/packages/PEGTL/doc/README.md +++ b/packages/PEGTL/doc/README.md @@ -4,7 +4,11 @@ * [Getting Started](Getting-Started.md) * [Installing and Using](Installing-and-Using.md) * [Requirements](Installing-and-Using.md#requirements) + * [Filesystem](Installing-and-Using.md#filesystem) + * [Disabling Exceptions](Installing-and-Using.md#disabling-exceptions) + * [Disabling RTTI](Installing-and-Using.md#disabling-rtti) * [Installation Packages](Installing-and-Using.md#installation-packages) + * [Using Vcpkg](Installing-and-Using.md#using-vcpkg) * [Using Conan](Installing-and-Using.md#using-conan) * [Using CMake](Installing-and-Using.md#using-cmake) * [CMake Installation](Installing-and-Using.md#cmake-installation) @@ -45,7 +49,7 @@ * [State Mismatch](Actions-and-States.md#state-mismatch) * [Legacy Actions](Actions-and-States.md#legacy-actions) * [Errors and Exceptions](Errors-and-Exceptions.md) - * [Global Failure]((Errors-and-Exceptions.md#global-failure) + * [Global Failure](Errors-and-Exceptions.md#global-failure) * [Local to Global Failure](Errors-and-Exceptions.md#local-to-global-failure) * [Intrusive Local to Global Failure](Errors-and-Exceptions.md#intrusive-local-to-global-failure) * [Non-Intrusive Local to Global Failure](Errors-and-Exceptions.md#non-intrusive-local-to-global-failure) @@ -96,10 +100,16 @@ * [Full Parse Tree](Parse-Tree.md#full-parse-tree) * [Partial Parse Tree](Parse-Tree.md#partial-parse-tree) * [Transforming Nodes](Parse-Tree.md#transforming-nodes) - * [Transformers](Parse-Tree.md#transformers) + * [Transformer](Parse-Tree.md#transformer) * [`tao::pegtl::parse_tree::node`](Parse-Tree.md#taopegtlparse_treenode) * [Custom Node Class](Parse-Tree.md#custom-node-class) * [Meta Data and Visit](Meta-Data-and-Visit.md) + * [Internals](Meta-Data-and-Visit.md#internals) + * [Rule Type](Meta-Data-and-Visit.md#rule-type) + * [Sub Rules](Meta-Data-and-Visit.md#sub-rules) + * [Grammar Visit](Meta-Data-and-Visit.md#grammar-visit) + * [Grammar Print](Meta-Data-and-Visit.md#grammar-print) + * [Rule Coverage](Meta-Data-and-Visit.md#rule-coverage) * [Contrib and Examples](Contrib-and-Examples.md) * [Contrib](Contrib-and-Examples.md#contrib) * [Examples](Contrib-and-Examples.md#examples) @@ -288,4 +298,4 @@ * [`xid_continue`](Rule-Reference.md#xid_continue) <sup>[(icu rules)](Rule-Reference.md#icu-rules-for-binary-properties)</sup> * [`xid_start`](Rule-Reference.md#xid_start) <sup>[(icu rules)](Rule-Reference.md#icu-rules-for-binary-properties)</sup> -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/doc/Rule-Reference.md b/packages/PEGTL/doc/Rule-Reference.md index 4072fd94462affe39a677fb2358ff49470b9b2f7..a39700edf41e97cddcce989d0d67cd0c5cefe1eb 100644 --- a/packages/PEGTL/doc/Rule-Reference.md +++ b/packages/PEGTL/doc/Rule-Reference.md @@ -768,14 +768,14 @@ ASCII rules do not usually rely on other rules. ###### `shebang` * [Equivalent] to `if_must< string< '#', '!' >, until< eolf > >`. +* [Meta data] and [implementation] mapping: + - `ascii::shebang::rule_t` is `internal::seq< false, internal::string< '#', '!' >, internal::until< internal::eolf > >` + - `ascii::shebang::subs_t` is `type_list< internal::string< '#', '!' >, internal::until< internal::eolf > >` ###### `space` * Matches and consumes a single space, line-feed, carriage-return, horizontal-tab, vertical-tab or form-feed. * [Equivalent] to `one< ' ', '\n', '\r', '\t', '\v', '\f' >`. -* [Meta data] and [implementation] mapping: - - `ascii::shebang::rule_t` is `internal::seq< false, internal::string< '#', '!' >, internal::until< internal::eolf > >` - - `ascii::shebang::subs_t` is `type_list< internal::string< '#', '!' >, internal::until< internal::eolf > >` ###### `string< C... >` @@ -857,9 +857,11 @@ The following limitations apply to the UTF-16 and UTF-32 rules: * The line and column numbers are not counted correctly. * They are not automatically included with `tao/pegtl.hpp`. -The UTF-16 and UTF-32 rules need to be manually included from their corresponding headers in the `contrib` section. +The UTF-8 rules are included with `include/tao/pegtl.hpp` while the UTF-16 and UTF-32 rules require manual inclusion of the following files. +* `tao/pegtl/contrib/utf16.hpp` +* `tao/pegtl/contrib/utf32.hpp` -Unaligned memory is no problem on x86 compatible processors; on ARM and most other architectures an unaligned access will crash the application. +While unaligned accesses are no problem on x86 compatible processors, on other architectures they might be very slow or even crash the application. In the following descriptions a Unicode code point is considered *valid* when it is in the range `0` to `0x10ffff`. The parameter N stands for the size of the encoding of the next Unicode code point in the input, i.e. @@ -925,7 +927,7 @@ Unicode rules do not rely on other rules. ### ICU Support The following rules depend on the [International Components for Unicode (ICU)](http://icu-project.org/) that provide the means to match characters with specific Unicode character properties. -Because of the external dependency, the rules are in contrib, and the required header files are not automatically included in `tao/pegtl.hpp`. +Because of this external dependency the rules are not automatically included in `tao/pegtl.hpp`. The ICU-based rules are again available in multiple versions, @@ -1538,7 +1540,7 @@ Binary rules do not rely on other rules. * [`xid_continue`](#xid_continue) <sup>[(icu rules)](#icu-rules-for-binary-properties)</sup> * [`xid_start`](#xid_start) <sup>[(icu rules)](#icu-rules-for-binary-properties)</sup> -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey [Equivalent]: #equivalence [implementation]: #implementation diff --git a/packages/PEGTL/doc/Rules-and-Grammars.md b/packages/PEGTL/doc/Rules-and-Grammars.md index ece2da2dfc8269b4d95571f674c6957cf999dadf..675ebfc3473a6e8f4407ec4e2ac7bebd8f1e8e88 100644 --- a/packages/PEGTL/doc/Rules-and-Grammars.md +++ b/packages/PEGTL/doc/Rules-and-Grammars.md @@ -145,9 +145,9 @@ struct simple_rule Here is an excerpt from the included example program `src/example/pegtl/modulus_match.cpp` that shows a simple custom rule. The - slightly artificial - rule `my_rule` uses three important `input` functions, -1. first `size()` to check whether the input is not empty, +1. first `empty()` to check whether the input is not empty, -2. then `begin()` to access the data and check whether the remainder of the first remaining input character `C` happens to satisfy `C % M == R`, +2. then `current()` to access the data and check whether the remainder of the first remaining input character `C` happens to satisfy `C % M == R`, 3. and finally `bump()` to consume one `char` from the input if the two above conditions are satisfied. @@ -155,6 +155,8 @@ Note how the return value reflects the result of the checks, and how input is on The remainder of the program checks that all characters of `argv[ 1 ]` are equal to 0 when divided by 3. ```c++ +using namespace TAO_PEGTL_NAMESPACE; + namespace modulus { template< unsigned M, unsigned R = 0 > @@ -166,8 +168,8 @@ namespace modulus template< typename ParseInput > static bool match( ParseInput& in ) { - if( ! in.empty() ) { - if( ( ( *in.begin() ) % M ) == R ) { + if( !in.empty() ) { + if( ( ( *in.current() ) % M ) == R ) { in.bump( 1 ); return true; } @@ -177,15 +179,16 @@ namespace modulus }; struct grammar - : tao::pegtl::until< tao::pegtl::eof, my_rule< 3 > > {}; + : until< eolf, must< my_rule< 3 > > > + {}; } // namespace modulus -int main( int argc, char* argv[] ) +int main( int argc, char** argv ) { if( argc > 1 ) { - tao::pegtl::argv_input in( argv, 1 ); - tao::pegtl::parse< modulus::grammar >( in ); + argv_input in( argv, 1 ); + parse< modulus::grammar >( in ); } return 0; } @@ -395,4 +398,4 @@ long literal id was: "fraggle" long literal body was: "[foo[" ``` -Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey diff --git a/packages/PEGTL/include/tao/pegtl.hpp b/packages/PEGTL/include/tao/pegtl.hpp index 9ef19286fdc5f4663f284e70ee9c70a91133fe33..35cc4c6dcb31d6fea988f3df95b4208e6adef58d 100644 --- a/packages/PEGTL/include/tao/pegtl.hpp +++ b/packages/PEGTL/include/tao/pegtl.hpp @@ -1,10 +1,11 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_HPP #define TAO_PEGTL_HPP #include "pegtl/config.hpp" +#include "pegtl/demangle.hpp" #include "pegtl/parse.hpp" #include "pegtl/version.hpp" @@ -38,7 +39,10 @@ #include "pegtl/discard_input_on_failure.hpp" #include "pegtl/discard_input_on_success.hpp" -#include "pegtl/must_if.hpp" #include "pegtl/visit.hpp" +#if defined( __cpp_exceptions ) +#include "pegtl/must_if.hpp" +#endif + #endif diff --git a/packages/PEGTL/include/tao/pegtl/apply_mode.hpp b/packages/PEGTL/include/tao/pegtl/apply_mode.hpp index 962d4f00def6c26d40dc93af2a38f1bf90796578..10b98a6668276d8c7aa39e1f5f6d0d6235b11c90 100644 --- a/packages/PEGTL/include/tao/pegtl/apply_mode.hpp +++ b/packages/PEGTL/include/tao/pegtl/apply_mode.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_APPLY_MODE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/argv_input.hpp b/packages/PEGTL/include/tao/pegtl/argv_input.hpp index 311965e7f7bcdd24ede6d6fac5ab2084fd9e302d..06cbc74cdf2d15a0d563c930fd3b1db0b6cec957 100644 --- a/packages/PEGTL/include/tao/pegtl/argv_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/argv_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_ARGV_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/ascii.hpp b/packages/PEGTL/include/tao/pegtl/ascii.hpp index e7948367c3a7ae6ff2272d51fd6390987c7a267d..8e7b19e29789e2ea0df4e87627e69e810696ce70 100644 --- a/packages/PEGTL/include/tao/pegtl/ascii.hpp +++ b/packages/PEGTL/include/tao/pegtl/ascii.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_ASCII_HPP @@ -6,7 +6,6 @@ #include "config.hpp" -#include "internal/dependent_false.hpp" #include "internal/result_on_found.hpp" #include "internal/rules.hpp" diff --git a/packages/PEGTL/include/tao/pegtl/buffer_input.hpp b/packages/PEGTL/include/tao/pegtl/buffer_input.hpp index 35637d145d05d996daeeff71d8ecbf320f44edc9..0003442b0a07c0953ded634e27819f0331a14157 100644 --- a/packages/PEGTL/include/tao/pegtl/buffer_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/buffer_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_BUFFER_INPUT_HPP @@ -10,9 +10,15 @@ #include <cstdint> #include <cstring> #include <memory> -#include <stdexcept> #include <string> +#if defined( __cpp_exceptions ) +#include <stdexcept> +#else +#include <cstdio> +#include <exception> +#endif + #include "config.hpp" #include "eol.hpp" #include "memory_input.hpp" @@ -147,7 +153,12 @@ namespace TAO_PEGTL_NAMESPACE return; } if( m_current.data + amount > m_buffer.get() + m_maximum ) { - throw std::overflow_error( "require beyond end of buffer" ); +#if defined( __cpp_exceptions ) + throw std::overflow_error( "require() beyond end of buffer" ); +#else + std::fputs( "overflow error: require() beyond end of buffer\n", stderr ); + std::terminate(); +#endif } if( const auto r = m_reader( m_end, ( std::min )( buffer_free_after_end(), ( std::max )( amount - buffer_occupied(), Chunk ) ) ) ) { m_end += r; diff --git a/packages/PEGTL/include/tao/pegtl/change_action.hpp b/packages/PEGTL/include/tao/pegtl/change_action.hpp index e7ae6d96a8398e1b780bf659bffb31728ef594f9..6e049ea958fd593a21c145bc7d1abebd0968a0d0 100644 --- a/packages/PEGTL/include/tao/pegtl/change_action.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CHANGE_ACTION_HPP diff --git a/packages/PEGTL/include/tao/pegtl/change_action_and_state.hpp b/packages/PEGTL/include/tao/pegtl/change_action_and_state.hpp index 953e3a4bde64cc0476b02218b99484569b44069b..f226c71ee916f830849a1c1beabc82f3e1bb1035 100644 --- a/packages/PEGTL/include/tao/pegtl/change_action_and_state.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_action_and_state.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp b/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp index 91ec5bcf8915342fbed441787845a480c7004115..6c452e04be4adcc346d2ff88ba180d7b114ccc19 100644 --- a/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_action_and_states.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CHANGE_ACTION_AND_STATES_HPP diff --git a/packages/PEGTL/include/tao/pegtl/change_control.hpp b/packages/PEGTL/include/tao/pegtl/change_control.hpp index 0440e723df9292a529d47c7714e68ea31a40cff7..b77a238041ef2fb6586e213c25745ae95113d9fb 100644 --- a/packages/PEGTL/include/tao/pegtl/change_control.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_control.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CHANGE_CONTROL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/change_state.hpp b/packages/PEGTL/include/tao/pegtl/change_state.hpp index c433dd8a936948b704b991cf50636e0603cf70b8..bb1007979355ba37cff3c2f22c39bea5d01ec116 100644 --- a/packages/PEGTL/include/tao/pegtl/change_state.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_state.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CHANGE_STATE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/change_states.hpp b/packages/PEGTL/include/tao/pegtl/change_states.hpp index bc7ac78d0de92c2c8ecde6da7cbd9d5f9e2107c4..4ec26dd34bd10ca907cfe802980b2cc6d58798a6 100644 --- a/packages/PEGTL/include/tao/pegtl/change_states.hpp +++ b/packages/PEGTL/include/tao/pegtl/change_states.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CHANGE_STATES_HPP diff --git a/packages/PEGTL/include/tao/pegtl/config.hpp b/packages/PEGTL/include/tao/pegtl/config.hpp index 2a67638820588cd04a30f54fefdf19bf66a4bd59..f1a3b8874f5ae5804a0ff926ce6d2d7ddf879787 100644 --- a/packages/PEGTL/include/tao/pegtl/config.hpp +++ b/packages/PEGTL/include/tao/pegtl/config.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONFIG_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/abnf.hpp b/packages/PEGTL/include/tao/pegtl/contrib/abnf.hpp index 618c68c6136a875f7947d8d62876bb6526ab66e2..df5f39daf36cee116e5b1057616b26b87f60e079 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/abnf.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/abnf.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ABNF_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp b/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp index 4c8f39d201747eed92511b757d46e9bfdec15eec..1a9c24dbf276f8d8144a83f18db38a7fbd99f15f 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/alphabet.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ALPHABET_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/analyze.hpp b/packages/PEGTL/include/tao/pegtl/contrib/analyze.hpp index b777c02bc86961c27e4f80da06d9bc9028187e84..586710735f9225d65381cf547af2c56d929bd8ed 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/analyze.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/analyze.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ANALYZE_HPP @@ -20,8 +20,7 @@ #include "analyze_traits.hpp" #include "internal/set_stack_guard.hpp" - -#include "../internal/dependent_false.hpp" +#include "internal/vector_stack_guard.hpp" namespace TAO_PEGTL_NAMESPACE { @@ -50,123 +49,137 @@ namespace TAO_PEGTL_NAMESPACE [[nodiscard]] std::size_t problems() { - for( auto i = m_info.begin(); i != m_info.end(); ++i ) { - m_results[ i->first ] = work( i, false ); - m_cache.clear(); + for( auto& i : m_entries ) { + assert( m_trace.empty() ); + assert( m_stack.empty() ); + m_results[ i.first ] = work( i, false ); } + // The number of problems returned is not very informative as some problems will be found multiple times. return m_problems; } template< typename Rule > [[nodiscard]] bool consumes() const { + // The name "consumes" is a shortcut for "the analyze cycles algorithm could prove that this rule always consumes when it succeeds". return m_results.at( demangle< Rule >() ); } protected: - explicit analyze_cycles_impl( const bool verbose ) noexcept + explicit analyze_cycles_impl( const int verbose ) noexcept : m_verbose( verbose ), m_problems( 0 ) {} - [[nodiscard]] std::map< std::string_view, analyze_entry >::const_iterator find( const std::string_view name ) const noexcept + [[nodiscard]] const std::pair< const std::string_view, analyze_entry >& find( const std::string_view name ) const noexcept { - const auto iter = m_info.find( name ); - assert( iter != m_info.end() ); - return iter; + const auto iter = m_entries.find( name ); + assert( iter != m_entries.end() ); + return *iter; } - [[nodiscard]] bool work( const std::map< std::string_view, analyze_entry >::const_iterator& start, const bool accum ) + [[nodiscard]] bool work( const std::pair< const std::string_view, analyze_entry >& entry, const bool accum ) { - if( const auto j = m_cache.find( start->first ); j != m_cache.end() ) { - return j->second; - } - if( const auto g = set_stack_guard( m_stack, start->first ) ) { - switch( start->second.type ) { + if( const auto g = set_stack_guard( m_stack, entry.first ) ) { + const auto v = vector_stack_guard( m_trace, entry.first ); + switch( entry.second.type ) { case analyze_type::any: { bool a = false; - for( const auto& r : start->second.subs ) { + for( const auto& r : entry.second.subs ) { a = a || work( find( r ), accum || a ); } - return m_cache[ start->first ] = true; + return true; } case analyze_type::opt: { bool a = false; - for( const auto& r : start->second.subs ) { + for( const auto& r : entry.second.subs ) { a = a || work( find( r ), accum || a ); } - return m_cache[ start->first ] = false; + return false; } case analyze_type::seq: { bool a = false; - for( const auto& r : start->second.subs ) { + for( const auto& r : entry.second.subs ) { a = a || work( find( r ), accum || a ); } - return m_cache[ start->first ] = a; + return a; } case analyze_type::sor: { bool a = true; - for( const auto& r : start->second.subs ) { + for( const auto& r : entry.second.subs ) { a = a && work( find( r ), accum ); } - return m_cache[ start->first ] = a; + return a; } } assert( false ); // LCOV_EXCL_LINE } + assert( !m_trace.empty() ); + if( !accum ) { ++m_problems; - if( m_verbose ) { - std::cerr << "problem: cycle without progress detected at rule class " << start->first << std::endl; // LCOV_EXCL_LINE + // LCOV_EXCL_START + if( ( m_verbose >= 0 ) && ( m_trace.front() == entry.first ) ) { + for( const auto& r : m_trace ) { + if( r < entry.first ) { + return accum; + } + } + std::cerr << "WARNING: Possible cycle without progress at rule " << entry.first << std::endl; + if( m_verbose > 0 ) { + for( const auto& r : m_trace ) { + std::cerr << "- involved (transformed) rule: " << r << std::endl; + } + } } + // LCOV_EXCL_END } - return m_cache[ start->first ] = accum; + return accum; } - const bool m_verbose; + const int m_verbose; std::size_t m_problems; - std::map< std::string_view, analyze_entry > m_info; std::set< std::string_view > m_stack; - std::map< std::string_view, bool > m_cache; + std::vector< std::string_view > m_trace; std::map< std::string_view, bool > m_results; + std::map< std::string_view, analyze_entry > m_entries; }; template< typename Name > - std::string_view analyze_insert( std::map< std::string_view, analyze_entry >& info ) + std::string_view analyze_insert( std::map< std::string_view, analyze_entry >& entry ) { using Traits = analyze_traits< Name, typename Name::rule_t >; - const auto [ i, b ] = info.try_emplace( demangle< Name >(), Traits::type_v ); + const auto [ i, b ] = entry.try_emplace( demangle< Name >(), Traits::type_v ); if( b ) { - analyze_insert_impl( typename Traits::subs_t(), i->second.subs, info ); + analyze_insert_impl( typename Traits::subs_t(), i->second.subs, entry ); } return i->first; } template< typename... Subs > - void analyze_insert_impl( type_list< Subs... > /*unused*/, std::vector< std::string_view >& subs, std::map< std::string_view, analyze_entry >& info ) + void analyze_insert_impl( type_list< Subs... > /*unused*/, std::vector< std::string_view >& subs, std::map< std::string_view, analyze_entry >& entry ) { - ( subs.emplace_back( analyze_insert< Subs >( info ) ), ... ); + ( subs.emplace_back( analyze_insert< Subs >( entry ) ), ... ); } template< typename Grammar > - class analyze_cycles - : public analyze_cycles_impl + struct analyze_cycles + : analyze_cycles_impl { - public: - explicit analyze_cycles( const bool verbose ) + explicit analyze_cycles( const int verbose ) : analyze_cycles_impl( verbose ) { - analyze_insert< Grammar >( m_info ); + analyze_insert< Grammar >( m_entries ); } }; } // namespace internal template< typename Grammar > - [[nodiscard]] std::size_t analyze( const bool verbose = true ) + [[nodiscard]] std::size_t analyze( const int verbose = 1 ) { return internal::analyze_cycles< Grammar >( verbose ).problems(); } diff --git a/packages/PEGTL/include/tao/pegtl/contrib/analyze_traits.hpp b/packages/PEGTL/include/tao/pegtl/contrib/analyze_traits.hpp index 608f35b3f34d23862c07e9515c09030dfd91a2bf..1d82cf643997e834424405aab3994c5be3990143 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/analyze_traits.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/analyze_traits.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ANALYZE_TRAITS_HPP @@ -140,16 +140,6 @@ namespace TAO_PEGTL_NAMESPACE : analyze_traits< Name, typename Rule::rule_t > {}; - template< typename Name, typename Cond, typename... Rules > - struct analyze_traits< Name, internal::if_must< true, Cond, Rules... > > - : analyze_traits< Name, typename opt< Cond, Rules... >::rule_t > - {}; - - template< typename Name, typename Cond, typename... Rules > - struct analyze_traits< Name, internal::if_must< false, Cond, Rules... > > - : analyze_traits< Name, typename seq< Cond, Rules... >::rule_t > - {}; - template< typename Name, typename Cond, typename Then, typename Else > struct analyze_traits< Name, internal::if_then_else< Cond, Then, Else > > : analyze_traits< Name, typename sor< seq< Cond, Then >, Else >::rule_t > @@ -160,11 +150,6 @@ namespace TAO_PEGTL_NAMESPACE : std::conditional_t< ( sizeof...( Cs ) != 0 ), analyze_any_traits<>, analyze_opt_traits<> > {}; - template< typename Name, typename... Rules > - struct analyze_traits< Name, internal::must< Rules... > > - : analyze_traits< Name, typename seq< Rules... >::rule_t > - {}; - template< typename Name, typename... Rules > struct analyze_traits< Name, internal::not_at< Rules... > > : analyze_traits< Name, typename opt< Rules... >::rule_t > @@ -185,11 +170,6 @@ namespace TAO_PEGTL_NAMESPACE : analyze_traits< Name, typename seq< Rules..., opt< Name > >::rule_t > {}; - template< typename Name, typename T > - struct analyze_traits< Name, internal::raise< T > > - : analyze_any_traits<> - {}; - template< typename Name, internal::result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > struct analyze_traits< Name, internal::range< R, Peek, Lo, Hi > > : analyze_any_traits<> @@ -255,11 +235,6 @@ namespace TAO_PEGTL_NAMESPACE : analyze_opt_traits<> {}; - template< typename Name, typename Exception, typename... Rules > - struct analyze_traits< Name, internal::try_catch_type< Exception, Rules... > > - : analyze_traits< Name, typename seq< Rules... >::rule_t > - {}; - template< typename Name, typename Cond > struct analyze_traits< Name, internal::until< Cond > > : analyze_traits< Name, typename Cond::rule_t > @@ -270,6 +245,33 @@ namespace TAO_PEGTL_NAMESPACE : analyze_traits< Name, typename seq< star< Rules... >, Cond >::rule_t > {}; +#if defined( __cpp_exceptions ) + template< typename Name, typename Cond, typename... Rules > + struct analyze_traits< Name, internal::if_must< true, Cond, Rules... > > + : analyze_traits< Name, typename opt< Cond, Rules... >::rule_t > + {}; + + template< typename Name, typename Cond, typename... Rules > + struct analyze_traits< Name, internal::if_must< false, Cond, Rules... > > + : analyze_traits< Name, typename seq< Cond, Rules... >::rule_t > + {}; + + template< typename Name, typename... Rules > + struct analyze_traits< Name, internal::must< Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; + + template< typename Name, typename T > + struct analyze_traits< Name, internal::raise< T > > + : analyze_any_traits<> + {}; + + template< typename Name, typename Exception, typename... Rules > + struct analyze_traits< Name, internal::try_catch_type< Exception, Rules... > > + : analyze_traits< Name, typename seq< Rules... >::rule_t > + {}; +#endif + } // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/control_action.hpp b/packages/PEGTL/include/tao/pegtl/contrib/control_action.hpp index c716c66d69c2f1f75ad01bedadfd0073a43c196d..06d61e29591f1a2ae6d969355a92ee64548d4154 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/control_action.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/control_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_CONTROL_ACTION_HPP @@ -36,6 +36,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > [[nodiscard]] static bool match( ParseInput& in, States&&... st ) { +#if defined( __cpp_exceptions ) if constexpr( internal::action_has_unwind< void, Rule, Action, ParseInput, States... > ) { try { return control_action::match_impl< Rule, A, M, Action, Control >( in, st... ); @@ -48,6 +49,9 @@ namespace TAO_PEGTL_NAMESPACE else { return control_action::match_impl< Rule, A, M, Action, Control >( in, st... ); } +#else + return control_action::match_impl< Rule, A, M, Action, Control >( in, st... ); +#endif } private: diff --git a/packages/PEGTL/include/tao/pegtl/contrib/coverage.hpp b/packages/PEGTL/include/tao/pegtl/contrib/coverage.hpp index 78e9c64d167258337a3c039c85f051f8c11bd7ce..14d32ffcc133bfb3197c94571087b1ee083fd1c3 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/coverage.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/coverage.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_COVERAGE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/forward.hpp b/packages/PEGTL/include/tao/pegtl/contrib/forward.hpp index 4e2a592ef95accdc4e4b82dec6ceaf0edff50578..d60f9b54b8ee1ae3e32ddbe1d7354f6f0c43a415 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/forward.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/forward.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_FORWARD_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/function.hpp b/packages/PEGTL/include/tao/pegtl/contrib/function.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bed10604790529ef356ee5ce3da03966d62ad6fc --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/function.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_FUNCTION_HPP +#define TAO_PEGTL_CONTRIB_FUNCTION_HPP + +#include "../config.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" +#include "../type_list.hpp" + +#include "../internal/enable_control.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename F, F U > + struct function; + + template< typename ParseInput, typename... States, bool ( *U )( ParseInput&, States... ) > + struct function< bool ( * )( ParseInput&, States... ), U > + { + using rule_t = function; + using subs_t = empty_list; + + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control > + [[nodiscard]] static bool match( ParseInput& in, States... st ) noexcept( noexcept( U( in, st... ) ) ) + { + return U( in, st... ); + } + }; + + template< typename F, F U > + inline constexpr bool enable_control< function< F, U > > = false; + + } // namespace internal + + template< auto F > + struct function + : internal::function< decltype( F ), F > + {}; + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/http.hpp b/packages/PEGTL/include/tao/pegtl/contrib/http.hpp index 74b0e9eb7f080ea6570217e3cfd879a5b4307576..a1375aa9ec6219058063de1e643b1ba2f063469e 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/http.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/http.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_HTTP_HPP #define TAO_PEGTL_CONTRIB_HTTP_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required tao/pegtl/contrib/http.hpp" +#else + #include "../ascii.hpp" #include "../config.hpp" #include "../nothing.hpp" @@ -270,3 +274,4 @@ namespace TAO_PEGTL_NAMESPACE::http } // namespace TAO_PEGTL_NAMESPACE::http #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/icu/internal.hpp b/packages/PEGTL/include/tao/pegtl/contrib/icu/internal.hpp index 9ee98a1420d5682e5523a10bc6b1c0f696da1c9c..596a7eced7aaa70885965a69577ce41990cbfa33 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/icu/internal.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/icu/internal.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ICU_INTERNAL_HPP @@ -6,61 +6,93 @@ #include <unicode/uchar.h> +#include "../analyze_traits.hpp" + #include "../../config.hpp" #include "../../type_list.hpp" #include "../../internal/enable_control.hpp" -namespace TAO_PEGTL_NAMESPACE::internal +namespace TAO_PEGTL_NAMESPACE { - namespace icu + namespace internal { - template< typename Peek, UProperty P, bool V = true > - struct binary_property + namespace icu { - using rule_t = binary_property; - using subs_t = empty_list; - - template< typename ParseInput > - [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + template< typename Peek, UProperty P, bool V = true > + struct binary_property { - if( const auto r = Peek::peek( in ) ) { - if( u_hasBinaryProperty( r.data, P ) == V ) { - in.bump( r.size ); - return true; - } + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = binary_property; + using subs_t = empty_list; + + [[nodiscard]] static bool test( const data_t c ) noexcept + { + return u_hasBinaryProperty( c, P ) == V; } - return false; - } - }; - template< typename Peek, UProperty P, int V > - struct property_value - { - using rule_t = property_value; - using subs_t = empty_list; + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + in.bump( t.size ); + return true; + } + } + return false; + } + }; - template< typename ParseInput > - [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + template< typename Peek, UProperty P, int V > + struct property_value { - if( const auto r = Peek::peek( in ) ) { - if( u_getIntPropertyValue( r.data, P ) == V ) { - in.bump( r.size ); - return true; + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = property_value; + using subs_t = empty_list; + + [[nodiscard]] static bool test( const data_t c ) noexcept + { + return u_getIntPropertyValue( c, P ) == V; + } + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + in.bump( t.size ); + return true; + } } + return false; } - return false; - } - }; + }; + + } // namespace icu + + template< typename Peek, UProperty P, bool V > + inline constexpr bool enable_control< icu::binary_property< Peek, P, V > > = false; + + template< typename Peek, UProperty P, int V > + inline constexpr bool enable_control< icu::property_value< Peek, P, V > > = false; - } // namespace icu + } // namespace internal - template< typename Peek, UProperty P, bool V > - inline constexpr bool enable_control< icu::binary_property< Peek, P, V > > = false; + template< typename Name, typename Peek, UProperty P, bool V > + struct analyze_traits< Name, internal::icu::binary_property< Peek, P, V > > + : analyze_any_traits<> + {}; - template< typename Peek, UProperty P, int V > - inline constexpr bool enable_control< icu::property_value< Peek, P, V > > = false; + template< typename Name, typename Peek, UProperty P, int V > + struct analyze_traits< Name, internal::icu::property_value< Peek, P, V > > + : analyze_any_traits<> + {}; -} // namespace TAO_PEGTL_NAMESPACE::internal +} // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/icu/utf16.hpp b/packages/PEGTL/include/tao/pegtl/contrib/icu/utf16.hpp index 22c05ba0f1cc899682a95575313dc7fe78cd7e3a..b73db99271631eb58c5220e02e70607733bad7d0 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/icu/utf16.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/icu/utf16.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ICU_UTF16_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/icu/utf32.hpp b/packages/PEGTL/include/tao/pegtl/contrib/icu/utf32.hpp index aa59b04c753c58c5ca0b8fdbf28335e09f705c31..9781f567b35e6a58add6a634120db7850f1a3559 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/icu/utf32.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/icu/utf32.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ICU_UTF32_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/icu/utf8.hpp b/packages/PEGTL/include/tao/pegtl/contrib/icu/utf8.hpp index aaf6838d3051082c8975ace45fe06ead8c6483af..cf72da60ac3724a97dca3092db793db72255f0f8 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/icu/utf8.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/icu/utf8.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_ICU_UTF8_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/if_then.hpp b/packages/PEGTL/include/tao/pegtl/contrib/if_then.hpp index 734523c75376ca14bd933447c1f0ed21dafb8325..a17801355f5c07a87fcac9a0fb4836af2be2a42e 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/if_then.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/if_then.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_IF_THEN_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/instantiate.hpp b/packages/PEGTL/include/tao/pegtl/contrib/instantiate.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c04db3f541138c79fe50813a2b6f6e133ffd8251 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/instantiate.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_INSTANTIATE_HPP +#define TAO_PEGTL_CONTRIB_INSTANTIATE_HPP + +#include "../config.hpp" + +#include "../apply_mode.hpp" +#include "../match.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + template< typename T > + struct instantiate + : maybe_nothing + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&... st ) + { + const T t( static_cast< const ParseInput& >( in ), st... ); + return TAO_PEGTL_NAMESPACE::match< Rule, A, M, Action, Control >( in, st... ); + } + }; + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp b/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp index 30ba5464faa0961f5c94e78680960b4eac891a5c..f859662bf07e1f619feec3c0c42937a28fa67e1b 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/integer.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTEGER_HPP #define TAO_PEGTL_CONTRIB_INTEGER_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required tao/pegtl/contrib/integer.hpp" +#else + #include <cstdint> #include <cstdlib> @@ -429,3 +433,4 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp index 9edcd67d0b49ea85fc14e7ec097ab7d5587b50e5..ac40ead5894cab5d0004b773fcf88ebeb86e80d0 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP @@ -17,6 +17,21 @@ namespace TAO_PEGTL_NAMESPACE::internal { + enum class endian + { +#if defined( _WIN32 ) + little = 0, + big = 1, + native = little +#elif defined( __BYTE_ORDER__ ) + little = __ORDER_LITTLE_ENDIAN__, + big = __ORDER_BIG_ENDIAN__, + native = __BYTE_ORDER__ +#else +#error Unknown endianness. +#endif + }; + template< typename N > [[nodiscard]] N h_to_be( const N n ) noexcept { diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_gcc.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_gcc.hpp index 55f96d71a658be481c41c6b81ff868b323caf8af..9eeb9ad71bffc2ad171ed00757dd793bad9014b1 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_gcc.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_gcc.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_GCC_HPP @@ -100,10 +100,6 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; -#define TAO_PEGTL_NATIVE_ORDER be -#define TAO_PEGTL_NATIVE_UTF16 utf16_be -#define TAO_PEGTL_NATIVE_UTF32 utf32_be - #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ template< std::size_t S > @@ -193,10 +189,6 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; -#define TAO_PEGTL_NATIVE_ORDER le -#define TAO_PEGTL_NATIVE_UTF16 utf16_le -#define TAO_PEGTL_NATIVE_UTF32 utf32_le - #else #error Unknown host byte order! #endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_win.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_win.hpp index db0b835c9862925d47a9e4ba5b4bb4a7e5c23bf6..308dd3f018361baeebde0cf080ae49406ebfbace 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_win.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/endian_win.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_WIN_HPP @@ -97,10 +97,6 @@ namespace TAO_PEGTL_NAMESPACE::internal } }; -#define TAO_PEGTL_NATIVE_ORDER le -#define TAO_PEGTL_NATIVE_UTF16 utf16_le -#define TAO_PEGTL_NATIVE_UTF32 utf32_le - } // namespace TAO_PEGTL_NAMESPACE::internal #endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp index e5930c104a482981dc74d628676283fbc8be9e44..2a6c8b3079d8661e76fe2bf385ea8ed908649fb9 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp index 1d214fa100d3acb8e24a88446d266657ce658bb4..15bd6926f26467ff01c883e24b18d72d181c7bc6 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_mask_uint8.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_MASK_UINT8_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint.hpp index cdd0cf43706829f7269ce7b4bbc76b1037df8f13..04925f5ac3480a7176645cb412d4777c52b68e6f 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint8.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint8.hpp index 43010dda933ae454907b0f844366b713e14b962f..47b78efb2549146a425849a4537478d76a8de1af 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint8.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_uint8.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UINT8_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf16.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf16.hpp index e52a87e256cb72365e76bb64a2eb4b4e5f320cea..c37b23918b7dad49dbd0d7bc7294a06b018ff25e 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf16.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf16.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UTF16_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf32.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf32.hpp index 19958a0fa7fdb90871417e04681309101411e25f..b48dc4d2c2b0fc96152b8aa4f17fae28c0ad52d4 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf32.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/peek_utf32.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_PEEK_UTF32_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/read_uint.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/read_uint.hpp index bf102357642d100387af5d83075abcb4fa10e338..184c55ee095eebad005a1719b216ed1fdf9511ae 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/read_uint.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/read_uint.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_READ_UINT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/set_stack_guard.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/set_stack_guard.hpp index 99870f9b04d70fceb0a7785f1344d3b4d5555cf1..94df74cab2edf16ab5ebed16a5eeb6af4db21873 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/internal/set_stack_guard.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/set_stack_guard.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_INTERNAL_SET_STACK_GUARD_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/internal/vector_stack_guard.hpp b/packages/PEGTL/include/tao/pegtl/contrib/internal/vector_stack_guard.hpp new file mode 100644 index 0000000000000000000000000000000000000000..146da0f1afe49f72005fc05389da261d144457f4 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/internal/vector_stack_guard.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP +#define TAO_PEGTL_CONTRIB_INTERNAL_VECTOR_STACK_GUARD_HPP + +#include <utility> +#include <vector> + +#include "../../config.hpp" + +namespace TAO_PEGTL_NAMESPACE::internal +{ + template< typename... Cs > + class vector_stack_guard + { + public: + template< typename... Ts > + vector_stack_guard( std::vector< Cs... >& vector, Ts&&... ts ) + : m_s( vector ) + { + m_s.emplace_back( std::forward< Ts >( ts )... ); + } + + vector_stack_guard( vector_stack_guard&& ) = delete; + vector_stack_guard( const vector_stack_guard& ) = delete; + + void operator=( vector_stack_guard&& ) = delete; + void operator=( const vector_stack_guard& ) = delete; + + ~vector_stack_guard() + { + m_s.pop_back(); + } + + private: + std::vector< Cs... >& m_s; + }; + + template< typename... Cs > + vector_stack_guard( std::vector< Cs... >&, const typename std::vector< Cs... >::value_type& ) -> vector_stack_guard< Cs... >; + +} // namespace TAO_PEGTL_NAMESPACE::internal + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/json.hpp b/packages/PEGTL/include/tao/pegtl/contrib/json.hpp index 5ae8326efb6cf8800d5dbf3845f7f6ca2cb437a2..027201ac88a1691e6fb5195389dd2afc907b0d40 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/json.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/json.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_JSON_HPP @@ -17,7 +17,7 @@ namespace TAO_PEGTL_NAMESPACE::json struct ws : one< ' ', '\t', '\n', '\r' > {}; template< typename R, typename P = ws > - struct padr : internal::seq< R, internal::star< P > > {}; + struct padr : seq< R, star< P > > {}; struct begin_array : padr< one< '[' > > {}; struct begin_object : padr< one< '{' > > {}; @@ -31,26 +31,26 @@ namespace TAO_PEGTL_NAMESPACE::json struct true_ : string< 't', 'r', 'u', 'e' > {}; // NOLINT(readability-identifier-naming) struct digits : plus< digit > {}; - struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, must< digits > > {}; - struct frac : if_must< one< '.' >, digits > {}; - struct int_ : sor< one< '0' >, digits > {}; // NOLINT(readability-identifier-naming) + struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, digits > {}; + struct frac : seq< one< '.' >, digits > {}; + struct int_ : sor< one< '0' >, plus< digit > > {}; // NOLINT(readability-identifier-naming) struct number : seq< opt< one< '-' > >, int_, opt< frac >, opt< exp > > {}; struct xdigit : pegtl::xdigit {}; - struct unicode : list< seq< one< 'u' >, rep< 4, must< xdigit > > >, one< '\\' > > {}; + struct unicode : list< seq< one< 'u' >, rep< 4, xdigit > >, one< '\\' > > {}; struct escaped_char : one< '"', '\\', '/', 'b', 'f', 'n', 'r', 't' > {}; struct escaped : sor< escaped_char, unicode > {}; struct unescaped : utf8::range< 0x20, 0x10FFFF > {}; - struct char_ : if_then_else< one< '\\' >, must< escaped >, unescaped > {}; // NOLINT(readability-identifier-naming) + struct char_ : if_then_else< one< '\\' >, escaped, unescaped > {}; // NOLINT(readability-identifier-naming) - struct string_content : until< at< one< '"' > >, must< char_ > > {}; - struct string : seq< one< '"' >, must< string_content >, any > + struct string_content : until< at< one< '"' > >, char_ > {}; + struct string : seq< one< '"' >, string_content, any > { using content = string_content; }; - struct key_content : until< at< one< '"' > >, must< char_ > > {}; - struct key : seq< one< '"' >, must< key_content >, any > + struct key_content : until< at< one< '"' > >, char_ > {}; + struct key : seq< one< '"' >, key_content, any > { using content = key_content; }; @@ -58,8 +58,9 @@ namespace TAO_PEGTL_NAMESPACE::json struct value; struct array_element; - struct array_content : opt< list_must< array_element, value_separator > > {}; - struct array : seq< begin_array, array_content, must< end_array > > + struct next_array_element : seq< array_element > {}; + struct array_content : opt< array_element, star< value_separator, next_array_element > > {}; + struct array : seq< begin_array, array_content, end_array > { using begin = begin_array; using end = end_array; @@ -67,9 +68,11 @@ namespace TAO_PEGTL_NAMESPACE::json using content = array_content; }; - struct member : if_must< key, name_separator, value > {}; - struct object_content : opt< list_must< member, value_separator > > {}; - struct object : seq< begin_object, object_content, must< end_object > > + struct member_value : padr< value > {}; + struct member : seq< key, name_separator, member_value > {}; + struct next_member : seq< member > {}; + struct object_content : opt< member, star< value_separator, next_member > > {}; + struct object : seq< begin_object, object_content, end_object > { using begin = begin_object; using end = end_object; @@ -77,10 +80,10 @@ namespace TAO_PEGTL_NAMESPACE::json using content = object_content; }; - struct value : padr< sor< string, number, object, array, false_, true_, null > > {}; - struct array_element : seq< value > {}; + struct value : sor< string, number, object, array, false_, true_, null > {}; + struct array_element : padr< value > {}; - struct text : seq< star< ws >, value > {}; + struct text : pad< value, ws > {}; // clang-format on } // namespace TAO_PEGTL_NAMESPACE::json diff --git a/packages/PEGTL/include/tao/pegtl/contrib/json_pointer.hpp b/packages/PEGTL/include/tao/pegtl/contrib/json_pointer.hpp index 9732f705edfa33190447afbd5dc0db64b983ce78..6230cfcea1263d460c76ee7d6ef4651012bf4243 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/json_pointer.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/json_pointer.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_JSON_POINTER_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp index 25742807037cd2fb5cc1288da7c7b7ce45de8f0b..2d83d557e6874f07f114075c4101647b96f6893a 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_PARSE_TREE_HPP @@ -32,7 +32,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree { - template< typename T > + template< typename T, typename Source = std::string_view > struct basic_node { using node_t = T; @@ -40,7 +40,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree children_t children; std::string_view type; - std::string source; + Source source; TAO_PEGTL_NAMESPACE::internal::iterator m_begin; TAO_PEGTL_NAMESPACE::internal::iterator m_end; @@ -67,7 +67,8 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree template< typename U > [[nodiscard]] bool is_type() const noexcept { - return type == demangle< U >(); + const auto u = demangle< U >(); + return ( ( type.data() == u.data() ) && ( type.size() == u.size() ) ) || ( type == u ); } template< typename U > @@ -242,6 +243,8 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree struct make_control< Node, Selector, Control >::state_handler< Rule, false, false > : remove_first_state< Control< Rule > > { + static constexpr bool enable = true; + template< typename ParseInput, typename... States > static void start( const ParseInput& /*unused*/, state< Node >& state, States&&... /*unused*/ ) { @@ -396,7 +399,7 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree : apply< discard_empty > { template< typename Node, typename... States > - static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( n->children.empty(), n->Node::remove_content( st... ) ) ) + static void transform( std::unique_ptr< Node >& n, States&&... st ) noexcept( noexcept( (void)n->children.empty(), n->Node::remove_content( st... ) ) ) { if( n->children.empty() ) { n.reset(); diff --git a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp index a16b171d5eedbee9d38f918ee3c9d8c2209c91ab..79dbb0104e0b51e8d2970e7c2f879f2e33199836 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/parse_tree_to_dot.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_PARSE_TREE_TO_DOT_HPP @@ -37,6 +37,9 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree os.write( l, p - l ); l = ++p; switch( c ) { + case '\a': + os << "\\\\a"; + break; case '\b': os << "\\\\b"; break; @@ -52,6 +55,9 @@ namespace TAO_PEGTL_NAMESPACE::parse_tree case '\t': os << "\\\\t"; break; + case '\v': + os << "\\\\v"; + break; default: os << "\\\\u00" << h[ ( c & 0xf0 ) >> 4 ] << h[ c & 0x0f ]; } diff --git a/packages/PEGTL/include/tao/pegtl/contrib/peg.hpp b/packages/PEGTL/include/tao/pegtl/contrib/peg.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a921e372c158cfa789f448cff3b67abaf859aec9 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/peg.hpp @@ -0,0 +1,125 @@ +// Copyright (c) 2021 Daniel Deptford +// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_PEG_HPP +#define TAO_PEGTL_CONTRIB_PEG_HPP + +#include <tao/pegtl.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + namespace peg + { + // PEG grammar from https://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf + namespace grammar + { + // clang-format off + struct AND; + struct Char; + struct Class; + struct CLOSE; + struct Comment; + struct Definition; + struct DOT; + struct EndOfFile; + struct EndOfLine; + struct Expression; + struct QUESTION; + struct IdentCont; + struct Identifier; + struct IdentStart; + struct LEFTARROW; + struct Literal; + struct NOT; + struct OPEN; + struct PLUS; + struct Prefix; + struct Primary; + struct Range; + struct Sequence; + struct SLASH; + struct Space; + struct Spacing; + struct STAR; + struct Suffix; + + struct Grammar : seq< Spacing, plus< Definition >, EndOfFile > {}; + + struct Definition : seq< Identifier, LEFTARROW, Expression > {}; + struct Expression : list< Sequence, SLASH > {}; + struct Sequence : star< Prefix > {}; + + struct Prefix : seq< opt< sor< AND, NOT > >, Suffix > {}; + struct Suffix : seq< Primary, opt< sor< QUESTION, STAR, PLUS > > > {}; + + struct Primary : sor< + seq< Identifier, not_at< LEFTARROW > >, + seq< OPEN, Expression, CLOSE >, + Literal, + Class, + DOT + > {}; + + struct Identifier : seq< IdentStart, star< IdentCont >, Spacing > {}; + + struct IdentStart : identifier_first {}; + + struct IdentCont : identifier_other {}; + + struct Literal : sor< + seq< one< '\'' >, until< one< '\'' >, Char >, Spacing >, + seq< one< '"' >, until< one< '"' >, Char >, Spacing > + > {}; + + struct Class : seq< one< '[' >, until< one< ']' >, Range >, Spacing > {}; + + struct Range : sor< + seq< Char, one< '-' >, Char >, + Char + > {}; + + struct Char : sor< + seq< + one< '\\' >, + one< 'n', 'r', 't', '\'', '"', '[', ']', '\\' > >, + seq< + one< '\\' >, + range< '0', '2' >, + range< '0', '7' >, + range< '0', '7' > >, + seq< + one< '\\' >, + range< '0','7' >, + opt< range< '0','7' > > >, + seq< + not_at< one< '\\' > >, + any > + > {}; + + struct LEFTARROW : seq< string< '<','-' >, Spacing > {}; + struct SLASH : seq< one< '/' >, Spacing > {}; + struct AND : seq< one< '&' >, Spacing > {}; + struct NOT : seq< one< '!' >, Spacing > {}; + struct QUESTION : seq< one< '?' >, Spacing > {}; + struct STAR : seq< one< '*' >, Spacing > {}; + struct PLUS : seq< one< '+' >, Spacing > {}; + struct OPEN : seq< one< '(' >, Spacing > {}; + struct CLOSE : seq< one< ')' >, Spacing > {}; + struct DOT : seq< one< '.' >, Spacing > {}; + + struct Spacing : star< sor< Space, Comment > > {}; + struct Comment : seq< one< '#' >, until< EndOfLine > > {}; + + struct Space : sor< one< ' ', '\t' >, EndOfLine > {}; + struct EndOfLine : sor< string< '\r', '\n' >, one< '\n' >, one< '\r' > > {}; + struct EndOfFile : eof {}; + // clang-format on + + } // namespace grammar + + } // namespace peg + +} // namespace TAO_PEGTL_NAMESPACE + +#endif // TAO_PEGTL_CONTRIB_PEG_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/predicates.hpp b/packages/PEGTL/include/tao/pegtl/contrib/predicates.hpp new file mode 100644 index 0000000000000000000000000000000000000000..35a1f9b2f71da1a558ca4118e0f427503a3d5ca7 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/predicates.hpp @@ -0,0 +1,126 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_PREDICATES_HPP +#define TAO_PEGTL_CONTRIB_PREDICATES_HPP + +#include "../config.hpp" +#include "../type_list.hpp" + +#include "../internal/bump_help.hpp" +#include "../internal/dependent_false.hpp" +#include "../internal/enable_control.hpp" +#include "../internal/failure.hpp" +#include "../internal/peek_char.hpp" +#include "../internal/peek_utf8.hpp" + +#include "analyze_traits.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + namespace internal + { + template< typename Peek, typename... Ps > + struct predicates_and_test + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( Ps::test( c ) && ... ); // TODO: Static assert that Ps::peek_t is the same as peek_t?! + } + }; + + template< typename Peek, typename P > + struct predicate_not_test + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return !P::test( c ); // TODO: Static assert that P::peek_t is the same as peek_t?! + } + }; + + template< typename Peek, typename... Ps > + struct predicates_or_test + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( Ps::test( c ) || ... ); // TODO: Static assert that Ps::peek_t is the same as peek_t?! + } + }; + + template< template< typename, typename... > class Test, typename Peek, typename... Ps > + struct predicates + : private Test< Peek, Ps... > + { + using peek_t = Peek; + using data_t = typename Peek::data_t; + + using rule_t = predicates; + using subs_t = empty_list; + + using base_t = Test< Peek, Ps... >; + using base_t::test; + + template< int Eol > + static constexpr bool can_match_eol = test( Eol ); + + template< typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) + { + if( const auto t = Peek::peek( in ) ) { + if( test( t.data ) ) { + bump_help< predicates >( in, t.size ); + return true; + } + } + return false; + } + }; + + template< template< typename, typename... > class Test, typename Peek > + struct predicates< Test, Peek > + { + static_assert( dependent_false< Peek >, "Empty predicate list is not allowed!" ); + }; + + template< template< typename, typename... > class Test, typename Peek, typename... Ps > + inline constexpr bool enable_control< predicates< Test, Peek, Ps... > > = false; + + } // namespace internal + + inline namespace ascii + { + // clang-format off + template< typename... Ps > struct predicates_and : internal::predicates< internal::predicates_and_test, internal::peek_char, Ps... > {}; + template< typename P > struct predicate_not : internal::predicates< internal::predicate_not_test, internal::peek_char, P > {}; + template< typename... Ps > struct predicates_or : internal::predicates< internal::predicates_or_test, internal::peek_char, Ps... > {}; + // clang-format on + + } // namespace ascii + + namespace utf8 + { + // clang-format off + template< typename... Ps > struct predicates_and : internal::predicates< internal::predicates_and_test, internal::peek_utf8, Ps... > {}; + template< typename P > struct predicate_not : internal::predicates< internal::predicate_not_test, internal::peek_utf8, P > {}; + template< typename... Ps > struct predicates_or : internal::predicates< internal::predicates_or_test, internal::peek_utf8, Ps... > {}; + // clang-format on + + } // namespace utf8 + + template< typename Name, template< typename, typename... > class Test, typename Peek, typename... Ps > + struct analyze_traits< Name, internal::predicates< Test, Peek, Ps... > > + : analyze_any_traits<> + {}; + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/print.hpp b/packages/PEGTL/include/tao/pegtl/contrib/print.hpp index cc4ce4857460945ebb382e4722cb61b29f62933b..1583630f9ec62a1bcdb2a87b71f80c92ddfb8ae3 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/print.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/print.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_PRINT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/print_coverage.hpp b/packages/PEGTL/include/tao/pegtl/contrib/print_coverage.hpp index f3ab737e8f1084e8f1920a5b78a9c048ce0e5dea..98be601d0d47a190df4383fb74ff0f27372c5a9c 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/print_coverage.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/print_coverage.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_PRINT_COVERAGE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/raw_string.hpp b/packages/PEGTL/include/tao/pegtl/contrib/raw_string.hpp index 3e4a6a7f4b561d25e1640879402738bc107f7a1e..819fb6248681a9b4e3dc95f213a914f00492676b 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/raw_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/raw_string.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_RAW_STRING_HPP @@ -31,9 +31,8 @@ namespace TAO_PEGTL_NAMESPACE class Action, template< typename... > class Control, - typename ParseInput, - typename... States > - [[nodiscard]] static bool match( ParseInput& in, std::size_t& marker_size, States&&... /*unused*/ ) noexcept( noexcept( in.size( 0 ) ) ) + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, std::size_t& marker_size ) noexcept( noexcept( in.size( 0 ) ) ) { if( in.empty() || ( in.peek_char( 0 ) != Open ) ) { return false; @@ -70,9 +69,8 @@ namespace TAO_PEGTL_NAMESPACE class Action, template< typename... > class Control, - typename ParseInput, - typename... States > - [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size, States&&... /*unused*/ ) noexcept( noexcept( in.size( 0 ) ) ) + typename ParseInput > + [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size ) noexcept( noexcept( in.size( 0 ) ) ) { if( in.size( marker_size ) < marker_size ) { return false; @@ -114,11 +112,11 @@ namespace TAO_PEGTL_NAMESPACE class Control, typename ParseInput, typename... States > - [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size, States&&... st ) + [[nodiscard]] static bool match( ParseInput& in, const std::size_t& marker_size, States&&... /*unused*/ ) { auto m = in.template mark< M >(); - while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size, st... ) ) { + while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size ) ) { if( in.empty() ) { return false; } @@ -147,7 +145,7 @@ namespace TAO_PEGTL_NAMESPACE auto m = in.template mark< M >(); using m_t = decltype( m ); - while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size, st... ) ) { + while( !Control< Cond >::template match< A, rewind_mode::required, Action, Control >( in, marker_size ) ) { if( !Control< Rule >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { return false; } @@ -196,7 +194,7 @@ namespace TAO_PEGTL_NAMESPACE {}; using rule_t = raw_string; - using subs_t = empty_list; // type_list< internal::raw_string_open< Open, Marker >, internal::must< content > >; + using subs_t = empty_list; // type_list< internal::raw_string_open< Open, Marker >, content >; template< apply_mode A, rewind_mode M, @@ -209,11 +207,11 @@ namespace TAO_PEGTL_NAMESPACE [[nodiscard]] static bool match( ParseInput& in, States&&... st ) { std::size_t marker_size; - if( Control< internal::raw_string_open< Open, Marker > >::template match< A, M, Action, Control >( in, marker_size, st... ) ) { - // TODO: Do not rely on must<> - (void)Control< internal::must< content > >::template match< A, M, Action, Control >( in, marker_size, st... ); - in.bump_in_this_line( marker_size ); - return true; + if( Control< internal::raw_string_open< Open, Marker > >::template match< A, M, Action, Control >( in, marker_size ) ) { + if( Control< content >::template match< A, M, Action, Control >( in, marker_size, st... ) ) { + in.bump_in_this_line( marker_size ); + return true; + } } return false; } diff --git a/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp b/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp index 755b913498edbc776be1f85699cc7765e26ec7e0..418347b757493e4acf8ea95e91209f3c5fa702d9 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/remove_first_state.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_REMOVE_FIRST_STATE_HPP @@ -12,8 +12,11 @@ namespace TAO_PEGTL_NAMESPACE { - // Applies to start(), success(), failure(), raise(), apply(), and apply0(): - // The first state is removed when the call is forwarded to Base. + // The first state is removed for most of the control functions forwarded to Base, + // start(), success(), failure(), unwind(), raise(), apply(), and apply0(). The call + // to match() is unchanged because it can call other grammar rules that require all + // states when starting their match to keep an even playing field. + template< typename Base > struct remove_first_state : Base diff --git a/packages/PEGTL/include/tao/pegtl/contrib/remove_last_states.hpp b/packages/PEGTL/include/tao/pegtl/contrib/remove_last_states.hpp index a9006fe1d13e25d4d7535b94f9e8a4b00c19dc71..8c6246407ff22fc68cf27f0150e48a9943272c71 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/remove_last_states.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/remove_last_states.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_REMOVE_LAST_STATES_HPP @@ -13,7 +13,11 @@ namespace TAO_PEGTL_NAMESPACE { - // Remove the last N states of start(), success(), failure(), raise(), apply(), and apply0() + // The last N states are removed for most of the control functions forwarded to Base, + // start(), success(), failure(), unwind(), raise(), apply(), and apply0(). The call + // to match() is unchanged because it can call other grammar rules that require all + // states when starting their match to keep an even playing field. + template< typename Base, std::size_t N > struct remove_last_states : Base diff --git a/packages/PEGTL/include/tao/pegtl/contrib/rep_one_min_max.hpp b/packages/PEGTL/include/tao/pegtl/contrib/rep_one_min_max.hpp index ee0a37820b2af3e548d61449383c246fd99cf2cf..13df3b3faa63d74d1f50e2de9adaa4fb21a2a0a5 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/rep_one_min_max.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/rep_one_min_max.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_REP_ONE_MIN_MAX_HPP @@ -29,6 +29,9 @@ namespace TAO_PEGTL_NAMESPACE static_assert( Min <= Max ); + template< int Eol > + static constexpr bool can_match_eol = ( C == Eol ); + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) { @@ -41,7 +44,7 @@ namespace TAO_PEGTL_NAMESPACE ++i; } if( ( Min <= i ) && ( i <= Max ) ) { - bump_help< result_on_found::success, ParseInput, char, C >( in, i ); + bump_help< rep_one_min_max >( in, i ); return true; } return false; @@ -54,6 +57,9 @@ namespace TAO_PEGTL_NAMESPACE using rule_t = rep_one_min_max; using subs_t = empty_list; + template< int Eol > + static constexpr bool can_match_eol = ( C == Eol ); + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) { @@ -63,7 +69,7 @@ namespace TAO_PEGTL_NAMESPACE ++i; } if( i <= Max ) { - bump_help< result_on_found::success, ParseInput, char, C >( in, i ); + bump_help< rep_one_min_max >( in, i ); return true; } return false; diff --git a/packages/PEGTL/include/tao/pegtl/contrib/rep_string.hpp b/packages/PEGTL/include/tao/pegtl/contrib/rep_string.hpp index 39796eef9816cc84c0594ad6d129b6001c3fa6f4..d29040d4a20fdee9016f8a75f536cac3922c1c41 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/rep_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/rep_string.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_REP_STRING_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/shuffle_states.hpp b/packages/PEGTL/include/tao/pegtl/contrib/shuffle_states.hpp index 43912c4f26631b008cc9e4f1f029fcabfed9da6b..31faaea9d4b1cab5fd2632df28a91def2f30620a 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/shuffle_states.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/shuffle_states.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_SHUFFLE_STATES_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/skip.hpp b/packages/PEGTL/include/tao/pegtl/contrib/skip.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8aea252e83710abc24afb6319d73a67da4c9fca4 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/contrib/skip.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_CONTRIB_SKIP_HPP +#define TAO_PEGTL_CONTRIB_SKIP_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../match.hpp" +#include "../normal.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + // this is currently experimental and may change at any time + template< typename How, typename Where, template< typename... > class Base = normal > + struct skip + { + template< typename Rule > + struct control + : Base< Rule > + { + template< apply_mode A, + rewind_mode M, + template< typename... > + class Action, + template< typename... > + class Control, + typename ParseInput, + typename... States > + [[nodiscard]] static bool match( ParseInput& in, States&&... st ) + { + // TODO: if we only skip after but not before the actual rule, + // we would not need this marker. + auto m = in.template mark< M >(); + + // TODO: different conditions for before/after skipping? + if( Where::template value< Rule > ) { + // TODO: assert on result to be successful? + (void)TAO_PEGTL_NAMESPACE::match< How, apply_mode::nothing, M, nothing, normal >( in ); + } + + const bool result = Base< Rule >::template match< A, M, Action, Control >( in, st... ); + + // TODO: different conditions for before/after skipping? + if( result && Where::template value< Rule > ) { + // TODO: assert on result to be successful? + (void)TAO_PEGTL_NAMESPACE::match< How, apply_mode::nothing, M, nothing, normal >( in ); + } + + return m( result ); + } + }; + }; + +} // namespace TAO_PEGTL_NAMESPACE + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/state_control.hpp b/packages/PEGTL/include/tao/pegtl/contrib/state_control.hpp index 28b105e913ae7a366d3cfa7c83bf3205e51a0b15..cb41b058c6bceb2c9022dc4dc5126b828d085316 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/state_control.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/state_control.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_STATE_CONTROL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp b/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp index 5df1a2feae9b85e3263f13d9216c5c19a3398e94..987f02875f6d45f1ccb784fbd75a631896d85e81 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/to_string.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_TO_STRING_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/trace.hpp b/packages/PEGTL/include/tao/pegtl/contrib/trace.hpp index 9bc5976ac71a391c73bdc2657fca934e9bd9cbcc..d1ac4380b25d2494cb824ec06b18c853ea468ae6 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/trace.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/trace.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_TRACE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/uint16.hpp b/packages/PEGTL/include/tao/pegtl/contrib/uint16.hpp index 54fe468fb71a75b1f60df1795ed03347aa33c5e4..c3c1bf1e35925a292841578cb299cb119a7dd6af 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/uint16.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/uint16.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UINT16_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/uint32.hpp b/packages/PEGTL/include/tao/pegtl/contrib/uint32.hpp index 31bc321c5b6b639696fee50cce07dba455c7f7f7..39a46c32230c8d000a8bbeaf1f3ca0b878cece2c 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/uint32.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/uint32.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UINT32_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/uint64.hpp b/packages/PEGTL/include/tao/pegtl/contrib/uint64.hpp index 027a3968c7fbe697c627371b84f0f417388f046b..3084a59d034f6264c668ebf0806bf883ccf7846b 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/uint64.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/uint64.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UINT64_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/uint8.hpp b/packages/PEGTL/include/tao/pegtl/contrib/uint8.hpp index fb094bec80b47d1ff5a12e4c8312e793320fe785..f9e7dc7cd40fcc6e28a8d1eee284b9252f324cba 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/uint8.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/uint8.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UINT8_HPP diff --git a/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp b/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp index 9aca033e8989c92d6b5f910af0cb04e902c14a6c..5079f8275d72a178a5bd5527c3f85e12e8f9764e 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/unescape.hpp @@ -1,10 +1,11 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UNESCAPE_HPP #define TAO_PEGTL_CONTRIB_UNESCAPE_HPP #include <cassert> +#include <exception> #include <string> #include "../ascii.hpp" @@ -79,8 +80,8 @@ namespace TAO_PEGTL_NAMESPACE::unescape case 'E': case 'F': return I( c - 'A' + 10 ); - default: // LCOV_EXCL_LINE - throw std::runtime_error( "invalid character in unhex" ); // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + std::terminate(); // LCOV_EXCL_LINE } } @@ -133,7 +134,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape return *( r.begin() + i ); } } - throw parse_error( "invalid character in unescape", in ); // LCOV_EXCL_LINE + std::terminate(); // LCOV_EXCL_LINE } }; @@ -143,6 +144,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape struct unescape_u { +#if defined( __cpp_exceptions ) template< typename ActionInput > static void apply( const ActionInput& in, std::string& s ) { @@ -151,6 +153,14 @@ namespace TAO_PEGTL_NAMESPACE::unescape throw parse_error( "invalid escaped unicode code point", in ); } } +#else + template< typename ActionInput > + static bool apply( const ActionInput& in, std::string& s ) + { + assert( !in.empty() ); // First character MUST be present, usually 'u' or 'U'. + return utf8_append_utf32( s, unhex_string< unsigned >( in.begin() + 1, in.end() ) ); + } +#endif }; struct unescape_x @@ -174,7 +184,7 @@ namespace TAO_PEGTL_NAMESPACE::unescape struct unescape_j { template< typename ActionInput > - static void apply( const ActionInput& in, std::string& s ) + static bool apply( const ActionInput& in, std::string& s ) { assert( ( ( in.size() + 1 ) % 6 ) == 0 ); // Expects multiple "\\u1234", starting with the first "u". for( const char* b = in.begin() + 1; b < in.end(); b += 6 ) { @@ -188,9 +198,14 @@ namespace TAO_PEGTL_NAMESPACE::unescape } } if( !utf8_append_utf32( s, c ) ) { +#if defined( __cpp_exceptions ) throw parse_error( "invalid escaped unicode code point", in ); +#else + return false; +#endif } } + return true; } }; diff --git a/packages/PEGTL/include/tao/pegtl/contrib/uri.hpp b/packages/PEGTL/include/tao/pegtl/contrib/uri.hpp index 90e0a6d911d56af12dd61ead62d731849d3b090b..701b2bb4102a6bdaa3d9b194cbd15ee5a74d4ed9 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/uri.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/uri.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_URI_HPP #define TAO_PEGTL_CONTRIB_URI_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required tao/pegtl/contrib/uri.hpp" +#else + #include <cstdint> #include "../ascii.hpp" @@ -104,3 +108,4 @@ namespace TAO_PEGTL_NAMESPACE::uri } // namespace TAO_PEGTL_NAMESPACE::uri #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/contrib/utf16.hpp b/packages/PEGTL/include/tao/pegtl/contrib/utf16.hpp index 499041408e5f3c501c798ac9afd7bfb7da728e51..090b6b0615069e13990cb21a5fbcaf81aca14f8a 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/utf16.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/utf16.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UTF16_HPP @@ -42,7 +42,15 @@ namespace TAO_PEGTL_NAMESPACE } // namespace utf16_le - namespace utf16 = TAO_PEGTL_NATIVE_UTF16; +#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ ) + namespace utf16 = utf16_le; +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + namespace utf16 = utf16_le; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + namespace utf16 = utf16_be; +#else +#error Unknown endianness. +#endif } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/include/tao/pegtl/contrib/utf32.hpp b/packages/PEGTL/include/tao/pegtl/contrib/utf32.hpp index ce820fe2080169f4351bacf0c799cf47040d33f8..d8b80517a6b5bec4f56e9c085f40f165e45aa9bb 100644 --- a/packages/PEGTL/include/tao/pegtl/contrib/utf32.hpp +++ b/packages/PEGTL/include/tao/pegtl/contrib/utf32.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CONTRIB_UTF32_HPP @@ -42,7 +42,15 @@ namespace TAO_PEGTL_NAMESPACE } // namespace utf32_le - namespace utf32 = TAO_PEGTL_NATIVE_UTF32; +#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ ) + namespace utf32 = utf32_le; +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + namespace utf32 = utf32_le; +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + namespace utf32 = utf32_be; +#else +#error Unknown endianness. +#endif } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/include/tao/pegtl/cstream_input.hpp b/packages/PEGTL/include/tao/pegtl/cstream_input.hpp index ad50942faf93da27efaebb8a15bf6b050ea51169..1496927b46cd78c85afeeee647a24798ec53a141 100644 --- a/packages/PEGTL/include/tao/pegtl/cstream_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/cstream_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_CSTREAM_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/demangle.hpp b/packages/PEGTL/include/tao/pegtl/demangle.hpp index 4122ce4afcee169ae4fbcb549704bc135dc81425..56cc170c6bd038b18cb95aa323ba033ccaeec45a 100644 --- a/packages/PEGTL/include/tao/pegtl/demangle.hpp +++ b/packages/PEGTL/include/tao/pegtl/demangle.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL #ifndef TAO_PEGTL_DEMANGLE_HPP @@ -7,7 +7,9 @@ #include <ciso646> #include <string_view> -namespace tao +#include "config.hpp" + +namespace TAO_PEGTL_NAMESPACE { #if defined( __clang__ ) @@ -133,6 +135,6 @@ namespace tao #endif -} // namespace tao +} // namespace TAO_PEGTL_NAMESPACE #endif diff --git a/packages/PEGTL/include/tao/pegtl/disable_action.hpp b/packages/PEGTL/include/tao/pegtl/disable_action.hpp index 55872ff8b84902b4e75ea1927b821dedcaae232f..0781516f4ecd0cf39e938360d92aa76b96a958a3 100644 --- a/packages/PEGTL/include/tao/pegtl/disable_action.hpp +++ b/packages/PEGTL/include/tao/pegtl/disable_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_DISABLE_ACTION_HPP diff --git a/packages/PEGTL/include/tao/pegtl/discard_input.hpp b/packages/PEGTL/include/tao/pegtl/discard_input.hpp index abf65fee56abe269d691123cc1bd3815dd05f83c..61ddf0dd224e2d129b0b22ffb09f7a6ae3cb7301 100644 --- a/packages/PEGTL/include/tao/pegtl/discard_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/discard_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_DISCARD_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp b/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp index d3596095e606c3ab0732d5642591cf62d668b204..6e4a9cd3014504519b7edd5d50a0ac954dcdda8c 100644 --- a/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp +++ b/packages/PEGTL/include/tao/pegtl/discard_input_on_failure.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_DISCARD_INPUT_ON_FAILURE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp b/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp index 5c1ee85a3a5a1d7f6b577a8ee888ee43ef8ee85e..3edc271bdc0136d796ea2fbe0953f1efefd1edad 100644 --- a/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp +++ b/packages/PEGTL/include/tao/pegtl/discard_input_on_success.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_DISCARD_INPUT_ON_SUCCESS_HPP diff --git a/packages/PEGTL/include/tao/pegtl/enable_action.hpp b/packages/PEGTL/include/tao/pegtl/enable_action.hpp index 8492df7a46da0e4c802cdc64e4f05c972fb22035..a87726f8852029e49fa73861d80a6e40c4075c88 100644 --- a/packages/PEGTL/include/tao/pegtl/enable_action.hpp +++ b/packages/PEGTL/include/tao/pegtl/enable_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_ENABLE_ACTION_HPP diff --git a/packages/PEGTL/include/tao/pegtl/eol.hpp b/packages/PEGTL/include/tao/pegtl/eol.hpp index 4eeaeba1b985ef3992888e8e3deb9a8c30ca65f3..8c496da7ebcc4ec937c45e2057870178715493ae 100644 --- a/packages/PEGTL/include/tao/pegtl/eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/eol_pair.hpp b/packages/PEGTL/include/tao/pegtl/eol_pair.hpp index f52198b521fb829d7929fa02ce8cbbce6d871e50..239af370ead7b6d26e6c7d8aef12c6dd1dfa3bcf 100644 --- a/packages/PEGTL/include/tao/pegtl/eol_pair.hpp +++ b/packages/PEGTL/include/tao/pegtl/eol_pair.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_EOL_PAIR_HPP diff --git a/packages/PEGTL/include/tao/pegtl/file_input.hpp b/packages/PEGTL/include/tao/pegtl/file_input.hpp index 1fba74bb583d95d15deea4076919de820c00e559..91895b31e4a9aad63b6968376eb9a2710e15b825 100644 --- a/packages/PEGTL/include/tao/pegtl/file_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/file_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_FILE_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/action.hpp b/packages/PEGTL/include/tao/pegtl/internal/action.hpp index 74e2f418b4efc4927a254b140c5f35819d8ddfeb..3443c299775424dc08b547662b9565826bd46149 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/action.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ACTION_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp b/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp index 3fff69687738b60a96f4b607a77d0a686929673b..ccc2d16501d84ac9926fe900bad3af0765a5ed50 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/action_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ACTION_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/any.hpp b/packages/PEGTL/include/tao/pegtl/internal/any.hpp index 927f257ca931cdf411f04e0328fc3ec051df3aa1..59ba05f5af3d052e99355a759b977435853462e5 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/any.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/any.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ANY_HPP @@ -19,9 +19,17 @@ namespace TAO_PEGTL_NAMESPACE::internal template<> struct any< peek_char > { + using peek_t = peek_char; + using data_t = char; + using rule_t = any; using subs_t = empty_list; + [[nodiscard]] static bool test( const char /*unused*/ ) noexcept + { + return true; + } + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.empty() ) ) { @@ -36,9 +44,20 @@ namespace TAO_PEGTL_NAMESPACE::internal template< typename Peek > struct any { + using peek_t = Peek; + using data_t = typename Peek::data_t; + using rule_t = any; using subs_t = empty_list; + template< int Eol > + static constexpr bool can_match_eol = true; + + [[nodiscard]] static bool test( const data_t /*unused*/ ) noexcept + { + return true; + } + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) { diff --git a/packages/PEGTL/include/tao/pegtl/internal/apply.hpp b/packages/PEGTL/include/tao/pegtl/internal/apply.hpp index 7dac482bffd3cbf166e0f9c5dc48714fb89bf201..cc5e9fd9e7f39de0d1da9413cb6cecad55d371e8 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/apply.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_APPLY_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp b/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp index 7c3b92c626b83d630856fd07ae7aaeffdf100e9c..a6e37f4e4d710f96a6deff53493d4ca920eb4750 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/apply0.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_APPLY0_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/apply0_single.hpp b/packages/PEGTL/include/tao/pegtl/internal/apply0_single.hpp index 0c8da5ddd7780736d36394c1e8de2786994f7473..11939064d828dbf41e00dce2cca02e5765bd2a04 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/apply0_single.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/apply0_single.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_APPLY0_SINGLE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/apply_single.hpp b/packages/PEGTL/include/tao/pegtl/internal/apply_single.hpp index 7120cd0ac2952271b8f1aace7c22a9cbae01d9b7..57b0ca8fc0e66c0093ec087953a86076c765b1db 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/apply_single.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/apply_single.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_APPLY_SINGLE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/at.hpp b/packages/PEGTL/include/tao/pegtl/internal/at.hpp index df853f71ef7c070f66ab69ad8d0a3f253e07382e..7f7d2894c52fe42c45d3736af80d103b2357035a 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/at.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/at.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_AT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/bof.hpp b/packages/PEGTL/include/tao/pegtl/internal/bof.hpp index 19367f5091cac287d85fa95c4a138ba0d81784e5..da5c920bcc8e30dd16389efaae616beeb1558053 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/bof.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/bof.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_BOF_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/bol.hpp b/packages/PEGTL/include/tao/pegtl/internal/bol.hpp index 20f029e54204ad9ae0f21946de63a357d90e1b81..a71109d77c3b3bb8a65d4e116f766c0dc8931d0a 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/bol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/bol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_BOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/bump.hpp b/packages/PEGTL/include/tao/pegtl/internal/bump.hpp index fded8cc2e2315b25c5dbf170bddfe5729fdf3285..02e2278a264596c4cfed965bfa249c91fc41b6d9 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/bump.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/bump.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_BUMP_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/bump_help.hpp b/packages/PEGTL/include/tao/pegtl/internal/bump_help.hpp index dc9a1779d8834e5f1117e8c72890bcf5b5fd84a1..68c82b99758b59f8e960874e56e2534eefc69ca2 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/bump_help.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/bump_help.hpp @@ -1,22 +1,19 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_BUMP_HELP_HPP #define TAO_PEGTL_INTERNAL_BUMP_HELP_HPP #include <cstddef> -#include <type_traits> #include "../config.hpp" -#include "result_on_found.hpp" - namespace TAO_PEGTL_NAMESPACE::internal { - template< result_on_found R, typename ParseInput, typename Char, Char... Cs > - void bump_help( ParseInput& in, const std::size_t count ) noexcept + template< typename Rule, typename ParseInput > + void bump_help( ParseInput& in, const std::size_t count ) { - if constexpr( ( ( Cs != ParseInput::eol_t::ch ) && ... ) != bool( R ) ) { + if constexpr( Rule::template can_match_eol< ParseInput::eol_t::ch > ) { in.bump( count ); } else { diff --git a/packages/PEGTL/include/tao/pegtl/internal/bytes.hpp b/packages/PEGTL/include/tao/pegtl/internal/bytes.hpp index 7bd29960effd86c508a82d95dea7a1697526a89c..476ce965df766c1869edc11657b8bdc6b1084873 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/bytes.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/bytes.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_BYTES_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/control.hpp b/packages/PEGTL/include/tao/pegtl/internal/control.hpp index 119c98a99f98fae6383d0a2b5c400de5b75c84b3..e434ae06769efe1884ab87b71d898cba24fc764f 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/control.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/control.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_CONTROL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/cr_crlf_eol.hpp b/packages/PEGTL/include/tao/pegtl/internal/cr_crlf_eol.hpp index 201842bbd1ec4aa80848b46c2d76b3f72980ff27..22504513922d6ace165d1cef4cf51bb27910e6df 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/cr_crlf_eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/cr_crlf_eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_CR_CRLF_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/cr_eol.hpp b/packages/PEGTL/include/tao/pegtl/internal/cr_eol.hpp index 859dd7f30ba2d17260aaefcdd601c40af664db06..833a7c0c31b193f5b0240991e32018fc46d385f6 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/cr_eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/cr_eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_CR_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/crlf_eol.hpp b/packages/PEGTL/include/tao/pegtl/internal/crlf_eol.hpp index 7a9ad5aa77d9beb238045c67f0a5e57d4e40436c..5b71de8306191a885e6352303f68ddbadb51dd8b 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/crlf_eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/crlf_eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_CRLF_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/cstream_reader.hpp b/packages/PEGTL/include/tao/pegtl/internal/cstream_reader.hpp index 5d46854c6debb092ed18a039958d9dbc0732d67c..e8ca048c3e202fe2df558b8cb33b13ecf6ef7898 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/cstream_reader.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/cstream_reader.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP @@ -8,7 +8,11 @@ #include <cstddef> #include <cstdio> +#if defined( __cpp_exceptions ) #include <system_error> +#else +#include <exception> +#endif #include "../config.hpp" @@ -35,9 +39,14 @@ namespace TAO_PEGTL_NAMESPACE::internal // The example on cppreference.com doesn't work, at least not on macOS. // LCOV_EXCL_START +#if defined( __cpp_exceptions ) const auto ec = std::ferror( m_cstream ); assert( ec != 0 ); - throw std::system_error( ec, std::system_category(), "fread() failed" ); + throw std::system_error( ec, std::system_category(), "std::fread() failed" ); +#else + std::fputs( "std::fread() failed\n", stderr ); + std::terminate(); +#endif // LCOV_EXCL_STOP } diff --git a/packages/PEGTL/include/tao/pegtl/internal/cstring_reader.hpp b/packages/PEGTL/include/tao/pegtl/internal/cstring_reader.hpp index 71947aa720af88779bd7402eb4974ecb41945c3c..c98044c812d3f3a4f48bc41bc279c4243a2c5993 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/cstring_reader.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/cstring_reader.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_CSTRING_READER_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/dependent_false.hpp b/packages/PEGTL/include/tao/pegtl/internal/dependent_false.hpp index 421dc496c32bfb0feec765db76617f9a38fd0a01..57661a415d295fbdb559518964e91b326f41e896 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/dependent_false.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/dependent_false.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_DEPENDENT_FALSE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/disable.hpp b/packages/PEGTL/include/tao/pegtl/internal/disable.hpp index 727f5eafd2b5839909b5c42a930d41e1577a8dab..9a294d3b8415bcf2733902dac9e61f9af3ec3ca2 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/disable.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/disable.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_DISABLE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/discard.hpp b/packages/PEGTL/include/tao/pegtl/internal/discard.hpp index 2b0b55af1ae691acbc0d390e7ff0892d6cd1bbe7..b92760d04479a95d0d21a9f2a5bb2807004c75a3 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/discard.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/discard.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_DISCARD_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/enable.hpp b/packages/PEGTL/include/tao/pegtl/internal/enable.hpp index e30e97b8a3bc92b886870feb23b43725dfb4e4dc..9c453435c97d5efe2be4d7e46da8ba2f8dc612e2 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/enable.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/enable.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ENABLE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/enable_control.hpp b/packages/PEGTL/include/tao/pegtl/internal/enable_control.hpp index d424b5d79e460a4bdc2f6d3f8a187a8fa6259650..16ca4236900044b7f29930d739a569d614d14205 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/enable_control.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/enable_control.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ENABLE_CONTROL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/eof.hpp b/packages/PEGTL/include/tao/pegtl/internal/eof.hpp index 7dddc14456129c29a1913029911160aa44e6dd32..c4f0f81321811fa876c7e79894e7f8f0fcee4540 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/eof.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/eof.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_EOF_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/eol.hpp b/packages/PEGTL/include/tao/pegtl/internal/eol.hpp index 38f5fb7e5ab9229559b7a36aa1500f6081803125..ecec04f32defd31c8f65e27abc0a0070e12219ba 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/eolf.hpp b/packages/PEGTL/include/tao/pegtl/internal/eolf.hpp index eb03141fbd67c5bdd1dc9a87d61ea362f2b492f1..71fa8d891398473c985b8fe7e055b7f7bed462f5 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/eolf.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/eolf.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_EOLF_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/failure.hpp b/packages/PEGTL/include/tao/pegtl/internal/failure.hpp index e8cfaa4ef8bf4e7d5d662e14d945978eafa1a75d..75084997700d74d50672e0a6974de0ff4f08fafd 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/failure.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/failure.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_FAILURE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp b/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp index 86791340031f4f89b8aca1b90c5e807ec21e04eb..ad8147a7dbf0d47ee8c3597735d78000d8c2b6b0 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/file_mapper_posix.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_FILE_MAPPER_POSIX_HPP @@ -10,16 +10,22 @@ #include <sys/types.h> #include <unistd.h> -#include <filesystem> +#if !defined( __cpp_exceptions ) +#include <cstdio> +#include <exception> +#endif + #include <utility> #include "../config.hpp" +#include "filesystem.hpp" + namespace TAO_PEGTL_NAMESPACE::internal { struct file_opener { - explicit file_opener( const std::filesystem::path& path ) // NOLINT(modernize-pass-by-value) + explicit file_opener( const internal::filesystem::path& path ) // NOLINT(modernize-pass-by-value) : m_path( path ), m_fd( open() ) {} @@ -40,13 +46,20 @@ namespace TAO_PEGTL_NAMESPACE::internal struct stat st; errno = 0; if( ::fstat( m_fd, &st ) < 0 ) { - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "fstat() failed", m_path, ec ); + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "fstat() failed", m_path, ec ); +#else + std::perror( "fstat() failed" ); + std::terminate(); +#endif + // LCOV_EXCL_END } return std::size_t( st.st_size ); } - const std::filesystem::path m_path; + const internal::filesystem::path m_path; const int m_fd; private: @@ -62,15 +75,20 @@ namespace TAO_PEGTL_NAMESPACE::internal if( fd >= 0 ) { return fd; } - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "open() failed", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "open() failed", m_path, ec ); +#else + std::perror( "open() failed" ); + std::terminate(); +#endif } }; class file_mapper { public: - explicit file_mapper( const std::filesystem::path& path ) + explicit file_mapper( const internal::filesystem::path& path ) : file_mapper( file_opener( path ) ) {} @@ -79,8 +97,15 @@ namespace TAO_PEGTL_NAMESPACE::internal m_data( static_cast< const char* >( ::mmap( nullptr, m_size, PROT_READ, MAP_PRIVATE, reader.m_fd, 0 ) ) ) { if( ( m_size != 0 ) && ( intptr_t( m_data ) == -1 ) ) { - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "mmap() failed", reader.m_path, ec ); + // LCOV_EXCL_START +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "mmap() failed", reader.m_path, ec ); +#else + std::perror( "mmap() failed" ); + std::terminate(); +#endif + // LCOV_EXCL_END } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/file_mapper_win32.hpp b/packages/PEGTL/include/tao/pegtl/internal/file_mapper_win32.hpp index e8dab183317686ab86d49a511493892e20c90018..a8a471fd9ed881c2f36ca09517d07ec971517735 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/file_mapper_win32.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/file_mapper_win32.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_FILE_MAPPER_WIN32_HPP @@ -26,41 +26,51 @@ #undef TAO_PEGTL_WIN32_LEAN_AND_MEAN_WAS_DEFINED #endif -#include <filesystem> - #include "../config.hpp" +#if !defined( __cpp_exceptions ) +#include <cstdio> +#include <exception> +#endif + +#include "filesystem.hpp" + namespace TAO_PEGTL_NAMESPACE::internal { - struct win32_file_opener + struct file_opener { - explicit win32_file_opener( const std::filesystem::path& path ) + explicit file_opener( const internal::filesystem::path& path ) : m_path( path ), m_handle( open() ) {} - win32_file_opener( const win32_file_opener& ) = delete; - win32_file_opener( win32_file_opener&& ) = delete; + file_opener( const file_opener& ) = delete; + file_opener( file_opener&& ) = delete; - ~win32_file_opener() + ~file_opener() { ::CloseHandle( m_handle ); } - void operator=( const win32_file_opener& ) = delete; - void operator=( win32_file_opener&& ) = delete; + void operator=( const file_opener& ) = delete; + void operator=( file_opener&& ) = delete; [[nodiscard]] std::size_t size() const { LARGE_INTEGER size; if( !::GetFileSizeEx( m_handle, &size ) ) { - const std::error_code ec( ::GetLastError(), std::system_category() ); - throw std::filesystem::filesystem_error( "GetFileSizeEx() failed", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "GetFileSizeEx() failed", m_path, ec ); +#else + std::perror( "GetFileSizeEx() failed" ); + std::terminate(); +#endif } return std::size_t( size.QuadPart ); } - const std::filesystem::path m_path; + const internal::filesystem::path m_path; const HANDLE m_handle; private: @@ -76,8 +86,13 @@ namespace TAO_PEGTL_NAMESPACE::internal if( handle != INVALID_HANDLE_VALUE ) { return handle; } - const std::error_code ec( ::GetLastError(), std::system_category() ); - throw std::filesystem::filesystem_error( "CreateFile2() failed", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "CreateFile2() failed", m_path, ec ); +#else + std::perror( "CreateFile2() failed" ); + std::terminate(); +#endif #else const HANDLE handle = ::CreateFileW( m_path.c_str(), GENERIC_READ, @@ -89,19 +104,24 @@ namespace TAO_PEGTL_NAMESPACE::internal if( handle != INVALID_HANDLE_VALUE ) { return handle; } - const std::error_code ec( ::GetLastError(), std::system_category() ); - throw std::filesystem::filesystem_error( "CreateFileW()", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "CreateFileW()", m_path, ec ); +#else + std::perror( "CreateFileW() failed" ); + std::terminate(); +#endif #endif } }; struct win32_file_mapper { - explicit win32_file_mapper( const std::filesystem::path& path ) - : win32_file_mapper( win32_file_opener( path ) ) + explicit win32_file_mapper( const internal::filesystem::path& path ) + : win32_file_mapper( file_opener( path ) ) {} - explicit win32_file_mapper( const win32_file_opener& reader ) + explicit win32_file_mapper( const file_opener& reader ) : m_size( reader.size() ), m_handle( open( reader ) ) {} @@ -121,7 +141,7 @@ namespace TAO_PEGTL_NAMESPACE::internal const HANDLE m_handle; private: - [[nodiscard]] HANDLE open( const win32_file_opener& reader ) const + [[nodiscard]] HANDLE open( const file_opener& reader ) const { const uint64_t file_size = reader.size(); SetLastError( 0 ); @@ -138,15 +158,20 @@ namespace TAO_PEGTL_NAMESPACE::internal if( handle != NULL || file_size == 0 ) { return handle; } - const std::error_code ec( ::GetLastError(), std::system_category() ); - throw std::filesystem::filesystem_error( "CreateFileMappingW() failed", reader.m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "CreateFileMappingW() failed", reader.m_path, ec ); +#else + std::perror( "CreateFileMappingW() failed" ); + std::terminate(); +#endif } }; class file_mapper { public: - explicit file_mapper( const std::filesystem::path& path ) + explicit file_mapper( const internal::filesystem::path& path ) : file_mapper( win32_file_mapper( path ) ) {} @@ -159,8 +184,13 @@ namespace TAO_PEGTL_NAMESPACE::internal 0 ) ) ) { if( ( m_size != 0 ) && ( intptr_t( m_data ) == 0 ) ) { - const std::error_code ec( ::GetLastError(), std::system_category() ); - throw std::filesystem::filesystem_error( "MapViewOfFile() failed", ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( ::GetLastError(), internal::system_category() ); + throw internal::filesystem::filesystem_error( "MapViewOfFile() failed", ec ); +#else + std::perror( "MapViewOfFile() failed" ); + std::terminate(); +#endif } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp b/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp index d2812abfc8fc62726ee55c93679beb91e07aa4ed..7b846e1bf246cec4086d6333a9021f810928e865 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/file_reader.hpp @@ -1,20 +1,25 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_FILE_READER_HPP #define TAO_PEGTL_INTERNAL_FILE_READER_HPP #include <cstdio> -#include <filesystem> #include <memory> #include <string> #include <utility> +#if !defined( __cpp_exceptions ) +#include <exception> +#endif + #include "../config.hpp" +#include "filesystem.hpp" + namespace TAO_PEGTL_NAMESPACE::internal { - [[nodiscard]] inline std::FILE* file_open( const std::filesystem::path& path ) + [[nodiscard]] inline std::FILE* file_open( const internal::filesystem::path& path ) { errno = 0; #if defined( _MSC_VER ) @@ -22,19 +27,29 @@ namespace TAO_PEGTL_NAMESPACE::internal if( ::_wfopen_s( &file, path.c_str(), L"rb" ) == 0 ) { return file; } - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "_wfopen_s() failed", path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "_wfopen_s() failed", path, ec ); +#else + std::perror( "_wfopen_s() failed" ); + std::terminate(); +#endif #else #if defined( __MINGW32__ ) - if( auto* file = std::fopen( path.c_str(), "rb" ) ) + if( auto* file = std::fopen( path.string().c_str(), "rb" ) ) #else if( auto* file = std::fopen( path.c_str(), "rbe" ) ) #endif { return file; } - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "std::fopen() failed", path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fopen() failed", path, ec ); +#else + std::perror( "std::fopen() failed" ); + std::terminate(); +#endif #endif } @@ -49,11 +64,11 @@ namespace TAO_PEGTL_NAMESPACE::internal class file_reader { public: - explicit file_reader( const std::filesystem::path& path ) + explicit file_reader( const internal::filesystem::path& path ) : file_reader( file_open( path ), path ) {} - file_reader( FILE* file, const std::filesystem::path& path ) // NOLINT(modernize-pass-by-value) + file_reader( FILE* file, const internal::filesystem::path& path ) // NOLINT(modernize-pass-by-value) : m_path( path ), m_file( file ) {} @@ -71,23 +86,38 @@ namespace TAO_PEGTL_NAMESPACE::internal errno = 0; if( std::fseek( m_file.get(), 0, SEEK_END ) != 0 ) { // LCOV_EXCL_START - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "std::fseek() failed [SEEK_END]", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fseek() failed [SEEK_END]", m_path, ec ); +#else + std::perror( "std::fseek() failed [SEEK_END]" ); + std::terminate(); +#endif // LCOV_EXCL_STOP } errno = 0; const auto s = std::ftell( m_file.get() ); if( s < 0 ) { // LCOV_EXCL_START - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "std::ftell() failed", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::ftell() failed", m_path, ec ); +#else + std::perror( "std::ftell() failed" ); + std::terminate(); +#endif // LCOV_EXCL_STOP } errno = 0; if( std::fseek( m_file.get(), 0, SEEK_SET ) != 0 ) { // LCOV_EXCL_START - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "std::fseek() failed [SEEK_SET]", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fseek() failed [SEEK_SET]", m_path, ec ); +#else + std::perror( "std::fseek() failed [SEEK_SET]" ); + std::terminate(); +#endif // LCOV_EXCL_STOP } return std::size_t( s ); @@ -100,15 +130,20 @@ namespace TAO_PEGTL_NAMESPACE::internal errno = 0; if( !nrv.empty() && ( std::fread( &nrv[ 0 ], nrv.size(), 1, m_file.get() ) != 1 ) ) { // LCOV_EXCL_START - const std::error_code ec( errno, std::system_category() ); - throw std::filesystem::filesystem_error( "std::fread() failed", m_path, ec ); +#if defined( __cpp_exceptions ) + internal::error_code ec( errno, internal::system_category() ); + throw internal::filesystem::filesystem_error( "std::fread() failed", m_path, ec ); +#else + std::perror( "std::fread() failed" ); + std::terminate(); +#endif // LCOV_EXCL_STOP } return nrv; } private: - const std::filesystem::path m_path; + const internal::filesystem::path m_path; const std::unique_ptr< std::FILE, file_close > m_file; }; diff --git a/packages/PEGTL/include/tao/pegtl/internal/filesystem.hpp b/packages/PEGTL/include/tao/pegtl/internal/filesystem.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ad241abd222ac917a8032b91bdb2be3e8c62cc00 --- /dev/null +++ b/packages/PEGTL/include/tao/pegtl/internal/filesystem.hpp @@ -0,0 +1,64 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAO_PEGTL_INTERNAL_FILESYSTEM_HPP +#define TAO_PEGTL_INTERNAL_FILESYSTEM_HPP + +#include "../config.hpp" + +#if defined( TAO_PEGTL_BOOST_FILESYSTEM ) + +#define BOOST_FILESYSTEM_NO_DEPRECATED + +#include <boost/filesystem.hpp> + +namespace TAO_PEGTL_NAMESPACE::internal +{ + namespace filesystem = ::boost::filesystem; + + using error_code = ::boost::system::error_code; + + inline const auto& system_category() noexcept + { + return ::boost::system::system_category(); + } + +} // namespace TAO_PEGTL_NAMESPACE::internal + +#elif defined( TAO_PEGTL_STD_EXPERIMENTAL_FILESYSTEM ) + +#include <experimental/filesystem> + +namespace TAO_PEGTL_NAMESPACE::internal +{ + namespace filesystem = ::std::experimental::filesystem; + + using error_code = ::std::error_code; + + inline const auto& system_category() noexcept + { + return ::std::system_category(); + } + +} // namespace TAO_PEGTL_NAMESPACE::internal + +#else + +#include <filesystem> + +namespace TAO_PEGTL_NAMESPACE::internal +{ + namespace filesystem = ::std::filesystem; + + using error_code = ::std::error_code; + + inline const auto& system_category() noexcept + { + return ::std::system_category(); + } + +} // namespace TAO_PEGTL_NAMESPACE::internal + +#endif + +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/has_apply.hpp b/packages/PEGTL/include/tao/pegtl/internal/has_apply.hpp index 8c9414aac85760ea1befd6bd810f5726c88a506a..697f6ff3c62528307a65a733497a305149fdd3d1 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/has_apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/has_apply.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_HAS_APPLY_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/has_apply0.hpp b/packages/PEGTL/include/tao/pegtl/internal/has_apply0.hpp index db49981a3b61df20a9c9e13e706e6270e9334b61..3f5fc599d3703110a6d568d236bd74ecdafeb06b 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/has_apply0.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/has_apply0.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_HAS_APPLY0_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/has_match.hpp b/packages/PEGTL/include/tao/pegtl/internal/has_match.hpp index 5b2892d959ee8c75167073e23c6a6cde9b5c82f6..0606d7a5a3d42c22fef50e80dc75908b63bccbb2 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/has_match.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/has_match.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_HAS_MATCH_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/has_unwind.hpp b/packages/PEGTL/include/tao/pegtl/internal/has_unwind.hpp index 20bd953f5b35b75f78588449507ae2234e0c899d..566c24e4e5f2cc14b8f54cadc4a5c68eb2480653 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/has_unwind.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/has_unwind.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_HAS_UNWIND_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/identifier.hpp b/packages/PEGTL/include/tao/pegtl/internal/identifier.hpp index f75eebd1406c3826734c8747305106134cebbbd0..4ecbbb3244959798596a667842bc6524a7e4d8da 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/identifier.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/identifier.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_IDENTIFIER_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp b/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp index 4ccfb9c1ff19645d130f0d63c70349c41e79172d..27dd002abd37be48b5d75d45397adec761745cd8 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/if_apply.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_IF_APPLY_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/if_must.hpp b/packages/PEGTL/include/tao/pegtl/internal/if_must.hpp index 68689f32338e7b94d8e0c739f021dff31319e914..4cf2260e10f32406c4a3d04c589531304261ed46 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/if_must.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/if_must.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_IF_MUST_HPP #define TAO_PEGTL_INTERNAL_IF_MUST_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/if_must.hpp" +#else + #include "../config.hpp" #include "enable_control.hpp" @@ -45,3 +49,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/if_must_else.hpp b/packages/PEGTL/include/tao/pegtl/internal/if_must_else.hpp index bad4358d6e5ff19d71b529527c1f7fe0e03f97f4..685c7ca211bc0615a88369dc6803e46c1fc77b44 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/if_must_else.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/if_must_else.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP #define TAO_PEGTL_INTERNAL_IF_MUST_ELSE_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/if_must_else.hpp" +#else + #include "../config.hpp" #include "if_then_else.hpp" @@ -19,3 +23,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/if_then_else.hpp b/packages/PEGTL/include/tao/pegtl/internal/if_then_else.hpp index ea0bf8a31954e8055c72e630d6f3f1231fda8280..bc6fa3cea2484526cfe0589763b8a1b1404b6b7c 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/if_then_else.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/if_then_else.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_IF_THEN_ELSE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/input_pair.hpp b/packages/PEGTL/include/tao/pegtl/internal/input_pair.hpp index 78dde050a7063af0cc6f95b3f95c31056d72b2f9..a3bf92210652df71f37f0af4271e8667aad442bf 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/input_pair.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/input_pair.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_INPUT_PAIR_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/istream_reader.hpp b/packages/PEGTL/include/tao/pegtl/internal/istream_reader.hpp index fa91b960daf466358a3d7a9a061da09cc3bc4ed3..371ffbab5c27bbdf97432f2b3adbc39451cff64d 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/istream_reader.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/istream_reader.hpp @@ -1,11 +1,17 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP #define TAO_PEGTL_INTERNAL_ISTREAM_READER_HPP #include <istream> + +#if defined( __cpp_exceptions ) #include <system_error> +#else +#include <cstdio> +#include <exception> +#endif #include "../config.hpp" @@ -27,8 +33,13 @@ namespace TAO_PEGTL_NAMESPACE::internal if( m_istream.eof() ) { return 0; } +#if defined( __cpp_exceptions ) const auto ec = errno; throw std::system_error( ec, std::system_category(), "std::istream::read() failed" ); +#else + std::fputs( "std::istream::read() failed\n", stderr ); + std::terminate(); +#endif } std::istream& m_istream; diff --git a/packages/PEGTL/include/tao/pegtl/internal/istring.hpp b/packages/PEGTL/include/tao/pegtl/internal/istring.hpp index 60e6a2fe2025f50b0086a8110f8e363e3dba84dc..f7abe365feef29043788340c99b4d2b9bcddc4b4 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/istring.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/istring.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ISTRING_HPP @@ -10,6 +10,7 @@ #include "bump_help.hpp" #include "enable_control.hpp" +#include "one.hpp" #include "result_on_found.hpp" #include "success.hpp" @@ -21,7 +22,7 @@ namespace TAO_PEGTL_NAMESPACE::internal inline constexpr bool is_alpha = ( ( 'a' <= C ) && ( C <= 'z' ) ) || ( ( 'A' <= C ) && ( C <= 'Z' ) ); template< char C > - [[nodiscard]] bool ichar_equal( const char c ) noexcept + [[nodiscard]] constexpr bool ichar_equal( const char c ) noexcept { if constexpr( is_alpha< C > ) { return ( C | 0x20 ) == ( c | 0x20 ); @@ -32,7 +33,7 @@ namespace TAO_PEGTL_NAMESPACE::internal } template< char... Cs > - [[nodiscard]] bool istring_equal( const char* r ) noexcept + [[nodiscard]] constexpr bool istring_equal( const char* r ) noexcept { return ( ichar_equal< Cs >( *r++ ) && ... ); } @@ -45,18 +46,26 @@ namespace TAO_PEGTL_NAMESPACE::internal : success {}; + // template< char C > + // struct istring< C > + // : std::conditional_t< is_alpha< C >, one< result_on_found::success, peek_char, C | 0x20, C & ~0x20 >, one< result_on_found::success, peek_char, C > > + // {}; + template< char... Cs > struct istring { using rule_t = istring; using subs_t = empty_list; + template< int Eol > + static constexpr bool can_match_eol = one< result_on_found::success, peek_char, Cs... >::template can_match_eol< Eol >; + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) { if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) { if( istring_equal< Cs... >( in.current() ) ) { - bump_help< result_on_found::success, ParseInput, char, Cs... >( in, sizeof...( Cs ) ); + bump_help< istring >( in, sizeof...( Cs ) ); return true; } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/iterator.hpp b/packages/PEGTL/include/tao/pegtl/internal/iterator.hpp index ae2cca18d962d44aa7eb53ea62918fd2a64644d7..758016772646b38eb436b712fe1ccc6870100a36 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/iterator.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/iterator.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ITERATOR_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/lf_crlf_eol.hpp b/packages/PEGTL/include/tao/pegtl/internal/lf_crlf_eol.hpp index 2c08186e570ddef4a01f394fc549e17ff81e548b..c3eae42c1b1a2e32ba85071926bab84d119c3cfc 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/lf_crlf_eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/lf_crlf_eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_LF_CRLF_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/lf_eol.hpp b/packages/PEGTL/include/tao/pegtl/internal/lf_eol.hpp index 9eee34ebf0777cd1ba25e82ec82c9bfcddb4cab3..0f4e33d64925aa4fd75888e75407d7803e85da28 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/lf_eol.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/lf_eol.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_LF_EOL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/list.hpp b/packages/PEGTL/include/tao/pegtl/internal/list.hpp index 7a69d4c78ee0889628868f6f80db53e298d62b38..07318e6572ac825d67e8eb562a85d81b6e62e889 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/list.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/list.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_LIST_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/list_must.hpp b/packages/PEGTL/include/tao/pegtl/internal/list_must.hpp index 545ef6c19e046074f93bd8969a78a83b2351ef76..aff1786960e1e4e053f95232af296d665d5faf76 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/list_must.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/list_must.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_LIST_MUST_HPP #define TAO_PEGTL_INTERNAL_LIST_MUST_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/list_must.hpp" +#else + #include "../config.hpp" #include "must.hpp" @@ -18,3 +22,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/list_tail.hpp b/packages/PEGTL/include/tao/pegtl/internal/list_tail.hpp index 05d4ade59e940bbd03fa18d47f81eb22890d80f4..5fe3ff413ed1be126fccc90c94f2d362fa5cfbbf 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/list_tail.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/list_tail.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/list_tail_pad.hpp b/packages/PEGTL/include/tao/pegtl/internal/list_tail_pad.hpp index e6a43294cdd03707830c5e07fd36f605c1ba4322..b96c626b8e8fe4b233a4cbcd4a2e28f4ba99f92c 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/list_tail_pad.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/list_tail_pad.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_LIST_TAIL_PAD_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/marker.hpp b/packages/PEGTL/include/tao/pegtl/internal/marker.hpp index 6cec4aa8f6122ff05e1180da6ef8fdcd16e272ac..4beb9293a17f18e6d9eac6370ead5d0a53866746 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/marker.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/marker.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_MARKER_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/minus.hpp b/packages/PEGTL/include/tao/pegtl/internal/minus.hpp index f928371623e96a086bc5b49eb30df3da9be47bde..4062f420e6bb7a301bb71b964b02a49249ba5562 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/minus.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/minus.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_MINUS_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/missing_apply.hpp b/packages/PEGTL/include/tao/pegtl/internal/missing_apply.hpp index d1e8f76837a68acff767962ca7c1ef9c9eb92acc..e69cbf3a9b30187091b0dbe3699f434aa9dd54fb 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/missing_apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/missing_apply.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_MISSING_APPLY_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/missing_apply0.hpp b/packages/PEGTL/include/tao/pegtl/internal/missing_apply0.hpp index a7b65f8c925c0b2c174cd406d7edc027dd2257c5..2b63a28e5a50f30363b8761c2a7f4eb3bc7e9213 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/missing_apply0.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/missing_apply0.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_MISSING_APPLY0_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/must.hpp b/packages/PEGTL/include/tao/pegtl/internal/must.hpp index 4cb6454be7c60efd48e115a95de44ed07e770051..213fc56eb2f0c336ea63d0c78c801c2cceeeb6e0 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/must.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/must.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_MUST_HPP #define TAO_PEGTL_INTERNAL_MUST_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/must.hpp" +#else + #include "../config.hpp" #include "enable_control.hpp" @@ -62,3 +66,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/not_at.hpp b/packages/PEGTL/include/tao/pegtl/internal/not_at.hpp index 09ba3c5eb089c61d27171cace08444b4e6b9a53e..00758969724a0838d1a3f0d93c20997afffe9d1c 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/not_at.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/not_at.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_NOT_AT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/one.hpp b/packages/PEGTL/include/tao/pegtl/internal/one.hpp index 65bc2e1236d109bcf4637f95f5c8e4c81dea8b75..e2bc05ef41cc1bc599ab0be5ce0fe73f3577e8ad 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/one.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/one.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_ONE_HPP @@ -21,15 +21,26 @@ namespace TAO_PEGTL_NAMESPACE::internal template< result_on_found R, typename Peek, typename Peek::data_t... Cs > struct one { + using peek_t = Peek; + using data_t = typename Peek::data_t; + using rule_t = one; using subs_t = empty_list; + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( ( c == Cs ) || ... ) == bool( R ); + } + + template< int Eol > + static constexpr bool can_match_eol = test( Eol ); + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) { if( const auto t = Peek::peek( in ) ) { - if( ( ( t.data == Cs ) || ... ) == bool( R ) ) { - bump_help< R, ParseInput, typename Peek::data_t, Cs... >( in, t.size ); + if( test( t.data ) ) { + bump_help< one >( in, t.size ); return true; } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/opt.hpp b/packages/PEGTL/include/tao/pegtl/internal/opt.hpp index 9f25c5038ef7e87894398c778186fdf18f04e758..9dd1a0cf419401bc657ec1d6f68b959db58529fe 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/opt.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/opt.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_OPT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/pad.hpp b/packages/PEGTL/include/tao/pegtl/internal/pad.hpp index c84f74135afb1d3334e1e41bf54101d27cb300a1..ff49ce22c78dc9626fb62913e4973805745b073d 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/pad.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/pad.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PAD_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/pad_opt.hpp b/packages/PEGTL/include/tao/pegtl/internal/pad_opt.hpp index aa965c4c26ce6cb131b7c7c69064488c79b20122..02af2363a9a8fffb48f777e66058c7aa78ef29da 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/pad_opt.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/pad_opt.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PAD_OPT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/path_to_string.hpp b/packages/PEGTL/include/tao/pegtl/internal/path_to_string.hpp index 04b0774e069b45472b47cce1e4d5d275e19b69ed..d28dbac739888cda5138ec6ea399ad2ae01036a6 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/path_to_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/path_to_string.hpp @@ -1,19 +1,21 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PATH_TO_STRING_HPP #define TAO_PEGTL_INTERNAL_PATH_TO_STRING_HPP -#include <filesystem> #include <string> #include "../config.hpp" +#include "filesystem.hpp" namespace TAO_PEGTL_NAMESPACE::internal { - [[nodiscard]] inline std::string path_to_string( const std::filesystem::path& path ) + [[nodiscard]] inline std::string path_to_string( const internal::filesystem::path& path ) { -#if defined( __cpp_char8_t ) +#if defined( TAO_PEGTL_BOOST_FILESYSTEM ) + return path.string(); +#elif defined( __cpp_char8_t ) const auto s = path.u8string(); return { reinterpret_cast< const char* >( s.data() ), s.size() }; #else diff --git a/packages/PEGTL/include/tao/pegtl/internal/peek_char.hpp b/packages/PEGTL/include/tao/pegtl/internal/peek_char.hpp index 85f1b4dbe022986634404ab6e353fccb6f86d34b..7dbb06f699faaeca7e4d8f9808e06a6505a5b93f 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/peek_char.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/peek_char.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PEEK_CHAR_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/peek_utf8.hpp b/packages/PEGTL/include/tao/pegtl/internal/peek_utf8.hpp index 8f1e5a991ddb42d07494c821fe5d504856d56ade..77f623d1069075b687f96053a70cfc9172f0cc78 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/peek_utf8.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/peek_utf8.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PEEK_UTF8_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp b/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp index 6440e97c94618333bf2e211bdc960d71de8d1cad..aac858d018e4300e0bf817c819776fd640bb14c4 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/pegtl_string.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PEGTL_STRING_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/plus.hpp b/packages/PEGTL/include/tao/pegtl/internal/plus.hpp index 82e191d8b755f07b22d7bf1841030eadad6f6a66..4a0ee5a99d9a7d6bf9e1f294d3794d35cda62e70 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/plus.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/plus.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_PLUS_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/raise.hpp b/packages/PEGTL/include/tao/pegtl/internal/raise.hpp index a84c92a894c2a6cdcdecf319548a8f979dc2cc8e..9d9c831889c5be7b2ee2654f11565bb19511bef0 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/raise.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/raise.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_RAISE_HPP #define TAO_PEGTL_INTERNAL_RAISE_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/raise.hpp" +#else + #include <stdexcept> #include "../config.hpp" @@ -42,3 +46,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/range.hpp b/packages/PEGTL/include/tao/pegtl/internal/range.hpp index e956b709ca2557018ac8258753d2dd2a9f06f9d8..d1ad9e98dde2d61f40e9689032299042706e1122 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/range.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/range.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_RANGE_HPP @@ -6,6 +6,7 @@ #include "../config.hpp" +#include "bump_help.hpp" #include "enable_control.hpp" #include "one.hpp" #include "result_on_found.hpp" @@ -17,25 +18,28 @@ namespace TAO_PEGTL_NAMESPACE::internal template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > struct range { + using peek_t = Peek; + using data_t = typename Peek::data_t; + using rule_t = range; using subs_t = empty_list; static_assert( Lo < Hi, "invalid range" ); + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ( ( Lo <= c ) && ( c <= Hi ) ) == bool( R ); + } + template< int Eol > - static constexpr bool can_match_eol = ( ( ( Lo <= Eol ) && ( Eol <= Hi ) ) == bool( R ) ); + static constexpr bool can_match_eol = test( Eol ); template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) { if( const auto t = Peek::peek( in ) ) { - if( ( ( Lo <= t.data ) && ( t.data <= Hi ) ) == bool( R ) ) { - if constexpr( can_match_eol< ParseInput::eol_t::ch > ) { - in.bump( t.size ); - } - else { - in.bump_in_this_line( t.size ); - } + if( test( t.data ) ) { + bump_help< range >( in, t.size ); return true; } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/ranges.hpp b/packages/PEGTL/include/tao/pegtl/internal/ranges.hpp index a26b45539ef196493b1aa01887fe87153afc581e..1af27d7552ac0df06d72b882e47ff35a3a1e1c97 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/ranges.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/ranges.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_RANGES_HPP @@ -6,6 +6,7 @@ #include "../config.hpp" +#include "bump_help.hpp" #include "enable_control.hpp" #include "failure.hpp" #include "one.hpp" @@ -15,64 +16,61 @@ namespace TAO_PEGTL_NAMESPACE::internal { - template< int Eol, typename Char, Char... Cs > + template< typename Char, Char... Cs > struct ranges_impl; - template< int Eol, typename Char > - struct ranges_impl< Eol, Char > + template< typename Char > + struct ranges_impl< Char > { - static constexpr bool can_match_eol = false; - - [[nodiscard]] static bool match( const Char /*unused*/ ) noexcept + [[nodiscard]] static constexpr bool test( const Char /*unused*/ ) noexcept { return false; } }; - template< int Eol, typename Char, Char Eq > - struct ranges_impl< Eol, Char, Eq > + template< typename Char, Char Eq > + struct ranges_impl< Char, Eq > { - static constexpr bool can_match_eol = ( Eq == Eol ); - - [[nodiscard]] static bool match( const Char c ) noexcept + [[nodiscard]] static constexpr bool test( const Char c ) noexcept { return c == Eq; } }; - template< int Eol, typename Char, Char Lo, Char Hi, Char... Cs > - struct ranges_impl< Eol, Char, Lo, Hi, Cs... > + template< typename Char, Char Lo, Char Hi, Char... Cs > + struct ranges_impl< Char, Lo, Hi, Cs... > { static_assert( Lo <= Hi, "invalid range detected" ); - static constexpr bool can_match_eol = ( ( ( Lo <= Eol ) && ( Eol <= Hi ) ) || ranges_impl< Eol, Char, Cs... >::can_match_eol ); - - [[nodiscard]] static bool match( const Char c ) noexcept + [[nodiscard]] static constexpr bool test( const Char c ) noexcept { - return ( ( Lo <= c ) && ( c <= Hi ) ) || ranges_impl< Eol, Char, Cs... >::match( c ); + return ( ( Lo <= c ) && ( c <= Hi ) ) || ranges_impl< Char, Cs... >::test( c ); } }; template< typename Peek, typename Peek::data_t... Cs > struct ranges { + using peek_t = Peek; + using data_t = typename Peek::data_t; + using rule_t = ranges; using subs_t = empty_list; + [[nodiscard]] static constexpr bool test( const data_t c ) noexcept + { + return ranges_impl< data_t, Cs... >::test( c ); + } + template< int Eol > - static constexpr bool can_match_eol = ranges_impl< Eol, typename Peek::data_t, Cs... >::can_match_eol; + static constexpr bool can_match_eol = test( Eol ); template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( Peek::peek( in ) ) ) { if( const auto t = Peek::peek( in ) ) { - if( ranges_impl< ParseInput::eol_t::ch, typename Peek::data_t, Cs... >::match( t.data ) ) { - if constexpr( can_match_eol< ParseInput::eol_t::ch > ) { - in.bump( t.size ); - } - else { - in.bump_in_this_line( t.size ); - } + if( test( t.data ) ) { + bump_help< ranges >( in, t.size ); return true; } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/rematch.hpp b/packages/PEGTL/include/tao/pegtl/internal/rematch.hpp index eefe9283b0a6b34514d6955576d1e73951a44656..a1f7e3496c283944bbbc9baaa270162677a7936f 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/rematch.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/rematch.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REMATCH_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/rep.hpp b/packages/PEGTL/include/tao/pegtl/internal/rep.hpp index 1b7bc8649b21128a031bd9c092931fed2086e04f..3ef122d64452670b63c5eeed229f1cfbcaff1d49 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/rep.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/rep.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REP_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/rep_min.hpp b/packages/PEGTL/include/tao/pegtl/internal/rep_min.hpp index ecf9bc014432bf927cee11f8a2d58d73c73e2bac..73f8531aa3e7d56bd2f62f13bb85e263ff9d1ada 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/rep_min.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/rep_min.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REP_MIN_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/rep_min_max.hpp b/packages/PEGTL/include/tao/pegtl/internal/rep_min_max.hpp index f153cd10a37e5c39f28d5c91ef689dbd42e381d6..b600152f019e1d2362573215879a3c80a93f2ead 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/rep_min_max.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/rep_min_max.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REP_MIN_MAX_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/rep_opt.hpp b/packages/PEGTL/include/tao/pegtl/internal/rep_opt.hpp index ea69ee5636c07ca7554e44e382bd23359f7d7fa2..435332d45fb393d6521526f257327bbc95b9d926 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/rep_opt.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/rep_opt.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REP_OPT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/require.hpp b/packages/PEGTL/include/tao/pegtl/internal/require.hpp index e6d6b0c9f8fe3ec545d69b43a2d666bce4cf405e..f2ce5a02280a90f72a787594f047da2c9ed9e834 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/require.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/require.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REQUIRE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/result_on_found.hpp b/packages/PEGTL/include/tao/pegtl/internal/result_on_found.hpp index 492ec212d2fce3a8b0adfe258494d32d2edfa9c6..09fa6ed6ee070ad76d1ba2c67e82bc7825847ebf 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/result_on_found.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/result_on_found.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_RESULT_ON_FOUND_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/rules.hpp b/packages/PEGTL/include/tao/pegtl/internal/rules.hpp index de13adfbe8ff8c967b1d990b62c3ddbf87aa8268..5496a94b8fa261133e276e0e2fddbcffbb871a61 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/rules.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/rules.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_RULES_HPP @@ -23,23 +23,18 @@ #include "failure.hpp" #include "identifier.hpp" #include "if_apply.hpp" -#include "if_must.hpp" -#include "if_must_else.hpp" #include "if_then_else.hpp" #include "istring.hpp" #include "list.hpp" -#include "list_must.hpp" #include "list_tail.hpp" #include "list_tail_pad.hpp" #include "minus.hpp" -#include "must.hpp" #include "not_at.hpp" #include "one.hpp" #include "opt.hpp" #include "pad.hpp" #include "pad_opt.hpp" #include "plus.hpp" -#include "raise.hpp" #include "range.hpp" #include "ranges.hpp" #include "rematch.hpp" @@ -51,11 +46,19 @@ #include "seq.hpp" #include "sor.hpp" #include "star.hpp" -#include "star_must.hpp" #include "state.hpp" #include "string.hpp" #include "success.hpp" -#include "try_catch_type.hpp" #include "until.hpp" +#if defined( __cpp_exceptions ) +#include "if_must.hpp" +#include "if_must_else.hpp" +#include "list_must.hpp" +#include "must.hpp" +#include "raise.hpp" +#include "star_must.hpp" +#include "try_catch_type.hpp" +#endif + #endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/seq.hpp b/packages/PEGTL/include/tao/pegtl/internal/seq.hpp index aa45dbe3163dff044a805cefa94cf8085155b93c..11af3dcca8f208cdecd6b1a4e85b9ed2b5f53701 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/seq.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/seq.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_SEQ_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/sor.hpp b/packages/PEGTL/include/tao/pegtl/internal/sor.hpp index c56bcc2da7a45a08603fd312be5edcc6ba4864c7..0a8fcdf73a718634b8d208fc3f07e40bd2766e04 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/sor.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/sor.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_SOR_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/star.hpp b/packages/PEGTL/include/tao/pegtl/internal/star.hpp index f1353ba238f2d6ac0c74ffa89aae834fcdd22db8..de779dffc5fed4c610e6767b99836efab2628fcb 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/star.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/star.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_STAR_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/star_must.hpp b/packages/PEGTL/include/tao/pegtl/internal/star_must.hpp index 3d276137b5c5e645001ef45f6b48fbfaef0bdf2d..2ac45e42bc2cef61d459ec5d9e8750decb393174 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/star_must.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/star_must.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_STAR_MUST_HPP #define TAO_PEGTL_INTERNAL_STAR_MUST_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/star_must.hpp" +#else + #include "../config.hpp" #include "if_must.hpp" @@ -17,3 +21,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/state.hpp b/packages/PEGTL/include/tao/pegtl/internal/state.hpp index 0fc6cfc0a8e5ccc3ce851bd6fd4f1c017931feed..e86965bf3bf3db50a484044d67741c246d82beeb 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/state.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/state.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_STATE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/string.hpp b/packages/PEGTL/include/tao/pegtl/internal/string.hpp index 3d2f2c433236af5d1bdb8bd299a3592c74ac0cf3..d659ab8b328534096af1e256ab0208285c967083 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/string.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/string.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_STRING_HPP @@ -11,6 +11,7 @@ #include "bump_help.hpp" #include "enable_control.hpp" +#include "one.hpp" #include "result_on_found.hpp" #include "success.hpp" @@ -31,18 +32,26 @@ namespace TAO_PEGTL_NAMESPACE::internal : success {}; + // template< char C > + // struct string + // : one< C > + // {}; + template< char... Cs > struct string { using rule_t = string; using subs_t = empty_list; + template< int Eol > + static constexpr bool can_match_eol = one< result_on_found::success, peek_char, Cs... >::template can_match_eol< Eol >; + template< typename ParseInput > [[nodiscard]] static bool match( ParseInput& in ) noexcept( noexcept( in.size( 0 ) ) ) { if( in.size( sizeof...( Cs ) ) >= sizeof...( Cs ) ) { if( unsafe_equals( in.current(), { Cs... } ) ) { - bump_help< result_on_found::success, ParseInput, char, Cs... >( in, sizeof...( Cs ) ); + bump_help< string >( in, sizeof...( Cs ) ); return true; } } diff --git a/packages/PEGTL/include/tao/pegtl/internal/success.hpp b/packages/PEGTL/include/tao/pegtl/internal/success.hpp index e93caff15a4c6c8d356f9a3357e5e8494da98f6e..03ea08d7d4c394b10e250f7ee3cdd074e9b3a026 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/success.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/success.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_SUCCESS_HPP diff --git a/packages/PEGTL/include/tao/pegtl/internal/try_catch_type.hpp b/packages/PEGTL/include/tao/pegtl/internal/try_catch_type.hpp index 630f3d89e1872e48647fa2e2921a72bb8b0a84e4..4e33287e50ad485bc15f9d54406f29f113a9cbfe 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/try_catch_type.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/try_catch_type.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_TRY_CATCH_TYPE_HPP #define TAO_PEGTL_INTERNAL_TRY_CATCH_TYPE_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/try_catch_type.hpp" +#else + #include <type_traits> #include "../config.hpp" @@ -62,3 +66,4 @@ namespace TAO_PEGTL_NAMESPACE::internal } // namespace TAO_PEGTL_NAMESPACE::internal #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/internal/until.hpp b/packages/PEGTL/include/tao/pegtl/internal/until.hpp index f32e23fb38776731f32427c898a81509783dd785..b5c5e2152c0a85aa8a94d0cdb97bcf8efc2da0af 100644 --- a/packages/PEGTL/include/tao/pegtl/internal/until.hpp +++ b/packages/PEGTL/include/tao/pegtl/internal/until.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_UNTIL_HPP diff --git a/packages/PEGTL/include/tao/pegtl/istream_input.hpp b/packages/PEGTL/include/tao/pegtl/istream_input.hpp index 68a484000fa372b915646e4d7089c85baa35ffa5..893316e5c8e06dd1f19f85c7ffa63c8f34b73f22 100644 --- a/packages/PEGTL/include/tao/pegtl/istream_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/istream_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_ISTREAM_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/match.hpp b/packages/PEGTL/include/tao/pegtl/match.hpp index 6bb87565b83dbe01472890412e2861cc0af31bce..6ac9f6178a1e17f2f103b687af614b4c027eb87c 100644 --- a/packages/PEGTL/include/tao/pegtl/match.hpp +++ b/packages/PEGTL/include/tao/pegtl/match.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_MATCH_HPP @@ -70,6 +70,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > [[nodiscard]] auto match_control_unwind( ParseInput& in, States&&... st ) { +#if defined( __cpp_exceptions ) if constexpr( has_unwind< Control< Rule >, void, const ParseInput&, States... > ) { try { return match_no_control< Rule, A, M, Action, Control >( in, st... ); @@ -82,6 +83,9 @@ namespace TAO_PEGTL_NAMESPACE else { return match_no_control< Rule, A, M, Action, Control >( in, st... ); } +#else + return match_no_control< Rule, A, M, Action, Control >( in, st... ); +#endif } } // namespace internal diff --git a/packages/PEGTL/include/tao/pegtl/memory_input.hpp b/packages/PEGTL/include/tao/pegtl/memory_input.hpp index 6f303f57c002f8dc936c6ca9ec2066c338579bf4..675e8b32fdee7203df98f20622ca50f934fc7137 100644 --- a/packages/PEGTL/include/tao/pegtl/memory_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/memory_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_MEMORY_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/mmap_input.hpp b/packages/PEGTL/include/tao/pegtl/mmap_input.hpp index acc24bbca28508ba862aa17501dd060cb59bc57e..1bd4dce191141af073cf5a0d7eba3c00298e9334 100644 --- a/packages/PEGTL/include/tao/pegtl/mmap_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/mmap_input.hpp @@ -1,10 +1,9 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_MMAP_INPUT_HPP #define TAO_PEGTL_MMAP_INPUT_HPP -#include <filesystem> #include <string> #include "config.hpp" @@ -12,6 +11,7 @@ #include "memory_input.hpp" #include "tracking_mode.hpp" +#include "internal/filesystem.hpp" #include "internal/path_to_string.hpp" #if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) @@ -33,7 +33,7 @@ namespace TAO_PEGTL_NAMESPACE { const file_mapper data; - explicit mmap_holder( const std::filesystem::path& path ) + explicit mmap_holder( const internal::filesystem::path& path ) : data( path ) {} @@ -53,12 +53,12 @@ namespace TAO_PEGTL_NAMESPACE : private internal::mmap_holder, public memory_input< P, Eol > { - mmap_input( const std::filesystem::path& path, const std::string& source ) + mmap_input( const internal::filesystem::path& path, const std::string& source ) : internal::mmap_holder( path ), memory_input< P, Eol >( data.begin(), data.end(), source ) {} - explicit mmap_input( const std::filesystem::path& path ) + explicit mmap_input( const internal::filesystem::path& path ) : mmap_input( path, internal::path_to_string( path ) ) {} diff --git a/packages/PEGTL/include/tao/pegtl/must_if.hpp b/packages/PEGTL/include/tao/pegtl/must_if.hpp index d229ae5711fc221a8e554f1129d595ab5519bca7..0140a57a6693d93f5837f2c54d1e8dd05cfb3920 100644 --- a/packages/PEGTL/include/tao/pegtl/must_if.hpp +++ b/packages/PEGTL/include/tao/pegtl/must_if.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_MUST_IF_HPP #define TAO_PEGTL_MUST_IF_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for tao/pegtl/internal/must.hpp" +#else + #include <type_traits> #include "config.hpp" @@ -62,3 +66,4 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #endif +#endif diff --git a/packages/PEGTL/include/tao/pegtl/normal.hpp b/packages/PEGTL/include/tao/pegtl/normal.hpp index dcb9e4d9430137ba2c5f9822d21e9ac8ae8a999a..ac9d77e26585a8307298e8da256b69b008ee2cf8 100644 --- a/packages/PEGTL/include/tao/pegtl/normal.hpp +++ b/packages/PEGTL/include/tao/pegtl/normal.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_NORMAL_HPP @@ -10,7 +10,6 @@ #include "apply_mode.hpp" #include "config.hpp" -#include "demangle.hpp" #include "match.hpp" #include "parse_error.hpp" #include "rewind_mode.hpp" @@ -18,6 +17,13 @@ #include "internal/enable_control.hpp" #include "internal/has_match.hpp" +#if defined( __cpp_exceptions ) +#include "demangle.hpp" +#else +#include "internal/dependent_false.hpp" +#include <exception> +#endif + namespace TAO_PEGTL_NAMESPACE { template< typename Rule > @@ -40,7 +46,13 @@ namespace TAO_PEGTL_NAMESPACE template< typename ParseInput, typename... States > [[noreturn]] static void raise( const ParseInput& in, States&&... /*unused*/ ) { +#if defined( __cpp_exceptions ) throw parse_error( "parse error matching " + std::string( demangle< Rule >() ), in ); +#else + static_assert( internal::dependent_false< Rule >, "exception support required for normal< Rule >::raise()" ); + (void)in; + std::terminate(); +#endif } template< template< typename... > class Action, diff --git a/packages/PEGTL/include/tao/pegtl/nothing.hpp b/packages/PEGTL/include/tao/pegtl/nothing.hpp index 6c4b759ce9f5fad6d80c5488707f9cdd2158a8e0..302b43555cf55adbc70a9fbdafad9b1451968e18 100644 --- a/packages/PEGTL/include/tao/pegtl/nothing.hpp +++ b/packages/PEGTL/include/tao/pegtl/nothing.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_NOTHING_HPP diff --git a/packages/PEGTL/include/tao/pegtl/parse.hpp b/packages/PEGTL/include/tao/pegtl/parse.hpp index 02528a032f5eab1c3a85911c1dea0a622e907e46..9634655c56791406a8d93101514335dc5b044312 100644 --- a/packages/PEGTL/include/tao/pegtl/parse.hpp +++ b/packages/PEGTL/include/tao/pegtl/parse.hpp @@ -1,16 +1,17 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_PARSE_HPP #define TAO_PEGTL_PARSE_HPP -#include <cassert> +#include <utility> #include "apply_mode.hpp" #include "config.hpp" #include "normal.hpp" #include "nothing.hpp" #include "parse_error.hpp" +#include "position.hpp" #include "rewind_mode.hpp" namespace TAO_PEGTL_NAMESPACE @@ -27,6 +28,33 @@ namespace TAO_PEGTL_NAMESPACE return Control< Rule >::template match< A, M, Action, Control >( in, st... ); } + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + apply_mode A = apply_mode::action, + rewind_mode M = rewind_mode::required, + typename ParseInput, + typename... States > + auto parse_nested( position op, ParseInput&& in, States&&... st ) + { +#if defined( __cpp_exceptions ) + try { + return parse< Rule, Action, Control, A, M >( in, st... ); + } + catch( parse_error& e ) { + e.add_position( std::move( op ) ); + throw; + } +#else + (void)op; + return parse< Rule, Action, Control, A, M >( in, st... ); +#endif + } + + // NOTE: The oi.position() in the version below can be expensive for lazy + // inputs, which is why the version below does not simply call the version + // above with said oi.position() as first parameter. + template< typename Rule, template< typename... > class Action = nothing, template< typename... > class Control = normal, @@ -37,6 +65,7 @@ namespace TAO_PEGTL_NAMESPACE typename... States > auto parse_nested( const OuterInput& oi, ParseInput&& in, States&&... st ) { +#if defined( __cpp_exceptions ) try { return parse< Rule, Action, Control, A, M >( in, st... ); } @@ -44,6 +73,10 @@ namespace TAO_PEGTL_NAMESPACE e.add_position( oi.position() ); throw; } +#else + (void)oi; + return parse< Rule, Action, Control, A, M >( in, st... ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/include/tao/pegtl/parse_error.hpp b/packages/PEGTL/include/tao/pegtl/parse_error.hpp index b2f8741ff7ded4dc6343ec68276761eaee830947..f471fb4205a64f3fd1e228af750e65f5c7677638 100644 --- a/packages/PEGTL/include/tao/pegtl/parse_error.hpp +++ b/packages/PEGTL/include/tao/pegtl/parse_error.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_PARSE_ERROR_HPP @@ -82,7 +82,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename ParseInput > parse_error( const std::string& msg, const ParseInput& in ) - : parse_error( msg.c_str(), in.position() ) + : parse_error( msg, in.position() ) {} [[nodiscard]] const char* what() const noexcept override diff --git a/packages/PEGTL/include/tao/pegtl/position.hpp b/packages/PEGTL/include/tao/pegtl/position.hpp index 7543fdb0ecbee4471381d9640bd0dadc35bd0369..36081668155eed64771b27c4ec3da58a40d48ec3 100644 --- a/packages/PEGTL/include/tao/pegtl/position.hpp +++ b/packages/PEGTL/include/tao/pegtl/position.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_POSITION_HPP @@ -20,12 +20,19 @@ namespace TAO_PEGTL_NAMESPACE { position() = delete; +#if defined( __GNUC__ ) && !defined( __clang__ ) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif position( position&& p ) noexcept : byte( p.byte ), line( p.line ), column( p.column ), source( std::move( p.source ) ) {} +#if defined( __GNUC__ ) && !defined( __clang__ ) +#pragma GCC diagnostic pop +#endif position( const position& ) = default; @@ -48,6 +55,14 @@ namespace TAO_PEGTL_NAMESPACE source( std::forward< T >( in_source ) ) {} + template< typename T > + position( const std::size_t in_byte, const std::size_t in_line, const std::size_t in_column, T&& in_source ) + : byte( in_byte ), + line( in_line ), + column( in_column ), + source( in_source ) + {} + ~position() = default; std::size_t byte; diff --git a/packages/PEGTL/include/tao/pegtl/read_input.hpp b/packages/PEGTL/include/tao/pegtl/read_input.hpp index f830de3b90bad0e4f56fcf966da7933ba3206520..7b748d0930c3feabcd4ac64f60d2d2df47b78c33 100644 --- a/packages/PEGTL/include/tao/pegtl/read_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/read_input.hpp @@ -1,10 +1,9 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_READ_INPUT_HPP #define TAO_PEGTL_READ_INPUT_HPP -#include <filesystem> #include <string> #include "config.hpp" @@ -13,6 +12,7 @@ #include "tracking_mode.hpp" #include "internal/file_reader.hpp" +#include "internal/filesystem.hpp" #include "internal/path_to_string.hpp" namespace TAO_PEGTL_NAMESPACE @@ -21,19 +21,19 @@ namespace TAO_PEGTL_NAMESPACE struct read_input : string_input< P, Eol > { - read_input( const std::filesystem::path& path, const std::string& source ) + read_input( const internal::filesystem::path& path, const std::string& source ) : string_input< P, Eol >( internal::file_reader( path ).read(), source ) {} - explicit read_input( const std::filesystem::path& path ) + explicit read_input( const internal::filesystem::path& path ) : read_input( path, internal::path_to_string( path ) ) {} - read_input( FILE* file, const std::filesystem::path& path, const std::string& source ) + read_input( FILE* file, const internal::filesystem::path& path, const std::string& source ) : string_input< P, Eol >( internal::file_reader( file, path ).read(), source ) {} - read_input( FILE* file, const std::filesystem::path& path ) + read_input( FILE* file, const internal::filesystem::path& path ) : read_input( file, path, internal::path_to_string( path ) ) {} diff --git a/packages/PEGTL/include/tao/pegtl/require_apply.hpp b/packages/PEGTL/include/tao/pegtl/require_apply.hpp index 0bc78fe660852ed09a96ff819c2071e2188722ac..1200909ae8bcd3628f92536e7c3b7fc592b39376 100644 --- a/packages/PEGTL/include/tao/pegtl/require_apply.hpp +++ b/packages/PEGTL/include/tao/pegtl/require_apply.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_REQUIRE_APPLY_HPP diff --git a/packages/PEGTL/include/tao/pegtl/require_apply0.hpp b/packages/PEGTL/include/tao/pegtl/require_apply0.hpp index 1487ae08cb8abed12d6d49621965df14d9ba15d7..368f9b37d26a213ef23962d283e5d0aa845ef940 100644 --- a/packages/PEGTL/include/tao/pegtl/require_apply0.hpp +++ b/packages/PEGTL/include/tao/pegtl/require_apply0.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_REQUIRE_APPLY0_HPP diff --git a/packages/PEGTL/include/tao/pegtl/rewind_mode.hpp b/packages/PEGTL/include/tao/pegtl/rewind_mode.hpp index dfd21c70ac252ffaff14f0756c298e38f17ffc20..48e9dc9528d6f2ce2b671b1a359b2208672a4d7c 100644 --- a/packages/PEGTL/include/tao/pegtl/rewind_mode.hpp +++ b/packages/PEGTL/include/tao/pegtl/rewind_mode.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_REWIND_MODE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/rules.hpp b/packages/PEGTL/include/tao/pegtl/rules.hpp index 09f7ad5d188c881fc8ea08e020cc8b8d2cd98d6b..675098833215d9b2e075d370d7487d9b10f158a8 100644 --- a/packages/PEGTL/include/tao/pegtl/rules.hpp +++ b/packages/PEGTL/include/tao/pegtl/rules.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_RULES_HPP @@ -27,24 +27,17 @@ namespace TAO_PEGTL_NAMESPACE struct eolf : internal::eolf {}; struct failure : internal::failure {}; template< typename Rule, typename... Actions > struct if_apply : internal::if_apply< Rule, Actions... > {}; - template< typename Cond, typename... Thens > struct if_must : internal::if_must< false, Cond, Thens... > {}; - template< typename Cond, typename Then, typename Else > struct if_must_else : internal::if_must_else< Cond, Then, Else > {}; template< typename Cond, typename Then, typename Else > struct if_then_else : internal::if_then_else< Cond, Then, Else > {}; template< typename Rule, typename Sep, typename Pad = void > struct list : internal::list< Rule, internal::pad< Sep, Pad > > {}; template< typename Rule, typename Sep > struct list< Rule, Sep, void > : internal::list< Rule, Sep > {}; - template< typename Rule, typename Sep, typename Pad = void > struct list_must : internal::list_must< Rule, internal::pad< Sep, Pad > > {}; - template< typename Rule, typename Sep > struct list_must< Rule, Sep, void > : internal::list_must< Rule, Sep > {}; template< typename Rule, typename Sep, typename Pad = void > struct list_tail : internal::list_tail_pad< Rule, Sep, Pad > {}; template< typename Rule, typename Sep > struct list_tail< Rule, Sep, void > : internal::list_tail< Rule, Sep > {}; template< typename M, typename S > struct minus : internal::minus< M, S > {}; - template< typename... Rules > struct must : internal::must< Rules... > {}; template< typename... Rules > struct not_at : internal::not_at< Rules... > {}; template< typename... Rules > struct opt : internal::opt< Rules... > {}; - template< typename Cond, typename... Rules > struct opt_must : internal::if_must< true, Cond, Rules... > {}; template< typename Rule, typename Pad1, typename Pad2 = Pad1 > struct pad : internal::pad< Rule, Pad1, Pad2 > {}; template< typename Rule, typename Pad > struct pad_opt : internal::pad_opt< Rule, Pad > {}; template< typename Rule, typename... Rules > struct plus : internal::plus< Rule, Rules... > {}; - template< typename Exception > struct raise : internal::raise< Exception > {}; template< typename Head, typename... Rules > struct rematch : internal::rematch< Head, Rules... > {}; template< unsigned Num, typename... Rules > struct rep : internal::rep< Num, Rules... > {}; template< unsigned Max, typename... Rules > struct rep_max : internal::rep_min_max< 0, Max, Rules... > {}; @@ -55,12 +48,22 @@ namespace TAO_PEGTL_NAMESPACE template< typename... Rules > struct seq : internal::seq< Rules... > {}; template< typename... Rules > struct sor : internal::sor< Rules... > {}; template< typename Rule, typename... Rules > struct star : internal::star< Rule, Rules... > {}; - template< typename Cond, typename... Rules > struct star_must : internal::star_must< Cond, Rules... > {}; template< typename State, typename... Rules > struct state : internal::state< State, Rules... > {}; struct success : internal::success {}; + template< typename Cond, typename... Rules > struct until : internal::until< Cond, Rules... > {}; + +#if defined( __cpp_exceptions ) + template< typename Cond, typename... Thens > struct if_must : internal::if_must< false, Cond, Thens... > {}; + template< typename Cond, typename Then, typename Else > struct if_must_else : internal::if_must_else< Cond, Then, Else > {}; + template< typename Rule, typename Sep, typename Pad = void > struct list_must : internal::list_must< Rule, internal::pad< Sep, Pad > > {}; + template< typename Rule, typename Sep > struct list_must< Rule, Sep, void > : internal::list_must< Rule, Sep > {}; + template< typename... Rules > struct must : internal::must< Rules... > {}; + template< typename Cond, typename... Rules > struct opt_must : internal::if_must< true, Cond, Rules... > {}; + template< typename Exception > struct raise : internal::raise< Exception > {}; + template< typename Cond, typename... Rules > struct star_must : internal::star_must< Cond, Rules... > {}; template< typename... Rules > struct try_catch : internal::try_catch_type< parse_error, Rules... > {}; template< typename Exception, typename... Rules > struct try_catch_type : internal::seq< internal::try_catch_type< Exception, Rules... > > {}; - template< typename Cond, typename... Rules > struct until : internal::until< Cond, Rules... > {}; +#endif // clang-format on } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/include/tao/pegtl/string_input.hpp b/packages/PEGTL/include/tao/pegtl/string_input.hpp index 8bacffbc4d1daffb98a69193a6330aae57b580e4..2d83a6334e887b7b429aa420046abb3dbb488f8b 100644 --- a/packages/PEGTL/include/tao/pegtl/string_input.hpp +++ b/packages/PEGTL/include/tao/pegtl/string_input.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_STRING_INPUT_HPP diff --git a/packages/PEGTL/include/tao/pegtl/tracking_mode.hpp b/packages/PEGTL/include/tao/pegtl/tracking_mode.hpp index d2b8ce871b18c9cb51fc6f3f548f339739c86a5d..18e11f4d11668e96cdd4ae6a0b7a1dcc3eeb94e6 100644 --- a/packages/PEGTL/include/tao/pegtl/tracking_mode.hpp +++ b/packages/PEGTL/include/tao/pegtl/tracking_mode.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_TRACKING_MODE_HPP diff --git a/packages/PEGTL/include/tao/pegtl/type_list.hpp b/packages/PEGTL/include/tao/pegtl/type_list.hpp index a6bfcdfd34baa871a891478e56cb8684b22030f5..243edeb8c15a4229c25729a55505f16d3f6d83cd 100644 --- a/packages/PEGTL/include/tao/pegtl/type_list.hpp +++ b/packages/PEGTL/include/tao/pegtl/type_list.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_TYPE_LIST_HPP diff --git a/packages/PEGTL/include/tao/pegtl/utf8.hpp b/packages/PEGTL/include/tao/pegtl/utf8.hpp index 10db39b39ca022198c16e7a8decb476ebfb1cc4a..f0c0a83a5e3accbef3c61fe1d4b9fe300bd48136 100644 --- a/packages/PEGTL/include/tao/pegtl/utf8.hpp +++ b/packages/PEGTL/include/tao/pegtl/utf8.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_UTF8_HPP @@ -14,7 +14,7 @@ namespace TAO_PEGTL_NAMESPACE::utf8 { // clang-format off struct any : internal::any< internal::peek_utf8 > {}; - struct bom : internal::one< internal::result_on_found::success, internal::peek_utf8, 0xfeff > {}; + struct bom : internal::one< internal::result_on_found::success, internal::peek_utf8, 0xfeff > {}; // Lemon curry? template< char32_t... Cs > struct not_one : internal::one< internal::result_on_found::failure, internal::peek_utf8, Cs... > {}; template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::failure, internal::peek_utf8, Lo, Hi > {}; template< char32_t... Cs > struct one : internal::one< internal::result_on_found::success, internal::peek_utf8, Cs... > {}; diff --git a/packages/PEGTL/include/tao/pegtl/version.hpp b/packages/PEGTL/include/tao/pegtl/version.hpp index 0a78ea4d0fff7d1479895e78c9c2b6844a8c21cd..4d460c536ae80908476227a9aef03d48929d3bea 100644 --- a/packages/PEGTL/include/tao/pegtl/version.hpp +++ b/packages/PEGTL/include/tao/pegtl/version.hpp @@ -1,13 +1,13 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_VERSION_HPP #define TAO_PEGTL_VERSION_HPP -#define TAO_PEGTL_VERSION "3.0.0" +#define TAO_PEGTL_VERSION "3.2.0" #define TAO_PEGTL_VERSION_MAJOR 3 -#define TAO_PEGTL_VERSION_MINOR 0 +#define TAO_PEGTL_VERSION_MINOR 2 #define TAO_PEGTL_VERSION_PATCH 0 #endif diff --git a/packages/PEGTL/include/tao/pegtl/visit.hpp b/packages/PEGTL/include/tao/pegtl/visit.hpp index ad575bd590e87883bae31a46c589321b560b3be3..dfce2f756650804ad3ba2adddb7186416e894fe4 100644 --- a/packages/PEGTL/include/tao/pegtl/visit.hpp +++ b/packages/PEGTL/include/tao/pegtl/visit.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_VISIT_HPP @@ -14,7 +14,17 @@ namespace TAO_PEGTL_NAMESPACE namespace internal { template< typename Type, typename... Types > - inline constexpr bool contains = ( std::is_same_v< Type, Types > || ... ); + inline constexpr bool contains_v = ( std::is_same_v< Type, Types > || ... ); + + template< typename Type, typename... Types > + struct contains + : std::bool_constant< contains_v< Type, Types... > > + {}; + + template< typename Type, typename... Types > + struct contains< Type, type_list< Types... > > + : contains< Type, Types... > + {}; template< typename Rules, typename Todo, typename Done > struct filter @@ -24,41 +34,45 @@ namespace TAO_PEGTL_NAMESPACE template< typename Rule, typename... Rules, typename... Todo, typename... Done > struct filter< type_list< Rule, Rules... >, type_list< Todo... >, type_list< Done... > > - : filter< type_list< Rules... >, std::conditional_t< contains< Rule, Todo..., Done... >, type_list< Todo... >, type_list< Rule, Todo... > >, type_list< Done... > > + : filter< type_list< Rules... >, std::conditional_t< contains_v< Rule, Todo..., Done... >, type_list< Todo... >, type_list< Rule, Todo... > >, type_list< Done... > > {}; template< typename Rules, typename Todo, typename Done > using filter_t = typename filter< Rules, Todo, Done >::type; - template< template< typename... > class Func, typename Done, typename... Rules > - struct visitor + template< typename Done, typename... Rules > + struct visit_list { - template< typename... Args > - static void visit( Args&&... args ) - { - ( Func< Rules >::visit( args... ), ... ); - using NextDone = type_list_concat_t< type_list< Rules... >, Done >; - using NextSubs = type_list_concat_t< typename Rules::subs_t... >; - using NextTodo = filter_t< NextSubs, empty_list, NextDone >; - if constexpr( !std::is_same_v< NextTodo, empty_list > ) { - visit_next< NextDone >( NextTodo(), args... ); - } - } - - private: - template< typename NextDone, typename... NextTodo, typename... Args > - static void visit_next( type_list< NextTodo... > /*unused*/, Args&&... args ) - { - visitor< Func, NextDone, NextTodo... >::visit( args... ); - } + using NextDone = type_list_concat_t< type_list< Rules... >, Done >; + using NextSubs = type_list_concat_t< typename Rules::subs_t... >; + using NextTodo = filter_t< NextSubs, empty_list, NextDone >; + + using type = typename std::conditional_t< std::is_same_v< NextTodo, empty_list >, type_list_concat< NextDone >, visit_list< NextDone, NextTodo > >::type; }; + template< typename Done, typename... Rules > + struct visit_list< Done, type_list< Rules... > > + : visit_list< Done, Rules... > + {}; + + template< template< typename... > class Func, typename... Args, typename... Rules > + void visit( type_list< Rules... > /*unused*/, Args&&... args ) + { + ( Func< Rules >::visit( args... ), ... ); + } + } // namespace internal + template< typename Grammar > + using rule_list_t = typename internal::visit_list< empty_list, Grammar >::type; + + template< typename Grammar, typename Rule > + inline constexpr bool contains_v = internal::contains< Rule, rule_list_t< Grammar > >::value; + template< typename Rule, template< typename... > class Func, typename... Args > void visit( Args&&... args ) { - internal::visitor< Func, empty_list, Rule >::visit( args... ); + internal::visit< Func >( rule_list_t< Rule >(), args... ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/example/pegtl/CMakeLists.txt b/packages/PEGTL/src/example/pegtl/CMakeLists.txt index 0cbdd6288262e34785bd5aef39dff669aeb7d8e2..46ffeb0685ed9dc45b9022c90460bb68e0fcc00c 100644 --- a/packages/PEGTL/src/example/pegtl/CMakeLists.txt +++ b/packages/PEGTL/src/example/pegtl/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.8...3.19) set(example_sources abnf2pegtl.cpp @@ -26,11 +26,14 @@ set(example_sources modulus_match.cpp parse_tree.cpp parse_tree_user_state.cpp + peg2pegtl.cpp proto3.cpp recover.cpp + skipper.cpp s_expression.cpp sum.cpp symbol_table.cpp + token_input.cpp unescape.cpp uri.cpp uri_print_debug.cpp @@ -61,10 +64,10 @@ foreach(examplesourcefile ${example_sources}) else() target_compile_options(${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror) endif() -endforeach(examplesourcefile) +endforeach() if(glob_example_sources) foreach(ignored_source_file ${glob_example_sources}) message(SEND_ERROR "File ${ignored_source_file} in src/example/pegtl is ignored") - endforeach(ignored_source_file) + endforeach() endif() diff --git a/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp b/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp index b019047c937ae57c44cfa5fbb2599f26cbbfd8bb..1a9b0d6b98d58e5cdff1abe7ccbfc4351654f6cb 100644 --- a/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp +++ b/packages/PEGTL/src/example/pegtl/abnf2pegtl.cpp @@ -1,7 +1,8 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <algorithm> +#include <exception> #include <iomanip> #include <iostream> #include <iterator> @@ -278,6 +279,7 @@ namespace TAO_PEGTL_NAMESPACE } // namespace grammar +#if defined( __cpp_exceptions ) // Using must_if<> we define a control class which is used for // the parsing run instead of the default control class. // @@ -315,6 +317,10 @@ namespace TAO_PEGTL_NAMESPACE struct error { template< typename Rule > static constexpr auto message = error_message< Rule >; }; template< typename Rule > using control = must_if< error >::control< Rule >; // clang-format on +#else + template< typename Rule > + using control = normal< Rule >; +#endif // Since we are going to generate a parse tree, we define a // selector that decides which rules will be included in our @@ -431,7 +437,12 @@ namespace TAO_PEGTL_NAMESPACE return *it; } if( keywords.count( v ) != 0 || v.find( "__" ) != std::string::npos ) { +#if defined( __cpp_exceptions ) throw parse_error( '\'' + n->string() + "' is a reserved rulename", n->begin() ); +#else + std::cerr << '\'' + n->string() + "' is a reserved rulename" << std::endl; + std::terminate(); +#endif } if( print_forward_declarations && find_rule( rules_defined, v ) != rules_defined.rend() ) { std::cout << "struct " << v << ";\n"; @@ -479,14 +490,24 @@ namespace TAO_PEGTL_NAMESPACE // when we insert a normal rule, we need to check for duplicates if( op == "=" ) { if( !previous_rules.try_emplace( rname, n.get() ).second ) { +#if defined( __cpp_exceptions ) throw parse_error( "rule '" + rname + "' is already defined", n->begin() ); +#else + std::cerr << "rule '" + rname + "' is already defined" << std::endl; + std::terminate(); +#endif } } // if it is an "incremental alternation", we need to consolidate the assigned alternations else if( op == "=/" ) { const auto p = previous_rules.find( rname ); if( p == previous_rules.end() ) { +#if defined( __cpp_exceptions ) throw parse_error( "incremental alternation '" + rname + "' without previous rule definition", n->begin() ); +#else + std::cerr << "incremental alternation '" + rname + "' without previous rule definition" << std::endl; + std::terminate(); +#endif } auto& previous = p->second->children.back(); @@ -517,7 +538,12 @@ namespace TAO_PEGTL_NAMESPACE n.reset(); } else { +#if defined( __cpp_exceptions ) throw parse_error( "invalid operator '" + op + "', this should not happen!", n->begin() ); +#else + std::cerr << "invalid operator '" + op + "', this should not happen!" << std::endl; + std::terminate(); +#endif } } }; @@ -552,7 +578,12 @@ namespace TAO_PEGTL_NAMESPACE { stringifier nrv; nrv.default_ = []( const node_ptr& n ) -> std::string { +#if defined( __cpp_exceptions ) throw parse_error( "missing to_string() for " + std::string( n->type ), n->begin() ); +#else + std::cerr << "missing to_string() for " + std::string( n->type ) << std::endl; + std::terminate(); +#endif }; nrv.add< grammar::rulename >( []( const node_ptr& n ) { return get_rulename( n, true ); } ); @@ -636,14 +667,24 @@ namespace TAO_PEGTL_NAMESPACE if( star == std::string::npos ) { const auto v = remove_leading_zeroes( rep ); if( v.empty() ) { +#if defined( __cpp_exceptions ) throw parse_error( "repetition of zero not allowed", n->begin() ); +#else + std::cerr << "repetition of zero not allowed" << std::endl; + std::terminate(); +#endif } return prefix + "rep< " + v + ", " + content + " >"; } const auto min = remove_leading_zeroes( rep.substr( 0, star ) ); const auto max = remove_leading_zeroes( rep.substr( star + 1 ) ); if( ( star != rep.size() - 1 ) && max.empty() ) { +#if defined( __cpp_exceptions ) throw parse_error( "repetition maximum of zero not allowed", n->begin() ); +#else + std::cerr << "repetition maximum of zero not allowed" << std::endl; + std::terminate(); +#endif } if( min.empty() && max.empty() ) { return prefix + "star< " + content + " >"; @@ -671,7 +712,12 @@ namespace TAO_PEGTL_NAMESPACE s >> max_val; } if( min_val > max_val ) { +#if defined( __cpp_exceptions ) throw parse_error( "repetition minimum which is greater than the repetition maximum not allowed", n->begin() ); +#else + std::cerr << "repetition minimum which is greater than the repetition maximum not allowed" << std::endl; + std::terminate(); +#endif } if( ( min_val == 1 ) && ( max_val == 1 ) ) { // note: content can not be used here! @@ -722,6 +768,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } file_input in( argv[ 1 ] ); +#if defined( __cpp_exceptions ) try { const auto root = parse_tree::parse< abnf::grammar::rulelist, abnf::selector, nothing, abnf::control >( in ); @@ -739,6 +786,21 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << in.line_at( p ) << '\n' << std::setw( p.column ) << '^' << '\n'; } +#else + if( const auto root = parse_tree::parse< abnf::grammar::rulelist, abnf::selector, nothing, abnf::control >( in ) ) { + for( const auto& rule : root->children ) { + abnf::rules_defined.push_back( abnf::get_rulename( rule->children.front() ) ); + } + + for( const auto& rule : root->children ) { + std::cout << abnf::to_string( rule ) << '\n'; + } + } + else { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif return 0; } diff --git a/packages/PEGTL/src/example/pegtl/analyze.cpp b/packages/PEGTL/src/example/pegtl/analyze.cpp index 1079686f185282854f767525c7ee295ec797ac9d..94b4c9aa5546f5c2b5e55771a6a8fdff91bbcc2c 100644 --- a/packages/PEGTL/src/example/pegtl/analyze.cpp +++ b/packages/PEGTL/src/example/pegtl/analyze.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <tao/pegtl.hpp> @@ -14,13 +14,13 @@ struct foo {}; struct bar - : plus< foo > + : plus< foo > // seq< foo, opt< bar > > {}; int main() // NOLINT(bugprone-exception-escape) { - if( analyze< foo >() != 0 ) { - std::cout << "there are problems" << std::endl; + if( analyze< foo >( 1 ) != 0 ) { + std::cerr << "there are problems" << std::endl; return 1; } return 0; diff --git a/packages/PEGTL/src/example/pegtl/calculator.cpp b/packages/PEGTL/src/example/pegtl/calculator.cpp index 4612216f58fe47efd7d85273f141ea1202217fce..f69110c06f49a2c56ac8be81a6b05ca41e02dbea 100644 --- a/packages/PEGTL/src/example/pegtl/calculator.cpp +++ b/packages/PEGTL/src/example/pegtl/calculator.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cassert> @@ -187,7 +187,7 @@ namespace calculator // Comments are introduced by a '#' and proceed to the end-of-line/file. struct comment - : if_must< one< '#' >, until< eolf > > + : seq< one< '#' >, until< eolf > > {}; // The calculator ignores all spaces and comments; space is a pegtl rule @@ -259,7 +259,7 @@ namespace calculator // proceed with an expression and a ')'. struct bracket - : if_must< one< '(' >, expression, one< ')' > > + : seq< one< '(' >, expression, one< ')' > > {}; // An atomic expression, i.e. one without operators, is either a number or @@ -280,7 +280,7 @@ namespace calculator // The top-level grammar allows one expression and then expects eof. struct grammar - : must< expression, eof > + : seq< expression, eof > {}; // After the grammar we proceed with the additional actions that are @@ -347,13 +347,14 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) for( int i = 1; i < argc; ++i ) { // Parse and process the command-line arguments as calculator expressions... - pegtl::argv_input in( argv, i ); - pegtl::parse< calculator::grammar, calculator::action >( in, b, s ); - - // ...and print the respective results to std::cout. - - std::cout << s.finish() << std::endl; + if( pegtl::parse< calculator::grammar, calculator::action >( in, b, s ) ) { + // ...and print the respective results to std::cout. + std::cout << s.finish() << std::endl; + } + else { + std::cerr << "parse error for: " << argv[ i ] << std::endl; + } } return 0; } diff --git a/packages/PEGTL/src/example/pegtl/chomsky_hierarchy.cpp b/packages/PEGTL/src/example/pegtl/chomsky_hierarchy.cpp index 7624b26f79ec132ebaffecb82210433146e60c3f..a135d3e50da36aa72754944aff4a628cf822c43e 100644 --- a/packages/PEGTL/src/example/pegtl/chomsky_hierarchy.cpp +++ b/packages/PEGTL/src/example/pegtl/chomsky_hierarchy.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cassert> diff --git a/packages/PEGTL/src/example/pegtl/csv1.cpp b/packages/PEGTL/src/example/pegtl/csv1.cpp index b81eb638e402c52302e95a75919d40b0b37c70c4..5bcdb2b336d9952c896eb8a0946e6b37020b5ad3 100644 --- a/packages/PEGTL/src/example/pegtl/csv1.cpp +++ b/packages/PEGTL/src/example/pegtl/csv1.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cassert> @@ -30,8 +30,8 @@ namespace csv1 // clang-format off struct value : pegtl::plus< pegtl::digit > {}; struct value_item : pegtl::pad< value, pegtl::blank > {}; - struct value_list : pegtl::list_must< value_item, pegtl::one< ',' > > {}; - struct value_line : pegtl::if_must< value_list, pegtl::eolf > {}; + struct value_list : pegtl::list< value_item, pegtl::one< ',' > > {}; + struct value_line : pegtl::seq< value_list, pegtl::eolf > {}; struct comment_line : pegtl::seq< pegtl::one< '#' >, pegtl::until< pegtl::eolf > > {}; struct line : pegtl::sor< comment_line, value_line > {}; struct file : pegtl::until< pegtl::eof, line > {}; @@ -91,7 +91,10 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) for( int i = 1; i < argc; ++i ) { pegtl::file_input in( argv[ i ] ); csv1::result_data data; - pegtl::parse< pegtl::must< csv1::file >, csv1::action, csv1::control >( in, data ); + if( !pegtl::parse< pegtl::seq< csv1::file >, csv1::action, csv1::control >( in, data ) ) { + std::cerr << "parse error" << std::endl; + return 1; + } for( const auto& line : data ) { assert( !line.empty() ); // The grammar doesn't allow empty lines. std::cout << line.front(); diff --git a/packages/PEGTL/src/example/pegtl/csv2.cpp b/packages/PEGTL/src/example/pegtl/csv2.cpp index 328744a0e9896590ac17ac14bd004d639f7fffef..fdc363634edb3c8d91663b2ab2df50f469fce561 100644 --- a/packages/PEGTL/src/example/pegtl/csv2.cpp +++ b/packages/PEGTL/src/example/pegtl/csv2.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#include <exception> #include <iostream> #include <utility> @@ -25,7 +26,7 @@ namespace csv2 // clang-format off template< char C > struct string_without : pegtl::star< pegtl::not_one< C, 10, 13 > > {}; struct plain_value : string_without< ',' > {}; - struct quoted_value : pegtl::if_must< pegtl::one< '"' >, string_without< '"' >, pegtl::one< '"' > > {}; + struct quoted_value : pegtl::seq< pegtl::one< '"' >, string_without< '"' >, pegtl::one< '"' > > {}; struct value : pegtl::sor< quoted_value, plain_value > {}; template< unsigned N > struct line : pegtl::seq< value, pegtl::rep< N - 1, pegtl::one< ',' >, value >, pegtl::eol > {}; template< unsigned N > struct file : pegtl::until< pegtl::eof, line< N > > { static_assert( N != 0 ); }; @@ -112,7 +113,8 @@ namespace csv2 static void apply( const ActionInput& in, result_data< N >& data ) { if( data.temp.size() != N ) { - throw pegtl::parse_error( "column count mismatch", in ); + std::cerr << "column count mismatch " << in.position() << std::endl; + std::terminate(); } tuple_t temp; tuple_init< N - 1 >::init( temp, data.temp ); @@ -174,9 +176,13 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) pegtl::file_input in( argv[ i ] ); constexpr unsigned number_of_columns = 3; csv2::result_data< number_of_columns > data; - pegtl::parse< pegtl::must< csv2::file< number_of_columns > >, csv2::action >( in, data ); - for( const auto& line : data.result ) { - csv2::print_tuple( line ); + if( pegtl::parse< pegtl::seq< csv2::file< number_of_columns > >, csv2::action >( in, data ) ) { + for( const auto& line : data.result ) { + csv2::print_tuple( line ); + } + } + else { + std::cerr << "parse error" << std::endl; } } return 0; diff --git a/packages/PEGTL/src/example/pegtl/double.hpp b/packages/PEGTL/src/example/pegtl/double.hpp index c7eedd4dccaea30f45bf819ed31f7117b798622d..8ceec7cd1c61727496bd6ebf378084a52d084552 100644 --- a/packages/PEGTL/src/example/pegtl/double.hpp +++ b/packages/PEGTL/src/example/pegtl/double.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP diff --git a/packages/PEGTL/src/example/pegtl/dynamic_match.cpp b/packages/PEGTL/src/example/pegtl/dynamic_match.cpp index 1f35ee9ec3d15e86bc80f6de9faa3eb8443355c7..73ed8258df709cf2c6f1f6bdc1932ddb5c932d5f 100644 --- a/packages/PEGTL/src/example/pegtl/dynamic_match.cpp +++ b/packages/PEGTL/src/example/pegtl/dynamic_match.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cassert> @@ -56,7 +56,7 @@ namespace dynamic {}; struct grammar - : pegtl::if_must< long_literal_open, pegtl::until< long_literal_close, long_literal_body >, pegtl::eof > + : pegtl::seq< long_literal_open, pegtl::until< long_literal_close, long_literal_body >, pegtl::eof > {}; template< typename Rule > @@ -106,10 +106,14 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) std::string body; pegtl::argv_input in( argv, 1 ); - pegtl::parse< dynamic::grammar, dynamic::action >( in, id, body ); - - std::cout << "long literal id was: " << id << std::endl; - std::cout << "long literal body was: " << body << std::endl; + if( pegtl::parse< dynamic::grammar, dynamic::action >( in, id, body ) ) { + std::cout << "long literal id was: " << id << std::endl; + std::cout << "long literal body was: " << body << std::endl; + } + else { + std::cerr << "parse error for: " << argv[ 1 ] << std::endl; + return 1; + } } return 0; } diff --git a/packages/PEGTL/src/example/pegtl/hello_world.cpp b/packages/PEGTL/src/example/pegtl/hello_world.cpp index 4ff0cd258e0358cedf28edacf4d4a388f39ce624..a15273daf6c28f9f1231aa85a84c62569b2ae01b 100644 --- a/packages/PEGTL/src/example/pegtl/hello_world.cpp +++ b/packages/PEGTL/src/example/pegtl/hello_world.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iostream> @@ -13,7 +13,7 @@ namespace hello // clang-format off struct prefix : pegtl::string< 'H', 'e', 'l', 'l', 'o', ',', ' ' > {}; struct name : pegtl::plus< pegtl::alpha > {}; - struct grammar : pegtl::must< prefix, name, pegtl::one< '!' >, pegtl::eof > {}; + struct grammar : pegtl::seq< prefix, name, pegtl::one< '!' >, pegtl::eof > {}; // clang-format on template< typename Rule > @@ -38,8 +38,11 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) std::string name; pegtl::argv_input in( argv, 1 ); - pegtl::parse< hello::grammar, hello::action >( in, name ); - - std::cout << "Good bye, " << name << "!" << std::endl; + if( pegtl::parse< hello::grammar, hello::action >( in, name ) ) { + std::cout << "Good bye, " << name << "!" << std::endl; + } + else { + std::cerr << "I don't understand." << std::endl; + } } } diff --git a/packages/PEGTL/src/example/pegtl/indent_aware.cpp b/packages/PEGTL/src/example/pegtl/indent_aware.cpp index 27b484aac59b77077e23cd83c9bb6bec136b41b9..0d6c65aacf3af1dd4f35b1c0676011526788dee4 100644 --- a/packages/PEGTL/src/example/pegtl/indent_aware.cpp +++ b/packages/PEGTL/src/example/pegtl/indent_aware.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <cassert> #include <cstddef> #include <iostream> @@ -212,3 +221,5 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/json_analyze.cpp b/packages/PEGTL/src/example/pegtl/json_analyze.cpp index bebef24754afbd5eb1a6c41032ca067c882c347d..ed5c83a2be8961fa3751ed9be20257f9bfb3271e 100644 --- a/packages/PEGTL/src/example/pegtl/json_analyze.cpp +++ b/packages/PEGTL/src/example/pegtl/json_analyze.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iostream> @@ -11,7 +11,7 @@ namespace pegtl = TAO_PEGTL_NAMESPACE; namespace example { - using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; + using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; } // namespace example diff --git a/packages/PEGTL/src/example/pegtl/json_ast.cpp b/packages/PEGTL/src/example/pegtl/json_ast.cpp index ecc8e57a9fa8244cbaa060d8996026999b3d0297..fecaab39a17d51b4d09e989f1d77f148aaade17c 100644 --- a/packages/PEGTL/src/example/pegtl/json_ast.cpp +++ b/packages/PEGTL/src/example/pegtl/json_ast.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iomanip> @@ -15,7 +15,7 @@ namespace pegtl = TAO_PEGTL_NAMESPACE; namespace example { - using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; + using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; template< typename Rule > using selector = pegtl::parse_tree::selector< @@ -39,11 +39,12 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) if( argc != 2 ) { std::cerr << "Usage: " << argv[ 0 ] << " JSON\n" << "Generate a 'dot' file from the JSON text.\n\n" - << "Example: " << argv[ 0 ] << " \"{\"foo\":[42,null]}\" | dot -Tpng -o parse_tree.png\n"; + << "Example: " << argv[ 0 ] << " '{\"foo\":[42,null]}' | dot -Tpng -o parse_tree.png\n"; return 1; } pegtl::argv_input in( argv, 1 ); +#if defined( __cpp_exceptions ) try { const auto root = pegtl::parse_tree::parse< example::grammar, example::selector, pegtl::nothing, example::control >( in ); pegtl::parse_tree::print_dot( std::cout, *root ); @@ -55,6 +56,15 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << std::setw( p.column ) << '^' << std::endl; return 1; } +#else + if( const auto root = pegtl::parse_tree::parse< example::grammar, example::selector, pegtl::nothing, example::control >( in ) ) { + pegtl::parse_tree::print_dot( std::cout, *root ); + } + else { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif return 0; } diff --git a/packages/PEGTL/src/example/pegtl/json_build.cpp b/packages/PEGTL/src/example/pegtl/json_build.cpp index fe8f06f44d1728529c4b34aa9d4aed0f6be572d1..c5e607b7c46047df3ddf93ba8122f6be5e7d0e01 100644 --- a/packages/PEGTL/src/example/pegtl/json_build.cpp +++ b/packages/PEGTL/src/example/pegtl/json_build.cpp @@ -1,7 +1,9 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cassert> +#include <iomanip> +#include <iostream> #include <sstream> #include <vector> @@ -155,19 +157,36 @@ namespace example } }; - using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; + using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; } // namespace example int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc != 2 ) { - std::cerr << "usage: " << argv[ 0 ] << " <json>"; + std::cerr << "usage: " << argv[ 0 ] << " <json>\n"; } else { example::json_state state; pegtl::file_input in( argv[ 1 ] ); - pegtl::parse< example::grammar, example::action, example::control >( in, state ); +#if defined( __cpp_exceptions ) + try { + pegtl::parse< example::grammar, example::action, example::control >( in, state ); + } + catch( const pegtl::parse_error& e ) { + const auto p = e.positions().front(); + std::cerr << e.what() << '\n' + << in.line_at( p ) << '\n' + << std::setw( p.column ) << '^' << std::endl; + return 1; + } +#else + + if( !pegtl::parse< example::grammar, example::action, example::control >( in, state ) ) { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif assert( state.keys.empty() ); assert( state.arrays.empty() ); assert( state.objects.empty() ); diff --git a/packages/PEGTL/src/example/pegtl/json_classes.hpp b/packages/PEGTL/src/example/pegtl/json_classes.hpp index 9b0c8bb1eb9cf574b80fdd1878e18ff0472eaaaf..c9f26de16fc3945cea12f3dcd780e89e47f5c72a 100644 --- a/packages/PEGTL/src/example/pegtl/json_classes.hpp +++ b/packages/PEGTL/src/example/pegtl/json_classes.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_CLASSES_HPP diff --git a/packages/PEGTL/src/example/pegtl/json_count.cpp b/packages/PEGTL/src/example/pegtl/json_count.cpp index ee4bb71c0b22b8e51dcfd07d74fac05cedb9df1c..09bf155ef930b3bdc5b28f00798d49f1a7ab0292 100644 --- a/packages/PEGTL/src/example/pegtl/json_count.cpp +++ b/packages/PEGTL/src/example/pegtl/json_count.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cstddef> @@ -52,7 +52,7 @@ namespace TAO_PEGTL_NAMESPACE using namespace TAO_PEGTL_NAMESPACE; -using grammar = must< json::text, eof >; +using grammar = seq< json::text, eof >; int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { @@ -62,7 +62,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) file_input in( argv[ i ] ); parse< grammar, nothing, counter >( in, cs ); } - std::cout << std::right << std::setw( 72 ) << "RULE NAME" << std::left << " START success FAILURE" << std::endl; + std::cout << std::right << std::setw( 72 ) << "RULE NAME" << std::left << " START SUCCESS FAILURE" << std::endl; for( const auto& j : cs.counts ) { std::cout << std::right << std::setw( 72 ) << j.first << " " << std::setw( 8 ) << j.second.start << " " << std::setw( 8 ) << j.second.success << " " << std::setw( 8 ) << j.second.failure << std::endl; } diff --git a/packages/PEGTL/src/example/pegtl/json_coverage.cpp b/packages/PEGTL/src/example/pegtl/json_coverage.cpp index 3d0ff1657d28288f8d8e457efa5db7b7e46bd375..3748eb16003079d866c8b3c952e090564854ece3 100644 --- a/packages/PEGTL/src/example/pegtl/json_coverage.cpp +++ b/packages/PEGTL/src/example/pegtl/json_coverage.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iomanip> @@ -15,7 +15,7 @@ namespace pegtl = TAO_PEGTL_NAMESPACE; namespace example { - using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; + using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; } // namespace example @@ -28,10 +28,10 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } pegtl::file_input in( argv[ 1 ] ); + pegtl::coverage_result result; +#if defined( __cpp_exceptions ) try { - pegtl::coverage_result result; - pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ); // Ignore return value...? - std::cout << result; + pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ); } catch( const pegtl::parse_error& e ) { const auto p = e.positions().front(); @@ -40,6 +40,13 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << std::setw( p.column ) << '^' << std::endl; return 1; } +#else + if( !pegtl::coverage< example::grammar, pegtl::nothing, example::control >( in, result ) ) { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif + std::cout << result; return 0; } diff --git a/packages/PEGTL/src/example/pegtl/json_errors.hpp b/packages/PEGTL/src/example/pegtl/json_errors.hpp index 847ae6fa5e4f534ea1dbda2227224a0b4c66b8ca..c03d21f75d14b5b668d4e377e6b14330fcc0d5a2 100644 --- a/packages/PEGTL/src/example/pegtl/json_errors.hpp +++ b/packages/PEGTL/src/example/pegtl/json_errors.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_ERRORS_HPP @@ -13,21 +13,21 @@ namespace example { // This file shows how to throw exceptions with // custom error messages for parse errors. - // As the grammar contains must<>-rules, - // the compiler will complain when a - // specialization is missing. + +#if defined( __cpp_exceptions ) // clang-format off template< typename > inline constexpr const char* error_message = nullptr; template<> inline constexpr auto error_message< pegtl::json::text > = "no valid JSON"; + template<> inline constexpr auto error_message< pegtl::json::next_array_element > = "expected value"; template<> inline constexpr auto error_message< pegtl::json::end_array > = "incomplete array, expected ']'"; - template<> inline constexpr auto error_message< pegtl::json::end_object > = "incomplete object, expected '}'"; - template<> inline constexpr auto error_message< pegtl::json::member > = "expected member"; + template<> inline constexpr auto error_message< pegtl::json::name_separator > = "expected ':'"; - template<> inline constexpr auto error_message< pegtl::json::array_element > = "expected value"; - template<> inline constexpr auto error_message< pegtl::json::value > = "expected value"; + template<> inline constexpr auto error_message< pegtl::json::member_value > = "expected value"; + template<> inline constexpr auto error_message< pegtl::json::next_member > = "expected member"; + template<> inline constexpr auto error_message< pegtl::json::end_object > = "incomplete object, expected '}'"; template<> inline constexpr auto error_message< pegtl::json::digits > = "expected at least one digit"; template<> inline constexpr auto error_message< pegtl::json::xdigit > = "incomplete universal character name"; @@ -39,15 +39,21 @@ namespace example template<> inline constexpr auto error_message< pegtl::eof > = "unexpected character after JSON value"; // As must_if<> can not take error_message as a template parameter directly, we need to wrap it. - // Additionally, we make sure only must<>-rules trigger global error. - struct error { - template< typename Rule > static constexpr auto raise_on_failure = false; + struct error + { template< typename Rule > static constexpr auto message = error_message< Rule >; }; template< typename Rule > using control = pegtl::must_if< error >::control< Rule >; // clang-format on +#else + + template< typename Rule > + using control = pegtl::normal< Rule >; + +#endif + } // namespace example #endif diff --git a/packages/PEGTL/src/example/pegtl/json_parse.cpp b/packages/PEGTL/src/example/pegtl/json_parse.cpp index 53cbd81e4b23d45c5bb1233d5afa76e1cbe43e7b..f3c572d12e984765fac7715e966c20a13dfd4248 100644 --- a/packages/PEGTL/src/example/pegtl/json_parse.cpp +++ b/packages/PEGTL/src/example/pegtl/json_parse.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iomanip> @@ -14,7 +14,7 @@ namespace pegtl = TAO_PEGTL_NAMESPACE; namespace example { - using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; + using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; } // namespace example @@ -28,6 +28,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } pegtl::argv_input in( argv, 1 ); +#if defined( __cpp_exceptions ) try { pegtl::parse< example::grammar, pegtl::nothing, example::control >( in ); } @@ -38,6 +39,12 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << std::setw( p.column ) << '^' << std::endl; return 1; } +#else + if( !pegtl::parse< example::grammar, pegtl::nothing, example::control >( in ) ) { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif return 0; } diff --git a/packages/PEGTL/src/example/pegtl/json_print_debug.cpp b/packages/PEGTL/src/example/pegtl/json_print_debug.cpp index 9815d2c1e0fb29446e5321e74c2e0488c04d1b92..ce7b08862b9474aeff3b70be9ee8a392c4d4b577 100644 --- a/packages/PEGTL/src/example/pegtl/json_print_debug.cpp +++ b/packages/PEGTL/src/example/pegtl/json_print_debug.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iostream> diff --git a/packages/PEGTL/src/example/pegtl/json_print_names.cpp b/packages/PEGTL/src/example/pegtl/json_print_names.cpp index 9f97008cf0469dab69603598de2b670a3bfb0ef5..ffb4a929a559691437acad0d70d37513aa6acc7d 100644 --- a/packages/PEGTL/src/example/pegtl/json_print_names.cpp +++ b/packages/PEGTL/src/example/pegtl/json_print_names.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iostream> diff --git a/packages/PEGTL/src/example/pegtl/json_trace.cpp b/packages/PEGTL/src/example/pegtl/json_trace.cpp index 5cba1349f8cbe12123a6dc237aff6f392f15ba6a..0084722c54fdbb7b8fd603de2f137afb62c2947b 100644 --- a/packages/PEGTL/src/example/pegtl/json_trace.cpp +++ b/packages/PEGTL/src/example/pegtl/json_trace.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iomanip> @@ -14,7 +14,7 @@ namespace pegtl = TAO_PEGTL_NAMESPACE; namespace example { - using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; + using grammar = pegtl::seq< pegtl::json::text, pegtl::eof >; } // namespace example @@ -28,6 +28,7 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } pegtl::argv_input in( argv, 1 ); +#if defined( __cpp_exceptions ) try { pegtl::standard_trace< example::grammar, pegtl::nothing, example::control >( in ); } @@ -38,6 +39,12 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) << std::setw( p.column ) << '^' << std::endl; return 1; } +#else + if( !pegtl::standard_trace< example::grammar, pegtl::nothing, example::control >( in ) ) { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif return 0; } diff --git a/packages/PEGTL/src/example/pegtl/json_unescape.hpp b/packages/PEGTL/src/example/pegtl/json_unescape.hpp index 60e30c7beff0eddadd0077f0acb6171e002203ce..79c6074c5668a3d8120f4877bad9f59fa3bfc86b 100644 --- a/packages/PEGTL/src/example/pegtl/json_unescape.hpp +++ b/packages/PEGTL/src/example/pegtl/json_unescape.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_JSON_UNESCAPE_HPP diff --git a/packages/PEGTL/src/example/pegtl/lua53.hpp b/packages/PEGTL/src/example/pegtl/lua53.hpp index 5f040509029fb3e8ef40d450032f92dad2af7dff..3bfc953702c4192849e610eeb9978820331ebe52 100644 --- a/packages/PEGTL/src/example/pegtl/lua53.hpp +++ b/packages/PEGTL/src/example/pegtl/lua53.hpp @@ -1,9 +1,13 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_LUA53_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_LUA53_HPP +#if !defined( __cpp_exceptions ) +#error "Exception support required for lua53.hpp" +#else + #include <tao/pegtl.hpp> #include <tao/pegtl/contrib/raw_string.hpp> @@ -333,3 +337,4 @@ namespace lua53 } // namespace lua53 #endif +#endif diff --git a/packages/PEGTL/src/example/pegtl/lua53_analyze.cpp b/packages/PEGTL/src/example/pegtl/lua53_analyze.cpp index f6d6c847e7c576726bc6e86e6a7effd8929f205a..788ee84bac12b2d034f2c3b203e6eed409a07f8e 100644 --- a/packages/PEGTL/src/example/pegtl/lua53_analyze.cpp +++ b/packages/PEGTL/src/example/pegtl/lua53_analyze.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <tao/pegtl/contrib/analyze.hpp> @@ -15,3 +24,5 @@ int main() // NOLINT(bugprone-exception-escape) } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/lua53_parse.cpp b/packages/PEGTL/src/example/pegtl/lua53_parse.cpp index 6b84aff24753be1b2027d050b7516e390badf282..72c1fddabbb34f5cd8beb78d9d4f69cd4108dde9 100644 --- a/packages/PEGTL/src/example/pegtl/lua53_parse.cpp +++ b/packages/PEGTL/src/example/pegtl/lua53_parse.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include "lua53.hpp" @@ -14,3 +23,5 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/lua53_print_debug.cpp b/packages/PEGTL/src/example/pegtl/lua53_print_debug.cpp index a9303d54ab36b514b7856e36cc3b44d2426b55b3..6703c5a1c14dd05e46069698d264ead0f813a2e7 100644 --- a/packages/PEGTL/src/example/pegtl/lua53_print_debug.cpp +++ b/packages/PEGTL/src/example/pegtl/lua53_print_debug.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <tao/pegtl/contrib/print.hpp> @@ -12,3 +21,5 @@ int main() // NOLINT(bugprone-exception-escape) tao::pegtl::print_debug< lua53::grammar >( std::cout ); return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/lua53_print_names.cpp b/packages/PEGTL/src/example/pegtl/lua53_print_names.cpp index 39bb917e710c1c8f6500279cd5567de3b92c6494..12260a20c889aea9b06a35ce09801a3f31880020 100644 --- a/packages/PEGTL/src/example/pegtl/lua53_print_names.cpp +++ b/packages/PEGTL/src/example/pegtl/lua53_print_names.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <tao/pegtl/contrib/print.hpp> @@ -12,3 +21,5 @@ int main() // NOLINT(bugprone-exception-escape) tao::pegtl::print_names< lua53::grammar >( std::cout ); return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/modulus_match.cpp b/packages/PEGTL/src/example/pegtl/modulus_match.cpp index e748a1940eb8beb72af3392f44a860d8a0143301..f3a7d348d50d26ed23b793412e5472e684842e4e 100644 --- a/packages/PEGTL/src/example/pegtl/modulus_match.cpp +++ b/packages/PEGTL/src/example/pegtl/modulus_match.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <tao/pegtl.hpp> @@ -27,7 +27,7 @@ namespace modulus }; struct grammar - : until< eolf, must< my_rule< 3 > > > + : until< eolf, my_rule< 3 > > {}; } // namespace modulus @@ -36,7 +36,9 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) { if( argc > 1 ) { argv_input in( argv, 1 ); - parse< modulus::grammar >( in ); + if( !parse< modulus::grammar >( in ) ) { + return 1; + } } return 0; } diff --git a/packages/PEGTL/src/example/pegtl/parse_tree.cpp b/packages/PEGTL/src/example/pegtl/parse_tree.cpp index 1ccde1fef374eeb6ad47918a684bb9e2c8e24b61..1a37e3d05bd4dd28b930231e3a27d6a88d063ebd 100644 --- a/packages/PEGTL/src/example/pegtl/parse_tree.cpp +++ b/packages/PEGTL/src/example/pegtl/parse_tree.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <array> @@ -30,12 +30,12 @@ namespace example struct close_bracket : seq< star< space >, one< ')' > > {}; struct expression; - struct bracketed : if_must< open_bracket, expression, close_bracket > {}; + struct bracketed : seq< open_bracket, expression, close_bracket > {}; struct value : sor< integer, variable, bracketed >{}; - struct product : list_must< value, sor< multiply, divide > > {}; - struct expression : list_must< product, sor< plus, minus > > {}; + struct product : list< value, sor< multiply, divide > > {}; + struct expression : list< product, sor< plus, minus > > {}; - struct grammar : must< expression, eof > {}; + struct grammar : seq< expression, eof > {}; // clang-format on // after a node is stored successfully, you can add an optional transformer like this: @@ -169,20 +169,11 @@ int main( int argc, char** argv ) return 1; } argv_input in( argv, 1 ); - try { - const auto root = parse_tree::parse< example::grammar, example::node, example::selector >( in ); + if( const auto root = parse_tree::parse< example::grammar, example::node, example::selector >( in ) ) { parse_tree::print_dot( std::cout, *root ); return 0; } - catch( const parse_error& e ) { - const auto p = e.positions().front(); - std::cerr << e.what() << std::endl - << in.line_at( p ) << std::endl - << std::setw( p.column ) << '^' << std::endl; - } - catch( const std::exception& e ) { - std::cerr << e.what() << std::endl; - } + std::cerr << "parse error" << std::endl; return 1; } diff --git a/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp b/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp index e6baa01cdabbbc5813a3e1c769b4e8d182b8ccd2..7268bca8a3b5372ee197895e33fe155346bc9004 100644 --- a/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp +++ b/packages/PEGTL/src/example/pegtl/parse_tree_user_state.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <type_traits> diff --git a/packages/PEGTL/src/example/pegtl/peg.peg b/packages/PEGTL/src/example/pegtl/peg.peg new file mode 100644 index 0000000000000000000000000000000000000000..99a7c12a89466a1bb6d89a1fae70ed8a06dd418c --- /dev/null +++ b/packages/PEGTL/src/example/pegtl/peg.peg @@ -0,0 +1,37 @@ +# Parsing Expression Grammar (PEG) taken from +# https://pdos.csail.mit.edu/~baford/packrat/popl04/peg-popl04.pdf + +# Hierarchical syntax +Grammar <- Spacing Definition+ EndOfFile +Definition <- Identifier LEFTARROW Expression +Expression <- Sequence (SLASH Sequence)* +Sequence <- Prefix* +Prefix <- (AND / NOT)? Suffix +Suffix <- Primary (QUESTION / STAR / PLUS)? +Primary <- Identifier !LEFTARROW / OPEN Expression CLOSE / Literal / Class / DOT + +# Lexical syntax +Identifier <- IdentStart IdentCont* Spacing +IdentStart <- [a-zA-Z_] +IdentCont <- IdentStart / [0-9] +Literal <- ['] (!['] Char)* ['] Spacing / ["] (!["] Char)* ["] Spacing +Class <- '[' (!']' Range)* ']' Spacing +Range <- Char '-' Char / Char +Char <- '\\' [nrt'"\[\]\\] / '\\' [0-2][0-7][0-7] / '\\' [0-7][0-7]? / !'\\' . + +LEFTARROW <- '<-' Spacing +SLASH <- '/' Spacing +AND <- '&' Spacing +NOT <- '!' Spacing +QUESTION <- '?' Spacing +STAR <- '*' Spacing +PLUS <- '+' Spacing +OPEN <- '(' Spacing +CLOSE <- ')' Spacing +DOT <- '.' Spacing + +Spacing <- (Space / Comment)* +Comment <- '#' (!EndOfLine .)* EndOfLine +Space <- ' ' / '\t' / EndOfLine +EndOfLine <- '\r\n' / '\n' / '\r' +EndOfFile <- !. \ No newline at end of file diff --git a/packages/PEGTL/src/example/pegtl/peg2pegtl.cpp b/packages/PEGTL/src/example/pegtl/peg2pegtl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1ce89438ffe0137163f5e1b2aff5199d1d76306 --- /dev/null +++ b/packages/PEGTL/src/example/pegtl/peg2pegtl.cpp @@ -0,0 +1,539 @@ +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2021 Daniel Deptford +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <algorithm> +#include <iomanip> +#include <iostream> +#include <iterator> +#include <sstream> +#include <string> +#include <unordered_map> +#include <unordered_set> +#include <utility> +#include <vector> + +#include <cassert> +#include <cctype> +#include <cstdlib> + +#if defined( _MSC_VER ) +#include <string.h> +#define TAO_PEGTL_STRCASECMP _stricmp +#else +#include <strings.h> +#define TAO_PEGTL_STRCASECMP strcasecmp +#endif + +#include <tao/pegtl.hpp> +#include <tao/pegtl/contrib/parse_tree.hpp> +#include <tao/pegtl/contrib/peg.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + namespace peg + { + using node_ptr = std::unique_ptr< parse_tree::node >; + + namespace + { + std::string prefix = "tao::pegtl::"; + + std::unordered_set< std::string > keywords = { + "alignas", + "alignof", + "and", + "and_eq", + "asm", + "auto", + "bitand", + "bitor", + "bool", + "break", + "case", + "catch", + "char", + "char8_t", + "char16_t", + "char32_t", + "class", + "compl", + "concept", + "const", + "consteval", + "constexpr", + "constinit", + "const_cast", + "continue", + "co_await", + "co_return", + "co_yield", + "decltype", + "default", + "delete", + "do", + "double", + "dynamic_cast", + "else", + "enum", + "explicit", + "export", + "extern", + "false", + "float", + "for", + "friend", + "goto", + "if", + "inline", + "int", + "long", + "mutable", + "namespace", + "new", + "noexcept", + "not", + "not_eq", + "nullptr", + "operator", + "or", + "or_eq", + "private", + "protected", + "public", + "register", + "reinterpret_cast", + "return", + "requires", + "short", + "signed", + "sizeof", + "static", + "static_assert", + "static_cast", + "struct", + "switch", + "template", + "this", + "thread_local", + "throw", + "true", + "try", + "typedef", + "typeid", + "typename", + "union", + "unsigned", + "using", + "virtual", + "void", + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq" + }; + + using identifiers_t = std::vector< std::string >; + identifiers_t identifiers_defined; + identifiers_t identifiers; + + identifiers_t::reverse_iterator find_identifier( identifiers_t& r, const std::string& v, const identifiers_t::reverse_iterator& rbegin ) + { + return std::find_if( rbegin, r.rend(), [ & ]( const identifiers_t::value_type& p ) { return TAO_PEGTL_STRCASECMP( p.c_str(), v.c_str() ) == 0; } ); + } + + identifiers_t::reverse_iterator find_identifier( identifiers_t& r, const std::string& v ) + { + return find_identifier( r, v, r.rbegin() ); + } + + char char_node_to_char( const node_ptr& n ) + { + const char ch = n->string_view().at( 0 ); + + if( ch == '\\' ) { + static const std::unordered_map< char, char > mappings( { + { 'n', '\n' }, + { 'r', '\r' }, + { 't', '\t' }, + { '\'', '\'' }, + { '\"', '\"' }, + { '[', '[' }, + { ']', ']' }, + { '\\', '\\' }, + } ); + + auto iter = mappings.find( n->string_view().at( 1 ) ); + if( iter != std::end( mappings ) ) { + return iter->second; + } + + return static_cast< char >( std::stoi( n->string().substr( 1 ) ) ); + } + + return ch; + } + + void append_char_node( std::string& s, const node_ptr& n ) + { + if( !s.empty() ) { + s += ", "; + } + s += '\''; + + const char c = char_node_to_char( n ); + + static const std::unordered_map< char, std::string > escapes( { + { '\b', "b" }, + { '\f', "f" }, + { '\n', "n" }, + { '\r', "r" }, + { '\t', "t" }, + { '\v', "v" }, + { '\\', "\\" }, + { '\'', "\'" }, + } ); + + auto iter = escapes.find( c ); + if( iter != std::end( escapes ) ) { + s += '\\'; + s += iter->second; + } + else { + s += c; + } + + s += '\''; + } + + } // namespace + +#if defined( __cpp_exceptions ) + // Using must_if<> we define a control class which is used for + // the parsing run instead of the default control class. + // + // This improves the errors reported to the user. + // + // The following turns local errors into global errors, i.e. + // if one of the rules for which a custom error message is + // defined fails, it throws a parse_error exception (aka global + // failure) instead of returning false (aka local failure). + + // clang-format off + template< typename > inline constexpr const char* error_message = nullptr; + + template<> inline constexpr auto error_message< peg::grammar::Char > = "unterminated character literal"; + template<> inline constexpr auto error_message< peg::grammar::Expression > = "unterminated expression"; + template<> inline constexpr auto error_message< peg::grammar::Grammar > = "unterminated grammar"; + template<> inline constexpr auto error_message< peg::grammar::Range > = "unterminated range"; + + struct error { template< typename Rule > static constexpr auto message = error_message< Rule >; }; + template< typename Rule > using control = must_if< error >::control< Rule >; + // clang-format on +#else + template< typename Rule > + using control = normal< Rule >; +#endif + + // Since we are going to generate a parse tree, we define a + // selector that decides which rules will be included in our + // parse tree, which rules will be omitted from the parse tree, + // and which of the nodes will store the matched content. + // Additionally, some nodes will fold when they have exactly + // one child node. (see fold_one below) + + template< typename Rule > + struct selector + : pegtl::parse_tree::selector< + Rule, + pegtl::parse_tree::store_content::on< + grammar::Definition, + grammar::Prefix, + grammar::Suffix, + grammar::Sequence, + grammar::Expression, + grammar::Class, + grammar::Literal, + grammar::Identifier, + grammar::IdentStart, + grammar::Range, + grammar::Char, + grammar::AND, + grammar::NOT, + grammar::QUESTION, + grammar::STAR, + grammar::PLUS, + grammar::DOT >, + pegtl::parse_tree::fold_one::on< grammar::IdentCont > > + { + template< typename... States > + static void transform( node_ptr& n ) + { + // As we use the PEG grammar taken directly from the original PEG + // paper, some nodes may have excess content from nodes not included + // in the parse tree (e.g. Comment, Space, etc). + if( !n->children.empty() ) { + n->m_end = n->children.back()->m_end; + } + } + }; + + std::string to_string( const node_ptr& n ); + std::string to_string( const std::vector< node_ptr >& v ); + + namespace + { + std::string get_identifier( const node_ptr& n ) + { + assert( n->is_type< grammar::Identifier >() ); + std::string v = n->string(); + std::replace( v.begin(), v.end(), '-', '_' ); + return v; + } + + std::string get_identifier( const node_ptr& n, const bool print_forward_declarations ) + { + std::string v = get_identifier( n ); + const auto it = find_identifier( identifiers, v ); + if( it != identifiers.rend() ) { + return *it; + } + if( keywords.count( v ) != 0 || v.find( "__" ) != std::string::npos ) { +#if defined( __cpp_exceptions ) + throw parse_error( '\'' + n->string() + "' is a reserved identifier", n->begin() ); +#else + std::cerr << '\'' + n->string() + "' is a reserved identifier" << std::endl; + std::terminate(); +#endif + } + if( print_forward_declarations && find_identifier( identifiers_defined, v ) != identifiers_defined.rend() ) { + std::cout << "struct " << v << ";\n"; + } + identifiers.push_back( v ); + return v; + } + + std::unordered_map< std::string, parse_tree::node* > previous_identifiers; + + } // namespace + + template<> + struct selector< grammar::Definition > + : std::true_type + { + template< typename... States > + static void transform( node_ptr& n ) + { + const auto idname = get_identifier( n->children.front() ); + assert( n->children.back()->is_type< grammar::Expression >() ); + if( !previous_identifiers.try_emplace( idname, n.get() ).second ) { +#if defined( __cpp_exceptions ) + throw parse_error( "identifier '" + idname + "' is already defined", n->begin() ); +#else + std::cerr << "identifier '" + idname + "' is already defined" << std::endl; + std::terminate(); +#endif + } + } + }; + + // Finally, the generated parse tree for each node is converted to + // a C++ source code string. + + struct stringifier + { + using function_t = std::string ( * )( const node_ptr& n ); + function_t default_ = nullptr; + + std::unordered_map< std::string_view, function_t > map_; + + template< typename T > + void add( const function_t& f ) + { + map_.try_emplace( demangle< T >(), f ); + } + + std::string operator()( const node_ptr& n ) const + { + const auto it = map_.find( n->type ); + if( it != map_.end() ) { + return it->second( n ); + } + + return default_( n ); + } + }; + + stringifier make_stringifier() + { + stringifier nrv; + nrv.default_ = []( const node_ptr& n ) -> std::string { +#if defined( __cpp_exceptions ) + throw parse_error( "missing to_string() for " + std::string( n->type ), n->begin() ); +#else + std::cerr << "missing to_string() for " + std::string( n->type ) << std::endl; + std::terminate(); +#endif + }; + + nrv.add< grammar::Identifier >( []( const node_ptr& n ) { return get_identifier( n, true ); } ); + + nrv.add< grammar::Definition >( []( const node_ptr& n ) { + return "struct " + get_identifier( n->children.front(), false ) + " : " + to_string( n->children.back() ) + " {};"; + } ); + + nrv.add< grammar::Char >( []( const node_ptr& n ) { + std::string s; + append_char_node( s, n ); + return s; + } ); + + nrv.add< grammar::Sequence >( []( const node_ptr& n ) { + if( n->children.size() == 1 ) { + return to_string( n->children.front() ); + } + + return prefix + "seq< " + to_string( n->children ) + " >"; + } ); + + nrv.add< grammar::Expression >( []( const node_ptr& n ) { + if( n->children.size() == 1 ) { + return to_string( n->children.front() ); + } + + return prefix + "sor< " + to_string( n->children ) + " >"; + } ); + + nrv.add< grammar::Range >( []( const node_ptr& n ) { + if( n->children.size() == 1 ) { + return prefix + "one< " + to_string( n->children.front() ) + " >"; + } + + return prefix + "range< " + to_string( n->children.front() ) + ", " + to_string( n->children.back() ) + " >"; + } ); + + nrv.add< grammar::Class >( []( const node_ptr& n ) { + if( n->children.size() == 1 ) { + return to_string( n->children.front() ); + } + + return prefix + "sor < " + to_string( n->children ) + " >"; + } ); + + nrv.add< grammar::Literal >( []( const node_ptr& n ) { + if( n->children.size() == 1 ) { + return prefix + "one< " + to_string( n->children.front() ) + " >"; + } + + return prefix + "string< " + to_string( n->children ) + " >"; + } ); + + nrv.add< grammar::Prefix >( []( const node_ptr& n ) { + auto sub = to_string( n->children.back() ); + + if( n->children.front()->is_type< grammar::AND >() ) { + return prefix + "at< " + sub + " >"; + } + + if( n->children.front()->is_type< grammar::NOT >() ) { + return prefix + "not_at< " + sub + " >"; + } + + assert( n->children.size() == 1 ); + return sub; + } ); + + nrv.add< grammar::Suffix >( []( const node_ptr& n ) { + auto sub = to_string( n->children.front() ); + + if( n->children.back()->is_type< grammar::QUESTION >() ) { + return prefix + "opt< " + sub + " >"; + } + + if( n->children.back()->is_type< grammar::STAR >() ) { + return prefix + "star< " + sub + " >"; + } + + if( n->children.back()->is_type< grammar::PLUS >() ) { + return prefix + "plus< " + sub + " >"; + } + + assert( n->children.size() == 1 ); + return sub; + } ); + + nrv.add< grammar::DOT >( []( const node_ptr& /*unused*/ ) { + return prefix + "any"; + } ); + + return nrv; + } + + std::string to_string( const node_ptr& n ) + { + static stringifier s = make_stringifier(); + return s( n ); + } + + std::string to_string( const std::vector< node_ptr >& v ) + { + std::string result; + for( const auto& c : v ) { + if( !result.empty() ) { + result += ", "; + } + result += to_string( c ); + } + return result; + } + + } // namespace peg + +} // namespace TAO_PEGTL_NAMESPACE + +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) +{ + using namespace TAO_PEGTL_NAMESPACE; + + if( argc != 2 ) { + std::cerr << "Usage: " << argv[ 0 ] << " SOURCE\n"; + return 1; + } + + file_input in( argv[ 1 ] ); +#if defined( __cpp_exceptions ) + try { + const auto root = parse_tree::parse< peg::grammar::Grammar, peg::selector, nothing, peg::control >( in ); + + for( const auto& definition : root->children ) { + peg::identifiers_defined.push_back( peg::get_identifier( definition->children.front() ) ); + } + + for( const auto& rule : root->children ) { + std::cout << peg::to_string( rule ) << '\n'; + } + } + catch( const parse_error& e ) { + const auto p = e.positions().front(); + std::cerr << e.what() << '\n' + << in.line_at( p ) << '\n' + << std::setw( p.column ) << '^' << '\n'; + } +#else + if( const auto root = parse_tree::parse< peg::grammar::Grammar, peg::selector, nothing, peg::control >( in ) ) { + for( const auto& definition : root->children ) { + peg::identifiers_defined.push_back( peg::get_identifier( definition->children.front() ) ); + } + + for( const auto& rule : root->children ) { + std::cout << peg::to_string( rule ) << '\n'; + } + } + else { + std::cerr << "error occurred" << std::endl; + return 1; + } +#endif + return 0; +} diff --git a/packages/PEGTL/src/example/pegtl/proto3.cpp b/packages/PEGTL/src/example/pegtl/proto3.cpp index 2797187882ecd123bab1c097fa74d572af0f3d5f..4283a8b275007a78fb3fe221cd0abc38561df5ce 100644 --- a/packages/PEGTL/src/example/pegtl/proto3.cpp +++ b/packages/PEGTL/src/example/pegtl/proto3.cpp @@ -1,6 +1,17 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + +#include <iomanip> + #include <tao/pegtl.hpp> #include <tao/pegtl/contrib/analyze.hpp> @@ -132,7 +143,17 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) for( int i = 1; i < argc; ++i ) { file_input in( argv[ i ] ); - parse< proto3::proto >( in ); + try { + parse< proto3::proto >( in ); + } + catch( const parse_error& e ) { + const auto p = e.positions().front(); + std::cerr << e.what() << '\n' + << in.line_at( p ) << '\n' + << std::setw( p.column ) << '^' << '\n'; + } } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/recover.cpp b/packages/PEGTL/src/example/pegtl/recover.cpp index c76a5f9f3199700425203f8d1050d1dcec21ab6c..15baabd5e543bde94ad412b5ecdd1f201e1649e4 100644 --- a/packages/PEGTL/src/example/pegtl/recover.cpp +++ b/packages/PEGTL/src/example/pegtl/recover.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ // This is a small experiment with a grammar that can recover from errors. @@ -11,6 +11,15 @@ // // Try: build/src/example/pegtl/recover '1+2*3;1+2*(3-)-4;-5;6/;7*(8+9)' +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <string> @@ -69,7 +78,7 @@ struct found static void apply( const ActionInput& in, bool& error ) { if( !error ) { - std::cout << in.position() << ": Found " << tao::demangle< R >() << ": \"" << in.string() << "\"" << std::endl; + std::cout << in.position() << ": Found " << demangle< R >() << ": \"" << in.string() << "\"" << std::endl; } } }; @@ -103,7 +112,7 @@ struct my_control template< typename ParseInput, typename... States > [[noreturn]] static void raise( const ParseInput& in, States&&... st ) { - std::cout << in.position() << ": Parse error matching " << tao::demangle< Rule >() << std::endl; + std::cout << in.position() << ": Parse error matching " << demangle< Rule >() << std::endl; normal< Rule >::raise( in, st... ); } }; @@ -117,3 +126,5 @@ int main( int argc, char** argv ) } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/s_expression.cpp b/packages/PEGTL/src/example/pegtl/s_expression.cpp index 8eb4204708e80a9653613de26bfb9f108115c649..28dcace3a280998415d7b1aa2fe713ed244dac61 100644 --- a/packages/PEGTL/src/example/pegtl/s_expression.cpp +++ b/packages/PEGTL/src/example/pegtl/s_expression.cpp @@ -1,6 +1,16 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + +#include <iomanip> #include <iostream> #include <tao/pegtl.hpp> @@ -77,7 +87,17 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) for( int i = 1; i < argc; ++i ) { std::string fn; tao::pegtl::argv_input in( argv, i ); - tao::pegtl::parse< sexpr::main, sexpr::action >( in, fn ); + try { + tao::pegtl::parse< sexpr::main, sexpr::action >( in, fn ); + } + catch( const tao::pegtl::parse_error& e ) { + const auto p = e.positions().front(); + std::cerr << e.what() << '\n' + << in.line_at( p ) << '\n' + << std::setw( p.column ) << '^' << '\n'; + } } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/skipper.cpp b/packages/PEGTL/src/example/pegtl/skipper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd11200bbd16442ff4d90ddd815bc8664b625fb4 --- /dev/null +++ b/packages/PEGTL/src/example/pegtl/skipper.cpp @@ -0,0 +1,88 @@ +// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <iostream> +#include <string> + +#include <tao/pegtl.hpp> +#include <tao/pegtl/contrib/skip.hpp> + +namespace pegtl = TAO_PEGTL_NAMESPACE; + +namespace demo +{ + // define your grammar without concerning yourself with skipping whitespace + + // clang-format off + struct key : pegtl::identifier {}; + struct value : pegtl::identifier {}; + struct assign : pegtl::one< '=' > {}; + struct grammar : pegtl::seq< key, assign, value, pegtl::eof > {}; + // clang-format on + + // define your actions as usual + + template< typename Rule > + struct action + {}; + + template<> + struct action< key > + { + template< typename ActionInput > + static void apply( const ActionInput& in ) + { + std::cout << "key: '" << in.string() << "'\n"; + } + }; + + template<> + struct action< value > + { + template< typename ActionInput > + static void apply( const ActionInput& in ) + { + std::cout << "value: '" << in.string() << "'\n"; + } + }; + + // now specify how and where to skip whitespace + + using skip_how = pegtl::star< pegtl::sor< pegtl::space, pegtl::eol > >; + + // clang-format off + template< typename > inline constexpr bool where = false; + template<> inline constexpr bool where< key > = true; + template<> inline constexpr bool where< value > = true; + // clang-format on + + // as 'skip<>' can not take 'where' as a template parameter directly, we need to wrap it. + struct skip_where + { + // when to skip + template< typename Rule > + static constexpr auto value = where< Rule >; + }; + + template< typename Rule > + using control = pegtl::skip< skip_how, skip_where >::control< Rule >; + + // The above is a first step, the helper (skip<>) may change in the future + // to allow separate skipping before and after and also support different skip + // rules for each rule/set-of-rules. Also, a more convenient way to specify + // the whole thing. + +} // namespace demo + +int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) +{ + if( argc > 1 ) { + pegtl::argv_input in( argv, 1 ); + if( pegtl::parse< demo::grammar, demo::action, demo::control >( in ) ) { + std::cout << "success!" << std::endl; + } + else { + std::cerr << "failure." << std::endl; + } + } +} diff --git a/packages/PEGTL/src/example/pegtl/sum.cpp b/packages/PEGTL/src/example/pegtl/sum.cpp index 196a2a87dd23370e0db1f3a8e82ba2dbdd897405..6a17863cacafb27d70f62bf7e804c77037002326 100644 --- a/packages/PEGTL/src/example/pegtl/sum.cpp +++ b/packages/PEGTL/src/example/pegtl/sum.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cstdlib> diff --git a/packages/PEGTL/src/example/pegtl/symbol_table.cpp b/packages/PEGTL/src/example/pegtl/symbol_table.cpp index 75a520135bc31b9202ef01e6c6673cb1ca8f5f83..673174c9b88e8033b8c7db4d118e6161ca932d7a 100644 --- a/packages/PEGTL/src/example/pegtl/symbol_table.cpp +++ b/packages/PEGTL/src/example/pegtl/symbol_table.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <cstring> #include <iostream> #include <map> @@ -105,3 +114,5 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/token_input.cpp b/packages/PEGTL/src/example/pegtl/token_input.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f03dad7ec91668e27c9fe9b3157a9d21f0cdf95 --- /dev/null +++ b/packages/PEGTL/src/example/pegtl/token_input.cpp @@ -0,0 +1,274 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <iostream> +#include <string> +#include <vector> + +#include <tao/pegtl.hpp> + +#include <tao/pegtl/contrib/analyze_traits.hpp> + +// This file contains some experiments towards generalising inputs to +// represent sequences of arbitrary objects; it's not very complete, but +// it does get a minimal example up-and-running. One main limitation is +// that nothing that throws a parse_error can be used because positions +// aren't supported by the token_parse_input. + +namespace TAO_PEGTL_NAMESPACE +{ + template< typename ParseInput > + class token_action_input + { + public: + using input_t = ParseInput; + using value_t = typename ParseInput::value_t; + using iterator_t = typename ParseInput::iterator_t; + + token_action_input( const iterator_t& in_begin, const ParseInput& in_input ) noexcept + : m_begin( in_begin ), + m_input( in_input ) + {} + + token_action_input( const token_action_input& ) = delete; + token_action_input( token_action_input&& ) = delete; + + ~token_action_input() = default; + + token_action_input operator=( const token_action_input& ) = delete; + token_action_input operator=( token_action_input&& ) = delete; + + [[nodiscard]] const iterator_t& iterator() const noexcept + { + return m_begin; + } + + [[nodiscard]] const ParseInput& input() const noexcept + { + return m_input; + } + + [[nodiscard]] iterator_t begin() const noexcept + { + return m_begin; + } + + [[nodiscard]] iterator_t end() const noexcept + { + return m_input.current(); + } + + [[nodiscard]] bool empty() const noexcept + { + return begin() == end(); + } + + [[nodiscard]] std::size_t size() const noexcept + { + return std::size_t( end() - begin() ); + } + + protected: + const iterator_t m_begin; + const ParseInput& m_input; + }; + + template< typename T, typename Source = std::string > + class token_parse_input + { + public: + using value_t = T; + using source_t = Source; + using iterator_t = const T*; + + using action_t = token_action_input< token_parse_input >; + + template< typename S > + token_parse_input( const iterator_t in_begin, const iterator_t in_end, S&& in_source ) + : m_begin( in_begin ), + m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< S >( in_source ) ) + {} + + template< typename S > + token_parse_input( const std::vector< T >& in_vector, S&& in_source ) + : token_parse_input( in_vector.data(), in_vector.data() + in_vector.size(), std::forward< S >( in_source ) ) + {} + + token_parse_input( const token_parse_input& ) = delete; + token_parse_input( token_parse_input&& ) = delete; + + ~token_parse_input() = default; + + token_parse_input operator=( const token_parse_input& ) = delete; + token_parse_input operator=( token_parse_input&& ) = delete; + + void discard() const noexcept {} + + void require( const std::size_t /*unused*/ ) const noexcept {} + + [[nodiscard]] iterator_t current() const noexcept + { + return m_current; + } + + [[nodiscard]] iterator_t begin() const noexcept + { + return m_begin; + } + + [[nodiscard]] iterator_t end( const std::size_t /*unused*/ = 0 ) const noexcept + { + return m_end; + } + + [[nodiscard]] std::size_t byte() const noexcept + { + return std::size_t( m_current - m_begin ); // We don't return the byte offset even if this function is still called 'byte'. + } + + template< rewind_mode M > + [[nodiscard]] internal::marker< iterator_t, M > mark() noexcept + { + return internal::marker< iterator_t, M >( iterator() ); + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + std::advance( m_current, in_count ); + } + + void restart() + { + m_current = m_begin; + } + + [[nodiscard]] const Source& source() const noexcept + { + return this->m_source; + } + + [[nodiscard]] bool empty() const noexcept + { + return this->current() == this->end(); + } + + [[nodiscard]] std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept + { + return std::size_t( this->end() - this->current() ); + } + + [[nodiscard]] T peek_token( const std::size_t offset = 0 ) const noexcept + { + return this->current()[ offset ]; + } + + [[nodiscard]] iterator_t& iterator() noexcept + { + return this->m_current; + } + + [[nodiscard]] const iterator_t& iterator() const noexcept + { + return this->m_current; + } + + private: + const iterator_t m_begin; + iterator_t m_current; + const iterator_t m_end; + const Source m_source; + }; + + namespace internal + { + template< typename Type, Type Value > + struct token_type + { + using rule_t = token_type; + using subs_t = empty_list; + + template< typename ParseInput > + static bool match( ParseInput& in ) + { + if( ( !in.empty() ) && ( in.peek_token().type == Value ) ) { + in.bump( 1 ); + return true; + } + return false; + } + }; + + } // namespace internal + + template< auto Value > + using token_type = internal::token_type< decltype( Value ), Value >; + + template< typename Name, typename Type, Type Value > + struct analyze_traits< Name, internal::token_type< Type, Value > > + : analyze_any_traits<> + {}; + +} // namespace TAO_PEGTL_NAMESPACE + +using namespace TAO_PEGTL_NAMESPACE; + +enum my_type +{ + a, + b, + c, + d, + e, + f +}; + +struct my_token +{ + my_type type; + std::string data; +}; + +template< typename Rule > +struct my_action + : nothing< Rule > +{}; + +template<> +struct my_action< eof > +{ + static void apply0() + { + std::cout << "We have eof!" << std::endl; + } +}; + +template<> +struct my_action< token_type< my_type::b > > +{ + template< typename ActionInput > + static void apply( const ActionInput& /*unused*/ ) + { + std::cout << "We have a token of type 'b'!" << std::endl; + } +}; + +struct my_grammar + : seq< plus< token_type< my_type::b > >, eof > +{}; + +int main() +{ + const std::vector< my_token > v{ + { my_type::b, "" }, + { my_type::b, "" } + }; + + token_parse_input< my_token > in( v, __FUNCTION__ ); + if( !parse< my_grammar, my_action >( in ) ) { + return 1; + } + + return 0; +} diff --git a/packages/PEGTL/src/example/pegtl/unescape.cpp b/packages/PEGTL/src/example/pegtl/unescape.cpp index 8296ce0400b8b68ca827fcb2cf491b735f9c968d..f445435b112989cf8215bfa7e0dbae0b2983e012 100644 --- a/packages/PEGTL/src/example/pegtl/unescape.cpp +++ b/packages/PEGTL/src/example/pegtl/unescape.cpp @@ -1,10 +1,9 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iostream> #include <tao/pegtl.hpp> - #include <tao/pegtl/contrib/unescape.hpp> using namespace TAO_PEGTL_NAMESPACE; @@ -18,9 +17,9 @@ namespace example // - A backslash followed by one of the characters listed in the grammar below. // clang-format off - struct escaped_x : seq< one< 'x' >, rep< 2, must< xdigit > > > {}; - struct escaped_u : seq< one< 'u' >, rep< 4, must< xdigit > > > {}; - struct escaped_U : seq< one< 'U' >, rep< 8, must< xdigit > > > {}; + struct escaped_x : seq< one< 'x' >, rep< 2, xdigit > > {}; + struct escaped_u : seq< one< 'u' >, rep< 4, xdigit > > {}; + struct escaped_U : seq< one< 'U' >, rep< 8, xdigit > > {}; struct escaped_c : one< '\'', '"', '?', '\\', 'a', 'b', 'f', 'n', 'r', 't', 'v' > {}; struct escaped : sor< escaped_x, @@ -28,10 +27,10 @@ namespace example escaped_U, escaped_c > {}; - struct character : if_must_else< one< '\\' >, escaped, utf8::range< 0x20, 0x10FFFF > > {}; - struct literal : if_must< one< '"' >, until< one< '"' >, character > > {}; + struct character : if_then_else< one< '\\' >, escaped, utf8::range< 0x20, 0x10FFFF > > {}; + struct literal : seq< one< '"' >, until< one< '"' >, character > > {}; - struct padded : must< pad< literal, blank >, eof > {}; + struct padded : seq< pad< literal, blank >, eof > {}; // Action class that uses the actions from tao/pegtl/contrib/unescape.hpp to // produce a UTF-8 encoded result string where all escape sequences are @@ -53,8 +52,12 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) for( int i = 1; i < argc; ++i ) { std::string s; argv_input in( argv, i ); - parse< example::padded, example::action >( in, s ); - std::cout << "argv[ " << i << " ] = " << s << std::endl; + if( parse< example::padded, example::action >( in, s ) ) { + std::cout << "argv[ " << i << " ] = " << s << std::endl; + } + else { + std::cerr << "error parsing: " << argv[ i ] << std::endl; + } } return 0; } diff --git a/packages/PEGTL/src/example/pegtl/uri.cpp b/packages/PEGTL/src/example/pegtl/uri.cpp index 38559c574b1c0f928248b42786c05b5225731ca0..413caf99e6349678ec116735972cd4b8f3d8453e 100644 --- a/packages/PEGTL/src/example/pegtl/uri.cpp +++ b/packages/PEGTL/src/example/pegtl/uri.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <tao/pegtl.hpp> #include <tao/pegtl/contrib/uri.hpp> @@ -87,3 +96,5 @@ int main( int argc, char** argv ) } return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/uri_print_debug.cpp b/packages/PEGTL/src/example/pegtl/uri_print_debug.cpp index 25858179b541efb9f646892944be31b630b55315..10e42f2433cbfc6c9afbca6ed5ebd55330b55401 100644 --- a/packages/PEGTL/src/example/pegtl/uri_print_debug.cpp +++ b/packages/PEGTL/src/example/pegtl/uri_print_debug.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <tao/pegtl/contrib/print.hpp> @@ -11,3 +20,5 @@ int main() // NOLINT(bugprone-exception-escape) tao::pegtl::print_debug< tao::pegtl::uri::URI >( std::cout ); return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/uri_print_names.cpp b/packages/PEGTL/src/example/pegtl/uri_print_names.cpp index 6867333364e527b20fe24fd76e72f3e33f8368d9..708c3e71113b6844da410a7d7b46926c61d58b96 100644 --- a/packages/PEGTL/src/example/pegtl/uri_print_names.cpp +++ b/packages/PEGTL/src/example/pegtl/uri_print_names.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <tao/pegtl/contrib/print.hpp> @@ -11,3 +20,5 @@ int main() // NOLINT(bugprone-exception-escape) tao::pegtl::print_names< tao::pegtl::uri::URI >( std::cout ); return 0; } + +#endif diff --git a/packages/PEGTL/src/example/pegtl/uri_trace.cpp b/packages/PEGTL/src/example/pegtl/uri_trace.cpp index 14a3a29588640562d1f2f73d4ad7cfb71c7abaf0..e1392f85a54f967ffa563b89e82f2530c97d9214 100644 --- a/packages/PEGTL/src/example/pegtl/uri_trace.cpp +++ b/packages/PEGTL/src/example/pegtl/uri_trace.cpp @@ -1,6 +1,15 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cerr << "Exception support required, example unavailable." << std::endl; + return 1; +} +#else + #include <iostream> #include <tao/pegtl.hpp> @@ -20,3 +29,5 @@ int main( int argc, char** argv ) // NOLINT(bugprone-exception-escape) } return 0; } + +#endif diff --git a/packages/PEGTL/src/test/pegtl/CMakeLists.txt b/packages/PEGTL/src/test/pegtl/CMakeLists.txt index 446ef2921f64949a984155553cf0c099a6bcecf3..889b0520af98201aeeead2caaeef175fa0503578 100644 --- a/packages/PEGTL/src/test/pegtl/CMakeLists.txt +++ b/packages/PEGTL/src/test/pegtl/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.8...3.19) set(test_sources action_enable.cpp @@ -23,20 +23,31 @@ set(test_sources change_action_and_states.cpp change_state.cpp change_states.cpp + contains.cpp contrib_alphabet.cpp contrib_analyze.cpp contrib_control_action.cpp + contrib_coverage.cpp + contrib_function.cpp contrib_http.cpp contrib_if_then.cpp + contrib_instantiate.cpp contrib_integer.cpp contrib_json.cpp contrib_parse_tree.cpp + contrib_parse_tree_to_dot.cpp contrib_partial_trace.cpp + contrib_predicates.cpp + contrib_print.cpp contrib_raw_string.cpp + contrib_remove_first_state.cpp + contrib_remove_last_states.cpp contrib_rep_one_min_max.cpp + contrib_rep_string.cpp contrib_state_control.cpp contrib_to_string.cpp - contrib_tracer.cpp + contrib_trace1.cpp + contrib_trace2.cpp contrib_unescape.cpp contrib_uri.cpp control_unwind.cpp @@ -50,12 +61,14 @@ set(test_sources file_istream.cpp file_mmap.cpp file_read.cpp + icu_general.cpp internal_endian.cpp internal_file_mapper.cpp internal_file_opener.cpp parse_error.cpp pegtl_string_t.cpp position.cpp + restart_input.cpp rule_action.cpp rule_apply0.cpp rule_apply.cpp @@ -100,7 +113,9 @@ set(test_sources rule_success.cpp rule_try_catch.cpp rule_until.cpp - tester.cpp + test_empty.cpp + test_result.cpp + test_setup.cpp uint16_general.cpp uint32_general.cpp uint64_general.cpp @@ -108,6 +123,7 @@ set(test_sources utf16_general.cpp utf32_general.cpp utf8_general.cpp + visit.cpp ) # file(GLOB ...) is used to validate the above list of test_sources @@ -138,10 +154,10 @@ foreach(testsourcefile ${test_sources}) else() add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${exename}) endif() -endforeach(testsourcefile) +endforeach() if(glob_test_sources) foreach(ignored_source_file ${glob_test_sources}) message(SEND_ERROR "File ${ignored_source_file} in src/test/pegtl is ignored") - endforeach(ignored_source_file) + endforeach() endif() diff --git a/packages/PEGTL/src/test/pegtl/action_enable.cpp b/packages/PEGTL/src/test/pegtl/action_enable.cpp index 148973c5183350eb0a5ad564d94cfc04d2339d50..eaead46a3d235a9c6ac867392e5d6b72435680b0 100644 --- a/packages/PEGTL/src/test/pegtl/action_enable.cpp +++ b/packages/PEGTL/src/test/pegtl/action_enable.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/action_match.cpp b/packages/PEGTL/src/test/pegtl/action_match.cpp index c6205367a777f8fd3e982f011a6641e8aa23aecf..f8f448c44fb1cce6fa4939550b4cd888e838d291 100644 --- a/packages/PEGTL/src/test/pegtl/action_match.cpp +++ b/packages/PEGTL/src/test/pegtl/action_match.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/actions_one.cpp b/packages/PEGTL/src/test/pegtl/actions_one.cpp index 40128c1680bcc28b83eb49d148790449454cffc2..9e8998c3050b023150ca1351e7db223cb5307319 100644 --- a/packages/PEGTL/src/test/pegtl/actions_one.cpp +++ b/packages/PEGTL/src/test/pegtl/actions_one.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -14,7 +14,7 @@ namespace TAO_PEGTL_NAMESPACE namespace test1 { struct fiz - : if_must< at< one< 'a' > >, two< 'a' > > + : seq< at< one< 'a' > >, two< 'a' > > {}; struct foo @@ -29,16 +29,16 @@ namespace TAO_PEGTL_NAMESPACE { TAO_PEGTL_TEST_ASSERT( applied.size() == 10 ); - TAO_PEGTL_TEST_ASSERT( applied[ 0 ].first == tao::demangle< one< 'b' > >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 1 ].first == tao::demangle< foo >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 2 ].first == tao::demangle< at< one< 'a' > > >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 3 ].first == tao::demangle< two< 'a' > >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 4 ].first == tao::demangle< fiz >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 5 ].first == tao::demangle< foo >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 6 ].first == tao::demangle< one< 'b' > >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 7 ].first == tao::demangle< foo >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 8 ].first == tao::demangle< eof >() ); - TAO_PEGTL_TEST_ASSERT( applied[ 9 ].first == tao::demangle< bar >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 0 ].first == demangle< one< 'b' > >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 1 ].first == demangle< foo >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 2 ].first == demangle< at< one< 'a' > > >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 3 ].first == demangle< two< 'a' > >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 4 ].first == demangle< fiz >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 5 ].first == demangle< foo >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 6 ].first == demangle< one< 'b' > >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 7 ].first == demangle< foo >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 8 ].first == demangle< eof >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 9 ].first == demangle< bar >() ); TAO_PEGTL_TEST_ASSERT( applied[ 0 ].second == "b" ); TAO_PEGTL_TEST_ASSERT( applied[ 1 ].second == "b" ); @@ -60,7 +60,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename ActionInput > static void apply( const ActionInput& in ) { - applied.emplace_back( tao::demangle< Rule >(), in.string() ); + applied.emplace_back( demangle< Rule >(), in.string() ); } }; @@ -69,7 +69,7 @@ namespace TAO_PEGTL_NAMESPACE parse< disable< test1::bar >, test_action >( memory_input( "baab", __FUNCTION__ ) ); TAO_PEGTL_TEST_ASSERT( applied.size() == 1 ); - TAO_PEGTL_TEST_ASSERT( applied[ 0 ].first == tao::demangle< disable< test1::bar > >() ); + TAO_PEGTL_TEST_ASSERT( applied[ 0 ].first == demangle< disable< test1::bar > >() ); TAO_PEGTL_TEST_ASSERT( applied[ 0 ].second == "baab" ); applied.clear(); diff --git a/packages/PEGTL/src/test/pegtl/actions_three.cpp b/packages/PEGTL/src/test/pegtl/actions_three.cpp index 992d655b9dd01d36ee4a5e16325efe568ccdc0f5..8f9fa9b351026eeddd2137253ca72242a013dff7 100644 --- a/packages/PEGTL/src/test/pegtl/actions_three.cpp +++ b/packages/PEGTL/src/test/pegtl/actions_three.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/actions_two.cpp b/packages/PEGTL/src/test/pegtl/actions_two.cpp index d3dcb224ee3d83324ca39e5eebd72ea6d95338da..40f736757f87ad9ca519800a5a2b4c91a6e4e83e 100644 --- a/packages/PEGTL/src/test/pegtl/actions_two.cpp +++ b/packages/PEGTL/src/test/pegtl/actions_two.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -116,8 +116,7 @@ namespace TAO_PEGTL_NAMESPACE { const char* foo = "f"; memory_input in( foo, foo + 1, count_source, count_byte, count_line, count_column ); - const auto result = parse< must< alpha >, count_action >( in ); - TAO_PEGTL_TEST_ASSERT( result ); + TAO_PEGTL_TEST_ASSERT( parse< alpha, count_action >( in ) ); } } // namespace test1 diff --git a/packages/PEGTL/src/test/pegtl/argv_input.cpp b/packages/PEGTL/src/test/pegtl/argv_input.cpp index 2c649d504e7a5e65c9c2ee1c0fb75de8de7bb89c..933e29c06d71351a1401bc8c3388222749b2e5db 100644 --- a/packages/PEGTL/src/test/pegtl/argv_input.cpp +++ b/packages/PEGTL/src/test/pegtl/argv_input.cpp @@ -1,12 +1,10 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cstring> #include "test.hpp" -#include <tao/pegtl.hpp> - namespace TAO_PEGTL_NAMESPACE { void unit_test() diff --git a/packages/PEGTL/src/test/pegtl/ascii_classes.cpp b/packages/PEGTL/src/test/pegtl/ascii_classes.cpp index 8271091cbe15d587337bf8d17b5016d758a096eb..2989634c00709cdcba9c79f14357dd046436e1ab 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_classes.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_classes.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_eol.cpp b/packages/PEGTL/src/test/pegtl/ascii_eol.cpp index 2d46c03a5b49600fd060201f49afc863c43862f4..851eba98f5009ac9ec68bd4120ea85558729f98d 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_eol.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_eol.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_eolf.cpp b/packages/PEGTL/src/test/pegtl/ascii_eolf.cpp index c91c155100b4e230c32cf559d5f6b6b3c26201c6..c0016df14de850706cf4cbe9bc9c2e03fe0c4fc8 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_eolf.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_eolf.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_forty_two.cpp b/packages/PEGTL/src/test/pegtl/ascii_forty_two.cpp index 1bbc0c01db01dda98b504969936f5971fa05783f..efcafff31a8e8f646a76f4651ddd5abad1b4822b 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_forty_two.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_forty_two.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_identifier.cpp b/packages/PEGTL/src/test/pegtl/ascii_identifier.cpp index 5d521d4d2745c74b286ef486b0f08cfd7524f3d0..2e97e5851660647a367a4e2cfdcea2661d791ecd 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_identifier.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_identifier.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_istring.cpp b/packages/PEGTL/src/test/pegtl/ascii_istring.cpp index b29b8a6eceafe1771a7f2b0d8b7e3334954b3e4d..a5a74e8b84e752222b5f373547ce64eaf63a9926 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_istring.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_istring.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_keyword.cpp b/packages/PEGTL/src/test/pegtl/ascii_keyword.cpp index 6959625add9b26b1a96ea6828573039e4ad33591..d4b6dd128622d17847510e9064d025c3865a53ad 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_keyword.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_keyword.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_shebang.cpp b/packages/PEGTL/src/test/pegtl/ascii_shebang.cpp index 47d9bc9b3a82dcfb6a73e7c81c84f18dd5e3ea9a..3f030ee5e8f98bbe904a5e27789eb62df12b7153 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_shebang.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_shebang.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_string.cpp b/packages/PEGTL/src/test/pegtl/ascii_string.cpp index bc97c6f947902773937886792ee2e6937dc0bc63..9712d3132c547be18520f65ee2e20000fef14527 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_string.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_string.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_three.cpp b/packages/PEGTL/src/test/pegtl/ascii_three.cpp index e6341dcc4bb1df8c019324eabd0c5434ff5494e6..2b0b1c03e6e5bf6f6b9d220cceb3fde2c4ed5eb1 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_three.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_three.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/ascii_two.cpp b/packages/PEGTL/src/test/pegtl/ascii_two.cpp index 5ca9d36b00716d44f8ed924e1ef421c648bbba19..5326620bdbfa59fca923239148bf68d82ea5d3b0 100644 --- a/packages/PEGTL/src/test/pegtl/ascii_two.cpp +++ b/packages/PEGTL/src/test/pegtl/ascii_two.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/buffer_input.cpp b/packages/PEGTL/src/test/pegtl/buffer_input.cpp index 65e696151d038f015aaba5093f47b1a15f24c7d6..e5ab52ba1d502b34ec20923ea59787fe187e7fd3 100644 --- a/packages/PEGTL/src/test/pegtl/buffer_input.cpp +++ b/packages/PEGTL/src/test/pegtl/buffer_input.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <string> @@ -25,15 +25,19 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( parse_cstring< seq< string< 'a', 'b', 'c' >, eof > >( "abc", TAO_TEST_LINE, 128 ) ); // We need one extra byte in the buffer so that eof calling in.empty() calling in.require( 1 ) does not throw a "require beyond end of buffer" exception. +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( parse_cstring< seq< rep< chunk_size + 2, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 2 ), 'a' ).c_str(), TAO_TEST_LINE, 2 ) ); +#endif TAO_PEGTL_TEST_ASSERT( parse_cstring< seq< rep< chunk_size + 2, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 2 ), 'a' ).c_str(), TAO_TEST_LINE, 3 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< chunk_size + 9, one< 'a' > > >( std::string( std::size_t( chunk_size + 9 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< chunk_size + 9, one< 'a' > > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( parse_cstring< rep< chunk_size + 10, one< 'a' > > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) ); TAO_PEGTL_TEST_THROWS( parse_cstring< rep< chunk_size + 10, one< 'a' > > >( std::string( std::size_t( chunk_size + 11 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) ); TAO_PEGTL_TEST_THROWS( parse_cstring< seq< rep< chunk_size + 10, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 9 ) ); TAO_PEGTL_TEST_THROWS( parse_cstring< seq< rep< chunk_size + 10, one< 'a' > >, eof > >( std::string( std::size_t( chunk_size + 10 ), 'a' ).c_str(), TAO_TEST_LINE, 10 ) ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/change_action_and_state.cpp b/packages/PEGTL/src/test/pegtl/change_action_and_state.cpp index abbaaa5e1ae2622bf23e30a395188753e19d9cf9..a631f9dc02016cc9267d794f0a9032d08a7f0751 100644 --- a/packages/PEGTL/src/test/pegtl/change_action_and_state.cpp +++ b/packages/PEGTL/src/test/pegtl/change_action_and_state.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -24,9 +24,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& c ) { - if( c != 0 ) { - throw std::runtime_error( "fail1" ); - } + TAO_PEGTL_TEST_ASSERT( c == 0 ); c = 1; } }; @@ -42,9 +40,7 @@ namespace TAO_PEGTL_NAMESPACE v = 6; } else { - if( c != 1 ) { - throw std::runtime_error( "fail2" ); - } + TAO_PEGTL_TEST_ASSERT( c == 1 ); v = 2; } } @@ -52,9 +48,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename ParseInput > void success( const ParseInput& /*unused*/, int& c ) { - if( v != 3 ) { - throw std::runtime_error( "fail3" ); - } + TAO_PEGTL_TEST_ASSERT( v == 3 ); c = 4; } }; @@ -69,7 +63,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( S& /*s*/ ) { - throw std::runtime_error( "fail4" ); + TAO_PEGTL_TEST_UNREACHABLE; } }; @@ -78,9 +72,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( S& s ) { - if( s.v != 2 ) { - throw std::runtime_error( "fail5" ); - } + TAO_PEGTL_TEST_ASSERT( s.v == 2 ); s.v = 3; } }; diff --git a/packages/PEGTL/src/test/pegtl/change_action_and_states.cpp b/packages/PEGTL/src/test/pegtl/change_action_and_states.cpp index 74cb0c976e20d710218c4b9e67a3ff44a94b7142..4bd4f5ffec701333d7bd50767708fd342b77703d 100644 --- a/packages/PEGTL/src/test/pegtl/change_action_and_states.cpp +++ b/packages/PEGTL/src/test/pegtl/change_action_and_states.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -24,9 +24,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& c ) { - if( c != 0 ) { - throw std::runtime_error( "fail1" ); - } + TAO_PEGTL_TEST_ASSERT( c == 0 ); c = 1; } }; @@ -38,18 +36,14 @@ namespace TAO_PEGTL_NAMESPACE // not called because my_action_2 is active static void apply0( int& /*v*/ ) { - throw std::runtime_error( "fail2" ); + TAO_PEGTL_TEST_UNREACHABLE; } template< typename ParseInput > static void success( const ParseInput& /*unused*/, int& v, int& c ) { - if( v != 2 ) { - throw std::runtime_error( "fail3" ); - } - if( c != 1 ) { - throw std::runtime_error( "fail4" ); - } + TAO_PEGTL_TEST_ASSERT( v == 2 ); + TAO_PEGTL_TEST_ASSERT( c == 1 ); c = 3; } }; @@ -59,7 +53,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& /*c*/ ) { - throw std::runtime_error( "fail5" ); + TAO_PEGTL_TEST_UNREACHABLE; } }; @@ -68,9 +62,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& v ) { - if( v != 0 ) { - throw std::runtime_error( "fail6" ); - } + TAO_PEGTL_TEST_ASSERT( v == 0 ); v = 2; } }; diff --git a/packages/PEGTL/src/test/pegtl/change_state.cpp b/packages/PEGTL/src/test/pegtl/change_state.cpp index 10a64f154e322778f5da2f32be148c72e520b0ca..bc7840256a7f884b87841cbaad5df6d0d7390743 100644 --- a/packages/PEGTL/src/test/pegtl/change_state.cpp +++ b/packages/PEGTL/src/test/pegtl/change_state.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -20,9 +20,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& c ) { - if( c != 0 ) { - throw std::runtime_error( "fail1" ); - } + TAO_PEGTL_TEST_ASSERT( c == 0 ); c = 1; } }; @@ -38,9 +36,7 @@ namespace TAO_PEGTL_NAMESPACE v = 6; } else { - if( c != 1 ) { - throw std::runtime_error( "fail2" ); - } + TAO_PEGTL_TEST_ASSERT( c == 1 ); v = 2; } } @@ -48,9 +44,7 @@ namespace TAO_PEGTL_NAMESPACE template< typename ParseInput > void success( const ParseInput& /*unused*/, int& c ) { - if( v != 3 ) { - throw std::runtime_error( "fail3" ); - } + TAO_PEGTL_TEST_ASSERT( v == 3 ); c = 4; } }; @@ -61,9 +55,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( S& s ) { - if( s.v != 2 ) { - throw std::runtime_error( "fail4" ); - } + TAO_PEGTL_TEST_ASSERT( s.v == 2 ); s.v = 3; } }; diff --git a/packages/PEGTL/src/test/pegtl/change_states.cpp b/packages/PEGTL/src/test/pegtl/change_states.cpp index d6cdbd0a3a374df3dcba1461cb14523cbef6d256..0dc0f533f90a15ffc727d496c6f348b4dcfcd405 100644 --- a/packages/PEGTL/src/test/pegtl/change_states.cpp +++ b/packages/PEGTL/src/test/pegtl/change_states.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -20,9 +20,7 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& c ) { - if( c != 0 ) { - throw std::runtime_error( "fail1" ); - } + TAO_PEGTL_TEST_ASSERT( c == 0 ); c = 1; } }; @@ -33,21 +31,15 @@ namespace TAO_PEGTL_NAMESPACE { static void apply0( int& v ) { - if( v != 0 ) { - throw std::runtime_error( "fail2" ); - } + TAO_PEGTL_TEST_ASSERT( v == 0 ); v = 2; } template< typename ParseInput > static void success( const ParseInput& /*unused*/, int& v, int& c ) { - if( v != 2 ) { - throw std::runtime_error( "fail3" ); - } - if( c != 1 ) { - throw std::runtime_error( "fail4" ); - } + TAO_PEGTL_TEST_ASSERT( v == 2 ); + TAO_PEGTL_TEST_ASSERT( c == 1 ); c = 3; } }; diff --git a/packages/PEGTL/src/test/pegtl/contains.cpp b/packages/PEGTL/src/test/pegtl/contains.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68b24b73cd3a6e9cea1b3427028e25bd899aa9ad --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contains.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <type_traits> + +#include "test.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + // clang-format off + struct A : plus< alpha, opt< A > > {}; + struct B : star< sor< space, digit, A > > {}; + struct grammar : seq< A, B > {}; + // clang-format on + + void unit_test() + { + static_assert( contains_v< grammar, digit > ); + static_assert( !contains_v< grammar, xdigit > ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_alphabet.cpp b/packages/PEGTL/src/test/pegtl/contrib_alphabet.cpp index fc3275f4261aca4ddecd3533fbac5f64a4549b82..1aac0e762a06e36dd7c209ab757578b57606c6b6 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_alphabet.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_alphabet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_analyze.cpp b/packages/PEGTL/src/test/pegtl/contrib_analyze.cpp index 65f1d4831fc4be550caf3fb191114105fe7e4af0..438b3a19120909c220aca5c8991da45177dcb423 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_analyze.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_analyze.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -191,6 +191,7 @@ namespace TAO_PEGTL_NAMESPACE struct tst : list< star< any >, opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } +#if defined( __cpp_exceptions ) { struct tst : list_must< any, any > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); @@ -207,6 +208,7 @@ namespace TAO_PEGTL_NAMESPACE struct tst : list_must< star< any >, opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } +#endif { struct tst : plus< pad_opt< alpha, digit > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); diff --git a/packages/PEGTL/src/test/pegtl/contrib_control_action.cpp b/packages/PEGTL/src/test/pegtl/contrib_control_action.cpp index 1d03133953e1cfaf098ea167dcb30be1b4372bd9..b60f796e96e0a97125be6ac321ea3dbb0ed2c056 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_control_action.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_control_action.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <string> @@ -18,9 +18,11 @@ namespace TAO_PEGTL_NAMESPACE : sor< alpha, digit > {}; +#if defined( __cpp_exceptions ) struct second_rule : must< alnum > {}; +#endif std::string story; @@ -40,11 +42,13 @@ namespace TAO_PEGTL_NAMESPACE story += 'b'; } + // LCOV_EXCL_START template< typename ParseInput > static void failure( const ParseInput& /*unused*/, int /*unused*/ ) { - story += 'c'; + TAO_PEGTL_TEST_UNREACHABLE; } + // LCOV_EXCL_END }; template<> @@ -57,11 +61,14 @@ namespace TAO_PEGTL_NAMESPACE story += 'd'; } + // LCOV_EXCL_START template< typename ParseInput > static void success( const ParseInput& /*unused*/, int /*unused*/ ) { - story += 'e'; + TAO_PEGTL_TEST_UNREACHABLE; } + // LCOV_EXCL_END + template< typename ParseInput > static void failure( const ParseInput& /*unused*/, int /*unused*/ ) { @@ -84,13 +91,17 @@ namespace TAO_PEGTL_NAMESPACE { story += 'h'; } + + // LCOV_EXCL_START template< typename ParseInput > static void failure( const ParseInput& /*unused*/, int /*unused*/ ) { - story += 'i'; + TAO_PEGTL_TEST_UNREACHABLE; } + // LCOV_EXCL_END }; +#if defined( __cpp_exceptions ) template<> struct test_action< second_rule > : control_action @@ -101,16 +112,19 @@ namespace TAO_PEGTL_NAMESPACE story += 'j'; } + // LCOV_EXCL_START template< typename ParseInput > static void success( const ParseInput& /*unused*/, int /*unused*/ ) { - story += 'k'; + TAO_PEGTL_TEST_UNREACHABLE; } + template< typename ParseInput > static void failure( const ParseInput& /*unused*/, int /*unused*/ ) { - story += 'l'; + TAO_PEGTL_TEST_UNREACHABLE; } + // LCOV_EXCL_END template< typename ParseInput > static void unwind( const ParseInput& /*unused*/, int /*unused*/ ) @@ -118,6 +132,7 @@ namespace TAO_PEGTL_NAMESPACE story += 'm'; } }; +#endif void unit_test() { @@ -127,12 +142,14 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( b ); TAO_PEGTL_TEST_ASSERT( story == "adfghb" ); } +#if defined( __cpp_exceptions ) story.clear(); { memory_input in( "*", __FUNCTION__ ); TAO_PEGTL_TEST_THROWS( parse< second_rule, test_action >( in, 42 ) ); TAO_PEGTL_TEST_ASSERT( story == "jm" ); } +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/contrib_coverage.cpp b/packages/PEGTL/src/test/pegtl/contrib_coverage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9661624facc95358e6635f51d73582b1ec2380c --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_coverage.cpp @@ -0,0 +1,66 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <iostream> + +#include "test.hpp" + +#include <tao/pegtl/contrib/coverage.hpp> +#include <tao/pegtl/contrib/print_coverage.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + [[nodiscard]] inline bool operator==( const coverage_info& l, const coverage_info& r ) noexcept + { + return ( l.start == r.start ) && ( l.success == r.success ) && ( l.failure == r.failure ) && ( l.unwind == r.unwind ) && ( l.raise == r.raise ); + } + + template< typename Rule > + [[nodiscard]] bool equals( const coverage_result& result, const coverage_info& i ) + { + const coverage_entry m = result.at( demangle< Rule >() ); // Slice + return i == m; + } + +#if defined( __cpp_exceptions ) + using grammar = seq< sor< try_catch< must< one< 'a' > > >, one< 'F' > >, eof >; + + void unit_test() + { + const std::string data = "F"; + coverage_result result; + memory_input in( data, __FILE__ ); + const bool success = coverage< grammar >( in, result ); + std::cout << result; // To manually see that printing does the right thing, too. + TAO_PEGTL_TEST_ASSERT( success ); + TAO_PEGTL_TEST_ASSERT( result.size() == 7 ); + TAO_PEGTL_TEST_ASSERT( equals< grammar >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< one< 'a' > >( result, coverage_info{ 1, 0, 1, 0, 1 } ) ); // TODO: Should this really be counted as both failure and raise? + TAO_PEGTL_TEST_ASSERT( equals< one< 'F' > >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< eof >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< try_catch< must< one< 'a' > > > >( result, coverage_info{ 1, 0, 1, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< must< one< 'a' > > >( result, coverage_info{ 1, 0, 0, 1, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< sor< try_catch< must< one< 'a' > > >, one< 'F' > > >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + } +#else + using grammar = seq< sor< one< 'a' >, one< 'F' > >, eof >; + + void unit_test() + { + const std::string data = "F"; + coverage_result result; + memory_input in( data, __FILE__ ); + const bool success = coverage< grammar >( in, result ); + std::cout << result; // To manually see that printing does the right thing, too. + TAO_PEGTL_TEST_ASSERT( success ); + TAO_PEGTL_TEST_ASSERT( result.size() == 5 ); + TAO_PEGTL_TEST_ASSERT( equals< grammar >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< one< 'a' > >( result, coverage_info{ 1, 0, 1, 0, 0 } ) ); // TODO: Should this really be counted as both failure and raise? + TAO_PEGTL_TEST_ASSERT( equals< one< 'F' > >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< eof >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + TAO_PEGTL_TEST_ASSERT( equals< sor< one< 'a' >, one< 'F' > > >( result, coverage_info{ 1, 1, 0, 0, 0 } ) ); + } +#endif +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_function.cpp b/packages/PEGTL/src/test/pegtl/contrib_function.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3191981de18fbaa6830d203d75edb6969fb7b9ae --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_function.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +#include <tao/pegtl/contrib/function.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + bool call1 = false; + + [[nodiscard]] bool func1( memory_input<>& /*unused*/, int /*unused*/, char*& /*unused*/, const double& /*unused*/ ) + { + call1 = true; + return true; + } + + struct rule1 : TAO_PEGTL_NAMESPACE::function< func1 > + {}; + + void unit_test() + { + int i = 42; + char c = 'a'; + double d = 42.0; + memory_input in( "foo", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< rule1 >( in, i, &c, d ) ); + TAO_PEGTL_TEST_ASSERT( call1 ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_http.cpp b/packages/PEGTL/src/test/pegtl/contrib_http.cpp index 0273d43b10a34b25b94bf35bda4bc5ffaa0f4639..3fb449d0ae3a17adbfe2694d302159a8775ab097 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_http.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_http.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" @@ -92,3 +100,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/contrib_if_then.cpp b/packages/PEGTL/src/test/pegtl/contrib_if_then.cpp index b81c7840c89ad7c490be8a56ccc8788067898742..dac262144e0c2577ce753d73bf86772c9b90407d 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_if_then.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_if_then.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_instantiate.cpp b/packages/PEGTL/src/test/pegtl/contrib_instantiate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c6c268cb6ee4b8bbc27cde7eb2ce779459875c8 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_instantiate.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +#include <tao/pegtl/contrib/instantiate.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + bool ctor = false; + bool dtor = false; + + struct test_class + { + template< typename ParseInput > + test_class( const ParseInput& /*unused*/ ) + { + TAO_PEGTL_TEST_ASSERT( ctor == false ); + TAO_PEGTL_TEST_ASSERT( dtor == false ); + + ctor = true; + } + + test_class( test_class&& ) = delete; + test_class( const test_class& ) = delete; + + ~test_class() + { + TAO_PEGTL_TEST_ASSERT( ctor == true ); + TAO_PEGTL_TEST_ASSERT( dtor == false ); + + dtor = true; + } + + void operator=( test_class&& ) = delete; + void operator=( const test_class& ) = delete; + }; + + using test_grammar = sor< alpha, digit >; + + template< typename Rule > + struct test_action + : nothing< Rule > + {}; + + template<> + struct test_action< alpha > + { + static void apply0() + { + TAO_PEGTL_TEST_ASSERT( ctor == true ); + TAO_PEGTL_TEST_ASSERT( dtor == false ); + } + }; + + template<> + struct test_action< sor< alpha, digit > > + : instantiate< test_class > + {}; + + void unit_test() + { + memory_input in( "a", __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< test_grammar, test_action >( in ) ); + + TAO_PEGTL_TEST_ASSERT( ctor == true ); + TAO_PEGTL_TEST_ASSERT( dtor == true ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_integer.cpp b/packages/PEGTL/src/test/pegtl/contrib_integer.cpp index 0a9cc8eaf857e700bb96b0ea237e5dee69b506e7..3f0f461951bdd37c059b719db709cc43c55a1b52 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_integer.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_integer.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include <limits> #include <sstream> @@ -250,3 +258,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/contrib_json.cpp b/packages/PEGTL/src/test/pegtl/contrib_json.cpp index 2cd30e1320783cbf066e844b8f3d40168b5b41b2..b7a2945b4253f004afc6f404bad043c01d7c3423 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_json.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_json.cpp @@ -1,8 +1,7 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" -#include "verify_fail.hpp" #include "verify_meta.hpp" #include "verify_rule.hpp" @@ -10,19 +9,7 @@ namespace TAO_PEGTL_NAMESPACE { - template< typename Rule > - void verify_file_fail( const std::size_t line, const char* file, const std::string& s ) - { - file_input in( s ); - try { - parse< Rule >( in ); - TAO_PEGTL_TEST_FAILED( "expected exception" ); - } - catch( ... ) { - } - } - - using GRAMMAR = must< json::text, eof >; + using GRAMMAR = seq< json::text, eof >; void unit_test() { @@ -55,34 +42,34 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\xF4\x8F\xBF\xBF\"]", result_type::success, 0 ); // largest allowed codepoint U+10FFFF verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\U0010FFFF\"]", result_type::success, 0 ); // largest allowed codepoint U+10FFFF - verify_fail< GRAMMAR >( __LINE__, __FILE__, "" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, " " ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, " " ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, " [" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, " ]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[ " ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "] " ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, " [ " ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, " ] " ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\a\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\c\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\d\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\e\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\v\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\'\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\b\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\f\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\n\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\r\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\t\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\\\\\\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\u12\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\xFF\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\xF4\x90\x80\x80\"]" ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\xF7\xBF\xBF\xBF\"]" ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " [", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[ ", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "] ", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " [ ", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( " ] ", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\a\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\c\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\d\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\e\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\v\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\'\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\b\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\f\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\n\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\r\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\t\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\\\\\\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\\u12\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\xFF\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\xF4\x90\x80\x80\"]", "" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( memory_input( "[\"\xF7\xBF\xBF\xBF\"]", "" ) ) ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/pass1.json" ) ) ); TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/pass2.json" ) ) ); @@ -90,45 +77,45 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( parse< GRAMMAR >( file_input( "src/test/pegtl/data/blns.json" ) ) ); - // verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail1.json" ); // disabled as it is valid now - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail2.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail3.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail4.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail5.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail6.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail7.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail8.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail9.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail10.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail11.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail12.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail13.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail14.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail15.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail16.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail17.json" ); - // verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail18.json" ); // disabled as deep nesting is allowed - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail19.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail20.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail21.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail22.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail23.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail24.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail25.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail26.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail27.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail28.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail29.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail30.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail31.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail32.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail33.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail34.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail35.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail36.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail37.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail38.json" ); - verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "src/test/pegtl/data/fail39.json" ); + // TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail1.json" ) )); // disabled as it is valid now + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail2.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail3.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail4.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail5.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail6.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail7.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail8.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail9.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail10.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail11.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail12.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail13.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail14.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail15.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail16.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail17.json" ) ) ); + // TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail18.json" ) )); // disabled as deep nesting is allowed + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail19.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail20.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail21.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail22.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail23.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail24.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail25.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail26.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail27.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail28.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail29.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail30.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail31.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail32.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail33.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail34.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail35.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail36.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail37.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail38.json" ) ) ); + TAO_PEGTL_TEST_ASSERT( !parse< GRAMMAR >( file_input( "src/test/pegtl/data/fail39.json" ) ) ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp b/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp index bce6834501b9d887fe3cae3bc773a6f6d8998cff..2bcd188518fb5a1e4349bf547194d545014aab37 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_parse_tree.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -13,14 +13,28 @@ namespace TAO_PEGTL_NAMESPACE struct C : one< 'c' > {}; struct D : sor< seq< A, B >, seq< A, C > > {}; + struct E : star< A, B > {}; + struct F : seq< E > {}; +#if defined( __cpp_exceptions ) struct D2 : sor< try_catch< if_must< A, B > >, seq< A, C > > {}; +#else + struct D2 : D {}; +#endif // clang-format on template< typename Rule > - struct selector - : parse_tree::selector< Rule, parse_tree::store_content::on< A, B, C, D > > - {}; + using selector = parse_tree::selector< Rule, + parse_tree::store_content::on< A, B >, + parse_tree::remove_content::on< C >, + parse_tree::fold_one::on< D > >; + + template< typename Rule > + using selector2 = parse_tree::selector< Rule, + parse_tree::store_content::on< A >, + parse_tree::discard_empty::on< B >, + parse_tree::discard_empty::on< F >, + parse_tree::fold_one::on< E > >; void unit_test() { @@ -35,11 +49,7 @@ namespace TAO_PEGTL_NAMESPACE const auto& d = r->children.front(); TAO_PEGTL_TEST_ASSERT( !d->is_root() ); TAO_PEGTL_TEST_ASSERT( d->is_type< D >() ); - - TAO_PEGTL_TEST_ASSERT( d->has_content() ); - TAO_PEGTL_TEST_ASSERT( d->begin().byte == 0 ); - TAO_PEGTL_TEST_ASSERT( d->end().byte == 2 ); - TAO_PEGTL_TEST_ASSERT( d->string_view() == "ac" ); + TAO_PEGTL_TEST_ASSERT( !d->has_content() ); TAO_PEGTL_TEST_ASSERT( d->children.size() == 2 ); TAO_PEGTL_TEST_ASSERT( d->children.front()->is_type< A >() ); @@ -50,6 +60,50 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( !r2 ); } + { + memory_input in( "aba", "input" ); + const auto r = parse_tree::parse< E, selector >( in ); + TAO_PEGTL_TEST_ASSERT( r ); + TAO_PEGTL_TEST_ASSERT( r->is_root() ); + TAO_PEGTL_TEST_ASSERT( !r->has_content() ); + + TAO_PEGTL_TEST_ASSERT( r->children.size() == 2 ); + TAO_PEGTL_TEST_ASSERT( r->children.front()->is_type< A >() ); + TAO_PEGTL_TEST_ASSERT( r->children.back()->is_type< B >() ); + } + + { + memory_input in( "ab", "input" ); + const auto r = parse_tree::parse< E, selector2 >( in ); + TAO_PEGTL_TEST_ASSERT( r ); + TAO_PEGTL_TEST_ASSERT( r->is_root() ); + TAO_PEGTL_TEST_ASSERT( !r->has_content() ); + + TAO_PEGTL_TEST_ASSERT( r->children.size() == 1 ); + TAO_PEGTL_TEST_ASSERT( r->children.front()->is_type< A >() ); + } + + { + memory_input in( "aba", "input" ); + const auto r = parse_tree::parse< F, selector2 >( in ); + TAO_PEGTL_TEST_ASSERT( r ); + TAO_PEGTL_TEST_ASSERT( r->is_root() ); + TAO_PEGTL_TEST_ASSERT( !r->has_content() ); + TAO_PEGTL_TEST_ASSERT( r->children.size() == 1 ); + + const auto& f = r->children.front(); + TAO_PEGTL_TEST_ASSERT( !f->is_root() ); + TAO_PEGTL_TEST_ASSERT( f->is_type< F >() ); + TAO_PEGTL_TEST_ASSERT( !f->has_content() ); + TAO_PEGTL_TEST_ASSERT( f->children.size() == 1 ); + + const auto& a = f->children.front(); + TAO_PEGTL_TEST_ASSERT( !a->is_root() ); + TAO_PEGTL_TEST_ASSERT( a->is_type< A >() ); + TAO_PEGTL_TEST_ASSERT( a->has_content() ); + TAO_PEGTL_TEST_ASSERT( a->children.empty() ); + } + { memory_input in( "ac", "input" ); const auto r = parse_tree::parse< D2, selector >( in ); diff --git a/packages/PEGTL/src/test/pegtl/contrib_parse_tree_to_dot.cpp b/packages/PEGTL/src/test/pegtl/contrib_parse_tree_to_dot.cpp new file mode 100644 index 0000000000000000000000000000000000000000..98bc76f467799e524adf41a45760974a395fec29 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_parse_tree_to_dot.cpp @@ -0,0 +1,39 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +#include <tao/pegtl/contrib/parse_tree.hpp> +#include <tao/pegtl/contrib/parse_tree_to_dot.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + // clang-format off + struct A : one< 'a' > {}; + struct B : one< 'b' > {}; + struct C : one< 'c' > {}; + +#if defined( __cpp_exceptions ) + struct S : if_must< one< '[' >, until< one< ']' > > > {}; +#else + struct S : seq< one< '[' >, until< one< ']' > > > {}; +#endif + + struct D : sor< seq< A, B >, seq< A, C, S > > {}; + // clang-format on + + template< typename Rule > + struct selector + : parse_tree::selector< Rule, parse_tree::store_content::on< A, B, C, D, S > > + {}; + + void unit_test() + { + memory_input in( "ac[\"\\\x01\x7f\b\n\r\f\t\a\v]", "input" ); + const auto root = parse_tree::parse< D, selector >( in ); + parse_tree::print_dot( std::cout, *root ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_partial_trace.cpp b/packages/PEGTL/src/test/pegtl/contrib_partial_trace.cpp index 5743114608c7c0adabe767034808b880443d4799..d4e829852fedabf84738d838efffd19813aae49e 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_partial_trace.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_partial_trace.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_predicates.cpp b/packages/PEGTL/src/test/pegtl/contrib_predicates.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0af55ea6249487986aa669d490afc13e3b443e1c --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_predicates.cpp @@ -0,0 +1,101 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" +#include "verify_meta.hpp" +#include "verify_rule.hpp" + +#include <tao/pegtl/contrib/predicates.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + verify_analyze< predicates_or< one< ' ' > > >( __LINE__, __FILE__, true, false ); + verify_analyze< predicates_or< one< ' ' >, range< 'a', 'z' > > >( __LINE__, __FILE__, true, false ); + + verify_rule< predicates_or< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); + + for( char i = 1; i < 'a'; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< one< 'a' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + for( char i = 'b'; i < 127; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< one< 'a' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + + verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); + verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, "b", result_type::success, 0 ); + + for( char i = 1; i < 'a'; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + for( char i = 'c'; i < 127; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< one< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + + verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); + verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", result_type::success, 0 ); + + for( char i = 1; i < 'a'; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + for( char i = 'c'; i < 127; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + + verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); + verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, "b", result_type::success, 0 ); + + for( char i = 1; i < 'a'; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + for( char i = 'c'; i < 127; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< range< 'a', 'b' > > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + + using rule_t = predicates_or< one< 'f' >, range< 'b', 'd' >, range< 'm', 'n' >, one< 'x', 'y' > >; + + verify_rule< rule_t >( __LINE__, __FILE__, "b", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "c", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "d", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "m", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "n", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "x", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "y", result_type::success, 0 ); + verify_rule< rule_t >( __LINE__, __FILE__, "f", result_type::success, 0 ); + + verify_rule< rule_t >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "e", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "g", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "l", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "w", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "z", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "k", result_type::local_failure, 1 ); + verify_rule< rule_t >( __LINE__, __FILE__, "r", result_type::local_failure, 1 ); + + using pred_t = predicates_or< one< 'a' >, predicates_or< one< 'b' > > >; + + verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, "a", result_type::success, 0 ); + verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, "b", result_type::success, 0 ); + + for( char i = 1; i < 'a'; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + for( char i = 'c'; i < 127; ++i ) { + char t[] = { i, 0 }; + verify_rule< predicates_or< pred_t > >( __LINE__, __FILE__, std::string( t ), result_type::local_failure, 1 ); + } + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_print.cpp b/packages/PEGTL/src/test/pegtl/contrib_print.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b19e150c32fd3b6c0ec51b7c7f5daa06a76d521 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_print.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <iostream> + +#include "test.hpp" + +#include <tao/pegtl/contrib/print.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + using grammar = seq< alpha, digit >; + + void unit_test() + { + // Just enough to see that it compiles and nothing explodes; + // the output format probabaly changes between compilers and + // versions making a proper test difficult. + print_names< grammar >( std::cout ); + print_debug< grammar >( std::cout ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp b/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp index 6ae1980754fdc5f6402a5a8d96f437312063c00c..f02f9bc666857746814364a11f4a42db6be4af76 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_raw_string.cpp @@ -1,8 +1,7 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" -#include "verify_fail.hpp" #include "verify_meta.hpp" #include <tao/pegtl/contrib/raw_string.hpp> @@ -43,11 +42,11 @@ namespace TAO_PEGTL_NAMESPACE }; struct rgrammar - : must< rstring, eof > + : seq< rstring, eof > {}; struct qgrammar - : must< qstring, eof > + : seq< qstring, eof > {}; template< typename Rule, template< typename > class Action, unsigned M, unsigned N > @@ -57,13 +56,22 @@ namespace TAO_PEGTL_NAMESPACE memory_input in( m, m + M - 1, file, 0, line, 1 ); const auto r = parse< Rule, Action >( in ); if( ( !r ) || ( content != std::string_view( n, N - 1 ) ) ) { - TAO_PEGTL_TEST_FAILED( "input data [ '" << m << "' ] expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r << " ]" ); + TAO_PEGTL_TEST_FAILED( "input data [ '" << m << "' ] expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r << " ]" ); // LCOV_EXCL_LINE } content.clear(); memory_input< tracking_mode::lazy > in2( m, m + M - 1, file, 0, line, 1 ); const auto r2 = parse< Rule, Action >( in2 ); if( ( !r2 ) || ( content != std::string_view( n, N - 1 ) ) ) { - TAO_PEGTL_TEST_FAILED( "input data [ '" << m << "' ] with tracking_mode::lazy expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r2 << " ]" ); + TAO_PEGTL_TEST_FAILED( "input data [ '" << m << "' ] with tracking_mode::lazy expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r2 << " ]" ); // LCOV_EXCL_LINE + } + } + + template< typename Rule > + void verify_fail( const std::size_t line, const char* file, const std::string& s ) + { + memory_input in( s, "expect exception" ); + if( parse< Rule >( in ) ) { + TAO_PEGTL_TEST_FAILED( "expected exception" ); // LCOV_EXCL_LINE } } diff --git a/packages/PEGTL/src/test/pegtl/contrib_remove_first_state.cpp b/packages/PEGTL/src/test/pegtl/contrib_remove_first_state.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd2aedb94c297e6b1e848cd6d4a5eed29c25a7a9 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_remove_first_state.cpp @@ -0,0 +1,102 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +#include <tao/pegtl/contrib/remove_first_state.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + template< typename Rule > + struct test_action + : nothing< Rule > + {}; + + template<> + struct test_action< one< 'F' > > + { + static void apply0( unsigned& u ) noexcept + { + u |= 1; + } + }; + + template<> + struct test_action< eof > + { + template< typename ActionInput > + static void apply( const ActionInput& /*unused*/, unsigned& u ) noexcept + { + u |= 2; + } + }; + + template< typename Rule > + struct control_impl + : normal< Rule > + { + template< typename ParseInput > + static void start( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 64; + } + + template< typename ParseInput > + static void success( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 32; + } + + template< typename ParseInput > + static void failure( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 16; + } + +#if defined( __cpp_exceptions ) + template< typename ParseInput > + [[noreturn]] static void raise( ParseInput& in, unsigned& u ) + { + u |= 4; + throw parse_error( "raise", in ); + } + + template< typename ParseInput > + static void unwind( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 8; + } +#endif + }; + + template< typename Rule > + struct test_control + : remove_first_state< control_impl< Rule > > + {}; + +#if defined( __cpp_exceptions ) + struct test_rule + : seq< sor< try_catch< must< one< 'a' > > >, one< 'F' > >, eof > + {}; +#else + struct test_rule + : seq< sor< one< 'a' >, one< 'F' > >, eof > + {}; +#endif + + void unit_test() + { + unsigned u = 0; + const std::string d = "F"; + memory_input in( d, __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< test_rule, test_action, test_control >( in, d, u ) ); +#if defined( __cpp_exceptions ) + TAO_PEGTL_TEST_ASSERT( u == 127 ); +#else + TAO_PEGTL_TEST_ASSERT( u == 115 ); +#endif + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_remove_last_states.cpp b/packages/PEGTL/src/test/pegtl/contrib_remove_last_states.cpp new file mode 100644 index 0000000000000000000000000000000000000000..76dae2f5eabbde1bb755d861ea0bb0a03bdc0808 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_remove_last_states.cpp @@ -0,0 +1,102 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +#include <tao/pegtl/contrib/remove_last_states.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + template< typename Rule > + struct test_action + : nothing< Rule > + {}; + + template<> + struct test_action< one< 'F' > > + { + static void apply0( unsigned& u ) noexcept + { + u |= 1; + } + }; + + template<> + struct test_action< eof > + { + template< typename ActionInput > + static void apply( const ActionInput& /*unused*/, unsigned& u ) noexcept + { + u |= 2; + } + }; + + template< typename Rule > + struct control_impl + : normal< Rule > + { + template< typename ParseInput > + static void start( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 64; + } + + template< typename ParseInput > + static void success( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 32; + } + + template< typename ParseInput > + static void failure( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 16; + } + +#if defined( __cpp_exceptions ) + template< typename ParseInput > + [[noreturn]] static void raise( ParseInput& in, unsigned& u ) + { + u |= 4; + throw parse_error( "raise", in ); + } + + template< typename ParseInput > + static void unwind( ParseInput& /*unused*/, unsigned& u ) noexcept + { + u |= 8; + } +#endif + }; + + template< typename Rule > + struct test_control + : remove_last_states< control_impl< Rule >, 2 > + {}; + +#if defined( __cpp_exceptions ) + struct test_rule + : seq< sor< try_catch< must< one< 'a' > > >, one< 'F' > >, eof > + {}; +#else + struct test_rule + : seq< sor< one< 'a' >, one< 'F' > >, eof > + {}; +#endif + + void unit_test() + { + unsigned u = 0; + const std::string d = "F"; + memory_input in( d, __FUNCTION__ ); + TAO_PEGTL_TEST_ASSERT( parse< test_rule, test_action, test_control >( in, u, d, d ) ); +#if defined( __cpp_exceptions ) + TAO_PEGTL_TEST_ASSERT( u == 127 ); +#else + TAO_PEGTL_TEST_ASSERT( u == 115 ); +#endif + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_rep_one_min_max.cpp b/packages/PEGTL/src/test/pegtl/contrib_rep_one_min_max.cpp index ee9ecf7b6c2efa06b9a2249169698f1f03061f12..2ee88f010e30eaecd2dae96365d1b7559451e044 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_rep_one_min_max.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_rep_one_min_max.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_rep_string.cpp b/packages/PEGTL/src/test/pegtl/contrib_rep_string.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37b1b891e713ac4241adc14e80b12e1d1917b31b --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_rep_string.cpp @@ -0,0 +1,49 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +#include "verify_meta.hpp" +#include "verify_rule.hpp" + +#include <tao/pegtl/contrib/rep_string.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + verify_analyze< rep_string< 0 > >( __LINE__, __FILE__, false, false ); + verify_analyze< rep_string< 1 > >( __LINE__, __FILE__, false, false ); + verify_analyze< rep_string< 0, 'a' > >( __LINE__, __FILE__, false, false ); + verify_analyze< rep_string< 0, 'a', 'b' > >( __LINE__, __FILE__, false, false ); + + verify_analyze< rep_string< 1, 'a' > >( __LINE__, __FILE__, true, false ); + verify_analyze< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, true, false ); + verify_analyze< rep_string< 3, 'a' > >( __LINE__, __FILE__, true, false ); + verify_analyze< rep_string< 4, 'a', 'b' > >( __LINE__, __FILE__, true, false ); + + verify_rule< rep_string< 0 > >( __LINE__, __FILE__, "", result_type::success, 0 ); + verify_rule< rep_string< 1 > >( __LINE__, __FILE__, "", result_type::success, 0 ); + verify_rule< rep_string< 0, 'a' > >( __LINE__, __FILE__, "", result_type::success, 0 ); + + verify_rule< rep_string< 0 > >( __LINE__, __FILE__, "a", result_type::success, 1 ); + verify_rule< rep_string< 1 > >( __LINE__, __FILE__, "a", result_type::success, 1 ); + verify_rule< rep_string< 0, 'a' > >( __LINE__, __FILE__, "a", result_type::success, 1 ); + + verify_rule< rep_string< 1, 'a', 'b' > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); + verify_rule< rep_string< 1, 'a', 'b' > >( __LINE__, __FILE__, "aa", result_type::local_failure, 2 ); + verify_rule< rep_string< 1, 'a', 'b' > >( __LINE__, __FILE__, "ab", result_type::success, 0 ); + verify_rule< rep_string< 1, 'a', 'b' > >( __LINE__, __FILE__, "abab", result_type::success, 2 ); + + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "aa", result_type::local_failure, 2 ); + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "ab", result_type::local_failure, 2 ); + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "aabb", result_type::local_failure, 4 ); + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "abaa", result_type::local_failure, 4 ); + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "abab", result_type::success, 0 ); + verify_rule< rep_string< 2, 'a', 'b' > >( __LINE__, __FILE__, "ababab", result_type::success, 2 ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_state_control.cpp b/packages/PEGTL/src/test/pegtl/contrib_state_control.cpp index 8dc07cf3460ae9082b9b47a1977a45233301b6ac..2a68ace18232645dfb6ed36f219c2b7ea8cc3f2d 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_state_control.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_state_control.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include <iostream> #include <string_view> #include <vector> @@ -188,3 +196,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/contrib_to_string.cpp b/packages/PEGTL/src/test/pegtl/contrib_to_string.cpp index f2c4b175129d340f666b8d292d08858ad1623395..a956be930d82f62e4b3e9ff01dd03296f2fb6a0f 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_to_string.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_to_string.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_trace1.cpp b/packages/PEGTL/src/test/pegtl/contrib_trace1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a0212b023ad0cf91d4cd18427c3c485e727e401 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/contrib_trace1.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <iostream> + +#include "test.hpp" + +#include <tao/pegtl/contrib/trace.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ +#if defined( __cpp_exceptions ) + using grammar = seq< sor< try_catch< must< one< 'a' > > >, one< 'F' > >, eof >; +#else + using grammar = seq< sor< one< 'a' >, one< 'F' > >, eof >; +#endif + + void unit_test() + { + const std::string data = "F"; + memory_input in( data, __FILE__ ); + // Just enough to see that it compiles and nothing explodes; + // the output format probabaly changes between compilers and + // versions making a proper test difficult. + standard_trace< grammar >( in ); + in.restart(); + complete_trace< grammar >( in ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/contrib_tracer.cpp b/packages/PEGTL/src/test/pegtl/contrib_trace2.cpp similarity index 94% rename from packages/PEGTL/src/test/pegtl/contrib_tracer.cpp rename to packages/PEGTL/src/test/pegtl/contrib_trace2.cpp index a6f20b1a04b4d87febd4877f128a57cdeac3c339..a8a35a6b0bc027d8c24bf9d1a324e208e5b7d913 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_tracer.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_trace2.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -10,7 +10,9 @@ namespace TAO_PEGTL_NAMESPACE using GRAMMAR1 = sor< failure, one< 'a' > >; using GRAMMAR2 = seq< one< 'a' >, any, any, any, any, one< 'b' >, eof >; using GRAMMAR3 = sor< one< 'a' >, one< 'b' > >; +#if defined( __cpp_exceptions ) using GRAMMAR4 = try_catch< sor< one< 'a' >, must< one< 'b' > > > >; +#endif template< typename Rule > struct trace_action @@ -74,11 +76,13 @@ namespace TAO_PEGTL_NAMESPACE const auto result = standard_trace< GRAMMAR3 >( in ); TAO_PEGTL_TEST_ASSERT( !result ); } +#if defined( __cpp_exceptions ) { memory_input in( "c", "trace test please ignore" ); const auto result = standard_trace< GRAMMAR4 >( in ); TAO_PEGTL_TEST_ASSERT( !result ); } +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp b/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp index 8bf92f2aa7e990d6a604f46ed92008abec386242..7b010b6b1b815e8bbf04c1cd8c90ce6325a2d45e 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_unescape.cpp @@ -1,8 +1,7 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" -#include "verify_fail.hpp" #include <tao/pegtl/contrib/unescape.hpp> @@ -10,12 +9,12 @@ namespace TAO_PEGTL_NAMESPACE { // clang-format off struct escaped_c : one< '"', '\\', 't' > {}; - struct escaped_u : seq< one< 'u' >, rep< 4, must< xdigit > > > {}; - struct escaped_U : seq< one< 'U' >, rep< 8, must< xdigit > > > {}; - struct escaped_j : list< seq< one< 'j' >, rep< 4, must< xdigit > > >, one< '\\' > > {}; - struct escaped_x : seq< one< 'x' >, rep< 2, must< xdigit > > > {}; + struct escaped_u : seq< one< 'u' >, rep< 4, xdigit > > {}; + struct escaped_U : seq< one< 'U' >, rep< 8, xdigit > > {}; + struct escaped_j : list< seq< one< 'j' >, rep< 4, xdigit > >, one< '\\' > > {}; + struct escaped_x : seq< one< 'x' >, rep< 2, xdigit > > {}; struct escaped : sor< escaped_c, escaped_u, escaped_U, escaped_j, escaped_x > {}; - struct character : if_then_else< one< '\\' >, must< escaped >, utf8::any > {}; + struct character : if_then_else< one< '\\' >, escaped, utf8::any > {}; struct unstring : until< eof, character > {}; template< typename Rule > struct unaction {}; @@ -29,87 +28,102 @@ namespace TAO_PEGTL_NAMESPACE // clang-format on template< unsigned M, unsigned N > - void verify_data( const char ( &m )[ M ], const char ( &n )[ N ] ) + bool verify_data( const char ( &m )[ M ], const char ( &n )[ N ] ) { std::string s; memory_input in( m, M - 1, __FUNCTION__ ); - parse< unstring, unaction >( in, s ); - if( s != std::string( n, N - 1 ) ) { - throw std::runtime_error( "test failed!" ); + if( !parse< unstring, unaction >( in, s ) ) { + return false; // LCOV_EXCL_LINE } + return s == std::string( n, N - 1 ); + } + + bool verify_fail( const std::string& m ) + { + std::string s; + memory_input in( m, __FUNCTION__ ); +#if defined( __cpp_exceptions ) + try { + return !parse< unstring, unaction >( in, s ); + } + catch( const parse_error& ) { + } + return true; +#else + return !parse< unstring, unaction >( in, s ); +#endif } void unit_test() { - verify_data( "\\t", "\t" ); - verify_data( "\\\\", "\\" ); - verify_data( "abc", "abc" ); - verify_data( "\\\"foo\\\"", "\"foo\"" ); - verify_data( "\\x20", " " ); - verify_data( "\\x30", "0" ); - verify_data( "\\x2000", " 00" ); - verify_data( "\\u0020", " " ); - verify_data( "\\u0020\\u0020", " " ); - verify_data( "\\u00e4", "\xc3\xa4" ); - verify_data( "\\u00E4", "\xC3\xA4" ); - verify_data( "\\u20ac", "\xe2\x82\xac" ); - - TAO_PEGTL_TEST_THROWS( verify_data( "\\ud800", "" ) ); - TAO_PEGTL_TEST_THROWS( verify_data( "\\ud800X", "" ) ); - TAO_PEGTL_TEST_THROWS( verify_data( "\\ud800\\u0020", "" ) ); - TAO_PEGTL_TEST_THROWS( verify_data( "\\ud800\\udc00", "" ) ); // unescape_u does not support surrogate pairs. - TAO_PEGTL_TEST_THROWS( verify_data( "\\udc00\\ud800", "" ) ); - - verify_data( "\\j0020", " " ); - verify_data( "\\j0020\\j0020", " " ); - verify_data( "\\j20ac", "\xe2\x82\xac" ); - - verify_data( "\\jd800\\jdc00", "\xf0\x90\x80\x80" ); // unescape_j does support proper surrogate pairs. - - TAO_PEGTL_TEST_THROWS( verify_data( "\\jd800", "" ) ); - TAO_PEGTL_TEST_THROWS( verify_data( "\\jd800X", "" ) ); - TAO_PEGTL_TEST_THROWS( verify_data( "\\jd800\\j0020", "" ) ); - TAO_PEGTL_TEST_THROWS( verify_data( "\\jdc00\\jd800", "" ) ); - - verify_data( "\\j0000\\u0000\x00", "\x00\x00\x00" ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\t", "\t" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\\\", "\\" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "abc", "abc" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\\"foo\\\"", "\"foo\"" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\x20", " " ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\x30", "0" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\x2000", " 00" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\u0020", " " ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\u0020\\u0020", " " ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\u00e4", "\xc3\xa4" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\u00E4", "\xC3\xA4" ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\u20ac", "\xe2\x82\xac" ) ); - std::string s; - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\\\\\", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\x", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\xx", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\xa", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\x1", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\x1h", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\x", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\xx", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\xa", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\x1", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\x1h", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\a", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\_", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\z", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\1", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\a00", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\_1111", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\z22222222", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\13333333333333333", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\uu", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\uuuu", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u123", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u999", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u444h", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\ju", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\juuu", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j123", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j999", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j444h", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\U00110000", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\U80000000", s ); - verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\Uffffffff", s ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\ud800" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\ud800X" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\ud800\\u0020" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\ud800\\udc00" ) ); // unescape_u does not support surrogate pairs. + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\udc00\\ud800" ) ); + + TAO_PEGTL_TEST_ASSERT( verify_data( "\\j0020", " " ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\j0020\\j0020", " " ) ); + TAO_PEGTL_TEST_ASSERT( verify_data( "\\j20ac", "\xe2\x82\xac" ) ); + + TAO_PEGTL_TEST_ASSERT( verify_data( "\\jd800\\jdc00", "\xf0\x90\x80\x80" ) ); // unescape_j does support proper surrogate pairs. + + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\jd800" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\jd800X" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\jd800\\j0020" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\jdc00\\jd800" ) ); + + TAO_PEGTL_TEST_ASSERT( verify_data( "\\j0000\\u0000\x00", "\x00\x00\x00" ) ); + + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\\\\\" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\x" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\xx" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\xa" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\x1" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\x1h" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "a\\" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "a\\x" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "a\\xx" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "a\\xa" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "a\\x1" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "a\\x1h" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\a" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\_" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\z" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\1" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\a00" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\_1111" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\z22222222" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\13333333333333333" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\u" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\uu" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\uuuu" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\u123" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\u999" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\u444h" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\j" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\ju" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\juuu" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\j123" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\j999" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\j444h" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\U00110000" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\U80000000" ) ); + TAO_PEGTL_TEST_ASSERT( verify_fail( "\\Uffffffff" ) ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/contrib_uri.cpp b/packages/PEGTL/src/test/pegtl/contrib_uri.cpp index e77c3996744537c9fc4692705b359ced4de14e94..7ae74cd9038d4e2b0353acf62ac0a77d47a62855 100644 --- a/packages/PEGTL/src/test/pegtl/contrib_uri.cpp +++ b/packages/PEGTL/src/test/pegtl/contrib_uri.cpp @@ -1,8 +1,15 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" -#include "verify_fail.hpp" #include "verify_meta.hpp" #include "verify_rule.hpp" @@ -34,9 +41,11 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< GRAMMAR >( __LINE__, __FILE__, "crid://broadcaster.com/movies/BestActionMovieEver", result_type::success, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "http://nobody:password@example.org:8080/cgi-bin/script.php?action=submit&pageid=86392001#section_2", result_type::success, 0 ); - verify_fail< GRAMMAR >( __LINE__, __FILE__, "" ); + TAO_PEGTL_TEST_THROWS( parse< GRAMMAR >( memory_input( "", "" ) ) ); } } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/control_unwind.cpp b/packages/PEGTL/src/test/pegtl/control_unwind.cpp index ad7d1251b84831c605f45256dc4b1e0f29318a8d..b07dcdcccd91882f5db6d5514bc59ad6636e4ffc 100644 --- a/packages/PEGTL/src/test/pegtl/control_unwind.cpp +++ b/packages/PEGTL/src/test/pegtl/control_unwind.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include <tao/pegtl.hpp> #include "test.hpp" @@ -57,7 +65,7 @@ namespace TAO_PEGTL_NAMESPACE memory_input in( "a1", __FUNCTION__ ); try { parse< r, a, c >( in ); - TAO_PEGTL_TEST_ASSERT( false ); + TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } catch( const int& e ) { TAO_PEGTL_TEST_ASSERT( e == 42 ); @@ -68,3 +76,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/data_cstring.cpp b/packages/PEGTL/src/test/pegtl/data_cstring.cpp index bf8dd4a8036038c438b84831b4b493e039cc0b14..fc1e5c270c48c1b833781650b3def2e6ed342fe7 100644 --- a/packages/PEGTL/src/test/pegtl/data_cstring.cpp +++ b/packages/PEGTL/src/test/pegtl/data_cstring.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/demangle.cpp b/packages/PEGTL/src/test/pegtl/demangle.cpp index 8288a5d87ca48d9abf703692f1630b9da73bd198..c1ae7396e4c798e478f09547163bf4c54fd8c766 100644 --- a/packages/PEGTL/src/test/pegtl/demangle.cpp +++ b/packages/PEGTL/src/test/pegtl/demangle.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -20,7 +20,7 @@ namespace TAO_PEGTL_NAMESPACE test< int >( "i" ); test< double >( "d" ); test< seq< bytes< 42 >, eof > >( "N3tao5pegtl3seqIJNS0_5bytesILj42EEENS0_3eofEEEE" ); -#elif defined( _MSC_VER ) +#elif defined( _MSC_VER ) && !defined( __clang__ ) test< int >( "int" ); test< double >( "double" ); // in the Microsoft world, class and struct are not the same! diff --git a/packages/PEGTL/src/test/pegtl/discard_input.cpp b/packages/PEGTL/src/test/pegtl/discard_input.cpp index 3033d365db8c378dea636b55b59b7f5365eb9518..996d75c8a86512cf30ed192920c3212031f696a4 100644 --- a/packages/PEGTL/src/test/pegtl/discard_input.cpp +++ b/packages/PEGTL/src/test/pegtl/discard_input.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <string> @@ -30,20 +30,28 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( parse_cstring< rep< 4, sor< n, n > >, my_action >( "nnnn", TAO_TEST_LINE, 2 ) ); +#endif TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< a, n > >, my_action >( "nnnn", TAO_TEST_LINE, 2 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< f, n > >, my_action >( "nnnn", TAO_TEST_LINE, 2 ) ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( parse_cstring< rep< 4, sor< s, n > >, my_action >( "nnnn", TAO_TEST_LINE, 2 ) ); +#endif TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< n, a > >, my_action >( "aaaa", TAO_TEST_LINE, 2 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< a, a > >, my_action >( "aaaa", TAO_TEST_LINE, 2 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< f, a > >, my_action >( "aaaa", TAO_TEST_LINE, 2 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< s, a > >, my_action >( "aaaa", TAO_TEST_LINE, 2 ) ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( parse_cstring< rep< 4, sor< n, f > >, my_action >( "ffff", TAO_TEST_LINE, 2 ) ); +#endif TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< a, f > >, my_action >( "ffff", TAO_TEST_LINE, 2 ) ); +#if defined( __cpp_exceptions ) TAO_PEGTL_TEST_THROWS( parse_cstring< rep< 4, sor< f, f > >, my_action >( "ffff", TAO_TEST_LINE, 2 ) ); TAO_PEGTL_TEST_THROWS( parse_cstring< rep< 4, sor< s, f > >, my_action >( "ffff", TAO_TEST_LINE, 2 ) ); +#endif TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< n, s > >, my_action >( "ssss", TAO_TEST_LINE, 2 ) ); TAO_PEGTL_TEST_ASSERT( parse_cstring< rep< 4, sor< a, s > >, my_action >( "ssss", TAO_TEST_LINE, 2 ) ); diff --git a/packages/PEGTL/src/test/pegtl/enable_control.cpp b/packages/PEGTL/src/test/pegtl/enable_control.cpp index 672b4a4a932c97c6baf202d030dc5ee81aa805ae..29c76c1379a51cb120d4f3bcaee0b8dcc9a58a62 100644 --- a/packages/PEGTL/src/test/pegtl/enable_control.cpp +++ b/packages/PEGTL/src/test/pegtl/enable_control.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <tao/pegtl.hpp> diff --git a/packages/PEGTL/src/test/pegtl/error_message.cpp b/packages/PEGTL/src/test/pegtl/error_message.cpp index ff4d1780e9d69ce85a727d1d181c98fdb9168d95..8e19e9ae85f4ad0bc7f076def9b1b193d968ff1b 100644 --- a/packages/PEGTL/src/test/pegtl/error_message.cpp +++ b/packages/PEGTL/src/test/pegtl/error_message.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" namespace test1 @@ -27,15 +35,15 @@ namespace TAO_PEGTL_NAMESPACE { try { parse< test1::grammar, nothing, test1::control >( memory_input( "c", __FUNCTION__ ) ); - TAO_PEGTL_TEST_ASSERT( false ); + TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } catch( const parse_error& e ) { - if( e.message() != "test123" ) { - throw; - } + TAO_PEGTL_TEST_ASSERT( e.message() == "test123" ); } } } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/file_cstream.cpp b/packages/PEGTL/src/test/pegtl/file_cstream.cpp index 85d13f443da76f502c1515f5579c570ca193f4e2..93051028300e02b64231ee21f0fb8bbba8427969 100644 --- a/packages/PEGTL/src/test/pegtl/file_cstream.cpp +++ b/packages/PEGTL/src/test/pegtl/file_cstream.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <clocale> diff --git a/packages/PEGTL/src/test/pegtl/file_file.cpp b/packages/PEGTL/src/test/pegtl/file_file.cpp index c7a4a904161a549ee2e530ad17761231cc2ac1bf..61abd5e31a1e1a73ae8b8cc8f0e139088fdc455a 100644 --- a/packages/PEGTL/src/test/pegtl/file_file.cpp +++ b/packages/PEGTL/src/test/pegtl/file_file.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/file_istream.cpp b/packages/PEGTL/src/test/pegtl/file_istream.cpp index 9b76d071e728dad6521f9b68467aa963492fc8c1..41d1a84eb74e99e265c149fd9c32041e1a0f9933 100644 --- a/packages/PEGTL/src/test/pegtl/file_istream.cpp +++ b/packages/PEGTL/src/test/pegtl/file_istream.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <cerrno> @@ -18,18 +18,20 @@ namespace TAO_PEGTL_NAMESPACE void unit_test() { +#if defined( __cpp_exceptions ) { const char* filename = "src/test/pegtl/no_such_file.txt"; try { std::ifstream stream( filename ); parse< file_grammar >( istream_input( stream, 16, filename ) ); - TAO_PEGTL_TEST_ASSERT( false ); + TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } catch( const std::system_error& e ) { TAO_PEGTL_TEST_ASSERT( e.code().category() == std::system_category() ); TAO_PEGTL_TEST_ASSERT( e.code().value() == ENOENT ); } } +#endif const char* filename = "src/test/pegtl/file_data.txt"; std::ifstream stream( filename ); diff --git a/packages/PEGTL/src/test/pegtl/file_mmap.cpp b/packages/PEGTL/src/test/pegtl/file_mmap.cpp index 478b3b1f0181452324829c63011734b753da7e15..e9fd5804d06db85350aeadb05ccde36859561c96 100644 --- a/packages/PEGTL/src/test/pegtl/file_mmap.cpp +++ b/packages/PEGTL/src/test/pegtl/file_mmap.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ // this include gives us _POSIX_MAPPED_FILES to test and mmap_input<> if it is set diff --git a/packages/PEGTL/src/test/pegtl/file_read.cpp b/packages/PEGTL/src/test/pegtl/file_read.cpp index 66f52fdd54e348df8d2265be8aec14dee403f51a..4e2ee3bb7e15d15fedfe770cb2ca6812bd515dc4 100644 --- a/packages/PEGTL/src/test/pegtl/file_read.cpp +++ b/packages/PEGTL/src/test/pegtl/file_read.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -10,7 +10,7 @@ namespace TAO_PEGTL_NAMESPACE struct open_input : public read_input< P, Eol > { - explicit open_input( const std::filesystem::path& path ) + explicit open_input( const internal::filesystem::path& path ) : read_input< P, Eol >( internal::file_open( path ), path ) {} }; diff --git a/packages/PEGTL/src/test/pegtl/icu_general.cpp b/packages/PEGTL/src/test/pegtl/icu_general.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7191cbbe4188c627ac35ee08505f51f91fa8dbc1 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/icu_general.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" +#include "verify_meta.hpp" +#include "verify_rule.hpp" + +//#include <tao/pegtl/contrib/icu/utf8.hpp> + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + // verify_analyze< utf8::icu::alphabetic >( __LINE__, __FILE__, true, false ); + + // verify_rule< utf8::icu::alphabetic >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); + // verify_rule< utf8::icu::alphabetic >( __LINE__, __FILE__, "a", result_type::success ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/internal_endian.cpp b/packages/PEGTL/src/test/pegtl/internal_endian.cpp index 6319a70cec05a650de1f4f89684c09a31dd83eb6..50296fd176bab4dca5a457de3248e2834d072bd1 100644 --- a/packages/PEGTL/src/test/pegtl/internal_endian.cpp +++ b/packages/PEGTL/src/test/pegtl/internal_endian.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <tao/pegtl/contrib/internal/endian.hpp> @@ -18,8 +18,7 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( internal::le_to_h( std::int8_t( 0x7a ) ) == std::int8_t( 0x7a ) ); TAO_PEGTL_TEST_ASSERT( internal::le_to_h( std::uint8_t( 0x7a ) ) == std::uint8_t( 0x7a ) ); - const std::uint16_t a = 1; - if( *static_cast< const std::uint8_t* >( static_cast< const void* >( &a ) ) != 1 ) { + if constexpr( internal::endian::native == internal::endian::big ) { TAO_PEGTL_TEST_ASSERT( internal::h_to_be( std::int16_t( 0x7a39 ) ) == std::int16_t( 0x7a39 ) ); TAO_PEGTL_TEST_ASSERT( internal::h_to_be( std::uint16_t( 0x7a39 ) ) == std::uint16_t( 0x7a39 ) ); TAO_PEGTL_TEST_ASSERT( internal::h_to_le( std::int16_t( 0x7a39 ) ) == std::int16_t( 0x397a ) ); @@ -47,7 +46,7 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( internal::le_to_h( std::int64_t( 0x7a391f2b33445567 ) ) == std::int64_t( 0x675544332b1f397a ) ); TAO_PEGTL_TEST_ASSERT( internal::le_to_h( std::uint64_t( 0x7a391f2b33445567 ) ) == std::uint64_t( 0x675544332b1f397a ) ); } - else { + else if constexpr( internal::endian::native == internal::endian::little ) { TAO_PEGTL_TEST_ASSERT( internal::h_to_le( std::int16_t( 0x7a39 ) ) == std::int16_t( 0x7a39 ) ); TAO_PEGTL_TEST_ASSERT( internal::h_to_le( std::uint16_t( 0x7a39 ) ) == std::uint16_t( 0x7a39 ) ); TAO_PEGTL_TEST_ASSERT( internal::h_to_be( std::int16_t( 0x7a39 ) ) == std::int16_t( 0x397a ) ); @@ -75,6 +74,9 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( internal::be_to_h( std::int64_t( 0x7a391f2b33445567 ) ) == std::int64_t( 0x675544332b1f397a ) ); TAO_PEGTL_TEST_ASSERT( internal::be_to_h( std::uint64_t( 0x7a391f2b33445567 ) ) == std::uint64_t( 0x675544332b1f397a ) ); } + else { + TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE + } } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/internal_file_mapper.cpp b/packages/PEGTL/src/test/pegtl/internal_file_mapper.cpp index 99133ba8b0638b9da36e5498b38f20e4df7f20cc..2cf26fa40dbeb88f855407e24698e1c6a2ceb9df 100644 --- a/packages/PEGTL/src/test/pegtl/internal_file_mapper.cpp +++ b/packages/PEGTL/src/test/pegtl/internal_file_mapper.cpp @@ -1,9 +1,15 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#include <tao/pegtl/file_input.hpp> +#if !defined( __cpp_exceptions ) || !defined( _POSIX_MAPPED_FILES ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else -#if defined( _POSIX_MAPPED_FILES ) +#include <tao/pegtl/file_input.hpp> #include "test.hpp" @@ -13,15 +19,19 @@ namespace TAO_PEGTL_NAMESPACE { try { internal::file_mapper dummy( "include" ); + // LCOV_EXCL_START std::cerr << "pegtl: unit test failed for [ internal::file_mapper ]" << std::endl; ++failed; + // LCOV_EXCL_END } - catch( const std::system_error& ) { + catch( const internal::filesystem::filesystem_error& ) { } + // LCOV_EXCL_START catch( ... ) { std::cerr << "pegtl: unit test failed for [ internal::file_mapper ] with unexpected exception" << std::endl; ++failed; } + // LCOV_EXCL_END const std::string s = "dummy content\n"; const std::string dummy_content = s + s + s + s + s + s + s + s + s + s + s; @@ -37,11 +47,4 @@ namespace TAO_PEGTL_NAMESPACE #include "main.hpp" -#else - -int main() -{ - return 0; -} - #endif diff --git a/packages/PEGTL/src/test/pegtl/internal_file_opener.cpp b/packages/PEGTL/src/test/pegtl/internal_file_opener.cpp index 3a3dc3c2c8a6ab40678c4563bba8112f6aa9a1e7..33f7aba203bc5de016b09656095aec901adf2363 100644 --- a/packages/PEGTL/src/test/pegtl/internal_file_opener.cpp +++ b/packages/PEGTL/src/test/pegtl/internal_file_opener.cpp @@ -1,9 +1,15 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ -#include <tao/pegtl/file_input.hpp> +#if !defined( __cpp_exceptions ) || !defined( _POSIX_MAPPED_FILES ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else -#if defined( _POSIX_MAPPED_FILES ) +#include <tao/pegtl/file_input.hpp> #include "test.hpp" @@ -16,8 +22,10 @@ namespace TAO_PEGTL_NAMESPACE try { (void)fo.size(); // expected to throw + // LCOV_EXCL_START std::cerr << "pegtl: unit test failed for [ internal::file_opener ] " << std::endl; ++failed; + // LCOV_EXCL_END } catch( const std::exception& ) { } @@ -27,11 +35,4 @@ namespace TAO_PEGTL_NAMESPACE #include "main.hpp" -#else - -int main() -{ - return 0; -} - #endif diff --git a/packages/PEGTL/src/test/pegtl/main.hpp b/packages/PEGTL/src/test/pegtl/main.hpp index 3b92ee527c403f6f0961ce2eba2b313225cb9a08..f216e73dc4bbfe40be8f883eaa81a97bee648c26 100644 --- a/packages/PEGTL/src/test/pegtl/main.hpp +++ b/packages/PEGTL/src/test/pegtl/main.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_MAIN_HPP @@ -12,7 +12,7 @@ int main( int /*unused*/, char** argv ) TAO_PEGTL_NAMESPACE::unit_test(); if( TAO_PEGTL_NAMESPACE::failed != 0 ) { - std::cerr << "pegtl: unit test " << argv[ 0 ] << " failed " << TAO_PEGTL_NAMESPACE::failed << std::endl; + std::cerr << "pegtl: unit test " << argv[ 0 ] << " failed " << TAO_PEGTL_NAMESPACE::failed << std::endl; // LCOV_EXCL_LINE } return ( TAO_PEGTL_NAMESPACE::failed == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/packages/PEGTL/src/test/pegtl/parse_error.cpp b/packages/PEGTL/src/test/pegtl/parse_error.cpp index 6cab22e9a71bb7982b9162cc70e4bbf880ca2af1..6141e3efc7549ac1e48e8de36cb33ec5dcacd2cc 100644 --- a/packages/PEGTL/src/test/pegtl/parse_error.cpp +++ b/packages/PEGTL/src/test/pegtl/parse_error.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" @@ -45,7 +53,7 @@ namespace TAO_PEGTL_NAMESPACE return; } - TAO_PEGTL_TEST_UNREACHABLE; + TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } void unit_test() @@ -57,3 +65,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp b/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp index 2118e393428a6e29c90e87649a5c8c6822737c37..ff3cc3ac8498e245134c5cc775803c2d548b49a8 100644 --- a/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp +++ b/packages/PEGTL/src/test/pegtl/pegtl_string_t.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <type_traits> diff --git a/packages/PEGTL/src/test/pegtl/position.cpp b/packages/PEGTL/src/test/pegtl/position.cpp index c1912679067f95fd543519135bf6b5eaeb4a7bbd..666f182ab5bf79f2ab98ebfa07705a68cc099eb1 100644 --- a/packages/PEGTL/src/test/pegtl/position.cpp +++ b/packages/PEGTL/src/test/pegtl/position.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include <tao/pegtl/internal/cstring_reader.hpp> @@ -67,7 +75,7 @@ namespace TAO_PEGTL_NAMESPACE struct outer_action< two< 'b' > > { template< typename ActionInput > - static void apply( const ActionInput& oi ) + static void apply( const ActionInput& oi, const bool mode ) { const auto p = oi.position(); TAO_PEGTL_TEST_ASSERT( p.source == "outer" ); @@ -75,30 +83,63 @@ namespace TAO_PEGTL_NAMESPACE TAO_PEGTL_TEST_ASSERT( p.line == 1 ); TAO_PEGTL_TEST_ASSERT( p.column == 3 ); memory_input in( "dFF", "inner" ); - parse_nested< inner_grammar >( oi, in ); + if( mode ) { + parse_nested< inner_grammar >( oi, in ); + } + else { + parse_nested< inner_grammar >( oi.position(), in ); + } } }; + void test_nested_asserts( const parse_error& e ) + { + TAO_PEGTL_TEST_ASSERT( e.positions().size() == 2 ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].source == "inner" ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].byte == 1 ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].line == 1 ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].column == 2 ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].source == "outer" ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].byte == 2 ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].line == 1 ); + TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].column == 3 ); + } + template< typename ParseInput = memory_input<> > void test_nested() { try { memory_input oi( "aabbcc", "outer" ); - parse< outer_grammar, outer_action >( oi ); + parse< outer_grammar, outer_action >( oi, true ); } catch( const parse_error& e ) { - TAO_PEGTL_TEST_ASSERT( e.positions().size() == 2 ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].source == "inner" ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].byte == 1 ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].line == 1 ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 0 ].column == 2 ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].source == "outer" ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].byte == 2 ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].line == 1 ); - TAO_PEGTL_TEST_ASSERT( e.positions()[ 1 ].column == 3 ); + test_nested_asserts( e ); + } + try { + memory_input oi( "aabbcc", "outer" ); + parse< outer_grammar, outer_action >( oi, false ); + } + catch( const parse_error& e ) { + test_nested_asserts( e ); } } + void test_iterator() + { + const std::string s = "source"; + const internal::iterator i( nullptr, 1, 2, 3 ); + const position p( i, s ); + TAO_PEGTL_TEST_ASSERT( p.byte == 1 ); + TAO_PEGTL_TEST_ASSERT( p.line == 2 ); + TAO_PEGTL_TEST_ASSERT( p.column == 3 ); + TAO_PEGTL_TEST_ASSERT( p.source == s ); + const position q( 1, 2, 3, s ); + TAO_PEGTL_TEST_ASSERT( q.byte == 1 ); + TAO_PEGTL_TEST_ASSERT( q.line == 2 ); + TAO_PEGTL_TEST_ASSERT( q.column == 3 ); + TAO_PEGTL_TEST_ASSERT( q.source == s ); + } + void unit_test() { test_matches_lf< any >(); @@ -166,8 +207,12 @@ namespace TAO_PEGTL_NAMESPACE test_nested<>(); test_nested< buffer_input_t >(); + + test_iterator(); } } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/restart_input.cpp b/packages/PEGTL/src/test/pegtl/restart_input.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3cb964c88bc0019aa15c24201980b044659fcfa1 --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/restart_input.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + using grammar = seq< string< 'a', 'b', 'c' >, eof >; + + void test_lazy() + { + const std::string data = "abc"; + memory_input< tracking_mode::lazy, eol::lf_crlf, std::string > in( data, __FUNCTION__ ); + bool success = parse< grammar >( in ); + TAO_PEGTL_TEST_ASSERT( success ); + in.restart(); + success = parse< grammar >( in ); + TAO_PEGTL_TEST_ASSERT( success ); + } + + void test_eager() + { + const std::string data = "abc"; + memory_input< tracking_mode::eager, eol::lf_crlf, std::string > in( std::string_view( data ), __FUNCTION__ ); + bool success = parse< grammar >( in ); + TAO_PEGTL_TEST_ASSERT( success ); + in.restart(); + success = parse< grammar >( in ); + TAO_PEGTL_TEST_ASSERT( success ); + } + + void unit_test() + { + test_lazy(); + test_eager(); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/result_type.hpp b/packages/PEGTL/src/test/pegtl/result_type.hpp index 887fdde983fac1cddb8ec972ada6ba93b6601997..91b84a6e0906bb44bea4c375558d1537ea298705 100644 --- a/packages/PEGTL/src/test/pegtl/result_type.hpp +++ b/packages/PEGTL/src/test/pegtl/result_type.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_RESULT_TYPE_HPP @@ -10,7 +10,7 @@ namespace TAO_PEGTL_NAMESPACE { - enum class result_type + enum class result_type : int { success = 1, local_failure = 0, @@ -23,11 +23,11 @@ namespace TAO_PEGTL_NAMESPACE case result_type::success: return o << "success"; case result_type::local_failure: - return o << "local failure"; + return o << "local_failure"; case result_type::global_failure: - return o << "global failure"; + return o << "global_failure"; } - return o << int( t ); + return o << static_cast< int >( t ); } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/rule_action.cpp b/packages/PEGTL/src/test/pegtl/rule_action.cpp index 2e5096da0c437c788d73ddf50d032bcb6d5b9065..cdaae0c7c4df719f4d45cba93636eaa0cb51af17 100644 --- a/packages/PEGTL/src/test/pegtl/rule_action.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_action.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_apply.cpp b/packages/PEGTL/src/test/pegtl/rule_apply.cpp index 147e27936eb67e2179a8725a5aa16585365daa50..722fe096c632c7eca37e76c2fd53ef426ed7ee45 100644 --- a/packages/PEGTL/src/test/pegtl/rule_apply.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_apply.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -54,11 +54,13 @@ namespace TAO_PEGTL_NAMESPACE struct action2_c { + // LCOV_EXCL_START template< typename ActionInput > static void apply( const ActionInput& /*unused*/, bool& /*unused*/ ) { TAO_PEGTL_TEST_ASSERT( false ); } + // LCOV_EXCL_END }; } // namespace test1 @@ -67,16 +69,15 @@ namespace TAO_PEGTL_NAMESPACE { int state_r = 0; int state_s = 0; - parse< must< apply< test1::action_a, test1::action_b > > >( memory_input( "", __FUNCTION__ ), state_r, state_s ); + TAO_PEGTL_TEST_ASSERT( parse< apply< test1::action_a, test1::action_b > >( memory_input( "", __FUNCTION__ ), state_r, state_s ) ); TAO_PEGTL_TEST_ASSERT( state_r == 1 ); TAO_PEGTL_TEST_ASSERT( state_s == 2 ); - parse< must< disable< apply< test1::action_a, test1::action_b > > > >( memory_input( "", __FUNCTION__ ), state_r, state_s ); + TAO_PEGTL_TEST_ASSERT( parse< disable< apply< test1::action_a, test1::action_b > > >( memory_input( "", __FUNCTION__ ), state_r, state_s ) ); TAO_PEGTL_TEST_ASSERT( state_r == 1 ); TAO_PEGTL_TEST_ASSERT( state_s == 2 ); bool state_b = false; - const bool result = parse< apply< test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "", __FUNCTION__ ), state_b ); - TAO_PEGTL_TEST_ASSERT( !result ); + TAO_PEGTL_TEST_ASSERT( !parse< apply< test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "", __FUNCTION__ ), state_b ) ); TAO_PEGTL_TEST_ASSERT( state_b ); verify_meta< apply< test1::action_a, test1::action_b >, internal::apply< test1::action_a, test1::action_b > >(); diff --git a/packages/PEGTL/src/test/pegtl/rule_apply0.cpp b/packages/PEGTL/src/test/pegtl/rule_apply0.cpp index 1a5aebe7744ae421732a66289a017599bb9c1c20..010fca8d29aca776cd0c80e1d7599327c7fe4df1 100644 --- a/packages/PEGTL/src/test/pegtl/rule_apply0.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_apply0.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -50,10 +50,12 @@ namespace TAO_PEGTL_NAMESPACE struct action2_c { + // LCOV_EXCL_START static void apply0( bool& /*unused*/ ) { TAO_PEGTL_TEST_ASSERT( false ); } + // LCOV_EXCL_END }; } // namespace test1 @@ -62,16 +64,15 @@ namespace TAO_PEGTL_NAMESPACE { int state_r = 0; int state_s = 0; - parse< must< apply0< test1::action_a, test1::action_b > > >( memory_input( "", __FUNCTION__ ), state_r, state_s ); + TAO_PEGTL_TEST_ASSERT( parse< apply0< test1::action_a, test1::action_b > >( memory_input( "", __FUNCTION__ ), state_r, state_s ) ); TAO_PEGTL_TEST_ASSERT( state_r == 1 ); TAO_PEGTL_TEST_ASSERT( state_s == 2 ); - parse< must< disable< apply< test1::action_a, test1::action_b > > > >( memory_input( "", __FUNCTION__ ), state_r, state_s ); + TAO_PEGTL_TEST_ASSERT( parse< disable< apply< test1::action_a, test1::action_b > > >( memory_input( "", __FUNCTION__ ), state_r, state_s ) ); TAO_PEGTL_TEST_ASSERT( state_r == 1 ); TAO_PEGTL_TEST_ASSERT( state_s == 2 ); bool state_b = false; - const bool result = parse< apply0< test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "", __FUNCTION__ ), state_b ); - TAO_PEGTL_TEST_ASSERT( !result ); + TAO_PEGTL_TEST_ASSERT( !parse< apply0< test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "", __FUNCTION__ ), state_b ) ); TAO_PEGTL_TEST_ASSERT( state_b ); verify_meta< apply0< test1::action_a, test1::action_b >, internal::apply0< test1::action_a, test1::action_b > >(); diff --git a/packages/PEGTL/src/test/pegtl/rule_at.cpp b/packages/PEGTL/src/test/pegtl/rule_at.cpp index 0fd1626781d3ca9eb6c25ec2d31836b2fe02e7c8..8d24f4e217fdcc1105129a1d5d49637355cdfc54 100644 --- a/packages/PEGTL/src/test/pegtl/rule_at.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_at.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -40,8 +40,12 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< at< any > >( __LINE__, __FILE__, "a", result_type::success, 1 ); verify_rule< at< any > >( __LINE__, __FILE__, "aa", result_type::success, 2 ); verify_rule< at< any > >( __LINE__, __FILE__, "aaaa", result_type::success, 4 ); + +#if defined( __cpp_exceptions ) verify_rule< must< at< alpha > > >( __LINE__, __FILE__, "1", result_type::global_failure, 1 ); verify_rule< must< at< alpha, alpha > > >( __LINE__, __FILE__, "a1a", result_type::global_failure, 3 ); +#endif + { memory_input in( "f", 1, __FILE__ ); parse< any, at_action >( in ); diff --git a/packages/PEGTL/src/test/pegtl/rule_bof.cpp b/packages/PEGTL/src/test/pegtl/rule_bof.cpp index 996505c1645ad9bd9ec9273a6ffba2e231a67429..e7e563ee7999af7fbd2ea856e67a139531d5baf6 100644 --- a/packages/PEGTL/src/test/pegtl/rule_bof.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_bof.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_bol.cpp b/packages/PEGTL/src/test/pegtl/rule_bol.cpp index cda3de5a6ae3a24dedfef17d68582aa765db51cb..34c63020bcedddef349c9428aab458df37b93ef0 100644 --- a/packages/PEGTL/src/test/pegtl/rule_bol.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_bol.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_bytes.cpp b/packages/PEGTL/src/test/pegtl/rule_bytes.cpp index ea20546d3b80c25fe28db9512c6c05faad23a70d..2caa4834a28deb9ba00c0b2ca4830030fd961f3d 100644 --- a/packages/PEGTL/src/test/pegtl/rule_bytes.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_bytes.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_control.cpp b/packages/PEGTL/src/test/pegtl/rule_control.cpp index 214e536b7010ea6f1d04dbeff3ce4e35c29e0645..baaef260eab0c59bb4ab438ddb156993fd5b5757 100644 --- a/packages/PEGTL/src/test/pegtl/rule_control.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_control.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_disable.cpp b/packages/PEGTL/src/test/pegtl/rule_disable.cpp index f3b67b8ff55ab248327c465cb5fa1aec9d5258ed..acbbb9f3f1a9a0832f878b86557a07579468bbb7 100644 --- a/packages/PEGTL/src/test/pegtl/rule_disable.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_disable.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_discard.cpp b/packages/PEGTL/src/test/pegtl/rule_discard.cpp index 5cb4b52d3a15784cbee390b2d7695a474612cdd7..8e5b93d1e408edd016a1668c37e8522054244f3e 100644 --- a/packages/PEGTL/src/test/pegtl/rule_discard.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_discard.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_enable.cpp b/packages/PEGTL/src/test/pegtl/rule_enable.cpp index b045319e4b76b4d1185ee73ea64d321746a3fa19..9741545fe7390a753566f0b04b6ddb43fcb26c1b 100644 --- a/packages/PEGTL/src/test/pegtl/rule_enable.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_enable.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_eof.cpp b/packages/PEGTL/src/test/pegtl/rule_eof.cpp index f608a1597d745b5de5fc8a2fcd35705ff1be4a89..b5098b40cf178a1329d0fa27d21de660a1503b12 100644 --- a/packages/PEGTL/src/test/pegtl/rule_eof.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_eof.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_failure.cpp b/packages/PEGTL/src/test/pegtl/rule_failure.cpp index 9beb769b89ce0d27079fffd66e323868b8fd29a5..c1481d4d1d6c7d259fc00260553a31c514760434 100644 --- a/packages/PEGTL/src/test/pegtl/rule_failure.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_failure.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_if_apply.cpp b/packages/PEGTL/src/test/pegtl/rule_if_apply.cpp index 82d3cb7bfe7d7e49acc1b60815bc3cc1c47b1c94..4297e9a8c80d473dd765f800288cfd1e8ced903f 100644 --- a/packages/PEGTL/src/test/pegtl/rule_if_apply.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_if_apply.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -55,11 +55,13 @@ namespace TAO_PEGTL_NAMESPACE struct action2_c { + // LCOV_EXCL_START template< typename ActionInput > static void apply( const ActionInput& /*unused*/, bool& /*unused*/ ) { TAO_PEGTL_TEST_ASSERT( false ); } + // LCOV_EXCL_END }; template< typename Rule > @@ -91,27 +93,25 @@ namespace TAO_PEGTL_NAMESPACE std::string state_s; TAO_PEGTL_TEST_ASSERT( test1::flag == 0 ); memory_input in1( "-", __FUNCTION__ ); - parse< must< if_apply< one< '-' >, test1::action_a, test1::action_b > >, test1::action >( in1, state_r, state_s ); + TAO_PEGTL_TEST_ASSERT( parse< if_apply< one< '-' >, test1::action_a, test1::action_b >, test1::action >( in1, state_r, state_s ) ); TAO_PEGTL_TEST_ASSERT( test1::flag == 1 ); TAO_PEGTL_TEST_ASSERT( state_r == "-" ); TAO_PEGTL_TEST_ASSERT( state_s == "-*-" ); memory_input in2( "-", __FUNCTION__ ); - parse< must< disable< if_apply< one< '-' >, test1::action_a, test1::action_b > > >, test1::action >( in2, state_r, state_s ); + TAO_PEGTL_TEST_ASSERT( parse< disable< if_apply< one< '-' >, test1::action_a, test1::action_b > >, test1::action >( in2, state_r, state_s ) ); TAO_PEGTL_TEST_ASSERT( test1::flag == 1 ); TAO_PEGTL_TEST_ASSERT( state_r == "-" ); TAO_PEGTL_TEST_ASSERT( state_s == "-*-" ); { bool state_b = false; - const bool result = parse< if_apply< plus< alpha >, test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "foo bar", __FUNCTION__ ), state_b ); - TAO_PEGTL_TEST_ASSERT( !result ); + TAO_PEGTL_TEST_ASSERT( !parse< if_apply< plus< alpha >, test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "foo bar", __FUNCTION__ ), state_b ) ); TAO_PEGTL_TEST_ASSERT( state_b ); } { bool state_b = false; - const bool result = parse< if_apply< plus< alpha >, test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "", __FUNCTION__ ), state_b ); - TAO_PEGTL_TEST_ASSERT( !result ); + TAO_PEGTL_TEST_ASSERT( !parse< if_apply< plus< alpha >, test1::action2_a, test1::action2_b, test1::action2_c > >( memory_input( "", __FUNCTION__ ), state_b ) ); TAO_PEGTL_TEST_ASSERT( !state_b ); } verify_meta< if_apply< any >, internal::if_apply< any >, any >(); diff --git a/packages/PEGTL/src/test/pegtl/rule_if_must.cpp b/packages/PEGTL/src/test/pegtl/rule_if_must.cpp index 54297f01d46e7e63e6b6d39c3253581a0bf31c03..6dd3754232ce1b333215ab30dc0cd496ae7920d8 100644 --- a/packages/PEGTL/src/test/pegtl/rule_if_must.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_if_must.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" #include "verify_rule.hpp" @@ -46,3 +54,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_if_must_else.cpp b/packages/PEGTL/src/test/pegtl/rule_if_must_else.cpp index 8fae642416e00ef4f5e67896ac93bcd9356876c4..0b7f370596405829571a99bdc956953e7a71c204 100644 --- a/packages/PEGTL/src/test/pegtl/rule_if_must_else.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_if_must_else.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_ifmt.hpp" @@ -14,3 +22,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_if_then_else.cpp b/packages/PEGTL/src/test/pegtl/rule_if_then_else.cpp index c31c540349ce1daa7a593a724b979a07b79b4f3d..dc15f6fb0688e270487563f40fe501707caa2aa1 100644 --- a/packages/PEGTL/src/test/pegtl/rule_if_then_else.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_if_then_else.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_list.cpp b/packages/PEGTL/src/test/pegtl/rule_list.cpp index dfd789f75236b2283e54a81a0a20e90519c32c09..106942f6dcc348a55c45d7f0fa958b64bfc50160 100644 --- a/packages/PEGTL/src/test/pegtl/rule_list.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_list.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_list_must.cpp b/packages/PEGTL/src/test/pegtl/rule_list_must.cpp index b036d33ce36ff105065c25e90f6e60ac138f39af..9de21172d522e07c5d71980b4965116b952f0708 100644 --- a/packages/PEGTL/src/test/pegtl/rule_list_must.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_list_must.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" #include "verify_rule.hpp" @@ -54,3 +62,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_list_tail.cpp b/packages/PEGTL/src/test/pegtl/rule_list_tail.cpp index e121f083b2e43e9c0b7c615614680c727f9188ed..d6e9dd59b8a507916550c7ca6e43f8506f286f18 100644 --- a/packages/PEGTL/src/test/pegtl/rule_list_tail.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_list_tail.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -41,9 +41,9 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ,a", result_type::success, 3 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a, a", result_type::success, 2 ); - verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); - verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " ", result_type::local_failure, 1 ); - verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, ",", result_type::local_failure, 1 ); + verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); + verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " ", result_type::local_failure, 1 ); + verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, ",", result_type::local_failure, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ", result_type::success, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a", result_type::local_failure, 2 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ,a", result_type::success, 0 ); diff --git a/packages/PEGTL/src/test/pegtl/rule_minus.cpp b/packages/PEGTL/src/test/pegtl/rule_minus.cpp index 8c55093e00cdb4c27bb155ccb90820b7ca32a113..4fd5f5722022b4b29f0ab9238338fa0cc0bdeffc 100644 --- a/packages/PEGTL/src/test/pegtl/rule_minus.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_minus.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2016-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -18,8 +18,10 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< minus< alnum, digit > >( __LINE__, __FILE__, "%", result_type::local_failure, 1 ); verify_rule< minus< alnum, digit > >( __LINE__, __FILE__, "a%", result_type::success, 1 ); +#if defined( __cpp_exceptions ) verify_rule< must< minus< alnum, digit > > >( __LINE__, __FILE__, "%", result_type::global_failure, 1 ); verify_rule< must< minus< alnum, digit > > >( __LINE__, __FILE__, "1", result_type::global_failure, 0 ); +#endif verify_rule< minus< plus< alnum >, digit > >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); verify_rule< minus< plus< alnum >, digit > >( __LINE__, __FILE__, "a", result_type::success, 0 ); diff --git a/packages/PEGTL/src/test/pegtl/rule_must.cpp b/packages/PEGTL/src/test/pegtl/rule_must.cpp index b93354ff07427b227ffc3e01a2ab01ae11d9d80a..f1d481132352e07f857cf5cd728a858934215f27 100644 --- a/packages/PEGTL/src/test/pegtl/rule_must.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_must.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_seqs.hpp" @@ -18,3 +26,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_not_at.cpp b/packages/PEGTL/src/test/pegtl/rule_not_at.cpp index 25dfc9648631ddecb9673b16c9b2eb170ce11f04..77cc80fc64e807d35d24687accc75779df600218 100644 --- a/packages/PEGTL/src/test/pegtl/rule_not_at.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_not_at.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -40,8 +40,12 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< not_at< any > >( __LINE__, __FILE__, "a", result_type::local_failure, 1 ); verify_rule< not_at< any > >( __LINE__, __FILE__, "aa", result_type::local_failure, 2 ); verify_rule< not_at< any > >( __LINE__, __FILE__, "aaaa", result_type::local_failure, 4 ); + +#if defined( __cpp_exceptions ) verify_rule< must< not_at< alpha > > >( __LINE__, __FILE__, "a", result_type::global_failure, 1 ); verify_rule< must< not_at< alpha, alpha > > >( __LINE__, __FILE__, "aa1", result_type::global_failure, 3 ); +#endif + { memory_input in( "a", 1, __FILE__ ); parse< alpha, at_action >( in ); diff --git a/packages/PEGTL/src/test/pegtl/rule_opt.cpp b/packages/PEGTL/src/test/pegtl/rule_opt.cpp index 3c300b9a59a6bb7ba5c6fb7654938a704909a87a..c07d22a4f619d5031b42a118d054f1f7f1ad2892 100644 --- a/packages/PEGTL/src/test/pegtl/rule_opt.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_opt.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -44,6 +44,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bab", result_type::success, 3 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "cb", result_type::success, 2 ); +#if defined( __cpp_exceptions ) verify_rule< must< opt< one< 'a' > > > >( __LINE__, __FILE__, "", result_type::success, 0 ); verify_rule< must< opt< one< 'a' > > > >( __LINE__, __FILE__, "a", result_type::success, 0 ); verify_rule< must< opt< one< 'a' > > > >( __LINE__, __FILE__, "aa", result_type::success, 1 ); @@ -57,10 +58,10 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< must< opt< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "abab", result_type::success, 2 ); verify_rule< must< opt< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "bab", result_type::success, 3 ); verify_rule< must< opt< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "cb", result_type::success, 2 ); +#endif bool success = false; - const bool result = parse< opt< eof >, my_action >( memory_input( "", __FUNCTION__ ), success ); - TAO_PEGTL_TEST_ASSERT( result ); + TAO_PEGTL_TEST_ASSERT( parse< opt< eof >, my_action >( memory_input( "", __FUNCTION__ ), success ) ); TAO_PEGTL_TEST_ASSERT( success ); } diff --git a/packages/PEGTL/src/test/pegtl/rule_opt_must.cpp b/packages/PEGTL/src/test/pegtl/rule_opt_must.cpp index e13ef58af6f34396e5444c497241c5b5d1d72873..5c1ce6e45daf75561ee38a232041913139276390 100644 --- a/packages/PEGTL/src/test/pegtl/rule_opt_must.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_opt_must.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" #include "verify_rule.hpp" @@ -42,3 +50,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_pad.cpp b/packages/PEGTL/src/test/pegtl/rule_pad.cpp index a3151dc20a7aca37a218cf7d3b48d1a553064874..918b1c67b8e5c987b4362d568d66eb6c068b5e6e 100644 --- a/packages/PEGTL/src/test/pegtl/rule_pad.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_pad.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_pad_opt.cpp b/packages/PEGTL/src/test/pegtl/rule_pad_opt.cpp index bb06f3e483605f623bcbb6ef219207a5a91d29fb..5ff4ded637a490f8e82cfb6d5b5df0d586c3454c 100644 --- a/packages/PEGTL/src/test/pegtl/rule_pad_opt.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_pad_opt.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_plus.cpp b/packages/PEGTL/src/test/pegtl/rule_plus.cpp index 6345b4a46a5cc56368d30e4eebce9bc70b16588e..d1a82ad3462177a93b7f34c6c64fb2b75463ff86 100644 --- a/packages/PEGTL/src/test/pegtl/rule_plus.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_plus.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_raise.cpp b/packages/PEGTL/src/test/pegtl/rule_raise.cpp index 565df60d294c3f90d8546d53fd9018981db0d7fe..25a67c8136e84fa840775efba6f2487c7121f856 100644 --- a/packages/PEGTL/src/test/pegtl/rule_raise.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_raise.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" @@ -35,3 +43,5 @@ namespace TAO_PEGTL_NAMESPACE #endif #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_rematch.cpp b/packages/PEGTL/src/test/pegtl/rule_rematch.cpp index ee467deee34864932f88d88e7c1144881fdb9011..22fca401d93226b98e27ff5f0ee98858d50168a3 100644 --- a/packages/PEGTL/src/test/pegtl/rule_rematch.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_rematch.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2019-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_rep.cpp b/packages/PEGTL/src/test/pegtl/rule_rep.cpp index b4bd7f97abd7f596e0e391741824c7e111bc54a9..7d7ef941f44228ffc9119e370c2d197cc6a1bc75 100644 --- a/packages/PEGTL/src/test/pegtl/rule_rep.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_rep.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -52,6 +52,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< rep< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababa", result_type::success, 1 ); verify_rule< rep< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababab", result_type::success, 2 ); +#if defined( __cpp_exceptions ) verify_rule< must< rep< 2, one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "", result_type::global_failure, 0 ); verify_rule< must< rep< 2, one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "a", result_type::global_failure, 1 ); verify_rule< must< rep< 2, one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "ab", result_type::global_failure, 0 ); @@ -67,6 +68,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< try_catch< must< rep< 2, one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "abab", result_type::success, 0 ); verify_rule< try_catch< must< rep< 2, one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "ababa", result_type::success, 1 ); verify_rule< try_catch< must< rep< 2, one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "ababab", result_type::success, 2 ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/rule_rep_max.cpp b/packages/PEGTL/src/test/pegtl/rule_rep_max.cpp index db1205a68e79ba15dca8f677006d539d567ece23..0b4a2c0d2c0c767e1f00281350aababa89fd8e49 100644 --- a/packages/PEGTL/src/test/pegtl/rule_rep_max.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_rep_max.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_rep_min.cpp b/packages/PEGTL/src/test/pegtl/rule_rep_min.cpp index c3648b94d43c67feb8c1b71938ba0422c517689a..8564aabbf972551159d06b6b3c2e2fb72e20db8d 100644 --- a/packages/PEGTL/src/test/pegtl/rule_rep_min.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_rep_min.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_rep_min_max.cpp b/packages/PEGTL/src/test/pegtl/rule_rep_min_max.cpp index de847617749f3ff0d6756d6b6c415608fb92aa9e..95d3db6311e1eaa0efb867d53f439821d23d6e1e 100644 --- a/packages/PEGTL/src/test/pegtl/rule_rep_min_max.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_rep_min_max.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -39,9 +39,11 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "baaa", result_type::local_failure, 4 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "baaaa", result_type::local_failure, 5 ); +#if defined( __cpp_exceptions ) verify_rule< must< rep_min_max< 3, 4, one< 'a' > > > >( __LINE__, __FILE__, "aa", result_type::global_failure, 0 ); verify_rule< try_catch< must< rep_min_max< 3, 4, one< 'a' > > > > >( __LINE__, __FILE__, "aa", result_type::local_failure, 2 ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/rule_rep_opt.cpp b/packages/PEGTL/src/test/pegtl/rule_rep_opt.cpp index 5d3cbc708b6c624d6e1301cb3ec051b353efde72..0f5a6b6779f9b86fb9c5a0908c9d8a43e7ce3e57 100644 --- a/packages/PEGTL/src/test/pegtl/rule_rep_opt.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_rep_opt.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_require.cpp b/packages/PEGTL/src/test/pegtl/rule_require.cpp index 4f4206696f49641626100bc79f5721ba15cf3c34..e6598a4ee577bac69252a3997db216887a89a61d 100644 --- a/packages/PEGTL/src/test/pegtl/rule_require.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_require.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2017-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_seq.cpp b/packages/PEGTL/src/test/pegtl/rule_seq.cpp index c5e3722b3d3c419e05669fdc0dfe668a2c9f281c..b80f478b4bbcc85ab12208163b0f3fb4109216b6 100644 --- a/packages/PEGTL/src/test/pegtl/rule_seq.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_seq.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_sor.cpp b/packages/PEGTL/src/test/pegtl/rule_sor.cpp index 11eb9a623619aa5d3aa546f5a13bd9c7693bb3ce..ec4258c2c8f93c5735441b6828bad3fcc5702c0f 100644 --- a/packages/PEGTL/src/test/pegtl/rule_sor.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_sor.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_star.cpp b/packages/PEGTL/src/test/pegtl/rule_star.cpp index f870d6a4c475e721f595a29516c721d8b49198fa..c6f46e0001cca3de8950ea8a5bb3a0e8efa467aa 100644 --- a/packages/PEGTL/src/test/pegtl/rule_star.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_star.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_star_must.cpp b/packages/PEGTL/src/test/pegtl/rule_star_must.cpp index 0a6410ad554db9e40ca1c1288bdb7ce5cc3a56ee..20747861a808d444e93ffb956fd9f64ecf8e961d 100644 --- a/packages/PEGTL/src/test/pegtl/rule_star_must.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_star_must.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_meta.hpp" #include "verify_rule.hpp" @@ -34,3 +42,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_state.cpp b/packages/PEGTL/src/test/pegtl/rule_state.cpp index c940ac224445716b15358e941b6ea77bd15ff108..8d92565b91103aaf6675bed55e5aa21e55674aa2 100644 --- a/packages/PEGTL/src/test/pegtl/rule_state.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_state.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_success.cpp b/packages/PEGTL/src/test/pegtl/rule_success.cpp index a6917da3c701a709ca8a2eb24956ed9ec28d4870..cf810c685992cd7c41b2903472ea57ceaa43805f 100644 --- a/packages/PEGTL/src/test/pegtl/rule_success.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_success.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/rule_try_catch.cpp b/packages/PEGTL/src/test/pegtl/rule_try_catch.cpp index 4259db331f94ed75b2ba613ff6ca262307831219..c9a5103045946788beb63bc1a66a5ffb7054d887 100644 --- a/packages/PEGTL/src/test/pegtl/rule_try_catch.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_try_catch.cpp @@ -1,6 +1,14 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ +#if !defined( __cpp_exceptions ) +#include <iostream> +int main() +{ + std::cout << "Exception support disabled, skipping test..." << std::endl; +} +#else + #include "test.hpp" #include "verify_seqs.hpp" @@ -18,3 +26,5 @@ namespace TAO_PEGTL_NAMESPACE } // namespace TAO_PEGTL_NAMESPACE #include "main.hpp" + +#endif diff --git a/packages/PEGTL/src/test/pegtl/rule_until.cpp b/packages/PEGTL/src/test/pegtl/rule_until.cpp index 24ab38ef008d8ebec2cfad979862dec765925ace..2d8c7faccdadfefb58824b1111b4ceb43aa495b4 100644 --- a/packages/PEGTL/src/test/pegtl/rule_until.cpp +++ b/packages/PEGTL/src/test/pegtl/rule_until.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" @@ -54,9 +54,11 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bbab", result_type::success, 1 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbbab", result_type::success, 1 ); +#if defined( __cpp_exceptions ) verify_rule< must< until< one< 'a' > > > >( __LINE__, __FILE__, "bbb", result_type::global_failure, 0 ); verify_rule< try_catch< must< until< one< 'a' > > > > >( __LINE__, __FILE__, "bbb", result_type::local_failure, 3 ); +#endif verify_rule< until< eof, any > >( __LINE__, __FILE__, "", result_type::success, 0 ); verify_rule< until< any, any > >( __LINE__, __FILE__, "", result_type::local_failure, 0 ); @@ -101,11 +103,13 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "cbcbc", result_type::local_failure, 5 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bcbcbc", result_type::local_failure, 6 ); +#if defined( __cpp_exceptions ) verify_rule< must< until< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "bbb", result_type::global_failure, 0 ); verify_rule< must< until< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "bbbc", result_type::global_failure, 1 ); verify_rule< try_catch< must< until< one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "bbb", result_type::local_failure, 3 ); verify_rule< try_catch< must< until< one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "bbbc", result_type::local_failure, 4 ); +#endif bool success = false; const bool result = parse< until< my_rule, eof >, my_action >( memory_input<>( "", __FUNCTION__ ), success ); diff --git a/packages/PEGTL/src/test/pegtl/test.hpp b/packages/PEGTL/src/test/pegtl/test.hpp index 5b017a559477a5b5fb499fdf2c6312b3f237a17c..95c6a59b36da917cfc19d5f97720ba6af3c2051a 100644 --- a/packages/PEGTL/src/test/pegtl/test.hpp +++ b/packages/PEGTL/src/test/pegtl/test.hpp @@ -1,10 +1,11 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_TEST_HPP #define TAO_PEGTL_SRC_TEST_PEGTL_TEST_HPP #include <cstddef> +#include <exception> #include <iostream> #include <tao/pegtl.hpp> @@ -22,18 +23,18 @@ namespace TAO_PEGTL_NAMESPACE #define TAO_PEGTL_TEST_UNWRAP( ... ) __VA_ARGS__ -#define TAO_PEGTL_TEST_FAILED( MeSSaGe ) \ - do { \ - std::cerr << "pegtl: unit test failed for [ " \ - << tao::demangle< Rule >() \ - << " ] " \ - << TAO_PEGTL_TEST_UNWRAP( MeSSaGe ) \ - << " in line [ " \ - << line \ - << " ] file [ " \ - << file << " ]" \ - << std::endl; \ - ++failed; \ +#define TAO_PEGTL_TEST_FAILED( MeSSaGe ) \ + do { \ + std::cerr << "pegtl: unit test failed for [ " \ + << TAO_PEGTL_NAMESPACE::demangle< Rule >() \ + << " ] " \ + << TAO_PEGTL_TEST_UNWRAP( MeSSaGe ) \ + << " in line [ " \ + << line \ + << " ] file [ " \ + << file << " ]" \ + << std::endl; \ + ++TAO_PEGTL_NAMESPACE::failed; \ } while( false ) #define TAO_PEGTL_TEST_ASSERT( ... ) \ @@ -46,7 +47,7 @@ namespace TAO_PEGTL_NAMESPACE << " ] file [ " \ << __FILE__ << " ]" \ << std::endl; \ - ++failed; \ + ++TAO_PEGTL_NAMESPACE::failed; \ } \ } while( false ) @@ -61,7 +62,7 @@ namespace TAO_PEGTL_NAMESPACE << " ] file [ " \ << __FILE__ << " ]" \ << std::endl; \ - ++failed; \ + ++TAO_PEGTL_NAMESPACE::failed; \ } \ catch( ... ) { \ } \ @@ -70,7 +71,7 @@ namespace TAO_PEGTL_NAMESPACE #define TAO_PEGTL_TEST_UNREACHABLE \ do { \ std::cerr << "Code should be unreachable in " << __FUNCTION__ << " (" << __FILE__ << ':' << __LINE__ << ')' << std::endl; \ - std::abort(); \ + std::terminate(); \ } while( false ) #endif diff --git a/packages/PEGTL/src/test/pegtl/test_empty.cpp b/packages/PEGTL/src/test/pegtl/test_empty.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b213f1ea81482c359ad0911c0daa12370a82a16c --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/test_empty.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include "test.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + {} + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/test_result.cpp b/packages/PEGTL/src/test/pegtl/test_result.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2bf7c5355c693e6c6e3473efb5bc3e289afead5f --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/test_result.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <sstream> + +#include "test.hpp" + +#include "result_type.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + void unit_test() + { + { + std::ostringstream oss; + oss << result_type::success; + TAO_PEGTL_TEST_ASSERT( oss.str() == "success" ); + } + { + std::ostringstream oss; + oss << result_type::local_failure; + TAO_PEGTL_TEST_ASSERT( oss.str() == "local_failure" ); + } + { + std::ostringstream oss; + oss << result_type::global_failure; + TAO_PEGTL_TEST_ASSERT( oss.str() == "global_failure" ); + } + { + std::ostringstream oss; + oss << result_type( 1764 ); + TAO_PEGTL_TEST_ASSERT( oss.str() == "1764" ); + } + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/packages/PEGTL/src/test/pegtl/tester.cpp b/packages/PEGTL/src/test/pegtl/test_setup.cpp similarity index 59% rename from packages/PEGTL/src/test/pegtl/tester.cpp rename to packages/PEGTL/src/test/pegtl/test_setup.cpp index b57abd0aa4dfa4cb7b38462bc7288bc26f17c9b2..a6d87ed887155c48a31282948a19e32c9d3f5816 100644 --- a/packages/PEGTL/src/test/pegtl/tester.cpp +++ b/packages/PEGTL/src/test/pegtl/test_setup.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include <iostream> @@ -36,26 +36,5 @@ int main() std::cout << "_MSC_VER: " << _MSC_VER << std::endl; std::cout << "_MSC_FULL_VER: " << _MSC_FULL_VER << std::endl; #endif - -#ifdef __cplusplus - std::cout << "__cplusplus: " << __cplusplus << std::endl; -#endif -#ifdef __cpp_constexpr - std::cout << "__cpp_constexpr: " << __cpp_constexpr << std::endl; -#endif -#ifdef __cpp_variadic_templates - std::cout << "__cpp_variadic_templates: " << __cpp_variadic_templates << std::endl; -#endif -#ifdef __cpp_variable_templates - std::cout << "__cpp_variable_templates: " << __cpp_variable_templates << std::endl; -#endif -#ifdef __cpp_fold_expressions - std::cout << "__cpp_fold_expressions: " << __cpp_fold_expressions << std::endl; -#endif -#ifdef __cpp_deduction_guides - std::cout << "__cpp_deduction_guides: " << __cpp_deduction_guides << std::endl; -#endif -#ifdef __cpp_lib_integer_sequence - std::cout << "__cpp_lib_integer_sequence: " << __cpp_lib_integer_sequence << std::endl; -#endif + return 0; } diff --git a/packages/PEGTL/src/test/pegtl/uint16_general.cpp b/packages/PEGTL/src/test/pegtl/uint16_general.cpp index c43aa51563bb0bd4359fe7184a15e100b740b4c0..b1073af47f985541d612e2c3d4dfed8937feede3 100644 --- a/packages/PEGTL/src/test/pegtl/uint16_general.cpp +++ b/packages/PEGTL/src/test/pegtl/uint16_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/uint32_general.cpp b/packages/PEGTL/src/test/pegtl/uint32_general.cpp index 97430a5a8bd831199f514f75060d7d39b5a56172..18dfd34e6d5450f5c6e9325a71447e055f03e5ee 100644 --- a/packages/PEGTL/src/test/pegtl/uint32_general.cpp +++ b/packages/PEGTL/src/test/pegtl/uint32_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/uint64_general.cpp b/packages/PEGTL/src/test/pegtl/uint64_general.cpp index 2b5ef5e218d2aa46d6a45d014156ced41b690d49..54aba3821ce31a376b168940221aea6d7fb2c526 100644 --- a/packages/PEGTL/src/test/pegtl/uint64_general.cpp +++ b/packages/PEGTL/src/test/pegtl/uint64_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/uint8_general.cpp b/packages/PEGTL/src/test/pegtl/uint8_general.cpp index 20ad2a951e3f279b695c349764bcfe12e1abd85d..211fd7399410bd8af471eaf0e89bcbe8b70afb38 100644 --- a/packages/PEGTL/src/test/pegtl/uint8_general.cpp +++ b/packages/PEGTL/src/test/pegtl/uint8_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2018-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/utf16_general.cpp b/packages/PEGTL/src/test/pegtl/utf16_general.cpp index 57c7ba3bb9bf7d590277df5cbb2ca6e13c8a2134..12461ca55093149fcd76f465ed54a43c75b9c4e6 100644 --- a/packages/PEGTL/src/test/pegtl/utf16_general.cpp +++ b/packages/PEGTL/src/test/pegtl/utf16_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/utf32_general.cpp b/packages/PEGTL/src/test/pegtl/utf32_general.cpp index d9a435a2448923d5865fa64cda81d6965de7c31e..c63a44dfeb1edc2a2c55663bd8a47a4eab8f5945 100644 --- a/packages/PEGTL/src/test/pegtl/utf32_general.cpp +++ b/packages/PEGTL/src/test/pegtl/utf32_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/utf8_general.cpp b/packages/PEGTL/src/test/pegtl/utf8_general.cpp index 6ac8b6631c611668d98ff5447cfa49f00971c5c5..c61663e1bf1a857480509cc452e595fac5557564 100644 --- a/packages/PEGTL/src/test/pegtl/utf8_general.cpp +++ b/packages/PEGTL/src/test/pegtl/utf8_general.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #include "test.hpp" diff --git a/packages/PEGTL/src/test/pegtl/verify_char.hpp b/packages/PEGTL/src/test/pegtl/verify_char.hpp index 3d2c4b793e8457d11ed1e4ce2a9fe679fc3478e4..4f48fabc0aca00da4f63137ccdcef7780ab01694 100644 --- a/packages/PEGTL/src/test/pegtl/verify_char.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_char.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_CHAR_HPP diff --git a/packages/PEGTL/src/test/pegtl/verify_fail.hpp b/packages/PEGTL/src/test/pegtl/verify_fail.hpp deleted file mode 100644 index 07269fdfbbdb3986e5585aaf8b346838bdc4fd98..0000000000000000000000000000000000000000 --- a/packages/PEGTL/src/test/pegtl/verify_fail.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015-2020 Dr. Colin Hirsch and Daniel Frey -// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ - -#ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FAIL_HPP -#define TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FAIL_HPP - -#include <cstddef> -#include <string> - -#include <tao/pegtl/memory_input.hpp> -#include <tao/pegtl/nothing.hpp> -#include <tao/pegtl/parse.hpp> - -#include "test.hpp" - -namespace TAO_PEGTL_NAMESPACE -{ - template< typename Rule, template< typename > class Action = nothing, typename... States > - void verify_fail( const std::size_t line, const char* file, const std::string& s, States&&... st ) - { - try { - memory_input in( s, "expect exception" ); - parse< Rule, Action >( in, st... ); - TAO_PEGTL_TEST_FAILED( "expected exception" ); - } - catch( ... ) { - } - } - -} // namespace TAO_PEGTL_NAMESPACE - -#endif diff --git a/packages/PEGTL/src/test/pegtl/verify_file.hpp b/packages/PEGTL/src/test/pegtl/verify_file.hpp index 2f8a16a87eb1a0d7e59b47819cbadc78b4d965e6..c35c972488173d7559ec0fd719eba548fc6a3c68 100644 --- a/packages/PEGTL/src/test/pegtl/verify_file.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_file.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_FILE_HPP @@ -56,18 +56,19 @@ namespace TAO_PEGTL_NAMESPACE template< typename T > void verify_file() { +#if defined( __cpp_exceptions ) { try { T in( "src/test/pegtl/no_such_file.txt" ); - parse< file_grammar >( in ); - TAO_PEGTL_TEST_ASSERT( !"no error on opening non-existing file" ); + TAO_PEGTL_TEST_UNREACHABLE; // LCOV_EXCL_LINE } - catch( const std::system_error& ) { + catch( const internal::filesystem::filesystem_error& ) { } } +#endif + { T in( "src/test/pegtl/file_data.txt" ); - std::cout << in.source() << std::endl; TAO_PEGTL_TEST_ASSERT( in.source() == "src/test/pegtl/file_data.txt" ); TAO_PEGTL_TEST_ASSERT( parse< file_grammar >( in ) ); TAO_PEGTL_TEST_ASSERT( in.source() == "src/test/pegtl/file_data.txt" ); diff --git a/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp b/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp index 0e17e8c75a95df897949e4c44301567941a9f1e4..c957693b54fe1492dafe2412eb1dc1e452433173 100644 --- a/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_ifmt.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IFMT_HPP @@ -29,6 +29,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ab", result_type::success, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ac", failure, 2 ); +#if defined( __cpp_exceptions ) verify_rule< must< S< one< 'a' >, one< 'b' >, one< 'c' > > > >( __LINE__, __FILE__, "", result_type::global_failure, 0 ); verify_rule< must< S< one< 'a' >, one< 'b' >, one< 'c' > > > >( __LINE__, __FILE__, "a", result_type::global_failure, 0 ); verify_rule< must< S< one< 'a' >, one< 'b' >, one< 'c' > > > >( __LINE__, __FILE__, "ac", result_type::global_failure, 1 ); @@ -36,6 +37,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< must< S< one< 'a' >, one< 'b' >, seq< one< 'c' >, one< 'd' > > > > >( __LINE__, __FILE__, "c", result_type::global_failure, 0 ); verify_rule< must< S< one< 'a' >, one< 'b' >, seq< one< 'c' >, one< 'd' > > > > >( __LINE__, __FILE__, "cc", result_type::global_failure, 1 ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/verify_impl.hpp b/packages/PEGTL/src/test/pegtl/verify_impl.hpp index b98cf45a35af2cdcc57fa9297adad95065f1b0c1..312f2785ab01f76458d12e3cdb1fd40a10b33da8 100644 --- a/packages/PEGTL/src/test/pegtl/verify_impl.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_IMPL_HPP @@ -21,6 +21,8 @@ namespace TAO_PEGTL_NAMESPACE template< typename Rule, template< typename... > class Action, typename ParseInput > result_type verify_impl_two( ParseInput& in ) { +#if defined( __cpp_exceptions ) + try { if( normal< Rule >::template match< apply_mode::action, rewind_mode::required, Action, normal >( in ) ) { return result_type::success; @@ -30,9 +32,20 @@ namespace TAO_PEGTL_NAMESPACE catch( const std::exception& ) { return result_type::global_failure; } + // LCOV_EXCL_START catch( ... ) { TAO_PEGTL_TEST_UNREACHABLE; } + // LCOV_EXCL_END + +#else + + if( normal< Rule >::template match< apply_mode::action, rewind_mode::required, Action, normal >( in ) ) { + return result_type::success; + } + return result_type::local_failure; + +#endif } template< typename Rule, template< typename... > class Action, typename ParseInput > @@ -43,7 +56,7 @@ namespace TAO_PEGTL_NAMESPACE if( ( received == expected ) && ( ( received == result_type::global_failure ) || ( in.size( 999999999 ) == remain ) ) ) { return; } - TAO_PEGTL_TEST_FAILED( "input data [ '" << data << "' ] result received/expected [ " << received << " / " << expected << " ] remain received/expected [ " << in.size( 999999999 ) << " / " << remain << " ]" ); + TAO_PEGTL_TEST_FAILED( "input data [ '" << data << "' ] result received/expected [ " << received << " / " << expected << " ] remain received/expected [ " << in.size( 999999999 ) << " / " << remain << " ]" ); // LCOV_EXCL_LINE } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/verify_meta.hpp b/packages/PEGTL/src/test/pegtl/verify_meta.hpp index 9c005eb9f197a45cc7edaa1cf12592656421bbb3..e7350f132df2111ac520b6a088f73f355bfba0a0 100644 --- a/packages/PEGTL/src/test/pegtl/verify_meta.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_meta.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_META_HPP @@ -24,16 +24,20 @@ namespace TAO_PEGTL_NAMESPACE template< typename Rule > void verify_analyze( const unsigned line, const char* file, const bool expect_consume, const bool expect_problems ) { - internal::analyze_cycles< Rule > a( false ); + internal::analyze_cycles< Rule > a( -1 ); - const bool has_problems = ( a.problems() != 0 ); + const auto problems = a.problems(); + + TAO_PEGTL_TEST_ASSERT( problems == analyze< Rule >( -1 ) ); + + const bool has_problems = ( problems != 0 ); const bool does_consume = a.template consumes< Rule >(); if( has_problems != expect_problems ) { - TAO_PEGTL_TEST_FAILED( "analyze -- problems received/expected [ " << has_problems << " / " << expect_problems << " ]" ); + TAO_PEGTL_TEST_FAILED( "analyze -- problems received/expected [ " << has_problems << " / " << expect_problems << " ]" ); // LCOV_EXCL_LINE } if( does_consume != expect_consume ) { - TAO_PEGTL_TEST_FAILED( "analyze -- consumes received/expected [ " << does_consume << " / " << expect_consume << " ]" ); + TAO_PEGTL_TEST_FAILED( "analyze -- consumes received/expected [ " << does_consume << " / " << expect_consume << " ]" ); // LCOV_EXCL_LINE } } diff --git a/packages/PEGTL/src/test/pegtl/verify_rule.hpp b/packages/PEGTL/src/test/pegtl/verify_rule.hpp index 4ee93a9c8bc228894736da8221f234e2514aa193..390a5a369ae670a094512aed100c9a611049f035 100644 --- a/packages/PEGTL/src/test/pegtl/verify_rule.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_rule.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_RULE_HPP diff --git a/packages/PEGTL/src/test/pegtl/verify_seqs.hpp b/packages/PEGTL/src/test/pegtl/verify_seqs.hpp index 29c21681233b6682511640ee51cf5732f001f99b..1b01aad29e054acc426ae17be48db5854651c103 100644 --- a/packages/PEGTL/src/test/pegtl/verify_seqs.hpp +++ b/packages/PEGTL/src/test/pegtl/verify_seqs.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey +// Copyright (c) 2014-2021 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_TEST_PEGTL_VERIFY_SEQS_HPP @@ -47,6 +47,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' >, eof > >( __LINE__, __FILE__, "abc", result_type::success, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "abcd", result_type::success, 1 ); +#if defined( __cpp_exceptions ) verify_rule< must< S< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "", result_type::global_failure, 0 ); verify_rule< must< S< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "a", result_type::global_failure, 0 ); verify_rule< must< S< one< 'a' >, one< 'b' > > > >( __LINE__, __FILE__, "b", result_type::global_failure, 1 ); @@ -60,6 +61,7 @@ namespace TAO_PEGTL_NAMESPACE verify_rule< try_catch< must< S< one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "c", result_type::local_failure, 1 ); verify_rule< try_catch< must< S< one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "ab", result_type::success, 0 ); verify_rule< try_catch< must< S< one< 'a' >, one< 'b' > > > > >( __LINE__, __FILE__, "aba", result_type::success, 1 ); +#endif } } // namespace TAO_PEGTL_NAMESPACE diff --git a/packages/PEGTL/src/test/pegtl/visit.cpp b/packages/PEGTL/src/test/pegtl/visit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2bdcb86e2b0229a8f1bcdc6ec5b36f27b6b9640c --- /dev/null +++ b/packages/PEGTL/src/test/pegtl/visit.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2020-2021 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#include <string> +#include <vector> + +#include "test.hpp" + +namespace TAO_PEGTL_NAMESPACE +{ + using grammar = seq< plus< alpha >, star< sor< space, digit > > >; + + template< typename Name > + struct visitor + { + static void visit( std::vector< std::string >& names ) + { + names.emplace_back( demangle< Name >() ); + } + }; + + void unit_test() + { + std::vector< std::string > names; + visit< grammar, visitor >( names ); + TAO_PEGTL_TEST_ASSERT( names.size() == 7 ); + } + +} // namespace TAO_PEGTL_NAMESPACE + +#include "main.hpp" diff --git a/src/language/PEGGrammar.hpp b/src/language/PEGGrammar.hpp index beae437f0e5d0f9231b51afc0671e29e7ecfef30..a3ad0342839eb5cc5ee6693e4a49e22d99cf41d2 100644 --- a/src/language/PEGGrammar.hpp +++ b/src/language/PEGGrammar.hpp @@ -5,10 +5,10 @@ #include <language/utils/ParseError.hpp> -using namespace TAO_PEGTL_NAMESPACE; - namespace language { +using namespace TAO_PEGTL_NAMESPACE; + // clang-format off struct slashslash : TAO_PEGTL_STRING("//") {}; @@ -338,7 +338,7 @@ struct errors : public normal<Rule> }; template <typename Rule> -inline const std::string errors<Rule>::error_message = "parse error matching "+ demangle(tao::demangle< Rule >()); +inline const std::string errors<Rule>::error_message = "parse error matching "+ demangle(tao::pegtl::demangle< Rule >()); template <> inline const std::string errors<language::module_name>::error_message = "parse error, missing module name"; diff --git a/src/language/PugsParser.cpp b/src/language/PugsParser.cpp index faab47780f0736c43285b3245a8ee07cc966f036..1c02a820abda8b89a0e789703b547bb9b96ee2b1 100644 --- a/src/language/PugsParser.cpp +++ b/src/language/PugsParser.cpp @@ -37,7 +37,7 @@ void parser(const std::string& filename) { - const size_t grammar_issues = analyze<language::grammar>(); + const size_t grammar_issues = TAO_PEGTL_NAMESPACE::analyze<language::grammar>(); if (grammar_issues != 0) { std::ostringstream os; @@ -89,7 +89,7 @@ parser(const std::string& filename) }; if (not SignalManager::pauseOnError()) { - read_input input(filename); + TAO_PEGTL_NAMESPACE::read_input input(filename); try { parse_and_execute(input); } @@ -105,7 +105,7 @@ parser(const std::string& filename) std::exit(1); } } else { - read_input input(filename); + TAO_PEGTL_NAMESPACE::read_input input(filename); parse_and_execute(input); } } diff --git a/src/language/ast/ASTBuilder.cpp b/src/language/ast/ASTBuilder.cpp index ccf0f42db5c4144ef91475d3fa9c3c24520d1e35..0c433bbfd21704702ed87012d5956519a0f93bde 100644 --- a/src/language/ast/ASTBuilder.cpp +++ b/src/language/ast/ASTBuilder.cpp @@ -1,7 +1,5 @@ #include <language/ast/ASTBuilder.hpp> -using namespace TAO_PEGTL_NAMESPACE; - #include <language/PEGGrammar.hpp> #include <language/ast/ASTNode.hpp> #include <language/utils/SymbolTable.hpp> @@ -9,7 +7,7 @@ using namespace TAO_PEGTL_NAMESPACE; #include <pegtl/contrib/parse_tree.hpp> -struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange> +struct ASTBuilder::rearrange : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::rearrange> { template <typename... States> static void @@ -52,7 +50,7 @@ struct ASTBuilder::rearrange : parse_tree::apply<ASTBuilder::rearrange> } }; -struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary> +struct ASTBuilder::simplify_unary : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_unary> { template <typename... States> static void @@ -129,7 +127,7 @@ struct ASTBuilder::simplify_unary : parse_tree::apply<ASTBuilder::simplify_unary } }; -struct ASTBuilder::simplify_node_list : parse_tree::apply<ASTBuilder::simplify_node_list> +struct ASTBuilder::simplify_node_list : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_node_list> { template <typename... States> static void @@ -145,7 +143,8 @@ struct ASTBuilder::simplify_node_list : parse_tree::apply<ASTBuilder::simplify_n } }; -struct ASTBuilder::simplify_statement_block : parse_tree::apply<ASTBuilder::simplify_statement_block> +struct ASTBuilder::simplify_statement_block + : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_statement_block> { template <typename... States> static void @@ -162,7 +161,8 @@ struct ASTBuilder::simplify_statement_block : parse_tree::apply<ASTBuilder::simp } }; -struct ASTBuilder::simplify_for_statement_block : parse_tree::apply<ASTBuilder::simplify_for_statement_block> +struct ASTBuilder::simplify_for_statement_block + : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_for_statement_block> { template <typename... States> static void @@ -175,7 +175,7 @@ struct ASTBuilder::simplify_for_statement_block : parse_tree::apply<ASTBuilder:: } }; -struct ASTBuilder::simplify_for_init : parse_tree::apply<ASTBuilder::simplify_for_init> +struct ASTBuilder::simplify_for_init : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_for_init> { template <typename... States> static void @@ -188,7 +188,7 @@ struct ASTBuilder::simplify_for_init : parse_tree::apply<ASTBuilder::simplify_fo } }; -struct ASTBuilder::simplify_for_test : parse_tree::apply<ASTBuilder::simplify_for_test> +struct ASTBuilder::simplify_for_test : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_for_test> { template <typename... States> static void @@ -201,7 +201,7 @@ struct ASTBuilder::simplify_for_test : parse_tree::apply<ASTBuilder::simplify_fo } }; -struct ASTBuilder::simplify_for_post : parse_tree::apply<ASTBuilder::simplify_for_post> +struct ASTBuilder::simplify_for_post : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_for_post> { template <typename... States> static void @@ -214,7 +214,8 @@ struct ASTBuilder::simplify_for_post : parse_tree::apply<ASTBuilder::simplify_fo } }; -struct ASTBuilder::simplify_stream_statement : parse_tree::apply<ASTBuilder::simplify_stream_statement> +struct ASTBuilder::simplify_stream_statement + : TAO_PEGTL_NAMESPACE::parse_tree::apply<ASTBuilder::simplify_stream_statement> { template <typename... States> static void @@ -228,40 +229,40 @@ struct ASTBuilder::simplify_stream_statement : parse_tree::apply<ASTBuilder::sim }; template <typename Rule> -using selector = parse_tree::selector< +using selector = TAO_PEGTL_NAMESPACE::parse_tree::selector< Rule, - parse_tree::store_content::on<language::import_instruction, - language::module_name, - language::true_kw, - language::false_kw, - language::integer, - language::real, - language::literal, - language::name, - language::B_set, - language::N_set, - language::Z_set, - language::R_set, - language::type_name_id, - language::tuple_expression, - language::vector_type, - language::matrix_type, - language::string_type, - language::cout_kw, - language::cerr_kw, - language::clog_kw, - language::var_declaration, - language::fct_declaration, - language::type_mapping, - language::function_definition, - language::expression_list, - language::if_statement, - language::do_while_statement, - language::while_statement, - language::for_statement, - language::function_evaluation, - language::break_kw, - language::continue_kw>, + TAO_PEGTL_NAMESPACE::parse_tree::store_content::on<language::import_instruction, + language::module_name, + language::true_kw, + language::false_kw, + language::integer, + language::real, + language::literal, + language::name, + language::B_set, + language::N_set, + language::Z_set, + language::R_set, + language::type_name_id, + language::tuple_expression, + language::vector_type, + language::matrix_type, + language::string_type, + language::cout_kw, + language::cerr_kw, + language::clog_kw, + language::var_declaration, + language::fct_declaration, + language::type_mapping, + language::function_definition, + language::expression_list, + language::if_statement, + language::do_while_statement, + language::while_statement, + language::for_statement, + language::function_evaluation, + language::break_kw, + language::continue_kw>, ASTBuilder::rearrange::on<language::logical_or, language::logical_and, language::bitwise_xor, @@ -279,30 +280,30 @@ using selector = parse_tree::selector< language::type_expression, language::unary_expression, language::name_subscript_expression>, - parse_tree::remove_content::on<language::plus_op, - language::minus_op, - language::multiply_op, - language::divide_op, - language::lesser_op, - language::lesser_or_eq_op, - language::greater_op, - language::greater_or_eq_op, - language::eqeq_op, - language::not_eq_op, - language::and_op, - language::or_op, - language::xor_op, - language::eq_op, - language::multiplyeq_op, - language::divideeq_op, - language::pluseq_op, - language::minuseq_op, - language::unary_plusplus, - language::unary_minusminus, - language::post_minusminus, - language::post_plusplus>, + TAO_PEGTL_NAMESPACE::parse_tree::remove_content::on<language::plus_op, + language::minus_op, + language::multiply_op, + language::divide_op, + language::lesser_op, + language::lesser_or_eq_op, + language::greater_op, + language::greater_or_eq_op, + language::eqeq_op, + language::not_eq_op, + language::and_op, + language::or_op, + language::xor_op, + language::eq_op, + language::multiplyeq_op, + language::divideeq_op, + language::pluseq_op, + language::minuseq_op, + language::unary_plusplus, + language::unary_minusminus, + language::post_minusminus, + language::post_plusplus>, ASTBuilder::simplify_for_statement_block::on<language::for_statement_block>, - parse_tree::discard_empty::on<language::ignored, language::semicol, language::block>, + TAO_PEGTL_NAMESPACE::parse_tree::discard_empty::on<language::ignored, language::semicol, language::block>, ASTBuilder::simplify_node_list::on<language::name_list, language::lvalue_list, language::function_argument_list>, ASTBuilder::simplify_statement_block::on<language::statement_block>, ASTBuilder::simplify_for_init::on<language::for_init>, @@ -314,7 +315,9 @@ template <typename InputT> std::unique_ptr<ASTNode> ASTBuilder::build(InputT& input) { - std::unique_ptr root_node = parse_tree::parse<language::grammar, ASTNode, selector, nothing, language::errors>(input); + std::unique_ptr root_node = + TAO_PEGTL_NAMESPACE::parse_tree::parse<language::grammar, ASTNode, selector, TAO_PEGTL_NAMESPACE::nothing, + language::errors>(input); // build initial symbol tables std::shared_ptr symbol_table = std::make_shared<SymbolTable>(); @@ -324,5 +327,5 @@ ASTBuilder::build(InputT& input) return root_node; } -template std::unique_ptr<ASTNode> ASTBuilder::build(read_input<>& input); -template std::unique_ptr<ASTNode> ASTBuilder::build(string_input<>& input); +template std::unique_ptr<ASTNode> ASTBuilder::build(TAO_PEGTL_NAMESPACE::read_input<>& input); +template std::unique_ptr<ASTNode> ASTBuilder::build(TAO_PEGTL_NAMESPACE::string_input<>& input); diff --git a/src/language/ast/ASTNode.hpp b/src/language/ast/ASTNode.hpp index d9568c612dd3e3a6223994cff6273b43d900b3c0..19e410b72f9f68f12b9ae357fbf88c3a06d53309 100644 --- a/src/language/ast/ASTNode.hpp +++ b/src/language/ast/ASTNode.hpp @@ -10,11 +10,9 @@ #include <pegtl/contrib/parse_tree.hpp> -using namespace TAO_PEGTL_NAMESPACE; - class SymbolTable; -class ASTNode : public parse_tree::basic_node<ASTNode> +class ASTNode : public TAO_PEGTL_NAMESPACE::parse_tree::basic_node<ASTNode> { private: PUGS_INLINE @@ -51,7 +49,7 @@ class ASTNode : public parse_tree::basic_node<ASTNode> string() const { if (this->has_content()) { - return this->parse_tree::basic_node<ASTNode>::string(); + return this->TAO_PEGTL_NAMESPACE::parse_tree::basic_node<ASTNode>::string(); } else { auto end = this->_getEnd(); auto begin = this->_getBegin(); @@ -66,7 +64,7 @@ class ASTNode : public parse_tree::basic_node<ASTNode> string_view() const { if (this->has_content()) { - return this->parse_tree::basic_node<ASTNode>::string_view(); + return this->TAO_PEGTL_NAMESPACE::parse_tree::basic_node<ASTNode>::string_view(); } else { auto end = this->_getEnd(); auto begin = this->_getBegin(); diff --git a/tests/test_ASTBuilder.cpp b/tests/test_ASTBuilder.cpp index 7353fa9a46d6d08542c62d4bee89299c930fc5a1..75f41a36d1c5c4e737070d89a4500051e0a4a037 100644 --- a/tests/test_ASTBuilder.cpp +++ b/tests/test_ASTBuilder.cpp @@ -12,7 +12,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ std::stringstream ast_output; \ @@ -668,7 +668,7 @@ let y:(R^2), y=((0)); 1+; // syntax error )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; REQUIRE_THROWS_WITH(ASTBuilder::build(input), "parse error, missing expression"); } diff --git a/tests/test_ASTDotPrinter.cpp b/tests/test_ASTDotPrinter.cpp index d9597ebca0a7d4e448563ea50e109474e6dd7e80..9f11198bce541c2831312ab2d121af2c37fb9ad7 100644 --- a/tests/test_ASTDotPrinter.cpp +++ b/tests/test_ASTDotPrinter.cpp @@ -12,7 +12,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ std::stringstream ast_output; \ diff --git a/tests/test_ASTModulesImporter.cpp b/tests/test_ASTModulesImporter.cpp index a3a4e3d7a6bd6bfc7d624b9d1ee4a9d69e34b876..ca0962c6182b8c5127c7ba74d3fe06a403fb67b6 100644 --- a/tests/test_ASTModulesImporter.cpp +++ b/tests/test_ASTModulesImporter.cpp @@ -25,7 +25,7 @@ test_ASTExecutionInfo(const ASTNode& root_node, const ModuleRepository& module_r static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter importer{*ast}; \ @@ -95,7 +95,7 @@ import math; import unknown_module; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); REQUIRE_THROWS_AS(ASTModulesImporter{*ast}, ParseError); @@ -107,7 +107,7 @@ import unknown_module; import math; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ast->m_symbol_table->add("sin", ast->begin()); diff --git a/tests/test_ASTNode.cpp b/tests/test_ASTNode.cpp index 173c83f8634ef01d8f5b74c526c165f0b2796f48..00f1e108488b14435ecbcbbde474bb2641cba01a 100644 --- a/tests/test_ASTNode.cpp +++ b/tests/test_ASTNode.cpp @@ -46,10 +46,10 @@ TEST_CASE("ASTNode", "[language]") SECTION("has content") { ASTNode ast_node; - ast_node.source = "content"; - auto& source = ast_node.source; - ast_node.m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - ast_node.m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + ast_node.source = "content"; + const char* const start = &ast_node.source[0]; + ast_node.m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{start}; + ast_node.m_end = TAO_PEGTL_NAMESPACE::internal::iterator{start + 7}; REQUIRE(ast_node.string() == "content"); REQUIRE(ast_node.string_view() == "content"); @@ -58,15 +58,15 @@ TEST_CASE("ASTNode", "[language]") SECTION("children have content") { ASTNode ast_node; - ast_node.source = "content"; - auto& source = ast_node.source; - ast_node.m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[2]}; + ast_node.source = "content"; + const char* const start = &ast_node.source[0]; + ast_node.m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{start + 2}; { std::unique_ptr<ASTNode> child0_node = std::make_unique<ASTNode>(); - child0_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - child0_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[3]}; + child0_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{start}; + child0_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{start + 3}; ast_node.children.emplace_back(std::move(child0_node)); } @@ -74,8 +74,8 @@ TEST_CASE("ASTNode", "[language]") { std::unique_ptr<ASTNode> child1_node = std::make_unique<ASTNode>(); - child1_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[4]}; - child1_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + child1_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{start + 4}; + child1_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{start + 7}; ast_node.children.emplace_back(std::move(child1_node)); } diff --git a/tests/test_ASTNodeAffectationExpressionBuilder.cpp b/tests/test_ASTNodeAffectationExpressionBuilder.cpp index d2aeabb06ed1e69c51e04a9c83842c260b796852..5a6bd835b5ee47d4628aa5081fdc50d2b57f2be3 100644 --- a/tests/test_ASTNodeAffectationExpressionBuilder.cpp +++ b/tests/test_ASTNodeAffectationExpressionBuilder.cpp @@ -24,7 +24,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ \ BasicAffectationRegisterFor<EmbeddedData>{ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t")}; \ \ @@ -59,7 +59,7 @@ const auto builtin_data_type = ast_node_data_type_from<std::shared_ptr<const dou \ BasicAffectationRegisterFor<EmbeddedData>{ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t")}; \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ SymbolTable& symbol_table = *ast->m_symbol_table; \ @@ -108,7 +108,7 @@ const auto builtin_data_type = ast_node_data_type_from<std::shared_ptr<const dou static_assert(std::is_same_v<std::decay_t<decltype(expected_error)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_error)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -128,7 +128,7 @@ const auto builtin_data_type = ast_node_data_type_from<std::shared_ptr<const dou \ BasicAffectationRegisterFor<EmbeddedData>{ASTNodeDataType::build<ASTNodeDataType::type_id_t>("builtin_t")}; \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ SymbolTable& symbol_table = *ast->m_symbol_table; \ @@ -1792,7 +1792,7 @@ let x : R^1; let y : R^1; x *= y; let (x,y,z):R*R*R, (x,y) = (2,3); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1807,7 +1807,7 @@ let y:R; let x:R, (x,y) = (2,3); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1822,7 +1822,7 @@ let y:R; let x:R, y = 3; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1835,7 +1835,7 @@ let x:R, y = 3; let (x,y):R, (y,x) = (3,2); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; diff --git a/tests/test_ASTNodeArraySubscriptExpressionBuilder.cpp b/tests/test_ASTNodeArraySubscriptExpressionBuilder.cpp index 7eadd2067e54e670021aa2bee03e92fe0abedccd..29bffa7bc5e7ca5ecbddcfc6401e97f58569d26b 100644 --- a/tests/test_ASTNodeArraySubscriptExpressionBuilder.cpp +++ b/tests/test_ASTNodeArraySubscriptExpressionBuilder.cpp @@ -4,8 +4,6 @@ #include <language/ast/ASTNodeArraySubscriptExpressionBuilder.hpp> #include <language/node_processor/ArraySubscriptProcessor.hpp> -#include <pegtl/string_input.hpp> - // clazy:excludeall=non-pod-global-static TEST_CASE("ASTNodeArraySubscriptExpressionBuilder", "[language]") diff --git a/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp b/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp index 1c030e91791827d6a4b69a087c116b2cdd61fc33..f5a0ef7e2aefbbd8772effe8123be8a6503a72f9 100644 --- a/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp +++ b/tests/test_ASTNodeBinaryOperatorExpressionBuilder.cpp @@ -18,7 +18,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -39,31 +39,13 @@ { \ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ REQUIRE_THROWS_WITH(ASTNodeDataTypeBuilder{*ast}, expected_output); \ } -/* -#define REQUIRE_AST_THROWS_WITH(data, expected_output) \ - { \ - static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ - \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ - \ - REQUIRE_THROWS_WITH(ASTNodeExpressionBuilder{*ast}, expected_output); \ - } -*/ - // clazy:excludeall=non-pod-global-static TEST_CASE("ASTNodeBinaryOperatorExpressionBuilder", "[language]") diff --git a/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp b/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp index 25115bfc2ff3011e582029ab495e17f4a9d108e2..b55ab6775600f5fc31caafa396c8df2f59b370ae 100644 --- a/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp +++ b/tests/test_ASTNodeBuiltinFunctionExpressionBuilder.cpp @@ -24,7 +24,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ test_only::test_BuiltinFunctionRegister{*ast}; \ @@ -48,7 +48,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_error)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_error)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ test_only::test_BuiltinFunctionRegister{*ast}; \ diff --git a/tests/test_ASTNodeDataType.cpp b/tests/test_ASTNodeDataType.cpp index 4e4e5759b68c3f94a288bc785f313711b41ec7d0..843a4b9daaf18e694b3121c5898f1eff4fb06a32 100644 --- a/tests/test_ASTNodeDataType.cpp +++ b/tests/test_ASTNodeDataType.cpp @@ -113,10 +113,10 @@ TEST_CASE("ASTNodeDataType", "[language]") { std::unique_ptr dimension_node = std::make_unique<ASTNode>(); dimension_node->set_type<language::integer>(); - dimension_node->source = "3"; - auto& source = dimension_node->source; - dimension_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - dimension_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + dimension_node->source = "3"; + const char* const beginning = &dimension_node->source[0]; + dimension_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + dimension_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; type_node->emplace_back(std::move(dimension_node)); } @@ -152,11 +152,32 @@ TEST_CASE("ASTNodeDataType", "[language]") SECTION("bad dimension value") { - type_node->children[1]->source = "0"; - REQUIRE_THROWS_WITH(getVectorDataType(*type_node), "invalid dimension (must be 1, 2 or 3)"); + { + type_node->children[1]->source = "0"; + const char* const beginning = &type_node->children[1]->source[0]; + type_node->children[1]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[1]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + + REQUIRE_THROWS_WITH(getVectorDataType(*type_node), "invalid dimension (must be 1, 2 or 3)"); + } + + { + type_node->children[1]->source = "1"; + const char* const beginning = &type_node->children[1]->source[0]; + type_node->children[1]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[1]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + + REQUIRE_NOTHROW(getVectorDataType(*type_node)); + } + + { + type_node->children[1]->source = "4"; + const char* const beginning = &type_node->children[1]->source[0]; + type_node->children[1]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[1]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; - type_node->children[1]->source = "4"; - REQUIRE_THROWS_WITH(getVectorDataType(*type_node), "invalid dimension (must be 1, 2 or 3)"); + REQUIRE_THROWS_WITH(getVectorDataType(*type_node), "invalid dimension (must be 1, 2 or 3)"); + } } } @@ -171,19 +192,19 @@ TEST_CASE("ASTNodeDataType", "[language]") { std::unique_ptr dimension0_node = std::make_unique<ASTNode>(); dimension0_node->set_type<language::integer>(); - dimension0_node->source = "3"; - auto& source0 = dimension0_node->source; - dimension0_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source0[0]}; - dimension0_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source0[source0.size()]}; + dimension0_node->source = "3"; + const char* const beginning = &dimension0_node->source[0]; + dimension0_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + dimension0_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; type_node->emplace_back(std::move(dimension0_node)); } { std::unique_ptr dimension1_node = std::make_unique<ASTNode>(); dimension1_node->set_type<language::integer>(); - dimension1_node->source = "3"; - auto& source1 = dimension1_node->source; - dimension1_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source1[0]}; - dimension1_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source1[source1.size()]}; + dimension1_node->source = "3"; + const char* const beginning = &dimension1_node->source[0]; + dimension1_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + dimension1_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; type_node->emplace_back(std::move(dimension1_node)); } } @@ -227,19 +248,51 @@ TEST_CASE("ASTNodeDataType", "[language]") SECTION("bad nb rows value") { - type_node->children[1]->source = "0"; - type_node->children[2]->source = "0"; + { + type_node->children[1]->source = "0"; + const char* const beginning = &type_node->children[1]->source[0]; + type_node->children[1]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[1]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + } + { + type_node->children[2]->source = "0"; + const char* const beginning = &type_node->children[2]->source[0]; + type_node->children[2]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[2]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + } + REQUIRE_THROWS_WITH(getMatrixDataType(*type_node), "invalid dimension (must be 1, 2 or 3)"); - type_node->children[1]->source = "4"; - type_node->children[2]->source = "4"; + { + type_node->children[1]->source = "4"; + const char* const beginning = &type_node->children[1]->source[0]; + type_node->children[1]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[1]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + } + { + type_node->children[2]->source = "4"; + const char* const beginning = &type_node->children[2]->source[0]; + type_node->children[2]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[2]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + } + REQUIRE_THROWS_WITH(getMatrixDataType(*type_node), "invalid dimension (must be 1, 2 or 3)"); } SECTION("none square matrices") { - type_node->children[1]->source = "1"; - type_node->children[2]->source = "2"; + { + type_node->children[1]->source = "1"; + const char* const beginning = &type_node->children[1]->source[0]; + type_node->children[1]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[1]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + } + { + type_node->children[2]->source = "2"; + const char* const beginning = &type_node->children[2]->source[0]; + type_node->children[2]->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + type_node->children[2]->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; + } REQUIRE_THROWS_WITH(getMatrixDataType(*type_node), "only square matrices are supported"); } } diff --git a/tests/test_ASTNodeDataTypeBuilder.cpp b/tests/test_ASTNodeDataTypeBuilder.cpp index 369374986fa27f69b12e147434ab3605872cac16..3de0130da3de2c911267d3467aa024af07ef8977 100644 --- a/tests/test_ASTNodeDataTypeBuilder.cpp +++ b/tests/test_ASTNodeDataTypeBuilder.cpp @@ -16,7 +16,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -38,7 +38,7 @@ const auto builtin_data_type = ast_node_data_type_from<std::shared_ptr<const dou static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ SymbolTable& symbol_table = *ast->m_symbol_table; \ @@ -301,7 +301,7 @@ let (x,b,n,s) : R*B*N*string; let x : R; x[2]; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -314,7 +314,7 @@ let x : R; x[2]; let x : R^2; x[2,2]; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -327,7 +327,7 @@ let x : R^2; x[2,2]; let x : R^2x2; x[2]; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -340,7 +340,7 @@ let x : R^2x2; x[2]; let x : R^2x2; x[2,3,1]; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -353,7 +353,7 @@ let x : R^2x2; x[2,3,1]; let (x,b,n,s,t) : R*B*N*string; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -367,7 +367,7 @@ let (x,b,n,s,t) : R*B*N*string; let (x,b,n) : R*B*N*string; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -381,7 +381,7 @@ let (x,b,n) : R*B*N*string; let (x,y) : R; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -394,7 +394,7 @@ let (x,y) : R; let square : R -> R^3, x -> (x, x*x); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -656,7 +656,7 @@ let t : (builtin_t), t= (1,2,3); let t : builtin_t; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -670,7 +670,7 @@ let a: R, a = 3; let t : a; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -684,7 +684,7 @@ let t : a; let t : (builtin_t); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -698,7 +698,7 @@ let a: R, a = 3; let t : (a); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -994,7 +994,7 @@ let cat : string*N -> string, (s,n) -> s+n; std::string_view data = R"( let f : R*Z -> B, x -> 3; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1006,7 +1006,7 @@ let f : R*Z -> B, x -> 3; std::string_view data = R"( let f : R -> B, (x,y) -> 3; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1018,7 +1018,7 @@ let f : R -> B, (x,y) -> 3; std::string_view data = R"( let f : R*Z -> B, (x,z) -> (3, x); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1031,7 +1031,7 @@ let f : R*Z -> B, (x,z) -> (3, x); std::string_view data = R"( let f : R -> R*R, x -> x*x*x; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1044,7 +1044,7 @@ let f : R -> R*R, x -> x*x*x; std::string_view data = R"( let f : R -> R^2x2, x -> (x, 2*x, 2); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1272,7 +1272,7 @@ let (x,x2) : R*R, (x,x2) = x_x2(3); let not_a_function : R, not_a_function = 3; not_a_function(2,3); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -1728,7 +1728,7 @@ if (true) { if ("string"); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; REQUIRE_THROWS_AS(ASTNodeDataTypeBuilder{*ast}, ParseError); @@ -1814,7 +1814,7 @@ while (true) { while ("string"); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; REQUIRE_THROWS_AS(ASTNodeDataTypeBuilder{*ast}, ParseError); @@ -1900,7 +1900,7 @@ do { do 1; while ("string"); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; REQUIRE_THROWS_AS(ASTNodeDataTypeBuilder{*ast}, ParseError); @@ -2219,7 +2219,7 @@ true xor false; 1+"string"; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; REQUIRE_THROWS_AS(ASTNodeDataTypeBuilder{*ast}, ParseError); diff --git a/tests/test_ASTNodeDataTypeChecker.cpp b/tests/test_ASTNodeDataTypeChecker.cpp index 60dfc787a65b6af66f3463fe0871bb0b0a79116d..4343f3eee060b8763807e49ae555f5ea49de707d 100644 --- a/tests/test_ASTNodeDataTypeChecker.cpp +++ b/tests/test_ASTNodeDataTypeChecker.cpp @@ -21,7 +21,7 @@ for(let i:Z, i=0; i<10; ++i) { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -39,7 +39,7 @@ for(let i:Z, i=0; i<10; ++i) { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; diff --git a/tests/test_ASTNodeDataTypeFlattener.cpp b/tests/test_ASTNodeDataTypeFlattener.cpp index dae7437d920694f63e544aca15dc3c4e6fdb8e84..ef9431655399cf0f1c45cdeb1a75a13680888adb 100644 --- a/tests/test_ASTNodeDataTypeFlattener.cpp +++ b/tests/test_ASTNodeDataTypeFlattener.cpp @@ -22,7 +22,7 @@ let b : B, b = true; b; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto root_node = ASTBuilder::build(input); ASTSymbolTableBuilder{*root_node}; @@ -45,7 +45,7 @@ let n : N; n; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto root_node = ASTBuilder::build(input); ASTSymbolTableBuilder{*root_node}; @@ -71,7 +71,7 @@ let f: N -> N, n -> n; f(2); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto root_node = ASTBuilder::build(input); ASTSymbolTableBuilder{*root_node}; @@ -100,7 +100,7 @@ let f: N -> N*R*B*string*Z, n -> (n, 0.5*n, n>2, n, 3-n); f(2); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto root_node = ASTBuilder::build(input); ASTSymbolTableBuilder{*root_node}; @@ -132,7 +132,7 @@ let f: R -> R*R^3, x -> (0.5*x, (x, x+1, x-1)); f(2); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto root_node = ASTBuilder::build(input); ASTSymbolTableBuilder{*root_node}; diff --git a/tests/test_ASTNodeDeclarationToAffectationConverter.cpp b/tests/test_ASTNodeDeclarationToAffectationConverter.cpp index 8e9912e1a43d94bef7bb7e707991b9a855d111ed..eb101857969a66da20ca82cf1d91d11969825a44 100644 --- a/tests/test_ASTNodeDeclarationToAffectationConverter.cpp +++ b/tests/test_ASTNodeDeclarationToAffectationConverter.cpp @@ -13,7 +13,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ASTNodeEmptyBlockCleaner.cpp b/tests/test_ASTNodeEmptyBlockCleaner.cpp index a52730e662268621db4a22fa5237136ef5d053a8..e1aa381509aff202a76722905528bff983336409 100644 --- a/tests/test_ASTNodeEmptyBlockCleaner.cpp +++ b/tests/test_ASTNodeEmptyBlockCleaner.cpp @@ -18,7 +18,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ASTNodeExpressionBuilder.cpp b/tests/test_ASTNodeExpressionBuilder.cpp index 3b09a0bb554e6692fe1f741229e9ea43725782af..999a6e63672dfccd60c50b78062c2754c7b96bcf 100644 --- a/tests/test_ASTNodeExpressionBuilder.cpp +++ b/tests/test_ASTNodeExpressionBuilder.cpp @@ -17,7 +17,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -35,7 +35,7 @@ #define CHECK_AST_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -893,7 +893,7 @@ continue; 1; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; diff --git a/tests/test_ASTNodeFunctionEvaluationExpressionBuilder.cpp b/tests/test_ASTNodeFunctionEvaluationExpressionBuilder.cpp index 7ecb9ee4de55d752151e33f922a50262e1a2eb7c..63cecd79b7865b197c42b5a7f5762e8a12c4200b 100644 --- a/tests/test_ASTNodeFunctionEvaluationExpressionBuilder.cpp +++ b/tests/test_ASTNodeFunctionEvaluationExpressionBuilder.cpp @@ -18,7 +18,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ diff --git a/tests/test_ASTNodeFunctionExpressionBuilder.cpp b/tests/test_ASTNodeFunctionExpressionBuilder.cpp index fd0163b7aed4f94bf99bee19eec4ae46ed9b7f3b..9a762ed5ea7b83ab81d1155163b22c89a8ef572b 100644 --- a/tests/test_ASTNodeFunctionExpressionBuilder.cpp +++ b/tests/test_ASTNodeFunctionExpressionBuilder.cpp @@ -19,7 +19,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ @@ -42,7 +42,7 @@ { \ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ @@ -61,7 +61,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(error)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ @@ -76,7 +76,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(error)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ diff --git a/tests/test_ASTNodeIncDecExpressionBuilder.cpp b/tests/test_ASTNodeIncDecExpressionBuilder.cpp index 2b64fcd03c2aeedb6ab3902cf374791205344815..da5e049555f7e581416682eac30ceac91b0c41ef 100644 --- a/tests/test_ASTNodeIncDecExpressionBuilder.cpp +++ b/tests/test_ASTNodeIncDecExpressionBuilder.cpp @@ -19,7 +19,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -42,7 +42,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(expected_error)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_error)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ASTNodeJumpPlacementChecker.cpp b/tests/test_ASTNodeJumpPlacementChecker.cpp index 040c2db1c3d7b0ee3be8c663a5c701827e230fb2..d3a5a3c59b47c4a220c701e9eaa7cd498f29eb8b 100644 --- a/tests/test_ASTNodeJumpPlacementChecker.cpp +++ b/tests/test_ASTNodeJumpPlacementChecker.cpp @@ -22,7 +22,7 @@ for(;;) { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -38,7 +38,7 @@ while(true) { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -54,7 +54,7 @@ do { } while(true); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -70,7 +70,7 @@ do { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -91,7 +91,7 @@ for(;;) { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -107,7 +107,7 @@ while(true) { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -123,7 +123,7 @@ do { } while(true); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; @@ -139,7 +139,7 @@ do { } )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; ASTNodeDataTypeBuilder{*ast}; diff --git a/tests/test_ASTNodeListAffectationExpressionBuilder.cpp b/tests/test_ASTNodeListAffectationExpressionBuilder.cpp index 62b584eaa1f9e0bac8b05ae8f8d1072cf4e46bae..78c0a2c0baadc4d016199e56d88c370f082cfe17 100644 --- a/tests/test_ASTNodeListAffectationExpressionBuilder.cpp +++ b/tests/test_ASTNodeListAffectationExpressionBuilder.cpp @@ -18,7 +18,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -41,7 +41,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(error)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ASTNodeListProcessor.cpp b/tests/test_ASTNodeListProcessor.cpp index bccd0080fb1de962815aef8f95d95f1e02a5fef3..946ec382cee6b25989a8f8ca9cfbc303cce8149e 100644 --- a/tests/test_ASTNodeListProcessor.cpp +++ b/tests/test_ASTNodeListProcessor.cpp @@ -23,7 +23,7 @@ true; 2.3; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; diff --git a/tests/test_ASTNodeNaturalConversionChecker.cpp b/tests/test_ASTNodeNaturalConversionChecker.cpp index a9e10344d3f6eaacd1ac6fde102b1d4b82214927..0e91a0b7dbba39c486b008cae05188af463e4a64 100644 --- a/tests/test_ASTNodeNaturalConversionChecker.cpp +++ b/tests/test_ASTNodeNaturalConversionChecker.cpp @@ -110,10 +110,10 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") { data_node->m_data_type = int_dt; data_node->set_type<language::integer>(); - data_node->source = "0"; - auto& source = data_node->source; - data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + data_node->source = "0"; + const char* const beginning = &data_node->source[0]; + data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; SECTION("d = 1") { @@ -249,10 +249,10 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") { data_node->m_data_type = int_dt; data_node->set_type<language::integer>(); - data_node->source = "0"; - auto& source = data_node->source; - data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + data_node->source = "0"; + const char* const beginning = &data_node->source[0]; + data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; SECTION("d = 1") { @@ -1156,10 +1156,10 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") { data_node->m_data_type = int_dt; data_node->set_type<language::integer>(); - data_node->source = "1"; - auto& source = data_node->source; - data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + data_node->source = "1"; + const char* const beginning = &data_node->source[0]; + data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; SECTION("d=1") { @@ -1609,10 +1609,10 @@ TEST_CASE("ASTNodeNaturalConversionChecker", "[language]") { data_node->m_data_type = int_dt; data_node->set_type<language::integer>(); - data_node->source = "1"; - auto& source = data_node->source; - data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{&source[0]}; - data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{&source[source.size()]}; + data_node->source = "1"; + const char* const beginning = &data_node->source[0]; + data_node->m_begin = TAO_PEGTL_NAMESPACE::internal::iterator{beginning}; + data_node->m_end = TAO_PEGTL_NAMESPACE::internal::iterator{beginning + 1}; SECTION("d=1") { diff --git a/tests/test_ASTNodeTypeCleaner.cpp b/tests/test_ASTNodeTypeCleaner.cpp index 80d7ccfc081a0d4cc5165a38b99ba0214975e11a..4f7adfcf162bb57a54b3c1d9c9a03d339969e654 100644 --- a/tests/test_ASTNodeTypeCleaner.cpp +++ b/tests/test_ASTNodeTypeCleaner.cpp @@ -11,7 +11,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp b/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp index 2ebe22cab68dc735836054b58ca4382340e09030..08fa22a71def33bceca5255b7dbc8064a1dd47b4 100644 --- a/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp +++ b/tests/test_ASTNodeUnaryOperatorExpressionBuilder.cpp @@ -18,7 +18,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view> or \ std::is_same_v<std::decay_t<decltype(expected_output)>, std::string>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -37,7 +37,7 @@ #define CHECK_AST_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ASTPrinter.cpp b/tests/test_ASTPrinter.cpp index 2e08706698313539e133f8cacd3b64145db84866..31ee8cac5e7cd193f3cda7ccca925388d26d4e99 100644 --- a/tests/test_ASTPrinter.cpp +++ b/tests/test_ASTPrinter.cpp @@ -13,7 +13,7 @@ static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \ static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ std::stringstream ast_output; \ diff --git a/tests/test_ASTSymbolInitializationChecker.cpp b/tests/test_ASTSymbolInitializationChecker.cpp index fb0c8598beb79861f6cbbb66ebe37461c66b61e5..1d104da14d53ce4918ecd33405ee1a6658d737ac 100644 --- a/tests/test_ASTSymbolInitializationChecker.cpp +++ b/tests/test_ASTSymbolInitializationChecker.cpp @@ -10,6 +10,8 @@ TEST_CASE("ASTSymbolInitializationChecker", "[language]") { + using namespace TAO_PEGTL_NAMESPACE; + SECTION("Declarative initialization") { std::string_view data = R"( diff --git a/tests/test_ASTSymbolTableBuilder.cpp b/tests/test_ASTSymbolTableBuilder.cpp index 028f79882eed45e8dc99c17efd414ce63c7ddd4e..fa0d31824eed8a3ddb0dcea45497ad5f5c580889 100644 --- a/tests/test_ASTSymbolTableBuilder.cpp +++ b/tests/test_ASTSymbolTableBuilder.cpp @@ -10,6 +10,8 @@ TEST_CASE("ASTSymbolTableBuilder", "[language]") { + using namespace TAO_PEGTL_NAMESPACE; + SECTION("Build symbols") { std::string_view data = R"( diff --git a/tests/test_AffectationProcessor.cpp b/tests/test_AffectationProcessor.cpp index 331046feb18edffb9e110a27a9050cdb94795bea..8319410a2217814c7a3fd2c4d7fc08bfbb249ced 100644 --- a/tests/test_AffectationProcessor.cpp +++ b/tests/test_AffectationProcessor.cpp @@ -16,7 +16,7 @@ #define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -44,7 +44,7 @@ #define CHECK_AFFECTATION_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_AffectationToStringProcessor.cpp b/tests/test_AffectationToStringProcessor.cpp index c432cdd00ddcd41213720feb9217ad4f20dfac5e..46593b24802e5400b43f81c94974109e6e030f3a 100644 --- a/tests/test_AffectationToStringProcessor.cpp +++ b/tests/test_AffectationToStringProcessor.cpp @@ -16,7 +16,7 @@ #define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_AffectationToTupleProcessor.cpp b/tests/test_AffectationToTupleProcessor.cpp index fccd584c6eb7c164e9b9389d8395f56bc3803ca0..61e95338e03d09ec2ed479e8a4ac27d157dac43f 100644 --- a/tests/test_AffectationToTupleProcessor.cpp +++ b/tests/test_AffectationToTupleProcessor.cpp @@ -16,7 +16,7 @@ #define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ArraySubscriptProcessor.cpp b/tests/test_ArraySubscriptProcessor.cpp index 43386ea66a5a207d319c8dd681dad4bb4a779b28..ab08a1d6ed2b69493e8bb06bf5d7bb2a7f9321c4 100644 --- a/tests/test_ArraySubscriptProcessor.cpp +++ b/tests/test_ArraySubscriptProcessor.cpp @@ -17,7 +17,7 @@ #define CHECK_EVALUATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ @@ -47,28 +47,28 @@ REQUIRE(value == expected_value); \ } -#define CHECK_EVALUATION_THROWS_WITH(data, error_message) \ - { \ - auto eval = [&] { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTModulesImporter{*ast}; \ - ASTNodeTypeCleaner<language::import_instruction>{*ast}; \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ - ASTNodeTypeCleaner<language::fct_declaration>{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecutionPolicy exec_policy; \ - ast->execute(exec_policy); \ - }; \ - \ - REQUIRE_THROWS_WITH(eval(), error_message); \ +#define CHECK_EVALUATION_THROWS_WITH(data, error_message) \ + { \ + auto eval = [&] { \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTModulesImporter{*ast}; \ + ASTNodeTypeCleaner<language::import_instruction>{*ast}; \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ + ASTNodeTypeCleaner<language::fct_declaration>{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecutionPolicy exec_policy; \ + ast->execute(exec_policy); \ + }; \ + \ + REQUIRE_THROWS_WITH(eval(), error_message); \ } // clazy:excludeall=non-pod-global-static diff --git a/tests/test_BinaryExpressionProcessor_utils.hpp b/tests/test_BinaryExpressionProcessor_utils.hpp index 176c91344be48d261282171eb460b7c7a358d2dd..7b32bff86087bf871eb70decafe952f273991b65 100644 --- a/tests/test_BinaryExpressionProcessor_utils.hpp +++ b/tests/test_BinaryExpressionProcessor_utils.hpp @@ -15,7 +15,7 @@ #define CHECK_BINARY_EXPRESSION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -43,7 +43,7 @@ #define CHECK_BINARY_EXPRESSION_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_BuiltinFunctionProcessor.cpp b/tests/test_BuiltinFunctionProcessor.cpp index a2a690a19fedb243b36fe23d88c0aa9b04079f5c..a00ce26465f395fc8396ee087f828c64ac9a6128 100644 --- a/tests/test_BuiltinFunctionProcessor.cpp +++ b/tests/test_BuiltinFunctionProcessor.cpp @@ -13,7 +13,7 @@ #define CHECK_BUILTIN_FUNCTION_EVALUATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ @@ -54,7 +54,7 @@ static_assert((std::is_same_v<std::decay_t<decltype(expected_error)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_error)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ test_only::test_BuiltinFunctionRegister{*ast}; \ diff --git a/tests/test_ConcatExpressionProcessor.cpp b/tests/test_ConcatExpressionProcessor.cpp index 57b68c4e7206c9eebd59942cddf2829f2fe236ab..74257b45f086cd93c868f3022be8c380e8cb1d12 100644 --- a/tests/test_ConcatExpressionProcessor.cpp +++ b/tests/test_ConcatExpressionProcessor.cpp @@ -16,7 +16,7 @@ #define CHECK_CONCAT_EXPRESSION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_DoWhileProcessor.cpp b/tests/test_DoWhileProcessor.cpp index b8f88a19aadf6236bc97e32e31518ea10d139a14..453859d83b8a7290ac738e7cb425cf8848ed622b 100644 --- a/tests/test_DoWhileProcessor.cpp +++ b/tests/test_DoWhileProcessor.cpp @@ -16,7 +16,7 @@ #define CHECK_WHILE_PROCESSOR_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -44,7 +44,7 @@ #define CHECK_DO_WHILE_PROCESSOR_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ForProcessor.cpp b/tests/test_ForProcessor.cpp index 31ec05abccbf27cb28c6f674d178b15b7709ba4a..1a26d1b06d237469749db1b383dfcb1b6ad0c5ae 100644 --- a/tests/test_ForProcessor.cpp +++ b/tests/test_ForProcessor.cpp @@ -16,7 +16,7 @@ #define CHECK_FOR_PROCESSOR_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -44,7 +44,7 @@ #define CHECK_FOR_PROCESSOR_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_FunctionProcessor.cpp b/tests/test_FunctionProcessor.cpp index 64fe6776ee427db8b2e3641ee952cff2477279ca..dcfbdf25a715466fd53b23ea683859f55e9a08e1 100644 --- a/tests/test_FunctionProcessor.cpp +++ b/tests/test_FunctionProcessor.cpp @@ -15,7 +15,7 @@ #define CHECK_FUNCTION_EVALUATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ diff --git a/tests/test_IfProcessor.cpp b/tests/test_IfProcessor.cpp index 71fc766845d22090e319ea02f071e8707d72eed5..865c4ef1b7882b927dc3a5e68a940778b2f4ce71 100644 --- a/tests/test_IfProcessor.cpp +++ b/tests/test_IfProcessor.cpp @@ -14,7 +14,7 @@ #define CHECK_IF_PROCESSOR_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -42,7 +42,7 @@ #define CHECK_IF_PROCESSOR_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_IncDecExpressionProcessor.cpp b/tests/test_IncDecExpressionProcessor.cpp index 7525ca9ff5cf796ecbe3a183f570793b4ed614fb..d217bae1c5583b44db502a2fd58875c30dff403d 100644 --- a/tests/test_IncDecExpressionProcessor.cpp +++ b/tests/test_IncDecExpressionProcessor.cpp @@ -14,7 +14,7 @@ #define CHECK_INC_DEC_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -42,7 +42,7 @@ #define CHECK_INCDEC_EXPRESSION_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_ListAffectationProcessor.cpp b/tests/test_ListAffectationProcessor.cpp index 0dc1b8d77c0e6dc23cb2681c30e8006d9e939f86..eeb3aa57c08083c4f3f2999ac5318dd26b1a5a1f 100644 --- a/tests/test_ListAffectationProcessor.cpp +++ b/tests/test_ListAffectationProcessor.cpp @@ -14,7 +14,7 @@ #define CHECK_AFFECTATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -42,7 +42,7 @@ #define CHECK_AFFECTATION_THROWS(data) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -57,7 +57,7 @@ #define CHECK_AFFECTATION_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_NameProcessor.cpp b/tests/test_NameProcessor.cpp index 84669c888673d8339fa2263130c7a480f57c1754..c789420a2d971503dc1de477b987fc156b87ab6c 100644 --- a/tests/test_NameProcessor.cpp +++ b/tests/test_NameProcessor.cpp @@ -23,7 +23,7 @@ let m:N, m = n; n = 2; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); ASTSymbolTableBuilder{*ast}; @@ -38,8 +38,7 @@ n = 2; auto symbol_table = ast->m_symbol_table; - using namespace TAO_PEGTL_NAMESPACE; - position use_position{internal::iterator{"fixture"}, "fixture"}; + TAO_PEGTL_NAMESPACE::position use_position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"}; use_position.byte = 100; // after declarative position auto symbol_n = symbol_table->find("n", use_position).first->attributes(); auto value_n = std::get<long unsigned int>(symbol_n.value()); diff --git a/tests/test_OStreamProcessor.cpp b/tests/test_OStreamProcessor.cpp index a88662b1a00f0dfaf4977da9a79b7d44dd2405f1..8da0c8c0db17b418499403ce453030d084bb70e4 100644 --- a/tests/test_OStreamProcessor.cpp +++ b/tests/test_OStreamProcessor.cpp @@ -25,26 +25,26 @@ _replaceOStream(ASTNode& node, std::ostringstream& sout) } } -#define CHECK_OSTREAM_EXPRESSION_RESULT(data, expected_value) \ - { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecutionPolicy exec_policy; \ - \ - std::ostringstream sout; \ - _replaceOStream(*ast, sout); \ - \ - ast->execute(exec_policy); \ - \ - REQUIRE(sout.str() == expected_value); \ +#define CHECK_OSTREAM_EXPRESSION_RESULT(data, expected_value) \ + { \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecutionPolicy exec_policy; \ + \ + std::ostringstream sout; \ + _replaceOStream(*ast, sout); \ + \ + ast->execute(exec_policy); \ + \ + REQUIRE(sout.str() == expected_value); \ } #define CHECK_OSTREAM_EXPRESSION_THROWS(data, expected_error) \ @@ -53,7 +53,7 @@ _replaceOStream(ASTNode& node, std::ostringstream& sout) static_assert((std::is_same_v<std::decay_t<decltype(expected_error)>, std::string_view>) or \ (std::is_same_v<std::decay_t<decltype(expected_error)>, std::string>)); \ \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_PugsFunctionAdapter.cpp b/tests/test_PugsFunctionAdapter.cpp index 4b04c7f5e088c1bdec314c91414fac4924b8bd6b..14cc1def65f1e25940653f95e39cd09a2fc0285d 100644 --- a/tests/test_PugsFunctionAdapter.cpp +++ b/tests/test_PugsFunctionAdapter.cpp @@ -89,7 +89,7 @@ let RtoR11: R -> R^1x1, x -> x*x; let R3toR3zero: R^3 -> R^3, x -> 0; let R33toR33zero: R^3x3 -> R^3x3, x -> 0; )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); @@ -105,7 +105,7 @@ let R33toR33zero: R^3x3 -> R^3x3, x -> 0; std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table; - position position{internal::iterator{"fixture"}, "fixture"}; + TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"}; position.byte = data.size(); // ensure that variables are declared at this { @@ -377,7 +377,7 @@ let RtoNS: R -> N*string, x -> (1, "foo"); let RtoR: R -> R, x -> 2*x; let R33toR22: R^3x3 -> R^2x2, x -> (x[0,0], x[0,1]+x[0,2], x[2,0]*x[1,1], x[2,1]+x[2,2]); )"; - string_input input{data, "test.pgs"}; + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; auto ast = ASTBuilder::build(input); @@ -393,7 +393,7 @@ let R33toR22: R^3x3 -> R^2x2, x -> (x[0,0], x[0,1]+x[0,2], x[2,0]*x[1,1], x[2,1] std::shared_ptr<SymbolTable> symbol_table = ast->m_symbol_table; - position position{internal::iterator{"fixture"}, "fixture"}; + TAO_PEGTL_NAMESPACE::position position{TAO_PEGTL_NAMESPACE::internal::iterator{"fixture"}, "fixture"}; position.byte = data.size(); // ensure that variables are declared at this { diff --git a/tests/test_TupleToVectorProcessor.cpp b/tests/test_TupleToVectorProcessor.cpp index 6ddbf513d35470dbd39d6a5842fdfc37b75e5eaf..c11ac7db2fdd76fdbce738d2f9daf7fe3f920266 100644 --- a/tests/test_TupleToVectorProcessor.cpp +++ b/tests/test_TupleToVectorProcessor.cpp @@ -15,7 +15,7 @@ #define CHECK_EVALUATION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTModulesImporter{*ast}; \ @@ -45,28 +45,28 @@ REQUIRE(value == expected_value); \ } -#define CHECK_EVALUATION_THROWS_WITH(data, error_message) \ - { \ - auto eval = [&] { \ - string_input input{data, "test.pgs"}; \ - auto ast = ASTBuilder::build(input); \ - \ - ASTModulesImporter{*ast}; \ - ASTNodeTypeCleaner<language::import_instruction>{*ast}; \ - \ - ASTSymbolTableBuilder{*ast}; \ - ASTNodeDataTypeBuilder{*ast}; \ - \ - ASTNodeDeclarationToAffectationConverter{*ast}; \ - ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ - ASTNodeTypeCleaner<language::fct_declaration>{*ast}; \ - \ - ASTNodeExpressionBuilder{*ast}; \ - ExecutionPolicy exec_policy; \ - ast->execute(exec_policy); \ - }; \ - \ - REQUIRE_THROWS_WITH(eval(), error_message); \ +#define CHECK_EVALUATION_THROWS_WITH(data, error_message) \ + { \ + auto eval = [&] { \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ + auto ast = ASTBuilder::build(input); \ + \ + ASTModulesImporter{*ast}; \ + ASTNodeTypeCleaner<language::import_instruction>{*ast}; \ + \ + ASTSymbolTableBuilder{*ast}; \ + ASTNodeDataTypeBuilder{*ast}; \ + \ + ASTNodeDeclarationToAffectationConverter{*ast}; \ + ASTNodeTypeCleaner<language::var_declaration>{*ast}; \ + ASTNodeTypeCleaner<language::fct_declaration>{*ast}; \ + \ + ASTNodeExpressionBuilder{*ast}; \ + ExecutionPolicy exec_policy; \ + ast->execute(exec_policy); \ + }; \ + \ + REQUIRE_THROWS_WITH(eval(), error_message); \ } // clazy:excludeall=non-pod-global-static diff --git a/tests/test_UnaryExpressionProcessor.cpp b/tests/test_UnaryExpressionProcessor.cpp index b309d6dd13c0791a909ab30e164325ac7d365e00..3f875b0bedd2164f1b354edac9483ce4ca528e77 100644 --- a/tests/test_UnaryExpressionProcessor.cpp +++ b/tests/test_UnaryExpressionProcessor.cpp @@ -14,7 +14,7 @@ #define CHECK_UNARY_EXPRESSION_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -42,7 +42,7 @@ #define CHECK_UNARY_EXPRESSION_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ diff --git a/tests/test_WhileProcessor.cpp b/tests/test_WhileProcessor.cpp index 4a823c068f92013530b4622ef665f9ed3a4713db..ef4d04ae230d86a93555d3903698d3bf796205cd 100644 --- a/tests/test_WhileProcessor.cpp +++ b/tests/test_WhileProcessor.cpp @@ -15,7 +15,7 @@ #define CHECK_WHILE_PROCESSOR_RESULT(data, variable_name, expected_value) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \ @@ -43,7 +43,7 @@ #define CHECK_WHILE_PROCESSOR_THROWS_WITH(data, error_message) \ { \ - string_input input{data, "test.pgs"}; \ + TAO_PEGTL_NAMESPACE::string_input input{data, "test.pgs"}; \ auto ast = ASTBuilder::build(input); \ \ ASTSymbolTableBuilder{*ast}; \