From 52130510f1b6ca912c24daec36ce3ca5533f40ec Mon Sep 17 00:00:00 2001 From: sean-parent Date: Sat, 21 Nov 2026 02:25:49 -0800 Subject: [PATCH] Migrate cpp-library infrastructure and inline private parser tests Use cpp-library 6.2.0 and released cel-runtime 1.1.3, preserve public contract tests, and isolate private test support from production builds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/ci.yml | 21 - ...ral-form-not-converted-binary64-payload.md | 8 +- ...the-caller-s-floating-point-environment.md | 4 +- ...-cel-runtime-out-of-parser-installation.md | 6 +- ...rage-out-of-recursive-precedence-frames.md | 4 +- ...runtime-source-with-a-versioned-cpm-uri.md | 4 +- .vscode/tasks.json | 2 +- CMakeLists.txt | 26 +- CMakePresets.json | 8 +- docs/builtin-census.md | 2 +- docs/evidence.md | 16 +- docs/expression-grammar.md | 9 +- docs/p4-handoff.md | 12 +- docs/validation.md | 30 +- src/compiler.cpp | 263 +++++- src/compiler.hpp | 18 - src/lookup.cpp | 609 +++++++++++++ src/parser.cpp | 813 +++++++++++++++++- src/type.cpp | 163 +++- src/type.hpp | 25 +- src/unicode_data.hpp | 404 --------- tests/cursor_copy_fail.cpp | 2 +- tests/expression_test.cpp | 215 +---- tests/lexer_copy_fail.cpp | 2 +- tests/lookup_test.cpp | 565 +----------- tests/parity_driver_test.cpp | 1 + tests/tests.cpp | 395 --------- tests/type_test.cpp | 134 --- tools/generate_unicode.py | 18 +- tools/parity/driver.cpp | 2 +- 30 files changed, 1927 insertions(+), 1854 deletions(-) delete mode 100644 src/compiler.hpp delete mode 100644 src/unicode_data.hpp delete mode 100644 tests/tests.cpp delete mode 100644 tests/type_test.cpp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9e0a6b..cc054ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,27 +57,6 @@ jobs: - name: Test run: ctest --preset=test - - name: Build and Install - run: | - cmake --preset=default - cmake --build --preset=default - cmake --install build/default --prefix "${{ runner.temp }}/install" - env: - CC: ${{ matrix.cc }} - CXX: ${{ matrix.cxx }} - if: ${{ matrix.cc }} - - - name: Build and Install - run: | - cmake --preset=default - cmake --build --preset=default - cmake --install build/default --prefix "${{ runner.temp }}/install" - if: ${{ !matrix.cc }} - - - name: Check installed package artifacts - run: | - cmake "-DPACKAGE_TEST_PREFIX=${{ runner.temp }}/install" -P build/default/cpp-library-test-package.cmake - clang-tidy: runs-on: ubuntu-latest diff --git a/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md b/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md index fb9942f..6b93fd9 100644 --- a/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md +++ b/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md @@ -7,13 +7,11 @@ last_accessed: 2026-11-18T06:48:35Z last_reinforced: 2026-11-18T06:48:35Z access_count: 2 sources: - - "include/cel/parser.hpp:62-80" - - "src/compiler.cpp:405-418" - - "src/parser.cpp:373-429" - "src/compiler.cpp:415-419" - - "src/parser.cpp:379-422" + - "src/parser.cpp:793-825" - "src/lexer.hpp:15-25" - - "tests/expression_test.cpp:157-194" + - "src/compiler.cpp:762-782" + - "tests/expression_test.cpp:125-136" tags: ["parser", "literals", "rust-parity", "tuple-selectors"] tier: knowledge votes_up: 1 diff --git a/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md b/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md index d6a8642..d90ef50 100644 --- a/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md +++ b/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md @@ -7,8 +7,8 @@ last_accessed: 2026-11-19T05:47:01Z last_reinforced: 2026-11-19T05:47:01Z access_count: 1 sources: - - "src/parser.cpp:180-194" - - "tests/tests.cpp:129-153" + - "src/parser.cpp:578-592" + - "src/parser.cpp:1120-1144" - "src/lexer.hpp:21-23" - "docs/lexical-contract.md:105-109" tags: ["parser", "floating-point", "macos", "locale", "compatibility"] diff --git a/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md b/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md index 8dff40b..60a90de 100644 --- a/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md +++ b/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md @@ -7,8 +7,8 @@ last_accessed: 2026-11-18T06:31:07Z last_reinforced: 2026-11-18T06:31:07Z access_count: 1 sources: - - "CMakeLists.txt:17-35" - - "docs/validation.md:121-130" + - "CMakeLists.txt:17-45" + - "docs/validation.md:117-138" supersedes: "[[Initialize shared installation defaults before CPM runtime and parser targets]]" tags: ["cmake", "cpm", "dependencies", "installation"] tier: knowledge @@ -24,4 +24,4 @@ last_voted: 2026-11-19T04:10:10Z # Keep cel-runtime out of parser installation -Let `cpp_library_setup` initialize the default `CEL_INSTALL` option before adding `cel-runtime`. Add the runtime with its versioned commit URI and keep CPM's short-form `EXCLUDE_FROM_ALL` default; do not override it to `NO`. CPM registry resolution supplies the package/version without an explicit `cpp_library_map_dependency`. Package validation relies on cpp-library's generated component-presence check, without custom source-consumer or installed-consumer tests. +Let `cpp_library_setup` initialize the default `CEL_INSTALL` option before adding `cel-runtime`. Add the runtime with its versioned commit URI and keep CPM's short-form `EXCLUDE_FROM_ALL` default; do not override it to `NO`. CPM registry resolution supplies the package/version without an explicit `cpp_library_map_dependency`. The cpp-library 6.2 presets disable installation except in the explicit install preset. Validate source builds; do not add installation, package-artifact, or installed-consumer gates. diff --git a/.scout/memory/knowledge/keep-operator-local-storage-out-of-recursive-precedence-frames.md b/.scout/memory/knowledge/keep-operator-local-storage-out-of-recursive-precedence-frames.md index f901efe..ae4f3b7 100644 --- a/.scout/memory/knowledge/keep-operator-local-storage-out-of-recursive-precedence-frames.md +++ b/.scout/memory/knowledge/keep-operator-local-storage-out-of-recursive-precedence-frames.md @@ -8,11 +8,11 @@ last_reinforced: 2026-11-11T00:46:42Z access_count: 1 sources: - "src/compiler.cpp:258-291" - - "tests/expression_test.cpp:467-510" + - "tests/expression_test.cpp:416-461" tags: ["parser", "recursion", "stack-usage", "MSVC"] tier: knowledge --- # Keep operator-local storage out of recursive precedence frames -Keep recursive precedence control in expression_compiler::binary separate from operator-local storage in binary_rhs (src/compiler.cpp:258-291). Every nested expression traverses the fixed precedence levels. Placing dyn_segment RHS builders and operator metadata in binary reserves their storage in every unoptimized frame, including frames that never encounter an operator; this can overflow the native MSVC Debug stack before the 128-production resource guard fires. binary_rhs runs only after operator_at(level), preserving operator consumption, lazy RHS ownership, source spans, lookup order, and non-chaining comparisons. Preserve the existing nesting contract rather than lowering its limit or enlarging test stacks. The public contract regression covers 32 and 127 parenthesis groups, resource rejection of excess nesting, and long iterative flat chains (tests/expression_test.cpp:467-510). Run that case with iterator debugging enabled when changing these frames. +Keep recursive precedence control in expression_compiler::binary separate from operator-local storage in binary_rhs (src/compiler.cpp:258-291). Every nested expression traverses the fixed precedence levels. Placing dyn_segment RHS builders and operator metadata in binary reserves their storage in every unoptimized frame, including frames that never encounter an operator; this can overflow the native MSVC Debug stack before the 128-production resource guard fires. binary_rhs runs only after operator_at(level), preserving operator consumption, lazy RHS ownership, source spans, lookup order, and non-chaining comparisons. Preserve the existing nesting contract rather than lowering its limit or enlarging test stacks. The public contract regression covers 32 and 127 parenthesis groups, resource rejection of excess nesting, and long iterative flat chains (tests/expression_test.cpp:416-461). Run that case with iterator debugging enabled when changing these frames. diff --git a/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md b/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md index 770b15f..eb2220c 100644 --- a/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md +++ b/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md @@ -8,7 +8,7 @@ last_reinforced: 2026-11-18T06:31:11Z access_count: 1 sources: - "CMakeLists.txt:5-6" - - "CMakeLists.txt:33-35" + - "CMakeLists.txt:43-45" - "docs/evidence.md:96-100" supersedes: "[[Pin CPM dependencies to reviewed commits]]" tags: ["cmake", "cpm", "dependencies", "supply-chain"] @@ -27,4 +27,4 @@ last_voted: 2026-11-19T04:10:12Z # Pin runtime source with a versioned CPM URI -Pin `cel-runtime` with a CPM URI that includes both the compatibility release (`1.1.2`) and reviewed full commit SHA `a819042cfa3fab8ede82052518f2b7f5175af5ad`. Keep the release tag-to-commit relationship in `docs/evidence.md`. `cpp-library` resolves the dependency from CPM's registry, so do not add a separate `cpp_library_map_dependency` for this CPM package. +Pin `cel-runtime` with a CPM URI that includes both the compatibility release (`1.1.3`) and reviewed full commit SHA `fc9fa3be8b0af9782a3491acacd6ba1f2e528a5b`. Keep the release tag-to-commit relationship in `docs/evidence.md`. `cpp-library` resolves the dependency from CPM's registry, so do not add a separate `cpp_library_map_dependency` for this CPM package. diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 297e047..df55722 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -240,7 +240,7 @@ "$gcc", "$msCompile" ], - "detail": "Release build for installation with CPM_USE_LOCAL_PACKAGES enabled for testing installed packages Requires the CMake Tools extension (ms-vscode.cmake-tools) — without it, this task fails to start.", + "detail": "Release build for installation, preferring locally installed dependencies before fetching. Requires the CMake Tools extension (ms-vscode.cmake-tools) — without it, this task fails to start.", "windows": { "options": { "shell": { diff --git a/CMakeLists.txt b/CMakeLists.txt index 090898f..38c28c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24) include(cmake/CPM.cmake) -CPMAddPackage("gh:stlab/cpp-library@6.1.0") +CPMAddPackage("gh:stlab/cpp-library@6.2.0") include(${cpp-library_SOURCE_DIR}/cpp-library.cmake) # Enable dependency tracking before project() @@ -20,7 +20,7 @@ cpp_library_setup( HEADERS parser.hpp parser/diagnostic.hpp parser/lookup.hpp parser/compiler.hpp parser/all.hpp SOURCES parser.cpp lookup.cpp type.cpp compiler.cpp EXAMPLES example.cpp cached_decoded.cpp - TESTS tests.cpp lookup_test.cpp type_test.cpp expression_test.cpp cached_test.cpp parity_driver_test.cpp header_layers_test.cpp + TESTS lookup_test.cpp expression_test.cpp cached_test.cpp parity_driver_test.cpp header_layers_test.cpp cursor_copy_fail.cpp lexer_copy_fail.cpp parser_copy_fail.cpp standard_library_fail.cpp converting_registration_fail.cpp converting_result_fail.cpp nontrivial_registration_fail.cpp token_interface_fail.cpp LICENSE_FILES licenses/Unicode-3.0.txt @@ -30,8 +30,18 @@ cpp_library_setup( DOCS_OPTIONS "USE_MDFILE_AS_MAINPAGE = ${CMAKE_CURRENT_SOURCE_DIR}/README.md" ) +# cpp-library adds src to tests directly and through the static implementation. +get_property(parser_targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS) +foreach(parser_target IN LISTS parser_targets) + get_target_property(parser_includes "${parser_target}" INCLUDE_DIRECTORIES) + if(parser_includes) + list(REMOVE_ITEM parser_includes "${CMAKE_CURRENT_SOURCE_DIR}/src") + set_property(TARGET "${parser_target}" PROPERTY INCLUDE_DIRECTORIES "${parser_includes}") + endif() +endforeach() + # Initialize cpp-library's default CEL_INSTALL before the same-namespace runtime. -CPMAddPackage("gh:stlab/cel-runtime@1.1.2#a819042cfa3fab8ede82052518f2b7f5175af5ad") +CPMAddPackage("gh:stlab/cel-runtime@1.1.3#fc9fa3be8b0af9782a3491acacd6ba1f2e528a5b") target_link_libraries(parser PUBLIC cel::runtime) # Exercise parity-driver helpers in ordinary unit tests without the driver's main(). @@ -40,15 +50,6 @@ if(TARGET parity_driver_test) target_compile_definitions(parity_driver_test PRIVATE CEL_PARITY_NO_MAIN) endif() -if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING) - # Give white-box tests access to implementation headers without exporting them. - foreach(test tests lookup_test type_test expression_test parity_driver_test cursor_copy_fail lexer_copy_fail) - target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") - endforeach() - - set_tests_properties(tests PROPERTIES TIMEOUT 180) -endif() - # Compare C++ and Rust results on shared fixtures; Python and Cargo are test-only. option(CEL_PARSER_ENABLE_PARITY "Require the local public Rust reference differential gate" OFF) set(CEL_PARSER_REFERENCE_SOURCE "" CACHE PATH "Local cel-rs checkout for test-only parity") @@ -72,7 +73,6 @@ if(CEL_PARSER_ENABLE_PARITY) --source "${CEL_PARSER_REFERENCE_SOURCE}" --build "${reference_build}" VERBATIM) add_executable(parity_driver tools/parity/driver.cpp) - target_include_directories(parity_driver PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_link_libraries(parity_driver PRIVATE cel::parser) cpp_library_copy_runtime_dlls(parity_driver) diff --git a/CMakePresets.json b/CMakePresets.json index 99ba84a..2efd009 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -8,6 +8,7 @@ "binaryDir": "${sourceDir}/build/default", "generator": "Ninja", "cacheVariables": { + "CEL_INSTALL": "OFF", "CMAKE_BUILD_TYPE": "Release", "BUILD_TESTING": "OFF", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", @@ -22,6 +23,7 @@ "binaryDir": "${sourceDir}/build/test", "generator": "Ninja", "cacheVariables": { + "CEL_INSTALL": "OFF", "CMAKE_BUILD_TYPE": "Debug", "BUILD_TESTING": "ON", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", @@ -36,6 +38,7 @@ "binaryDir": "${sourceDir}/build/docs", "generator": "Ninja", "cacheVariables": { + "CEL_INSTALL": "OFF", "CMAKE_BUILD_TYPE": "Release", "BUILD_TESTING": "OFF", "BUILD_DOCS": "ON", @@ -51,6 +54,7 @@ "binaryDir": "${sourceDir}/build/clang-tidy", "generator": "Ninja", "cacheVariables": { + "CEL_INSTALL": "OFF", "CMAKE_BUILD_TYPE": "Debug", "BUILD_TESTING": "ON", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", @@ -66,6 +70,7 @@ "binaryDir": "${sourceDir}/build/init", "generator": "Ninja", "cacheVariables": { + "CEL_INSTALL": "OFF", "CMAKE_BUILD_TYPE": "Release", "BUILD_TESTING": "OFF", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", @@ -77,10 +82,11 @@ { "name": "install", "displayName": "Install Configuration", - "description": "Release build for installation with CPM_USE_LOCAL_PACKAGES enabled for testing installed packages", + "description": "Release build for installation, preferring locally installed dependencies before fetching", "binaryDir": "${sourceDir}/build/install", "generator": "Ninja", "cacheVariables": { + "CEL_INSTALL": "ON", "CMAKE_BUILD_TYPE": "Release", "BUILD_TESTING": "OFF", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", diff --git a/docs/builtin-census.md b/docs/builtin-census.md index 87ab9d7..42b4fd7 100644 --- a/docs/builtin-census.md +++ b/docs/builtin-census.md @@ -32,7 +32,7 @@ Scope callbacks and descriptor emitters execute during compilation. Each row names exact arguments/results. `D` means `f64`; `B` means `bool`. Every row is implemented with public checked runtime emission. The test anchors -name cases in `tests/lookup_test.cpp`. +name in-source cases in `src/lookup.cpp`. Source syntax/precedence is also covered by `retained precedence` in `tests/expression_test.cpp`; `core lookup does not` checks absent library names. See the [expression grammar](expression-grammar.md) for every emission edge. diff --git a/docs/evidence.md b/docs/evidence.md index 50f925e..6b752db 100644 --- a/docs/evidence.md +++ b/docs/evidence.md @@ -12,8 +12,8 @@ pinned to the original baseline. The runtime source upstream is [stlab/cel-runtime](https://github.com/stlab/cel-runtime). The previous P4 baseline used release `v1.0.1` at revision -`a8e753b040664172fd3f526f9cf46029858ff788`. The parser pins release `v1.1.2` -at revision `a819042cfa3fab8ede82052518f2b7f5175af5ad` because its +`a8e753b040664172fd3f526f9cf46029858ff788`. The parser pins release `v1.1.3` +at revision `fc9fa3be8b0af9782a3491acacd6ba1f2e528a5b` because its record-registration API uses the runtime's record adapters. The parser consumes the public target from CPM and exports the matching minimum package version; it neither copies runtime implementation nor includes private headers. Rebuild the @@ -93,10 +93,11 @@ Production code depends on the C++20 standard library, committed Unicode property data, and the `cel-runtime` package through `cel::runtime`. There is no Unicode shared-library dependency. -Build infrastructure uses `stlab/cpp-library` release `v6.1.0` at -`13ff79ac9fbbf575bbab0ab3dee0c752b4501fcc` under BSL-1.0. Its pinned scaffold +Build infrastructure uses `stlab/cpp-library` release `v6.2.0` at +`4f60491f7550cb058af855346decc71ce0d5365e` under BSL-1.0. Its pinned scaffold provides CMake presets, doctest 2.5.3 (MIT), generated negative-compilation tests, -CTest, standalone public-header checks, exports, license installation, CI, +CTest, guarded in-source tests, static per-file test support, +standalone public-header checks, exports, license installation, source-build CI, and strict Doxygen configuration. Doxygen-awesome-css 2.5.0 (MIT) supplies the documentation theme. CPM.cmake 0.43.2 is MIT-licensed. Doxygen, Ninja, Clang tools, and Python are @@ -119,10 +120,11 @@ Regenerate and format the tables from the repository root: ```sh python3 tools/generate_unicode.py -clang-format -i src/unicode_data.hpp +clang-format -i src/parser.cpp ``` -Confirm that `git diff -- src/unicode_data.hpp` is empty. Consumers don't need +The generator replaces only the marked Unicode data block in `src/parser.cpp`. +Confirm that `git diff -- src/parser.cpp` is empty. Consumers don't need Python or network access to use the committed tables. ## Expression compilation and remaining verification diff --git a/docs/expression-grammar.md b/docs/expression-grammar.md index 0936a85..0b2667e 100644 --- a/docs/expression-grammar.md +++ b/docs/expression-grammar.md @@ -77,7 +77,11 @@ implicit ambient captures, or general block expressions. ## Verification disposition -The following cases in `tests/expression_test.cpp` cover the implementation: +The following cases cover the implementation. Public-interface tests remain in +`tests/expression_test.cpp`. Cases using private token or scope interfaces live +behind `CPP_LIBRARY_TESTING()` in `src/compiler.cpp`: `numeric values require`, +`decimal integer-form f64`, `postfix brackets remain`, `all six range forms`, +`independent closure scope`, and `text and token methods`. | Case-name prefix | Production and boundary coverage | | --- | --- | @@ -99,7 +103,8 @@ The following cases in `tests/expression_test.cpp` cover the implementation: | `text and token methods` | Both full methods, inline host preservation, producer diagnostics, visible/invisible malformed groups, exact spans | | `recursive input` | Bounded nesting, long arithmetic/unary/cast/member/lazy/list chains | -`tests/type_test.cpp` additionally verifies exact span-output prefix parsing. +In-source tests in `src/type.cpp` additionally verify exact span-output prefix +parsing. Lexer and token-cursor tests live in `src/parser.cpp`. The differential fixtures cover retained production families with identical sources. Narrower scalar/parameter availability, canonical record carriers, diff --git a/docs/p4-handoff.md b/docs/p4-handoff.md index f06fd4f..b7ccf31 100644 --- a/docs/p4-handoff.md +++ b/docs/p4-handoff.md @@ -21,7 +21,7 @@ below add comparisons without claiming exhaustive enumeration of infinite types. | Criterion | Status | Strongest exact evidence | Confidence / gap | | --- | --- | --- | --- | -| All 34 eager retained signatures | Differential plus public contracts | `scalar`, `numeric-functions`, `ranges`; census rows link `lookup_test.cpp` operator/range/cast/standard cases | High; no removed scalar surrogate | +| All 34 eager retained signatures | Differential plus public contracts | `scalar`, `numeric-functions`, `ranges`; census rows link `src/lookup.cpp` operator/range/cast/standard cases | High; no removed scalar surrogate | | Eleven numeric names; ordinary/member selectors; IEEE edges | Differential plus public contracts | `numeric-functions`, `numeric-errors`; `standard numeric names require explicit installation and use source call selectors` | High; NaN payload/equal-zero choices only | | Unit/group/singleton/multi tuples; exact selectors | Differential | `structural`, `raw-selector-errors`; `tuple selectors use retained raw digits rather than double conversion` | High; selector conversion defect corrected in Rust | | Recursive homogeneous arrays and complete annotations | Differential plus general runtime contracts | `structural`, `recursive-types-and-headers`, `exact-diagnostics`; tuple/array/type tests | High; explicit safe Rust witness set | @@ -34,7 +34,7 @@ below add comparisons without claiming exhaustive enumeration of infinite types. | Compiler lifetime, cached repeats, prefix/exception cleanup | Differential plus independent prefix tests | Both drivers repeat after destruction; `cached_test.cpp`; runtime rollback/reentry tests | High; Rust safe API lacks identical caller-prefix access | | Casts, strict separators, reserved alternatives, exact projection/annotation spans | Differential | `malformed-syntax`, `exact-diagnostics`, `raw-selector-errors`, `type-lookup-errors` | High; explicit group/EOF adaptations only | | C++ category enum; selected runtime failure kinds | Differential boundary plus C++ own contract | Harness `compare`; per-row categories; typed callback adapter and source-defined clamp error | High; no matching Rust enum exists | -| Text/Unicode/doc/numeric spelling and resource bounds | Independent public C++ adaptation tests | `tests.cpp`, recursive-expression resource case, compile-fail cursor/parser fixtures | High locally; no false proc-macro text-lexer equivalence | +| Text/Unicode/doc/numeric spelling and resource bounds | Independent C++ adaptation tests | `src/parser.cpp`, recursive-expression resource case, compile-fail cursor/parser fixtures | High locally; no false proc-macro text-lexer equivalence | | Bracket indexing and finite integral bounds | Explicit C++ adaptation | `cpp-adaptations`; `explicit C++ array indexing validates before structural access`; runtime index/prefix cases | High; Rust has no bracket-postfix syntax | | Removed integers/f32/strings, bitwise/casts/helpers, wrong nominal types | Excluded with public rejection tests | Census removed rows; lexer/type/lookup/expression tests; `type-lookup-errors` | High; no invented conversions/names | | Ownership binding, resource overflow, callable exclusion/reentry | Equivalent public runtime contract paths | Runtime parity ledger and callable/composite/resource tests; typed empty Fn fixtures | High; not relabeled as differential raw-storage tests | @@ -52,11 +52,9 @@ The final integrated wave corrects executable retirement and higher-order result ownership. Use the corrected runtime revision in [source evidence](evidence.md) and the build and test commands in the [README](../README.md). Current validation uses source-built parser and runtime targets; it does not verify -installed parser clients. The generated `cpp-library` package check verifies -the parser component only; runtime discovery is expected to fail when the -runtime isn't installed. -The shipped runtime tests `executable_retirement_test.cpp` and -`callable_test.cpp` cover these ownership regressions. +installed parser clients or package artifacts. +The runtime's in-source retirement and callable tests cover these ownership +regressions. Ordinary named scalar calls allocate owning marker/result intermediates. Native owning composites and dynamic invocation retain their costs. diff --git a/docs/validation.md b/docs/validation.md index 93603de..2fe766e 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -1,7 +1,7 @@ # Validate retained contracts {#parser_validation} This guide serves library maintainers. It covers public cross-language -exact-source subset checks, diagnostic differences, and package artifact checks. +exact-source subset checks, diagnostic differences, and local source-build tests. The production parser needs neither Rust, Cargo, Python, nor a JSON library. ## Configure the differential gate @@ -114,14 +114,28 @@ exceptions. No standard-function or bracket-indexing error adaptation remains. Unexpected errors still fail the driver. Exception wording is not compared between languages. -## Package artifact checks +## Run local source-build tests -The `cpp-library`-generated package check verifies that the parser component -is present in the install tree. It doesn't validate consumer discovery or -runtime availability; `find_dependency(cel-runtime)` is expected to fail -because CPM excludes the runtime from recursive installation by default. We -don't maintain an installed-consumer test. Address installation failures if a -client reports one. +For unit and negative-compilation tests without the optional Rust reference, +configure, build, and run: + +```sh +cmake --preset test -DCEL_PARSER_ENABLE_PARITY=OFF +cmake --build --preset test +ctest --preset test +``` + +Private behavioral tests live in their owning implementation files behind +`CPP_LIBRARY_TESTING()`. The generated `parser_in_source_tests` executable runs +them once. Separate public-contract tests link cpp-library's static test +implementation; production compilation excludes doctest and test fixtures. +The cursor and lexer copy-rejection fixtures remain separate compilation-failure +tests with explicit relative private-header includes. No test target receives +the `src` include root. + +Generated tests and example tests have finite 120-second timeouts. The optional +differential test retains its 180-second timeout. Hosted CI uses source builds; +installation, installed consumers, and package artifacts are outside validation. ## Provision CI inputs explicitly diff --git a/src/compiler.cpp b/src/compiler.cpp index 65976c9..81d7b11 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -1,10 +1,12 @@ // SPDX-License-Identifier: BSL-1.0 -#include "compiler.hpp" +#include "lexer.hpp" #include "lookup_access.hpp" #include "type.hpp" #include #include +#include #include +#include #include #include #include @@ -662,6 +664,26 @@ compiled_segment parser::parse_str(std::string_view source) { lex_lexer cursor(source); return expression_compiler(cursor, lookup_).compile(true); } +} // namespace cel + +#if CPP_LIBRARY_TESTING() +#include +#include +#include + +namespace cel::parser_detail { +/// Compiles internal producer streams under the parser's ownership and exclusivity contracts. +struct parser_access { + /// Compiles a complete borrowed stream; terminal producer tokens end traversal. + /// Complexity: O(tokens + emitted code + lookup and type metadata). + static compiled_segment parse_tokens(parser& compiler, std::span tokens); + /// Compiles a prefix, leaving the following host token unconsumed. + /// Complexity: O(consumed tokens + emitted code + lookup and type metadata). + static compiled_segment parse_expression(parser& compiler, token_cursor& cursor); +}; +} // namespace cel::parser_detail + +namespace cel { /// Compiles a complete external stream without copying its token payloads. /// Complexity: O(tokens + emitted operations + lookup/type/structural metadata work). compiled_segment parser_detail::parser_access::parse_tokens(parser& compiler, @@ -678,3 +700,242 @@ compiled_segment parser_detail::parser_access::parse_expression(parser& compiler return expression_compiler(cursor, compiler.lookup_).compile(false); } } // namespace cel + +#include +#include + +namespace { +/// Collects an external producer stream for the private borrowed-token boundary. +/// Complexity: O(source bytes + tokens) time and storage. +std::vector tokens(std::string_view source) { + cel::parser_detail::lex_lexer lexer(source); + std::vector result; + do { + result.push_back(lexer.current()); + if (std::holds_alternative(lexer.current().value)) break; + lexer.advance(); + } while (true); + return result; +} +/// Compiles and executes text with a fresh caller stack. +/// Complexity: O(compilation + execution). +cel::value evaluate(cel::parser& parser, std::string_view text) { + cel::raw_stack stack; + return parser.parse_str(text).execute(stack, {}); +} +/// Checks an exact source diagnostic through the public compiler. +/// Complexity: O(compilation). +void error_at(cel::parser& parser, + std::string_view text, + cel::error_category category, + cel::source_span span) { + try { + (void)parser.parse_str(text); + FAIL("invalid expression accepted"); + } catch (const cel::parse_error& error) { + CHECK(error.category() == category); + CHECK(error.span() == span); + } +} +} // namespace + +TEST_CASE("numeric values require floating literal forms without integer coercion") { + cel::parser parser{cel::op_lookup{}}; + for (const auto& [text, span] : std::array{ + std::pair{"1", cel::source_span{0, 1}}, std::pair{"1 as f64", cel::source_span{0, 1}}, + std::pair{"1+2.0", cel::source_span{0, 1}}, std::pair{"1.0+1", cel::source_span{4, 5}}, + std::pair{"(|x:f64|x)(1)", cel::source_span{11, 12}}, + std::pair{"0x10", cel::source_span{0, 4}}, std::pair{"0b10", cel::source_span{0, 4}}, + std::pair{"0o10", cel::source_span{0, 4}}, std::pair{"0b1f64", cel::source_span{0, 6}}, + std::pair{"0o7_f64", cel::source_span{0, 7}}, + std::pair{"0x1f64", cel::source_span{0, 6}}}) { + CAPTURE(text); + error_at(parser, text, cel::error_category::unsupported_literal, span); + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, tokens(text)), + cel::parse_error); + } + CHECK(evaluate(parser, "1.0+2.0").as() == 3.0); + CHECK(evaluate(parser, "(|x:f64|x)(1.0)").as() == 1.0); + CHECK(evaluate(parser, "(1.0,2.0).0x1").as() == 2.0); +} + +TEST_CASE("decimal integer-form f64 literals produce floating values") { + cel::parser parser{cel::op_lookup{}}; + for (const auto& [text, expected] : std::array{ + std::pair{"1f64", 1.0}, std::pair{"0f64", 0.0}, std::pair{"1_f64", 1.0}, + std::pair{"1__f64", 1.0}, std::pair{"1_000f64", 1000.0}, + std::pair{"9007199254740993f64", 9007199254740992.0}, std::pair{"1e2f64", 100.0}, + std::pair{"1f64 + 2.0", 3.0}, std::pair{"-1f64", -1.0}, std::pair{"1f64 as f64", 1.0}, + std::pair{"(|x:f64|x)(1f64)", 1.0}}) { + CAPTURE(std::string_view(text)); + CHECK(evaluate(parser, text).as() == expected); + cel::raw_stack stack; + CHECK(cel::parser_detail::parser_access::parse_tokens(parser, tokens(text)) + .execute(stack, {}) + .as() == expected); + } + CHECK(std::signbit(evaluate(parser, "-0f64").as())); + for (auto text : {"1f64x", "1f64_", "1f640", "1f32", "1.0f64x", "(1.0,2.0).1f64"}) { + CAPTURE(text); + CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); + } +} + +TEST_CASE("postfix brackets remain host input and are not core array indexing") { + cel::parser parser{cel::op_lookup{}}; + const auto input = tokens("[1.0][0.0]"); + CHECK_THROWS_AS(parser.parse_str("[1.0][0.0]"), cel::parse_error); + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, input), + cel::parse_error); + cel::parser_detail::token_cursor cursor(input); + const auto program = cel::parser_detail::parser_access::parse_expression(parser, cursor); + REQUIRE(std::holds_alternative(cursor.current().value)); + CHECK(cursor.current().span == cel::source_span{5, 6}); + cel::raw_stack stack; + CHECK(program.execute(stack, {}).at(0).as() == 1.0); +} + +TEST_CASE("all six range forms preserve complete type and endpoint order") { + cel::parser parser{cel::op_lookup{}}; + const auto forms = std::array{std::pair{"1.0 + 2.0..4.0 * 2.0", cel::range_kind::range}, + std::pair{"1.0..=3.0", cel::range_kind::range_inclusive}, + std::pair{"1.0..", cel::range_kind::range_from}, + std::pair{"..3.0", cel::range_kind::range_to}, + std::pair{"..=3.0", cel::range_kind::range_to_inclusive}, + std::pair{"..", cel::range_kind::range_full}}; + for (const auto& [text, kind] : forms) { + CAPTURE(text); + CHECK(evaluate(parser, text).type().form() == kind); + } + auto range = evaluate(parser, "1.0 + 2.0..4.0 * 2.0"); + CHECK(range.at(0).as() == 3); + CHECK(range.at(1).as() == 8); + for (auto text : {"..=", "1.0..=", "1.0..2.0..3.0", "true..false", "1.0==2.0..3.0==4.0"}) { + CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); + } + for (auto text : {"..else", "1.0..else", "..as", "1.0..as"}) { + const auto input = tokens(text); + cel::parser_detail::token_cursor cursor(input); + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_expression(parser, cursor), + cel::parse_error); + } +} + +TEST_CASE("independent closure scope isolation restores scopes after success and failure") { + cel::op_lookup lookup; + lookup.push_library_scope( + [](std::string_view name, cel::dyn_segment& b, std::size_t n, cel::source_span) { + if (name != "library" || n != 0) return false; + b.just(cel::value::from(7.0)); + return true; + }); + cel::parser_detail::lookup_access::push_scope( + lookup, [](std::string_view name, cel::dyn_segment& b, std::size_t n, cel::source_span) { + if (name != "ambient" || n != 0) return false; + b.just(cel::value::from(3.0)); + return true; + }); + cel::parser parser(std::move(lookup)); + CHECK(evaluate(parser, "ambient").as() == 3); + CHECK(evaluate(parser, "(|| library)()").as() == 7); + CHECK_THROWS_AS(parser.parse_str("|| ambient"), cel::parse_error); + CHECK(evaluate(parser, "ambient").as() == 3); + CHECK_THROWS_AS(parser.parse_str("|x:f64| || x"), cel::parse_error); + CHECK(evaluate(parser, "ambient").as() == 3); + CHECK(evaluate(parser, "(|ambient:f64| ambient)(9.0)").as() == 9); + CHECK(evaluate(parser, "ambient").as() == 3); + CHECK(evaluate(parser, "if true {ambient} else {0.0}").as() == 3); + CHECK(evaluate(parser, "(|ambient:bool| if ambient {1.0} else {2.0})(true)").as() == 1); +} + +TEST_CASE( + "text and token methods reject trailing input inline leaves host token diagnostics are owned") { + cel::parser parser{cel::op_lookup{}}; + auto input = tokens("1.0+2.0, host"); + cel::parser_detail::token_cursor cursor(input); + auto program = cel::parser_detail::parser_access::parse_expression(parser, cursor); + CHECK(std::get(cursor.current().value).spelling() == ","); + cel::raw_stack stack; + CHECK(program.execute(stack, {}).as() == 3); + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, input), + cel::parse_error); + CHECK(cel::parser_detail::parser_access::parse_tokens(parser, tokens("(1.0,2.0).1")) + .execute(stack, {}) + .as() == 2); + error_at(parser, "1.0 2.0", cel::error_category::malformed_input, {4, 7}); + error_at(parser, "[1.0,]", cel::error_category::malformed_input, {5, 6}); + error_at(parser, "(1.0]", cel::error_category::delimiter_error, {4, 5}); + error_at(parser, "missing", cel::error_category::lookup_error, {0, 7}); + error_at(parser, "[1.0,true]:[f64] ", cel::error_category::type_error, {0, 16}); + for (const auto& [text, expected] : + std::array{std::pair{"[]:(f64) , host", cel::source_span{3, 8}}, + std::pair{"[true]:([f64]) , host", cel::source_span{0, 14}}, + std::pair{"[[]:[bool]]:([[f64]]) , host", cel::source_span{0, 21}}}) { + CAPTURE(std::string_view(text)); + const auto annotated = tokens(text); + cel::parser_detail::token_cursor prefix(annotated); + try { + (void)cel::parser_detail::parser_access::parse_expression(parser, prefix); + FAIL("invalid annotation accepted"); + } catch (const cel::parse_error& error) { + CHECK(error.category() == cel::error_category::type_error); + CHECK(error.span() == expected); + } + CHECK(std::get(prefix.current().value).spelling() == ","); + } + auto invalid = std::array{cel::parser_detail::token{ + {20, 21}, + cel::parse_error(cel::error_category::unsupported_literal, {20, 21}, "producer")}}; + try { + (void)cel::parser_detail::parser_access::parse_tokens(parser, invalid); + FAIL("producer diagnostic ignored"); + } catch (const cel::parse_error& error) { + CHECK(error.category() == cel::error_category::unsupported_literal); + CHECK(error.span() == cel::source_span{20, 21}); + CHECK(std::string(error.what()) == "producer"); + } + const auto malformed = std::array{ + cel::parser_detail::token{ + {10, 11}, + cel::parser_detail::open_delimiter{cel::parser_detail::delimiter::parenthesis}}, + cel::parser_detail::token{{11, 14}, + cel::parser_detail::numeric_literal{ + 1, "1.0", "", cel::parser_detail::numeric_form::decimal}}, + cel::parser_detail::token{ + {14, 15}, cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::bracket}}}; + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, malformed), + cel::parse_error); + const auto invisible = std::array{ + cel::parser_detail::token{ + {0, 0}, cel::parser_detail::open_delimiter{cel::parser_detail::delimiter::none}}, + cel::parser_detail::token{ + {0, 0}, cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::none}}}; + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, invisible), + cel::parse_error); + auto host_close = tokens("1.0+2.0"); + host_close.back() = {{7, 8}, + cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::brace}}; + cel::parser_detail::token_cursor host(host_close); + CHECK(cel::parser_detail::parser_access::parse_expression(parser, host) + .execute(stack, {}) + .as() == 3); + CHECK(std::holds_alternative(host.current().value)); + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, host_close), + cel::parse_error); + const auto terminal = std::array{ + cel::parser_detail::token{{0, 3}, + cel::parser_detail::numeric_literal{ + 1, "1.0", "", cel::parser_detail::numeric_form::decimal}}, + cel::parser_detail::token{{3, 3}, cel::parser_detail::end_token{}}, + cel::parser_detail::token{{4, 5}, cel::parser_detail::identifier{"ignored"}}}; + CHECK(cel::parser_detail::parser_access::parse_tokens(parser, terminal) + .execute(stack, {}) + .as() == 1); + const auto external_suffix = std::array{cel::parser_detail::token{ + {0, 4}, + cel::parser_detail::numeric_literal{1, "1i32", "i32", + cel::parser_detail::numeric_form::integer}}}; + CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, external_suffix), + cel::parse_error); +} +#endif diff --git a/src/compiler.hpp b/src/compiler.hpp deleted file mode 100644 index 2860ac1..0000000 --- a/src/compiler.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#ifndef CEL_PARSER_INTERNAL_COMPILER_HPP -#define CEL_PARSER_INTERNAL_COMPILER_HPP -#include "lexer.hpp" -#include - -namespace cel::parser_detail { -/// Compiles internal producer streams under the parser's ownership and exclusivity contracts. -struct parser_access { - /// Compiles a complete borrowed stream; terminal producer tokens end traversal. - /// Complexity: O(tokens + emitted code + lookup and type metadata). - static compiled_segment parse_tokens(parser& compiler, std::span tokens); - /// Compiles a prefix, leaving the following host token unconsumed. - /// Complexity: O(consumed tokens + emitted code + lookup and type metadata). - static compiled_segment parse_expression(parser& compiler, token_cursor& cursor); -}; -} // namespace cel::parser_detail -#endif diff --git a/src/lookup.cpp b/src/lookup.cpp index ad2f46d..851b72f 100644 --- a/src/lookup.cpp +++ b/src/lookup.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace cel { @@ -360,3 +361,611 @@ void op_lookup::install_builtins() { } } // namespace cel + +#if CPP_LIBRARY_TESTING() +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace { +/// Distinguishes equal-layout client operands by nominal identity. +struct first { + double number; +}; +/// Distinguishes a second client operand with the same layout. +struct second { + double number; +}; +/// Supplies one adapter-backed nominal record for parser registration tests. +struct adapted_point { + double x; + double y; +}; +/// Supplies a same-layout second nominal record. +struct adapted_point_alias { + double x; + double y; +}; +/// Marks an ordinary registered function independently of its operand overloads. +struct named_function {}; +/// Marks an independent installer's binding of the same function name. +struct other_marker {}; +/// Owns a copyable, nonmovable over-aligned registered callback. +struct alignas(256) copy_only_factor { + double factor; ///< Owns the multiplication factor. + /// Initializes the factor. + explicit copy_only_factor(double input) : factor(input) {} + /// Copies the factor independently. + copy_only_factor(const copy_only_factor&) = default; + /// Disallows move construction. + copy_only_factor(copy_only_factor&&) = delete; + /// Multiplies the operand by the owned factor. + double operator()(double input) const { return factor * input; } +}; +/// Marks a function with a valid over-aligned opaque client leaf. +struct alignas(256) aligned_marker { + double number; ///< Owns observable marker state. +}; +/// Evaluates a complete ordinary program through the public prepared boundary. +/// Complexity: O(compiled operations + native conversion + callback execution). +template +R evaluate(cel::dyn_segment builder) { + auto program = std::move(builder).finish(); + auto prepared = program.template prepare(); + cel::raw_stack stack; + return prepared.call(stack); +} +/// Emits source-ordered native operands, applies a name, and evaluates its result. +/// Complexity: O(arity + matching + compiled operations + conversion + callback execution). +template +R operation(const cel::op_lookup& lookup, std::string_view name, A... arguments) { + cel::dyn_segment builder; + (builder.just(cel::value::from(arguments)), ...); + cel::parser_detail::lookup_access::apply(lookup, name, builder, sizeof...(A), {10, 14}); + return evaluate(std::move(builder)); +} +} // namespace + +namespace cel { +template <> +struct record_adapter<::adapted_point> { + /// Returns the canonical nominal descriptor for adapted_point. + static value_type type() { + static const auto descriptor = value_type::record( + "sample.point", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one point value in canonical field order. + static value to_value(const ::adapted_point& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one point value after descriptor validation. + static ::adapted_point from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong adapted point type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; + +template <> +struct record_adapter<::adapted_point_alias> { + /// Returns the canonical nominal descriptor for adapted_point_alias. + static value_type type() { + static const auto descriptor = value_type::record( + "AdapterPointAlias", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one alias value in canonical field order. + static value to_value(const ::adapted_point_alias& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one alias value after descriptor validation. + static ::adapted_point_alias from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong adapted point alias type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; + +} // namespace cel + +TEST_CASE("structural registrations reject nontrivial adapters without reserving names") { + cel::op_lookup lookup; + CHECK_THROWS_AS(lookup.register_type>("array"), std::invalid_argument); + CHECK_THROWS_AS(lookup.register_type>("tuple"), std::invalid_argument); + CHECK_THROWS_AS(lookup.register_function("marker", std::vector{}), + std::invalid_argument); + CHECK_THROWS_AS(lookup.register_function("marker", std::tuple{1.0}), std::invalid_argument); + CHECK_FALSE(lookup.find_type("array")); + CHECK_FALSE(lookup.find_type("tuple")); + lookup.register_type("array"); + lookup.register_type("tuple"); + lookup.register_function("marker", named_function{}); + CHECK_NOTHROW(operation(lookup, "marker")); +} + +TEST_CASE("lookup owns independent copies of over-aligned lvalue callbacks and markers") { + cel::op_lookup lookup; + copy_only_factor callback(3.0); + lookup.register_op("scale", callback); + callback.factor = 99.0; + CHECK(operation(lookup, "scale", 2.0) == 6.0); + aligned_marker marker{7.0}; + lookup.register_function("aligned", marker); + marker.number = 99.0; + CHECK(operation(lookup, "aligned").number == 7.0); +} + +TEST_CASE("native extension registrations preserve nested structural descriptors and origins") { + using nested = std::tuple, std::vector>>; + cel::op_lookup lookup; + lookup.register_op("copy_nested", [](nested input) { return input; }); + const nested input{{}, {{true, first{4.0}}}}; + const auto copied = operation(lookup, "copy_nested", input); + CHECK(std::get<1>(std::get<1>(copied)[0]).number == 4.0); + lookup.register_function("measure_named", named_function{}); + lookup.register_op("measure_named", [](first input) { return input.number; }); + cel::dyn_segment builder; + builder.just(cel::value::from(true)); + const auto prefix = builder.snapshot(); + cel::parser_detail::lookup_access::apply(lookup, "measure_named", builder, 0, {}); + builder.just(cel::value::from(first{9.0})); + cel::parser_detail::lookup_access::apply(lookup, "()", builder, 2, {}); + CHECK(builder.origin_below(1) == prefix); + builder.make_tuple(2, {}); + const auto result = evaluate>(std::move(builder)); + CHECK(std::get<0>(result)); + CHECK(std::get<1>(result) == 9.0); +} + +TEST_CASE("exact registrations preserve overload identity and callback lifetime") { + cel::dyn_segment compiled; + std::weak_ptr lifetime; + { + cel::op_lookup lookup; + lookup.register_type("First"); + lookup.register_type("Second"); + auto state = std::make_shared(3.0); + lifetime = state; + lookup.register_op("measure", + [state](first x) { return x.number + *state; }); + lookup.register_op("measure", [](second x) { return x.number * 2.0; }); + CHECK(operation(lookup, "measure", second{4.0}) == 8.0); + compiled.just(cel::value::from(first{4.0})); + cel::parser_detail::lookup_access::apply(lookup, "measure", compiled, 1, {1, 8}); + CHECK_THROWS_AS((lookup.register_op("measure", [](first) { return true; })), + std::invalid_argument); + CHECK_THROWS_AS(lookup.register_type("First"), std::invalid_argument); + } + CHECK_FALSE(lifetime.expired()); + CHECK(evaluate(std::move(compiled)) == 7.0); + CHECK(lifetime.expired()); +} + +TEST_CASE("scopes are LIFO and isolated bodies retain libraries and registrations") { + cel::op_lookup lookup; + lookup.register_op("constant", [] { return 1.0; }); + lookup.push_library_scope( + [](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { + if (n != "library" || a != 0) return false; + b.just(cel::value::from(2.0)); + return true; + }); + cel::parser_detail::lookup_access::push_scope( + lookup, [](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { + if (n != "constant" || a != 0) return false; + b.just(cel::value::from(3.0)); + return true; + }); + cel::parser_detail::lookup_access::push_scope( + lookup, [](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { + if (n != "constant" || a != 0) return false; + b.just(cel::value::from(4.0)); + return true; + }); + CHECK(operation(lookup, "constant") == 4.0); + cel::parser_detail::lookup_access::pop_scope(lookup); + CHECK(operation(lookup, "constant") == 3.0); + auto saved = cel::parser_detail::lookup_access::isolate_scopes(lookup); + CHECK(operation(lookup, "constant") == 1.0); + CHECK(operation(lookup, "library") == 2.0); + cel::parser_detail::lookup_access::restore_scopes(lookup, std::move(saved)); + CHECK(operation(lookup, "constant") == 3.0); +} + +TEST_CASE("ordinary named markers retain first binding and direct member selectors") { + cel::op_lookup lookup; + CHECK_THROWS_AS(lookup.register_function("bad_marker", std::tuple{}), std::invalid_argument); + CHECK_THROWS_AS(operation>(lookup, "bad_marker"), cel::parse_error); + lookup.register_function("convert", named_function{}); + lookup.register_function("convert", other_marker{}); + CHECK_THROWS_AS(lookup.register_function("elsewhere", named_function{}), std::invalid_argument); + lookup.register_op("convert", [](double x) { return x + 1.0; }); + cel::dyn_segment secondary; + secondary.just(cel::value::from(other_marker{})); + secondary.just(cel::value::from(4.0)); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "()", secondary, 2, {}), + cel::parse_error); + cel::dyn_segment builder; + builder.just(cel::value::from(true)); // Preserve a prefix beneath marker and arguments. + cel::parser_detail::lookup_access::apply(lookup, "convert", builder, 0, {}); + CHECK(builder.operand_types(1)[0].same_shape(cel::value_type::leaf())); + builder.just(cel::value::from(4.0)); + cel::parser_detail::lookup_access::apply(lookup, "()", builder, 2, {}); + builder.make_tuple(2, {}); + CHECK(evaluate>(std::move(builder)) == std::tuple{true, 5.0}); + cel::dyn_segment member; + member.just(cel::value::from(5.0)); + cel::parser_detail::lookup_access::apply(lookup, "convert", member, 1, {}, + cel::parser_detail::lookup_selector::member); + CHECK(evaluate(std::move(member)) == 6.0); +} + +TEST_CASE("declined overloads never execute and selected emitter failures propagate") { + cel::op_lookup lookup; + std::size_t invoked = 0; + lookup.register_op("fail", [&invoked](first) { + ++invoked; + return 1.0; + }); + cel::dyn_segment builder; + builder.just(cel::value::from(second{2.0})); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "fail", builder, 1, {2, 6}), + cel::parse_error); + CHECK(invoked == 0); + CHECK(evaluate(std::move(builder)).number == 2.0); + lookup.register_operation( + "setup_failure", {}, cel::value_type::leaf(), + [](cel::dyn_segment&, cel::source_span) { throw std::logic_error("selected failure"); }); + CHECK_THROWS_WITH(operation(lookup, "setup_failure"), "selected failure"); + lookup.register_op("throwing", + []() -> double { throw std::runtime_error("callback"); }); + CHECK_THROWS_WITH(operation(lookup, "throwing"), "callback"); +} + +TEST_CASE("record adapter registration preserves nominal types and member calls") { + cel::op_lookup lookup; + lookup.register_record_type("AdapterPoint"); + lookup.register_record_type("AdapterPointAlias"); + std::size_t adapted_point_calls = 0; + lookup.register_op("sum", [&adapted_point_calls](adapted_point input) { + ++adapted_point_calls; + return input.x + input.y; + }); + cel::dyn_segment mismatch; + mismatch.just(cel::value::from(adapted_point_alias{.x = 1.0, .y = 2.0})); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "sum", mismatch, 1, {}), + cel::parse_error); + CHECK(adapted_point_calls == 0); + CHECK(evaluate(std::move(mismatch)).x == 1.0); + lookup.register_op( + "sum", [](adapted_point_alias input) { return input.x - input.y; }); + cel::parser parser(std::move(lookup)); + cel::raw_stack stack; + CHECK( + parser.parse_str("AdapterPoint { y: 2.0, x: 1.0 }.sum()").execute(stack, {}).as() == + 3.0); + CHECK(parser.parse_str("AdapterPointAlias { y: 2.0, x: 1.0 }.sum()") + .execute(stack, {}) + .as() == -1.0); +} + +TEST_CASE("nominal records and arbitrary nested registration use public runtime emitters") { + cel::op_lookup lookup; + const auto field = cel::record_field{ + "payload", cel::value_type::array(cel::value_type::array(cel::value_type::tuple(std::array{ + cel::value_type::leaf(), cel::value_type::leaf()})))}; + lookup.register_record("Record", std::array{field}); + CHECK_THROWS_AS(lookup.register_record("Record", {}), std::invalid_argument); + const auto found = lookup.find_type("Record"); + if (!found) throw std::logic_error("registered record missing"); + auto schema = *found; + CHECK(schema.record_identity() == "Record"); + CHECK(schema.fields()[0].same_shape(field.type)); + using nested = std::vector>>; + lookup.register_op("copy", [](nested input) { return input; }); + nested input{{{true, 3.0}}}; + CHECK(operation(lookup, "copy", input) == input); + lookup.register_operation( + "payload", std::array{schema}, field.type, + [](cel::dyn_segment& b, cel::source_span) { b.project_record("payload"); }); + cel::dyn_segment builder; + builder.just(cel::value::record(schema, std::array{cel::value::from(input)})); + cel::parser_detail::lookup_access::apply(lookup, "payload", builder, 1, {}, + cel::parser_detail::lookup_selector::member); + CHECK(evaluate(std::move(builder)) == input); + const auto different_name = cel::value_type::record("OtherRecord", std::array{field}); + const auto alternate_payload = cel::value::from(std::vector>{{true}}); + const auto different_fields = cel::value_type::record( + "Record", std::array{cel::record_field{"payload", alternate_payload.type()}}); + for (const auto& record : { + cel::value::record(different_name, std::array{cel::value::from(input)}), + cel::value::record(different_fields, std::array{alternate_payload}), + }) { + cel::dyn_segment wrong; + wrong.just(record); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "payload", wrong, 1, {}), + cel::parse_error); + const auto operands = wrong.operand_types(1); + const bool retained = operands.size() == 1 && operands[0].compatible_with(record.type()); + CHECK(retained); + } +} + +TEST_CASE("retained operators use IEEE arithmetic and partial comparisons") { + cel::op_lookup lookup; + CHECK(operation(lookup, "+", 2.0, 3.0) == 5.0); + CHECK(operation(lookup, "-", 2.0, 3.0) == -1.0); + CHECK(operation(lookup, "*", 2.0, 3.0) == 6.0); + CHECK(operation(lookup, "/", 8.0, 2.0) == 4.0); + CHECK(operation(lookup, "%", -5.0, 2.0) == -1.0); + CHECK(std::signbit(operation(lookup, "-", 0.0))); + CHECK_THROWS_AS(operation(lookup, "+", 1.0), cel::parse_error); + CHECK(std::isinf(operation(lookup, "/", 1.0, 0.0))); + CHECK(std::isnan(operation(lookup, "/", 0.0, 0.0))); + CHECK(std::isnan(operation(lookup, "%", 1.0, 0.0))); + CHECK(operation(lookup, "!", false)); + CHECK(operation(lookup, "==", true, true)); + CHECK(operation(lookup, "!=", true, false)); + const double nan = std::numeric_limits::quiet_NaN(); + for (auto name : {"==", "<", "<=", ">", ">="}) { + CHECK_FALSE(operation(lookup, name, nan, 1.0)); + } + CHECK(operation(lookup, "!=", nan, nan)); + CHECK(operation(lookup, "==", -0.0, 0.0)); + CHECK(operation(lookup, "<", 1.0, 2.0)); + CHECK_FALSE(operation(lookup, "<", 2.0, 1.0)); + CHECK(operation(lookup, "<=", 2.0, 2.0)); + CHECK(operation(lookup, ">", 2.0, 1.0)); + CHECK_FALSE(operation(lookup, ">", 1.0, 2.0)); + CHECK(operation(lookup, ">=", 2.0, 2.0)); + for (auto name : {"&", "|", "^", "<<", ">>", "round"}) { + CHECK_THROWS_AS(operation(lookup, name, 1.0, 2.0), cel::parse_error); + } + lookup.register_op("+", [](double a, double b) { return a - b; }); + CHECK(operation(lookup, "+", 2.0, 3.0) == -1.0); +} + +TEST_CASE("standard numeric names are not parser-provided operations") { + cel::op_lookup lookup; + for (auto name : {"min", "max", "clamp", "abs", "signum", "sqrt", "floor", "ceil", "trunc", + "fract", "round_ties_even"}) { + CAPTURE(name); + CHECK_THROWS_AS(operation(lookup, name, -3.0), cel::parse_error); + } +} + +TEST_CASE("owned names schemas and scope captures survive registration input destruction") { + cel::dyn_segment builder; + cel::dyn_segment move_only_program; + std::optional schema; + { + cel::op_lookup lookup; + std::string name = "owned"; + lookup.register_op(name, + [state = std::make_unique(8.0)] { return *state; }); + cel::parser_detail::lookup_access::apply(lookup, name, move_only_program, 0, {}); + name.assign("changed"); + CHECK(operation(lookup, "owned") == 8.0); + std::array fields{cel::record_field{"field", cel::value_type::leaf()}}; + lookup.register_record("Owner", fields); + fields[0].name.assign("replaced"); + schema = lookup.find_type("Owner"); + auto state = std::make_unique(9.0); + auto captured = std::shared_ptr(std::move(state)); + cel::parser_detail::lookup_access::push_scope( + lookup, + [captured](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { + if (n != "scoped" || a != 0) return false; + b.op([captured] { return *captured; }); + return true; + }); + cel::parser_detail::lookup_access::apply(lookup, "scoped", builder, 0, {}); + } + if (!schema) throw std::logic_error("owned record missing"); + CHECK(schema->field_names()[0] == "field"); + CHECK(evaluate(std::move(move_only_program)) == 8.0); + CHECK(evaluate(std::move(builder)) == 9.0); + cel::op_lookup lookup; + CHECK_THROWS_AS(lookup.register_type("f64"), std::invalid_argument); + CHECK_THROWS_AS(lookup.register_type("i32"), std::invalid_argument); + CHECK_THROWS_AS(lookup.register_type(""), std::invalid_argument); + CHECK_THROWS_AS(lookup.register_type>("NotLeaf"), std::invalid_argument); + const auto field = cel::record_field{"x", cel::value_type::leaf()}; + CHECK_THROWS_AS(lookup.register_record("Bad", std::array{field, field}), std::invalid_argument); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::push_scope(lookup, {}), + std::invalid_argument); +} + +TEST_CASE("structural signatures follow operations and records project complete schemas") { + cel::op_lookup lookup; + using input_type = std::tuple>>; + const auto tuple_type = cel::value::from(input_type{true, {{3.0, false}}}).type(); + const auto vector_type = tuple_type.fields()[1]; + lookup.register_structural_op( + "part", std::array{tuple_type}, vector_type, + [](cel::dyn_segment& b, cel::source_span) { b.project_tuple(1); }); + CHECK(operation>>(lookup, "part", + input_type{true, {{3.0, false}}}) == + std::vector>{{3.0, false}}); + lookup.register_op>, input_type>( + "part", [](input_type) { return std::vector>{{5.0, true}}; }); + CHECK(operation>>(lookup, "part", input_type{true, {}}) == + std::vector>{{5.0, true}}); + lookup.register_record("Nominal", std::array{cel::record_field{"part", vector_type}}); + const auto found = lookup.find_type("Nominal"); + if (!found) throw std::logic_error("registered record missing"); + const auto schema = *found; + const auto payload = cel::value::from(std::vector>{{2.0, true}}); + cel::dyn_segment builder; + builder.just(cel::value::record(schema, std::array{payload})); + cel::parser_detail::lookup_access::apply(lookup, "part", builder, 1, {}, + cel::parser_detail::lookup_selector::member); + CHECK(evaluate>>(std::move(builder)) == + std::vector>{{2.0, true}}); + lookup.register_operation( + "part", std::array{schema}, vector_type, [](cel::dyn_segment& b, cel::source_span) { + b.project_record("part"); + b.op>, std::vector>>( + [](std::vector>) { + return std::vector>{{7.0, false}}; + }); + }); + cel::dyn_segment shadowed; + shadowed.just(cel::value::record(schema, std::array{payload})); + cel::parser_detail::lookup_access::apply(lookup, "part", shadowed, 1, {}, + cel::parser_detail::lookup_selector::member); + CHECK(evaluate>>(std::move(shadowed)) == + std::vector>{{7.0, false}}); + CHECK_THROWS_AS(operation(lookup, "==", input_type{true, {}}, input_type{true, {}}), + cel::parse_error); +} + +TEST_CASE("callable dispatch accepts complete nested parameters and client results") { + using input_type = std::tuple>>; + cel::dyn_segment body; + body.push_argument(0, cel::value::from(input_type{false, {}}).type()); + body.op([](input_type x) { return first{std::get<1>(x)[0][0]}; }); + cel::callable function(std::move(body).finish(), + std::array{cel::value::from(input_type{false, {}}).type()}); + cel::dyn_segment builder; + { + cel::op_lookup lookup; + builder.just(function.to_value()); + builder.just(cel::value::from(input_type{true, {{6.0}}})); + cel::parser_detail::lookup_access::apply(lookup, "()", builder, 2, {}); + } + CHECK(evaluate(std::move(builder)).number == 6.0); + cel::dyn_segment member; + member.just(function.to_value()); + member.just(cel::value::from(input_type{true, {{6.0}}})); + cel::op_lookup lookup; + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply( + lookup, "()", member, 2, {}, cel::parser_detail::lookup_selector::member), + cel::parse_error); + cel::dyn_segment missing_argument; + missing_argument.just(function.to_value()); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "()", missing_argument, 1, {}), + cel::parse_error); + CHECK(missing_argument.operand_types(1)[0].compatible_with(function.type())); + cel::dyn_segment wrong_argument; + wrong_argument.just(function.to_value()); + wrong_argument.just(cel::value::from(true)); + try { + cel::parser_detail::lookup_access::apply(lookup, "()", wrong_argument, 2, {3, 9}); + FAIL("wrong callable argument admitted"); + } catch (const cel::parse_error& error) { + CHECK(error.category() == cel::error_category::lookup_error); + CHECK(error.span() == cel::source_span{3, 9}); + } + CHECK(wrong_argument.operand_types(2)[1].compatible_with(cel::value_type::leaf())); +} + +TEST_CASE("range emitters and casts preserve exact retained types and diagnostics") { + cel::op_lookup lookup; + cel::raw_stack stack; + constexpr std::array forms{std::pair{"range", cel::range_kind::range}, + std::pair{"range_inclusive", cel::range_kind::range_inclusive}, + std::pair{"range_from", cel::range_kind::range_from}, + std::pair{"range_to", cel::range_kind::range_to}, + std::pair{"range_to_inclusive", cel::range_kind::range_to_inclusive}, + std::pair{"range_full", cel::range_kind::range_full}}; + for (auto [name, kind] : forms) { + cel::dyn_segment builder; + const auto arity = + kind == cel::range_kind::range_full ? 0U : + kind == cel::range_kind::range || kind == cel::range_kind::range_inclusive ? 2U : + 1U; + if (arity > 0) builder.just(cel::value::from(-0.0)); + if (arity > 1) builder.just(cel::value::from(std::numeric_limits::infinity())); + cel::parser_detail::lookup_access::apply(lookup, name, builder, arity, {}); + auto value = std::move(builder).finish().execute(stack, {}); + const bool same_form = value.type().form() == kind; + const bool same_count = value.size() == arity; + CHECK(same_form); + CHECK(same_count); + if (arity > 0) CHECK(std::signbit(value.at(0).as())); + if (arity > 1) CHECK(std::isinf(value.at(1).as())); + } + cel::dyn_segment number; + number.just(cel::value::from(-0.0)); + cel::parser_detail::lookup_access::apply_cast(lookup, "f64", number, {2, 8}); + CHECK(std::signbit(evaluate(std::move(number)))); + cel::dyn_segment boolean; + boolean.just(cel::value::from(true)); + cel::parser_detail::lookup_access::apply_cast(lookup, "bool", boolean, {}); + CHECK(evaluate(std::move(boolean))); + lookup.register_type("AliasD"); + for (auto target : {"bool", "f32", "i32", "String", "AliasD"}) { + cel::dyn_segment invalid; + invalid.just(cel::value::from(3.0)); + try { + cel::parser_detail::lookup_access::apply_cast(lookup, target, invalid, {4, 11}); + FAIL("unsupported cast accepted"); + } catch (const cel::parse_error& error) { + CHECK(error.span() == cel::source_span{4, 11}); + } + CHECK(evaluate(std::move(invalid)) == 3.0); + } + cel::dyn_segment empty; + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply_cast(lookup, "f64", empty, {}), + cel::parse_error); + CHECK_THROWS_AS(operation(lookup, "range", true, false), cel::parse_error); +} + +TEST_CASE("zero-argument functions skip value scopes during direct operation selection") { + cel::op_lookup lookup; + lookup.register_function("zero", named_function{}); + lookup.register_op("zero", [] { return 2.0; }); + cel::parser_detail::lookup_access::push_scope( + lookup, + [](std::string_view name, cel::dyn_segment& builder, std::size_t arity, cel::source_span) { + if (name != "zero" || arity != 0) return false; + builder.just(cel::value::from(7.0)); + return true; + }); + CHECK(operation(lookup, "zero") == 7.0); + cel::dyn_segment builder; + cel::parser_detail::lookup_access::apply(lookup, "zero", builder, 0, {}, + cel::parser_detail::lookup_selector::ordinary, + cel::parser_detail::scope_selection::library_only); + cel::parser_detail::lookup_access::apply(lookup, "()", builder, 1, {}); + CHECK(evaluate(std::move(builder)) == 2.0); +} + +TEST_CASE("function marker retirement preserves zero-byte source unit results") { + cel::op_lookup lookup; + lookup.register_function("unit", named_function{}); + lookup.register_op>("unit", [] { return std::tuple{}; }); + cel::dyn_segment builder; + cel::parser_detail::lookup_access::apply(lookup, "unit", builder, 0, {}); + cel::parser_detail::lookup_access::apply(lookup, "()", builder, 1, {}); + CHECK(evaluate>(std::move(builder)) == std::tuple{}); +} + +TEST_CASE("registered descriptors distinguish semantic equality from ownership compatibility") { + cel::dyn_segment body; + body.just(cel::value::from(3.0)); + cel::callable function(std::move(body).finish(), {}); + auto declared = cel::value_type::callable({}, cel::value_type::leaf()); + CHECK(declared.same_shape(function.type())); + REQUIRE_FALSE(declared.compatible_with(function.type())); + cel::op_lookup lookup; + lookup.register_operation( + "test", std::array{declared}, cel::value_type::leaf(), + [](cel::dyn_segment&, cel::source_span) { FAIL("incompatible ownership selected"); }); + cel::dyn_segment builder; + builder.just(function.to_value()); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "test", builder, 1, {}), + cel::parse_error); +} +#endif diff --git a/src/parser.cpp b/src/parser.cpp index 47a1404..680ec07 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1,9 +1,9 @@ -// SPDX-License-Identifier: BSL-1.0 +// SPDX-License-Identifier: BSL-1.0 AND Unicode-3.0 #include "lexer.hpp" - -#include "unicode_data.hpp" +#include #include +#include #include #include #include @@ -22,6 +22,406 @@ namespace cel::parser_detail { namespace { +// BEGIN GENERATED UNICODE DATA +// Unicode property data licensed under Unicode-3.0. +// Generated by tools/generate_unicode.py; Unicode 18.0.0. +// Input: https://www.unicode.org/Public/18.0.0/ucd/DerivedCoreProperties.txt +// SHA-256: 09c928886a178fcafd93c29e4bd59073a058e5a100b716d425cb563ab50f68c9 +/// Stores an inclusive Unicode property interval. +struct unicode_range { + std::uint32_t first; + std::uint32_t last; +}; +/// Stores Unicode 18 XID_Start intervals in ascending order. +constexpr std::array xid_start{{ + {0x41, 0x5A}, {0x61, 0x7A}, {0xAA, 0xAA}, {0xB5, 0xB5}, + {0xBA, 0xBA}, {0xC0, 0xD6}, {0xD8, 0xF6}, {0xF8, 0x2C1}, + {0x2C6, 0x2D1}, {0x2E0, 0x2E4}, {0x2EC, 0x2EC}, {0x2EE, 0x2EE}, + {0x370, 0x374}, {0x376, 0x377}, {0x37B, 0x37D}, {0x37F, 0x37F}, + {0x386, 0x386}, {0x388, 0x38A}, {0x38C, 0x38C}, {0x38E, 0x3A1}, + {0x3A3, 0x3F5}, {0x3F7, 0x481}, {0x48A, 0x52F}, {0x531, 0x556}, + {0x558, 0x559}, {0x560, 0x588}, {0x58B, 0x58C}, {0x5D0, 0x5EA}, + {0x5EF, 0x5F2}, {0x620, 0x64A}, {0x66E, 0x66F}, {0x671, 0x6D3}, + {0x6D5, 0x6D5}, {0x6E5, 0x6E6}, {0x6EE, 0x6EF}, {0x6FA, 0x6FC}, + {0x6FF, 0x6FF}, {0x710, 0x710}, {0x712, 0x72F}, {0x74D, 0x7A5}, + {0x7B1, 0x7B1}, {0x7CA, 0x7EA}, {0x7F4, 0x7F5}, {0x7FA, 0x7FA}, + {0x800, 0x815}, {0x81A, 0x81A}, {0x824, 0x824}, {0x828, 0x828}, + {0x840, 0x858}, {0x860, 0x86A}, {0x870, 0x887}, {0x889, 0x88F}, + {0x8A0, 0x8C9}, {0x904, 0x939}, {0x93D, 0x93D}, {0x950, 0x950}, + {0x958, 0x961}, {0x971, 0x980}, {0x985, 0x98C}, {0x98F, 0x990}, + {0x993, 0x9A8}, {0x9AA, 0x9B0}, {0x9B2, 0x9B2}, {0x9B6, 0x9B9}, + {0x9BD, 0x9BD}, {0x9CE, 0x9CE}, {0x9DC, 0x9DD}, {0x9DF, 0x9E1}, + {0x9F0, 0x9F1}, {0x9FC, 0x9FC}, {0xA05, 0xA0A}, {0xA0F, 0xA10}, + {0xA13, 0xA28}, {0xA2A, 0xA30}, {0xA32, 0xA33}, {0xA35, 0xA36}, + {0xA38, 0xA39}, {0xA59, 0xA5C}, {0xA5E, 0xA5E}, {0xA72, 0xA74}, + {0xA85, 0xA8D}, {0xA8F, 0xA91}, {0xA93, 0xAA8}, {0xAAA, 0xAB0}, + {0xAB2, 0xAB3}, {0xAB5, 0xAB9}, {0xABD, 0xABD}, {0xAD0, 0xAD0}, + {0xAE0, 0xAE1}, {0xAF9, 0xAF9}, {0xB05, 0xB0C}, {0xB0F, 0xB10}, + {0xB13, 0xB28}, {0xB2A, 0xB30}, {0xB32, 0xB33}, {0xB35, 0xB39}, + {0xB3D, 0xB3D}, {0xB5C, 0xB5D}, {0xB5F, 0xB61}, {0xB71, 0xB71}, + {0xB83, 0xB83}, {0xB85, 0xB8A}, {0xB8E, 0xB90}, {0xB92, 0xB95}, + {0xB99, 0xB9A}, {0xB9C, 0xB9C}, {0xB9E, 0xB9F}, {0xBA3, 0xBA4}, + {0xBA8, 0xBAA}, {0xBAE, 0xBB9}, {0xBD0, 0xBD0}, {0xC05, 0xC0C}, + {0xC0E, 0xC10}, {0xC12, 0xC28}, {0xC2A, 0xC39}, {0xC3D, 0xC3D}, + {0xC58, 0xC5A}, {0xC5C, 0xC5D}, {0xC60, 0xC61}, {0xC80, 0xC80}, + {0xC85, 0xC8C}, {0xC8E, 0xC90}, {0xC92, 0xCA8}, {0xCAA, 0xCB3}, + {0xCB5, 0xCB9}, {0xCBD, 0xCBD}, {0xCDC, 0xCDE}, {0xCE0, 0xCE1}, + {0xCF1, 0xCF2}, {0xD04, 0xD0C}, {0xD0E, 0xD10}, {0xD12, 0xD3A}, + {0xD3D, 0xD3D}, {0xD4E, 0xD4E}, {0xD54, 0xD56}, {0xD5F, 0xD61}, + {0xD7A, 0xD7F}, {0xD85, 0xD96}, {0xD9A, 0xDB1}, {0xDB3, 0xDBB}, + {0xDBD, 0xDBD}, {0xDC0, 0xDC6}, {0xE01, 0xE30}, {0xE32, 0xE32}, + {0xE40, 0xE46}, {0xE81, 0xE82}, {0xE84, 0xE84}, {0xE86, 0xE8A}, + {0xE8C, 0xEA3}, {0xEA5, 0xEA5}, {0xEA7, 0xEB0}, {0xEB2, 0xEB2}, + {0xEBD, 0xEBD}, {0xEC0, 0xEC4}, {0xEC6, 0xEC6}, {0xEDC, 0xEDF}, + {0xF00, 0xF00}, {0xF40, 0xF47}, {0xF49, 0xF6C}, {0xF88, 0xF8C}, + {0x1000, 0x102A}, {0x103F, 0x103F}, {0x1050, 0x1055}, {0x105A, 0x105D}, + {0x1061, 0x1061}, {0x1065, 0x1066}, {0x106E, 0x1070}, {0x1075, 0x1081}, + {0x108E, 0x108E}, {0x10A0, 0x10C5}, {0x10C7, 0x10C7}, {0x10CD, 0x10CD}, + {0x10D0, 0x10FA}, {0x10FC, 0x1248}, {0x124A, 0x124D}, {0x1250, 0x1256}, + {0x1258, 0x1258}, {0x125A, 0x125D}, {0x1260, 0x1288}, {0x128A, 0x128D}, + {0x1290, 0x12B0}, {0x12B2, 0x12B5}, {0x12B8, 0x12BE}, {0x12C0, 0x12C0}, + {0x12C2, 0x12C5}, {0x12C8, 0x12D6}, {0x12D8, 0x1310}, {0x1312, 0x1315}, + {0x1318, 0x135A}, {0x1380, 0x138F}, {0x13A0, 0x13F5}, {0x13F8, 0x13FD}, + {0x1401, 0x166C}, {0x166F, 0x167F}, {0x1681, 0x169A}, {0x16A0, 0x16EA}, + {0x16EE, 0x16F8}, {0x1700, 0x1711}, {0x171F, 0x1731}, {0x1740, 0x1751}, + {0x1760, 0x176C}, {0x176E, 0x1770}, {0x1780, 0x17B3}, {0x17D7, 0x17D7}, + {0x17DC, 0x17DC}, {0x1820, 0x1878}, {0x1880, 0x18A8}, {0x18AA, 0x18AA}, + {0x18B0, 0x18F5}, {0x1900, 0x191E}, {0x1950, 0x196D}, {0x1970, 0x1974}, + {0x1980, 0x19AB}, {0x19B0, 0x19C9}, {0x1A00, 0x1A16}, {0x1A20, 0x1A54}, + {0x1AA7, 0x1AA7}, {0x1B05, 0x1B33}, {0x1B45, 0x1B4C}, {0x1B83, 0x1BA0}, + {0x1BAE, 0x1BAF}, {0x1BBA, 0x1BE5}, {0x1C00, 0x1C23}, {0x1C4D, 0x1C4F}, + {0x1C5A, 0x1C7D}, {0x1C80, 0x1C8A}, {0x1C90, 0x1CBA}, {0x1CBD, 0x1CBF}, + {0x1CE9, 0x1CEC}, {0x1CEE, 0x1CF3}, {0x1CF5, 0x1CF6}, {0x1CFA, 0x1CFA}, + {0x1D00, 0x1DBF}, {0x1E00, 0x1F15}, {0x1F18, 0x1F1D}, {0x1F20, 0x1F45}, + {0x1F48, 0x1F4D}, {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, {0x1F5B, 0x1F5B}, + {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4}, {0x1FB6, 0x1FBC}, + {0x1FBE, 0x1FBE}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, {0x1FD0, 0x1FD3}, + {0x1FD6, 0x1FDB}, {0x1FE0, 0x1FEC}, {0x1FF2, 0x1FF4}, {0x1FF6, 0x1FFC}, + {0x2071, 0x2071}, {0x207F, 0x207F}, {0x208F, 0x209F}, {0x2102, 0x2102}, + {0x2107, 0x2107}, {0x210A, 0x2113}, {0x2115, 0x2115}, {0x2118, 0x211D}, + {0x2124, 0x2124}, {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212A, 0x2139}, + {0x213C, 0x213F}, {0x2145, 0x2149}, {0x214E, 0x214E}, {0x2160, 0x2188}, + {0x2C00, 0x2CE4}, {0x2CEB, 0x2CEE}, {0x2CF2, 0x2CF3}, {0x2D00, 0x2D25}, + {0x2D27, 0x2D27}, {0x2D2D, 0x2D2D}, {0x2D30, 0x2D67}, {0x2D6F, 0x2D6F}, + {0x2D80, 0x2D96}, {0x2DA0, 0x2DA6}, {0x2DA8, 0x2DAE}, {0x2DB0, 0x2DB6}, + {0x2DB8, 0x2DBE}, {0x2DC0, 0x2DC6}, {0x2DC8, 0x2DCE}, {0x2DD0, 0x2DD6}, + {0x2DD8, 0x2DDE}, {0x3005, 0x3007}, {0x3021, 0x3029}, {0x3031, 0x3035}, + {0x3038, 0x303C}, {0x3041, 0x3096}, {0x309D, 0x309F}, {0x30A1, 0x30FA}, + {0x30FC, 0x30FF}, {0x3105, 0x312F}, {0x3131, 0x318E}, {0x31A0, 0x31BF}, + {0x31F0, 0x31FF}, {0x3400, 0x4DBF}, {0x4E00, 0xA48C}, {0xA4D0, 0xA4FD}, + {0xA500, 0xA60C}, {0xA610, 0xA61F}, {0xA62A, 0xA62B}, {0xA640, 0xA66E}, + {0xA67F, 0xA69D}, {0xA6A0, 0xA6EF}, {0xA717, 0xA71F}, {0xA722, 0xA788}, + {0xA78B, 0xA7DD}, {0xA7E2, 0xA7E2}, {0xA7F1, 0xA801}, {0xA803, 0xA805}, + {0xA807, 0xA80A}, {0xA80C, 0xA822}, {0xA840, 0xA873}, {0xA882, 0xA8B3}, + {0xA8F2, 0xA8F7}, {0xA8FB, 0xA8FB}, {0xA8FD, 0xA8FE}, {0xA90A, 0xA925}, + {0xA930, 0xA946}, {0xA960, 0xA97C}, {0xA984, 0xA9B2}, {0xA9CF, 0xA9CF}, + {0xA9E0, 0xA9E4}, {0xA9E6, 0xA9EF}, {0xA9FA, 0xA9FE}, {0xAA00, 0xAA28}, + {0xAA40, 0xAA42}, {0xAA44, 0xAA4B}, {0xAA60, 0xAA76}, {0xAA7A, 0xAA7A}, + {0xAA7E, 0xAAAF}, {0xAAB1, 0xAAB1}, {0xAAB5, 0xAAB6}, {0xAAB9, 0xAABD}, + {0xAAC0, 0xAAC0}, {0xAAC2, 0xAAC2}, {0xAADB, 0xAADD}, {0xAAE0, 0xAAEA}, + {0xAAF2, 0xAAF4}, {0xAB01, 0xAB06}, {0xAB09, 0xAB0E}, {0xAB11, 0xAB16}, + {0xAB20, 0xAB26}, {0xAB28, 0xAB2E}, {0xAB30, 0xAB5A}, {0xAB5C, 0xAB69}, + {0xAB6C, 0xAB6D}, {0xAB70, 0xABE2}, {0xAC00, 0xD7A3}, {0xD7B0, 0xD7C6}, + {0xD7CB, 0xD7FB}, {0xF900, 0xFA6D}, {0xFA70, 0xFAD9}, {0xFB00, 0xFB06}, + {0xFB13, 0xFB17}, {0xFB1D, 0xFB1D}, {0xFB1F, 0xFB28}, {0xFB2A, 0xFB36}, + {0xFB38, 0xFB3C}, {0xFB3E, 0xFB3E}, {0xFB40, 0xFB41}, {0xFB43, 0xFB44}, + {0xFB46, 0xFBB1}, {0xFBD3, 0xFC5D}, {0xFC64, 0xFD3D}, {0xFD50, 0xFD8F}, + {0xFD92, 0xFDC7}, {0xFDF0, 0xFDF9}, {0xFE71, 0xFE71}, {0xFE73, 0xFE73}, + {0xFE77, 0xFE77}, {0xFE79, 0xFE79}, {0xFE7B, 0xFE7B}, {0xFE7D, 0xFE7D}, + {0xFE7F, 0xFEFC}, {0xFF21, 0xFF3A}, {0xFF41, 0xFF5A}, {0xFF66, 0xFF9D}, + {0xFFA0, 0xFFBE}, {0xFFC2, 0xFFC7}, {0xFFCA, 0xFFCF}, {0xFFD2, 0xFFD7}, + {0xFFDA, 0xFFDC}, {0x10000, 0x1000B}, {0x1000D, 0x10026}, {0x10028, 0x1003A}, + {0x1003C, 0x1003D}, {0x1003F, 0x1004D}, {0x10050, 0x1005D}, {0x10080, 0x100FA}, + {0x10140, 0x10174}, {0x10280, 0x1029C}, {0x102A0, 0x102D0}, {0x10300, 0x1031F}, + {0x1032D, 0x1034A}, {0x10350, 0x10375}, {0x10380, 0x1039D}, {0x103A0, 0x103C3}, + {0x103C8, 0x103CF}, {0x103D1, 0x103D5}, {0x10400, 0x1049D}, {0x104B0, 0x104D3}, + {0x104D8, 0x104FB}, {0x10500, 0x10527}, {0x10530, 0x10563}, {0x10570, 0x1057A}, + {0x1057C, 0x1058A}, {0x1058C, 0x10592}, {0x10594, 0x10595}, {0x10597, 0x105A1}, + {0x105A3, 0x105B1}, {0x105B3, 0x105B9}, {0x105BB, 0x105BC}, {0x105C0, 0x105F3}, + {0x10600, 0x10736}, {0x10740, 0x10755}, {0x10760, 0x10767}, {0x10780, 0x10785}, + {0x10787, 0x107B0}, {0x107B2, 0x107BF}, {0x10800, 0x10805}, {0x10808, 0x10808}, + {0x1080A, 0x10835}, {0x10837, 0x10838}, {0x1083C, 0x1083C}, {0x1083F, 0x10855}, + {0x10860, 0x10876}, {0x10880, 0x1089E}, {0x108E0, 0x108F2}, {0x108F4, 0x108F5}, + {0x10900, 0x10915}, {0x10920, 0x10939}, {0x10940, 0x10959}, {0x10980, 0x109B7}, + {0x109BE, 0x109BF}, {0x10A00, 0x10A00}, {0x10A10, 0x10A13}, {0x10A15, 0x10A17}, + {0x10A19, 0x10A35}, {0x10A60, 0x10A7C}, {0x10A80, 0x10A9C}, {0x10AC0, 0x10AC7}, + {0x10AC9, 0x10AE4}, {0x10B00, 0x10B35}, {0x10B40, 0x10B55}, {0x10B60, 0x10B72}, + {0x10B80, 0x10B91}, {0x10C00, 0x10C48}, {0x10C80, 0x10CB2}, {0x10CC0, 0x10CF2}, + {0x10D00, 0x10D23}, {0x10D4A, 0x10D65}, {0x10D6F, 0x10D85}, {0x10E80, 0x10EA9}, + {0x10EB0, 0x10EB1}, {0x10EC2, 0x10EC7}, {0x10ED9, 0x10EEE}, {0x10F00, 0x10F1C}, + {0x10F27, 0x10F27}, {0x10F30, 0x10F45}, {0x10F70, 0x10F81}, {0x10FB0, 0x10FC4}, + {0x10FE0, 0x10FF6}, {0x11003, 0x11037}, {0x11071, 0x11072}, {0x11075, 0x11075}, + {0x11083, 0x110AF}, {0x110D0, 0x110E8}, {0x11103, 0x11126}, {0x11144, 0x11144}, + {0x11147, 0x11147}, {0x11150, 0x11172}, {0x11176, 0x11176}, {0x11183, 0x111B2}, + {0x111C1, 0x111C4}, {0x111DA, 0x111DA}, {0x111DC, 0x111DC}, {0x11200, 0x11211}, + {0x11213, 0x1122B}, {0x1123F, 0x11240}, {0x11280, 0x11286}, {0x11288, 0x11288}, + {0x1128A, 0x1128D}, {0x1128F, 0x1129D}, {0x1129F, 0x112A8}, {0x112B0, 0x112DE}, + {0x11305, 0x1130C}, {0x1130F, 0x11310}, {0x11313, 0x11328}, {0x1132A, 0x11330}, + {0x11332, 0x11333}, {0x11335, 0x11339}, {0x1133D, 0x1133D}, {0x11350, 0x11350}, + {0x1135D, 0x11361}, {0x11380, 0x11389}, {0x1138B, 0x1138B}, {0x1138E, 0x1138E}, + {0x11390, 0x113B5}, {0x113B7, 0x113B7}, {0x113D1, 0x113D1}, {0x113D3, 0x113D3}, + {0x11400, 0x11434}, {0x11447, 0x1144A}, {0x1145F, 0x11461}, {0x11480, 0x114AF}, + {0x114C4, 0x114C5}, {0x114C7, 0x114C7}, {0x11580, 0x115AE}, {0x115D8, 0x115DB}, + {0x11600, 0x1162F}, {0x11644, 0x11644}, {0x11680, 0x116AA}, {0x116B8, 0x116B8}, + {0x11700, 0x1171A}, {0x11740, 0x11746}, {0x11800, 0x1182B}, {0x118A0, 0x118DF}, + {0x118FF, 0x11906}, {0x11909, 0x11909}, {0x1190C, 0x11913}, {0x11915, 0x11916}, + {0x11918, 0x1192F}, {0x1193F, 0x1193F}, {0x11941, 0x11941}, {0x119A0, 0x119A7}, + {0x119AA, 0x119D0}, {0x119E1, 0x119E1}, {0x119E3, 0x119E3}, {0x11A00, 0x11A00}, + {0x11A0B, 0x11A32}, {0x11A3A, 0x11A3A}, {0x11A50, 0x11A50}, {0x11A5C, 0x11A89}, + {0x11A9D, 0x11A9D}, {0x11AB0, 0x11AF8}, {0x11B0A, 0x11B0A}, {0x11BC0, 0x11BE0}, + {0x11C00, 0x11C08}, {0x11C0A, 0x11C2E}, {0x11C40, 0x11C40}, {0x11C72, 0x11C8F}, + {0x11D00, 0x11D06}, {0x11D08, 0x11D09}, {0x11D0B, 0x11D30}, {0x11D46, 0x11D46}, + {0x11D60, 0x11D65}, {0x11D67, 0x11D68}, {0x11D6A, 0x11D89}, {0x11D98, 0x11D98}, + {0x11DB0, 0x11DDB}, {0x11DF1, 0x11DF1}, {0x11EE0, 0x11EF2}, {0x11F02, 0x11F02}, + {0x11F04, 0x11F10}, {0x11F12, 0x11F33}, {0x11FB0, 0x11FB0}, {0x12000, 0x12399}, + {0x12400, 0x1246F}, {0x12475, 0x12543}, {0x12550, 0x12686}, {0x12F90, 0x12FF0}, + {0x13000, 0x1342F}, {0x13441, 0x13446}, {0x13460, 0x143FA}, {0x14400, 0x14646}, + {0x16100, 0x1611D}, {0x16800, 0x16A38}, {0x16A40, 0x16A5E}, {0x16A70, 0x16ABE}, + {0x16AD0, 0x16AED}, {0x16B00, 0x16B2F}, {0x16B40, 0x16B43}, {0x16B63, 0x16B77}, + {0x16B7D, 0x16B8F}, {0x16D40, 0x16D6C}, {0x16E40, 0x16E7F}, {0x16EA0, 0x16EB8}, + {0x16EBB, 0x16ED3}, {0x16F00, 0x16F4A}, {0x16F50, 0x16F50}, {0x16F93, 0x16F9F}, + {0x16FE0, 0x16FE1}, {0x16FE3, 0x16FE3}, {0x16FF2, 0x16FF6}, {0x17000, 0x18CDA}, + {0x18CFF, 0x18D20}, {0x18D80, 0x18DF2}, {0x18E00, 0x19191}, {0x191A0, 0x191D2}, + {0x1AFF0, 0x1AFF3}, {0x1AFF5, 0x1AFFB}, {0x1AFFD, 0x1AFFE}, {0x1B000, 0x1B128}, + {0x1B132, 0x1B132}, {0x1B150, 0x1B152}, {0x1B155, 0x1B155}, {0x1B164, 0x1B168}, + {0x1B170, 0x1B2FB}, {0x1BC00, 0x1BC6A}, {0x1BC70, 0x1BC7C}, {0x1BC80, 0x1BC88}, + {0x1BC90, 0x1BC99}, {0x1D400, 0x1D454}, {0x1D456, 0x1D49C}, {0x1D49E, 0x1D49F}, + {0x1D4A2, 0x1D4A2}, {0x1D4A5, 0x1D4A6}, {0x1D4A9, 0x1D4AC}, {0x1D4AE, 0x1D4B9}, + {0x1D4BB, 0x1D4BB}, {0x1D4BD, 0x1D4C3}, {0x1D4C5, 0x1D505}, {0x1D507, 0x1D50A}, + {0x1D50D, 0x1D514}, {0x1D516, 0x1D51C}, {0x1D51E, 0x1D539}, {0x1D53B, 0x1D53E}, + {0x1D540, 0x1D544}, {0x1D546, 0x1D546}, {0x1D54A, 0x1D550}, {0x1D552, 0x1D6A6}, + {0x1D6A8, 0x1D6C0}, {0x1D6C2, 0x1D6DA}, {0x1D6DC, 0x1D6FA}, {0x1D6FC, 0x1D714}, + {0x1D716, 0x1D734}, {0x1D736, 0x1D74E}, {0x1D750, 0x1D76E}, {0x1D770, 0x1D788}, + {0x1D78A, 0x1D7A8}, {0x1D7AA, 0x1D7C2}, {0x1D7C4, 0x1D7CB}, {0x1DF00, 0x1DF81}, + {0x1DF90, 0x1DF96}, {0x1DFCD, 0x1DFFF}, {0x1E030, 0x1E06D}, {0x1E100, 0x1E12C}, + {0x1E137, 0x1E13D}, {0x1E14E, 0x1E14E}, {0x1E290, 0x1E2AD}, {0x1E2C0, 0x1E2EB}, + {0x1E4D0, 0x1E4EB}, {0x1E5D0, 0x1E5ED}, {0x1E5F0, 0x1E5F0}, {0x1E6C0, 0x1E6DE}, + {0x1E6E0, 0x1E6E2}, {0x1E6E4, 0x1E6E5}, {0x1E6E7, 0x1E6ED}, {0x1E6F0, 0x1E6F4}, + {0x1E6FE, 0x1E6FF}, {0x1E7E0, 0x1E7E6}, {0x1E7E8, 0x1E7EB}, {0x1E7ED, 0x1E7EE}, + {0x1E7F0, 0x1E7FE}, {0x1E800, 0x1E8C4}, {0x1E900, 0x1E943}, {0x1E94B, 0x1E94B}, + {0x1EE00, 0x1EE03}, {0x1EE05, 0x1EE1F}, {0x1EE21, 0x1EE22}, {0x1EE24, 0x1EE24}, + {0x1EE27, 0x1EE27}, {0x1EE29, 0x1EE32}, {0x1EE34, 0x1EE37}, {0x1EE39, 0x1EE39}, + {0x1EE3B, 0x1EE3B}, {0x1EE42, 0x1EE42}, {0x1EE47, 0x1EE47}, {0x1EE49, 0x1EE49}, + {0x1EE4B, 0x1EE4B}, {0x1EE4D, 0x1EE4F}, {0x1EE51, 0x1EE52}, {0x1EE54, 0x1EE54}, + {0x1EE57, 0x1EE57}, {0x1EE59, 0x1EE59}, {0x1EE5B, 0x1EE5B}, {0x1EE5D, 0x1EE5D}, + {0x1EE5F, 0x1EE5F}, {0x1EE61, 0x1EE62}, {0x1EE64, 0x1EE64}, {0x1EE67, 0x1EE6A}, + {0x1EE6C, 0x1EE72}, {0x1EE74, 0x1EE77}, {0x1EE79, 0x1EE7C}, {0x1EE7E, 0x1EE7E}, + {0x1EE80, 0x1EE89}, {0x1EE8B, 0x1EE9B}, {0x1EEA1, 0x1EEA3}, {0x1EEA5, 0x1EEA9}, + {0x1EEAB, 0x1EEBB}, {0x20000, 0x2A6DF}, {0x2A700, 0x2B81E}, {0x2B820, 0x2CEAD}, + {0x2CEB0, 0x2EBE0}, {0x2EBF0, 0x2EE5D}, {0x2F800, 0x2FA1D}, {0x30000, 0x3134A}, + {0x31350, 0x33479}, {0x3D000, 0x3FC3F}, +}}; +/// Stores Unicode 18 XID_Continue intervals in ascending order. +constexpr std::array xid_continue{{ + {0x30, 0x39}, {0x41, 0x5A}, {0x5F, 0x5F}, {0x61, 0x7A}, + {0xAA, 0xAA}, {0xB5, 0xB5}, {0xB7, 0xB7}, {0xBA, 0xBA}, + {0xC0, 0xD6}, {0xD8, 0xF6}, {0xF8, 0x2C1}, {0x2C6, 0x2D1}, + {0x2E0, 0x2E4}, {0x2EC, 0x2EC}, {0x2EE, 0x2EE}, {0x300, 0x374}, + {0x376, 0x377}, {0x37B, 0x37D}, {0x37F, 0x37F}, {0x386, 0x38A}, + {0x38C, 0x38C}, {0x38E, 0x3A1}, {0x3A3, 0x3F5}, {0x3F7, 0x481}, + {0x483, 0x487}, {0x48A, 0x52F}, {0x531, 0x556}, {0x558, 0x559}, + {0x560, 0x588}, {0x58B, 0x58C}, {0x591, 0x5BD}, {0x5BF, 0x5BF}, + {0x5C1, 0x5C2}, {0x5C4, 0x5C5}, {0x5C7, 0x5C9}, {0x5D0, 0x5EA}, + {0x5EF, 0x5F2}, {0x610, 0x61A}, {0x620, 0x669}, {0x66E, 0x6D3}, + {0x6D5, 0x6DC}, {0x6DF, 0x6E8}, {0x6EA, 0x6FC}, {0x6FF, 0x6FF}, + {0x710, 0x74A}, {0x74D, 0x7B1}, {0x7C0, 0x7F5}, {0x7FA, 0x7FA}, + {0x7FD, 0x7FD}, {0x800, 0x82D}, {0x840, 0x85B}, {0x860, 0x86A}, + {0x870, 0x887}, {0x889, 0x88F}, {0x897, 0x8E1}, {0x8E3, 0x963}, + {0x966, 0x96F}, {0x971, 0x983}, {0x985, 0x98C}, {0x98F, 0x990}, + {0x993, 0x9A8}, {0x9AA, 0x9B0}, {0x9B2, 0x9B2}, {0x9B6, 0x9B9}, + {0x9BC, 0x9C4}, {0x9C7, 0x9C8}, {0x9CB, 0x9CE}, {0x9D7, 0x9D7}, + {0x9DC, 0x9DD}, {0x9DF, 0x9E3}, {0x9E6, 0x9F1}, {0x9FC, 0x9FC}, + {0x9FE, 0x9FE}, {0xA01, 0xA03}, {0xA05, 0xA0A}, {0xA0F, 0xA10}, + {0xA13, 0xA28}, {0xA2A, 0xA30}, {0xA32, 0xA33}, {0xA35, 0xA36}, + {0xA38, 0xA39}, {0xA3C, 0xA3C}, {0xA3E, 0xA42}, {0xA47, 0xA48}, + {0xA4B, 0xA4D}, {0xA51, 0xA51}, {0xA59, 0xA5C}, {0xA5E, 0xA5E}, + {0xA66, 0xA75}, {0xA81, 0xA83}, {0xA85, 0xA8D}, {0xA8F, 0xA91}, + {0xA93, 0xAA8}, {0xAAA, 0xAB0}, {0xAB2, 0xAB3}, {0xAB5, 0xAB9}, + {0xABC, 0xAC5}, {0xAC7, 0xAC9}, {0xACB, 0xACD}, {0xAD0, 0xAD0}, + {0xAE0, 0xAE3}, {0xAE6, 0xAEF}, {0xAF9, 0xAFF}, {0xB01, 0xB03}, + {0xB05, 0xB0C}, {0xB0F, 0xB10}, {0xB13, 0xB28}, {0xB2A, 0xB30}, + {0xB32, 0xB33}, {0xB35, 0xB39}, {0xB3C, 0xB44}, {0xB47, 0xB48}, + {0xB4B, 0xB4D}, {0xB53, 0xB57}, {0xB5C, 0xB5D}, {0xB5F, 0xB63}, + {0xB66, 0xB6F}, {0xB71, 0xB71}, {0xB82, 0xB83}, {0xB85, 0xB8A}, + {0xB8E, 0xB90}, {0xB92, 0xB95}, {0xB99, 0xB9A}, {0xB9C, 0xB9C}, + {0xB9E, 0xB9F}, {0xBA3, 0xBA4}, {0xBA8, 0xBAA}, {0xBAE, 0xBB9}, + {0xBBE, 0xBC2}, {0xBC6, 0xBC8}, {0xBCA, 0xBCD}, {0xBD0, 0xBD0}, + {0xBD7, 0xBD7}, {0xBE6, 0xBEF}, {0xC00, 0xC0C}, {0xC0E, 0xC10}, + {0xC12, 0xC28}, {0xC2A, 0xC39}, {0xC3C, 0xC44}, {0xC46, 0xC48}, + {0xC4A, 0xC4D}, {0xC55, 0xC56}, {0xC58, 0xC5A}, {0xC5C, 0xC5D}, + {0xC60, 0xC63}, {0xC66, 0xC6F}, {0xC80, 0xC83}, {0xC85, 0xC8C}, + {0xC8E, 0xC90}, {0xC92, 0xCA8}, {0xCAA, 0xCB3}, {0xCB5, 0xCB9}, + {0xCBC, 0xCC4}, {0xCC6, 0xCC8}, {0xCCA, 0xCCD}, {0xCD5, 0xCD6}, + {0xCDC, 0xCDE}, {0xCE0, 0xCE3}, {0xCE6, 0xCEF}, {0xCF1, 0xCF3}, + {0xD00, 0xD0C}, {0xD0E, 0xD10}, {0xD12, 0xD44}, {0xD46, 0xD48}, + {0xD4A, 0xD4E}, {0xD54, 0xD57}, {0xD5F, 0xD63}, {0xD66, 0xD6F}, + {0xD7A, 0xD7F}, {0xD81, 0xD83}, {0xD85, 0xD96}, {0xD9A, 0xDB1}, + {0xDB3, 0xDBB}, {0xDBD, 0xDBD}, {0xDC0, 0xDC6}, {0xDCA, 0xDCA}, + {0xDCF, 0xDD4}, {0xDD6, 0xDD6}, {0xDD8, 0xDDF}, {0xDE6, 0xDEF}, + {0xDF2, 0xDF3}, {0xE01, 0xE3A}, {0xE40, 0xE4E}, {0xE50, 0xE59}, + {0xE81, 0xE82}, {0xE84, 0xE84}, {0xE86, 0xE8A}, {0xE8C, 0xEA3}, + {0xEA5, 0xEA5}, {0xEA7, 0xEBD}, {0xEC0, 0xEC4}, {0xEC6, 0xEC6}, + {0xEC8, 0xECE}, {0xED0, 0xED9}, {0xEDC, 0xEDF}, {0xF00, 0xF00}, + {0xF18, 0xF19}, {0xF20, 0xF29}, {0xF35, 0xF35}, {0xF37, 0xF37}, + {0xF39, 0xF39}, {0xF3E, 0xF47}, {0xF49, 0xF6C}, {0xF71, 0xF84}, + {0xF86, 0xF97}, {0xF99, 0xFBC}, {0xFC6, 0xFC6}, {0x1000, 0x1049}, + {0x1050, 0x109D}, {0x10A0, 0x10C5}, {0x10C7, 0x10C7}, {0x10CD, 0x10CD}, + {0x10D0, 0x10FA}, {0x10FC, 0x1248}, {0x124A, 0x124D}, {0x1250, 0x1256}, + {0x1258, 0x1258}, {0x125A, 0x125D}, {0x1260, 0x1288}, {0x128A, 0x128D}, + {0x1290, 0x12B0}, {0x12B2, 0x12B5}, {0x12B8, 0x12BE}, {0x12C0, 0x12C0}, + {0x12C2, 0x12C5}, {0x12C8, 0x12D6}, {0x12D8, 0x1310}, {0x1312, 0x1315}, + {0x1318, 0x135A}, {0x135D, 0x135F}, {0x1369, 0x1371}, {0x1380, 0x138F}, + {0x13A0, 0x13F5}, {0x13F8, 0x13FD}, {0x1401, 0x166C}, {0x166F, 0x167F}, + {0x1681, 0x169A}, {0x16A0, 0x16EA}, {0x16EE, 0x16F8}, {0x1700, 0x1715}, + {0x171F, 0x1734}, {0x1740, 0x1753}, {0x1760, 0x176C}, {0x176E, 0x1770}, + {0x1772, 0x1773}, {0x1780, 0x17D3}, {0x17D7, 0x17D7}, {0x17DC, 0x17DD}, + {0x17E0, 0x17E9}, {0x180B, 0x180D}, {0x180F, 0x1819}, {0x1820, 0x1878}, + {0x1880, 0x18AA}, {0x18B0, 0x18F5}, {0x1900, 0x191E}, {0x1920, 0x192B}, + {0x1930, 0x193B}, {0x1946, 0x196D}, {0x1970, 0x1974}, {0x1980, 0x19AB}, + {0x19B0, 0x19C9}, {0x19D0, 0x19DA}, {0x1A00, 0x1A1B}, {0x1A20, 0x1A5E}, + {0x1A60, 0x1A7C}, {0x1A7F, 0x1A89}, {0x1A90, 0x1A99}, {0x1AA7, 0x1AA7}, + {0x1AB0, 0x1ABD}, {0x1ABF, 0x1AF0}, {0x1B00, 0x1B4C}, {0x1B50, 0x1B59}, + {0x1B6B, 0x1B73}, {0x1B80, 0x1BF3}, {0x1C00, 0x1C37}, {0x1C40, 0x1C49}, + {0x1C4D, 0x1C7D}, {0x1C80, 0x1C8A}, {0x1C90, 0x1CBA}, {0x1CBD, 0x1CBF}, + {0x1CD0, 0x1CD2}, {0x1CD4, 0x1CFA}, {0x1D00, 0x1F15}, {0x1F18, 0x1F1D}, + {0x1F20, 0x1F45}, {0x1F48, 0x1F4D}, {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, + {0x1F5B, 0x1F5B}, {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4}, + {0x1FB6, 0x1FBC}, {0x1FBE, 0x1FBE}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, + {0x1FD0, 0x1FD3}, {0x1FD6, 0x1FDB}, {0x1FE0, 0x1FEC}, {0x1FF2, 0x1FF4}, + {0x1FF6, 0x1FFC}, {0x200C, 0x200D}, {0x203F, 0x2040}, {0x2054, 0x2054}, + {0x2071, 0x2071}, {0x207F, 0x207F}, {0x208F, 0x209F}, {0x20D0, 0x20DC}, + {0x20E1, 0x20E1}, {0x20E5, 0x20F0}, {0x2102, 0x2102}, {0x2107, 0x2107}, + {0x210A, 0x2113}, {0x2115, 0x2115}, {0x2118, 0x211D}, {0x2124, 0x2124}, + {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212A, 0x2139}, {0x213C, 0x213F}, + {0x2145, 0x2149}, {0x214E, 0x214E}, {0x2160, 0x2188}, {0x2C00, 0x2CE4}, + {0x2CEB, 0x2CF3}, {0x2D00, 0x2D25}, {0x2D27, 0x2D27}, {0x2D2D, 0x2D2D}, + {0x2D30, 0x2D67}, {0x2D6F, 0x2D6F}, {0x2D7F, 0x2D96}, {0x2DA0, 0x2DA6}, + {0x2DA8, 0x2DAE}, {0x2DB0, 0x2DB6}, {0x2DB8, 0x2DBE}, {0x2DC0, 0x2DC6}, + {0x2DC8, 0x2DCE}, {0x2DD0, 0x2DD6}, {0x2DD8, 0x2DDE}, {0x2DE0, 0x2DFF}, + {0x3005, 0x3007}, {0x3021, 0x302F}, {0x3031, 0x3035}, {0x3038, 0x303C}, + {0x3041, 0x3096}, {0x3099, 0x309A}, {0x309D, 0x309F}, {0x30A1, 0x30FF}, + {0x3105, 0x312F}, {0x3131, 0x318E}, {0x31A0, 0x31BF}, {0x31F0, 0x31FF}, + {0x3400, 0x4DBF}, {0x4E00, 0xA48C}, {0xA4D0, 0xA4FD}, {0xA500, 0xA60C}, + {0xA610, 0xA62B}, {0xA640, 0xA66F}, {0xA674, 0xA67D}, {0xA67F, 0xA6F1}, + {0xA717, 0xA71F}, {0xA722, 0xA788}, {0xA78B, 0xA7DD}, {0xA7E2, 0xA7E2}, + {0xA7F1, 0xA827}, {0xA82C, 0xA82C}, {0xA840, 0xA873}, {0xA880, 0xA8C5}, + {0xA8D0, 0xA8D9}, {0xA8E0, 0xA8F7}, {0xA8FB, 0xA8FB}, {0xA8FD, 0xA92D}, + {0xA930, 0xA953}, {0xA960, 0xA97C}, {0xA980, 0xA9C0}, {0xA9CF, 0xA9D9}, + {0xA9E0, 0xA9FE}, {0xAA00, 0xAA36}, {0xAA40, 0xAA4D}, {0xAA50, 0xAA59}, + {0xAA60, 0xAA76}, {0xAA7A, 0xAAC2}, {0xAADB, 0xAADD}, {0xAAE0, 0xAAEF}, + {0xAAF2, 0xAAF6}, {0xAB01, 0xAB06}, {0xAB09, 0xAB0E}, {0xAB11, 0xAB16}, + {0xAB20, 0xAB26}, {0xAB28, 0xAB2E}, {0xAB30, 0xAB5A}, {0xAB5C, 0xAB69}, + {0xAB6C, 0xAB6D}, {0xAB70, 0xABEA}, {0xABEC, 0xABED}, {0xABF0, 0xABF9}, + {0xAC00, 0xD7A3}, {0xD7B0, 0xD7C6}, {0xD7CB, 0xD7FB}, {0xF900, 0xFA6D}, + {0xFA70, 0xFAD9}, {0xFB00, 0xFB06}, {0xFB13, 0xFB17}, {0xFB1D, 0xFB28}, + {0xFB2A, 0xFB36}, {0xFB38, 0xFB3C}, {0xFB3E, 0xFB3E}, {0xFB40, 0xFB41}, + {0xFB43, 0xFB44}, {0xFB46, 0xFBB1}, {0xFBD3, 0xFC5D}, {0xFC64, 0xFD3D}, + {0xFD50, 0xFD8F}, {0xFD92, 0xFDC7}, {0xFDF0, 0xFDF9}, {0xFE00, 0xFE0F}, + {0xFE20, 0xFE2F}, {0xFE33, 0xFE34}, {0xFE4D, 0xFE4F}, {0xFE71, 0xFE71}, + {0xFE73, 0xFE73}, {0xFE77, 0xFE77}, {0xFE79, 0xFE79}, {0xFE7B, 0xFE7B}, + {0xFE7D, 0xFE7D}, {0xFE7F, 0xFEFC}, {0xFF10, 0xFF19}, {0xFF21, 0xFF3A}, + {0xFF3F, 0xFF3F}, {0xFF41, 0xFF5A}, {0xFF65, 0xFFBE}, {0xFFC2, 0xFFC7}, + {0xFFCA, 0xFFCF}, {0xFFD2, 0xFFD7}, {0xFFDA, 0xFFDC}, {0x10000, 0x1000B}, + {0x1000D, 0x10026}, {0x10028, 0x1003A}, {0x1003C, 0x1003D}, {0x1003F, 0x1004D}, + {0x10050, 0x1005D}, {0x10080, 0x100FA}, {0x10140, 0x10174}, {0x101FD, 0x101FD}, + {0x10280, 0x1029C}, {0x102A0, 0x102D0}, {0x102E0, 0x102E0}, {0x10300, 0x1031F}, + {0x1032D, 0x1034A}, {0x10350, 0x1037A}, {0x10380, 0x1039D}, {0x103A0, 0x103C3}, + {0x103C8, 0x103CF}, {0x103D1, 0x103D5}, {0x10400, 0x1049D}, {0x104A0, 0x104A9}, + {0x104B0, 0x104D3}, {0x104D8, 0x104FB}, {0x10500, 0x10527}, {0x10530, 0x10563}, + {0x10570, 0x1057A}, {0x1057C, 0x1058A}, {0x1058C, 0x10592}, {0x10594, 0x10595}, + {0x10597, 0x105A1}, {0x105A3, 0x105B1}, {0x105B3, 0x105B9}, {0x105BB, 0x105BC}, + {0x105C0, 0x105F3}, {0x10600, 0x10736}, {0x10740, 0x10755}, {0x10760, 0x10767}, + {0x10780, 0x10785}, {0x10787, 0x107B0}, {0x107B2, 0x107BF}, {0x10800, 0x10805}, + {0x10808, 0x10808}, {0x1080A, 0x10835}, {0x10837, 0x10838}, {0x1083C, 0x1083C}, + {0x1083F, 0x10855}, {0x10860, 0x10876}, {0x10880, 0x1089E}, {0x108E0, 0x108F2}, + {0x108F4, 0x108F5}, {0x10900, 0x10915}, {0x10920, 0x10939}, {0x10940, 0x10959}, + {0x10980, 0x109B7}, {0x109BE, 0x109BF}, {0x10A00, 0x10A03}, {0x10A05, 0x10A06}, + {0x10A0C, 0x10A13}, {0x10A15, 0x10A17}, {0x10A19, 0x10A35}, {0x10A38, 0x10A3A}, + {0x10A3F, 0x10A3F}, {0x10A60, 0x10A7C}, {0x10A80, 0x10A9C}, {0x10AC0, 0x10AC7}, + {0x10AC9, 0x10AE6}, {0x10B00, 0x10B35}, {0x10B40, 0x10B55}, {0x10B60, 0x10B72}, + {0x10B80, 0x10B91}, {0x10C00, 0x10C48}, {0x10C80, 0x10CB2}, {0x10CC0, 0x10CF2}, + {0x10D00, 0x10D27}, {0x10D30, 0x10D39}, {0x10D40, 0x10D65}, {0x10D69, 0x10D6D}, + {0x10D6F, 0x10D85}, {0x10E80, 0x10EA9}, {0x10EAB, 0x10EAC}, {0x10EB0, 0x10EB1}, + {0x10EC2, 0x10EC7}, {0x10ECB, 0x10ECF}, {0x10ED9, 0x10EEE}, {0x10EF0, 0x10F1C}, + {0x10F27, 0x10F27}, {0x10F30, 0x10F50}, {0x10F70, 0x10F85}, {0x10FB0, 0x10FC4}, + {0x10FE0, 0x10FF6}, {0x11000, 0x11046}, {0x11066, 0x11075}, {0x1107F, 0x110BA}, + {0x110C2, 0x110C2}, {0x110D0, 0x110E8}, {0x110F0, 0x110F9}, {0x11100, 0x11134}, + {0x11136, 0x1113F}, {0x11144, 0x11147}, {0x11150, 0x11173}, {0x11176, 0x11176}, + {0x11180, 0x111C4}, {0x111C9, 0x111CC}, {0x111CE, 0x111DA}, {0x111DC, 0x111DC}, + {0x11200, 0x11211}, {0x11213, 0x11237}, {0x1123E, 0x11241}, {0x11280, 0x11286}, + {0x11288, 0x11288}, {0x1128A, 0x1128D}, {0x1128F, 0x1129D}, {0x1129F, 0x112A8}, + {0x112B0, 0x112EA}, {0x112F0, 0x112F9}, {0x11300, 0x11303}, {0x11305, 0x1130C}, + {0x1130F, 0x11310}, {0x11313, 0x11328}, {0x1132A, 0x11330}, {0x11332, 0x11333}, + {0x11335, 0x11339}, {0x1133B, 0x11344}, {0x11347, 0x11348}, {0x1134B, 0x1134D}, + {0x11350, 0x11350}, {0x11357, 0x11357}, {0x1135D, 0x11363}, {0x11366, 0x1136C}, + {0x11370, 0x11374}, {0x11380, 0x11389}, {0x1138B, 0x1138B}, {0x1138E, 0x1138E}, + {0x11390, 0x113B5}, {0x113B7, 0x113C0}, {0x113C2, 0x113C2}, {0x113C5, 0x113C5}, + {0x113C7, 0x113CA}, {0x113CC, 0x113D3}, {0x113E1, 0x113E2}, {0x11400, 0x1144A}, + {0x11450, 0x11459}, {0x1145E, 0x11461}, {0x11480, 0x114C5}, {0x114C7, 0x114C7}, + {0x114D0, 0x114D9}, {0x11580, 0x115B5}, {0x115B8, 0x115C0}, {0x115D8, 0x115DD}, + {0x11600, 0x11640}, {0x11644, 0x11644}, {0x11650, 0x11659}, {0x11680, 0x116B8}, + {0x116C0, 0x116C9}, {0x116D0, 0x116E3}, {0x11700, 0x1171A}, {0x1171D, 0x1172B}, + {0x11730, 0x11739}, {0x11740, 0x11746}, {0x11800, 0x1183A}, {0x118A0, 0x118E9}, + {0x118FF, 0x11906}, {0x11909, 0x11909}, {0x1190C, 0x11913}, {0x11915, 0x11916}, + {0x11918, 0x11935}, {0x11937, 0x11938}, {0x1193B, 0x11943}, {0x11950, 0x11959}, + {0x119A0, 0x119A7}, {0x119AA, 0x119D7}, {0x119DA, 0x119E1}, {0x119E3, 0x119E4}, + {0x11A00, 0x11A3E}, {0x11A47, 0x11A47}, {0x11A50, 0x11A99}, {0x11A9D, 0x11A9D}, + {0x11AB0, 0x11AF8}, {0x11B0A, 0x11B0A}, {0x11B60, 0x11B67}, {0x11BC0, 0x11BE0}, + {0x11BF0, 0x11BF9}, {0x11C00, 0x11C08}, {0x11C0A, 0x11C36}, {0x11C38, 0x11C40}, + {0x11C50, 0x11C59}, {0x11C72, 0x11C8F}, {0x11C92, 0x11CA7}, {0x11CA9, 0x11CB6}, + {0x11D00, 0x11D06}, {0x11D08, 0x11D09}, {0x11D0B, 0x11D36}, {0x11D3A, 0x11D3A}, + {0x11D3C, 0x11D3D}, {0x11D3F, 0x11D47}, {0x11D50, 0x11D59}, {0x11D60, 0x11D65}, + {0x11D67, 0x11D68}, {0x11D6A, 0x11D8E}, {0x11D90, 0x11D91}, {0x11D93, 0x11D98}, + {0x11DA0, 0x11DA9}, {0x11DB0, 0x11DDB}, {0x11DE0, 0x11DE9}, {0x11DF0, 0x11DF1}, + {0x11EE0, 0x11EF6}, {0x11F00, 0x11F10}, {0x11F12, 0x11F3A}, {0x11F3E, 0x11F42}, + {0x11F50, 0x11F5A}, {0x11FB0, 0x11FB0}, {0x12000, 0x12399}, {0x12400, 0x1246F}, + {0x12475, 0x12543}, {0x12550, 0x12686}, {0x12F90, 0x12FF0}, {0x13000, 0x1342F}, + {0x13440, 0x13455}, {0x13460, 0x143FA}, {0x14400, 0x14646}, {0x16100, 0x16139}, + {0x16800, 0x16A38}, {0x16A40, 0x16A5E}, {0x16A60, 0x16A69}, {0x16A70, 0x16ABE}, + {0x16AC0, 0x16AC9}, {0x16AD0, 0x16AED}, {0x16AF0, 0x16AF4}, {0x16B00, 0x16B36}, + {0x16B40, 0x16B43}, {0x16B50, 0x16B59}, {0x16B63, 0x16B77}, {0x16B7D, 0x16B8F}, + {0x16D40, 0x16D6C}, {0x16D70, 0x16D79}, {0x16E40, 0x16E7F}, {0x16EA0, 0x16EB8}, + {0x16EBB, 0x16ED3}, {0x16F00, 0x16F4A}, {0x16F4F, 0x16F87}, {0x16F8F, 0x16F9F}, + {0x16FE0, 0x16FE1}, {0x16FE3, 0x16FE4}, {0x16FF0, 0x16FF6}, {0x17000, 0x18CDA}, + {0x18CFF, 0x18D20}, {0x18D80, 0x18DF2}, {0x18E00, 0x19191}, {0x191A0, 0x191D2}, + {0x1AFF0, 0x1AFF3}, {0x1AFF5, 0x1AFFB}, {0x1AFFD, 0x1AFFE}, {0x1B000, 0x1B128}, + {0x1B132, 0x1B132}, {0x1B150, 0x1B152}, {0x1B155, 0x1B155}, {0x1B164, 0x1B168}, + {0x1B170, 0x1B2FB}, {0x1BC00, 0x1BC6A}, {0x1BC70, 0x1BC7C}, {0x1BC80, 0x1BC88}, + {0x1BC90, 0x1BC99}, {0x1BC9D, 0x1BC9E}, {0x1CCF0, 0x1CCF9}, {0x1CF00, 0x1CF2D}, + {0x1CF30, 0x1CF46}, {0x1D127, 0x1D128}, {0x1D165, 0x1D169}, {0x1D16D, 0x1D172}, + {0x1D17B, 0x1D182}, {0x1D185, 0x1D18B}, {0x1D1AA, 0x1D1AD}, {0x1D242, 0x1D244}, + {0x1D250, 0x1D252}, {0x1D25B, 0x1D25C}, {0x1D25F, 0x1D25F}, {0x1D280, 0x1D281}, + {0x1D400, 0x1D454}, {0x1D456, 0x1D49C}, {0x1D49E, 0x1D49F}, {0x1D4A2, 0x1D4A2}, + {0x1D4A5, 0x1D4A6}, {0x1D4A9, 0x1D4AC}, {0x1D4AE, 0x1D4B9}, {0x1D4BB, 0x1D4BB}, + {0x1D4BD, 0x1D4C3}, {0x1D4C5, 0x1D505}, {0x1D507, 0x1D50A}, {0x1D50D, 0x1D514}, + {0x1D516, 0x1D51C}, {0x1D51E, 0x1D539}, {0x1D53B, 0x1D53E}, {0x1D540, 0x1D544}, + {0x1D546, 0x1D546}, {0x1D54A, 0x1D550}, {0x1D552, 0x1D6A6}, {0x1D6A8, 0x1D6C0}, + {0x1D6C2, 0x1D6DA}, {0x1D6DC, 0x1D6FA}, {0x1D6FC, 0x1D714}, {0x1D716, 0x1D734}, + {0x1D736, 0x1D74E}, {0x1D750, 0x1D76E}, {0x1D770, 0x1D788}, {0x1D78A, 0x1D7A8}, + {0x1D7AA, 0x1D7C2}, {0x1D7C4, 0x1D7CB}, {0x1D7CE, 0x1D7FF}, {0x1DA00, 0x1DA36}, + {0x1DA3B, 0x1DA6C}, {0x1DA75, 0x1DA75}, {0x1DA84, 0x1DA84}, {0x1DA9B, 0x1DA9F}, + {0x1DAA1, 0x1DAAF}, {0x1DF00, 0x1DF81}, {0x1DF90, 0x1DF96}, {0x1DFCD, 0x1E006}, + {0x1E008, 0x1E018}, {0x1E01B, 0x1E021}, {0x1E023, 0x1E024}, {0x1E026, 0x1E02A}, + {0x1E030, 0x1E06D}, {0x1E08F, 0x1E08F}, {0x1E100, 0x1E12C}, {0x1E130, 0x1E13D}, + {0x1E140, 0x1E149}, {0x1E14E, 0x1E14E}, {0x1E290, 0x1E2AE}, {0x1E2C0, 0x1E2F9}, + {0x1E4D0, 0x1E4F9}, {0x1E5D0, 0x1E5FA}, {0x1E6C0, 0x1E6DE}, {0x1E6E0, 0x1E6F5}, + {0x1E6FE, 0x1E6FF}, {0x1E7E0, 0x1E7E6}, {0x1E7E8, 0x1E7EB}, {0x1E7ED, 0x1E7EE}, + {0x1E7F0, 0x1E7FE}, {0x1E800, 0x1E8C4}, {0x1E8D0, 0x1E8D6}, {0x1E900, 0x1E94B}, + {0x1E950, 0x1E959}, {0x1EE00, 0x1EE03}, {0x1EE05, 0x1EE1F}, {0x1EE21, 0x1EE22}, + {0x1EE24, 0x1EE24}, {0x1EE27, 0x1EE27}, {0x1EE29, 0x1EE32}, {0x1EE34, 0x1EE37}, + {0x1EE39, 0x1EE39}, {0x1EE3B, 0x1EE3B}, {0x1EE42, 0x1EE42}, {0x1EE47, 0x1EE47}, + {0x1EE49, 0x1EE49}, {0x1EE4B, 0x1EE4B}, {0x1EE4D, 0x1EE4F}, {0x1EE51, 0x1EE52}, + {0x1EE54, 0x1EE54}, {0x1EE57, 0x1EE57}, {0x1EE59, 0x1EE59}, {0x1EE5B, 0x1EE5B}, + {0x1EE5D, 0x1EE5D}, {0x1EE5F, 0x1EE5F}, {0x1EE61, 0x1EE62}, {0x1EE64, 0x1EE64}, + {0x1EE67, 0x1EE6A}, {0x1EE6C, 0x1EE72}, {0x1EE74, 0x1EE77}, {0x1EE79, 0x1EE7C}, + {0x1EE7E, 0x1EE7E}, {0x1EE80, 0x1EE89}, {0x1EE8B, 0x1EE9B}, {0x1EEA1, 0x1EEA3}, + {0x1EEA5, 0x1EEA9}, {0x1EEAB, 0x1EEBB}, {0x1FBF0, 0x1FBF9}, {0x20000, 0x2A6DF}, + {0x2A700, 0x2B81E}, {0x2B820, 0x2CEAD}, {0x2CEB0, 0x2EBE0}, {0x2EBF0, 0x2EE5D}, + {0x2F800, 0x2FA1D}, {0x30000, 0x3134A}, {0x31350, 0x33479}, {0x3D000, 0x3FC3F}, + {0xE0100, 0xE01EF}, +}}; +// END GENERATED UNICODE DATA + static_assert(std::numeric_limits::is_iec559 && std::numeric_limits::digits == 53 && std::numeric_limits::max_exponent == 1024 && sizeof(double) == 8, "CEL requires IEEE binary64"); @@ -66,22 +466,22 @@ scalar validated_scalar(std::string_view source, std::size_t offset) noexcept { /// Finds a scalar in sorted, disjoint inclusive ranges in O(log R) time. template -bool contains(const std::array& ranges, std::uint32_t value) noexcept { - const auto found = std::lower_bound(ranges.begin(), ranges.end(), value, - [](const detail::unicode_range& range, - std::uint32_t needle) { return range.last < needle; }); +bool contains(const std::array& ranges, std::uint32_t value) noexcept { + const auto found = std::lower_bound( + ranges.begin(), ranges.end(), value, + [](const unicode_range& range, std::uint32_t needle) { return range.last < needle; }); return found != ranges.end() && found->first <= value; } /// Checks the proc-macro2 identifier-start rule. /// Complexity: O(log R) time for R Unicode ranges. bool ident_start(std::uint32_t value) noexcept { - return value == '_' || contains(detail::xid_start, value); + return value == '_' || contains(xid_start, value); } /// Checks the proc-macro2 identifier-continuation rule. /// Complexity: O(log R) time for R Unicode ranges. -bool ident_continue(std::uint32_t value) noexcept { return contains(detail::xid_continue, value); } +bool ident_continue(std::uint32_t value) noexcept { return contains(xid_continue, value); } /// Checks Rust White_Space plus the producer's U+200E/U+200F additions. bool whitespace(std::uint32_t value) noexcept { @@ -590,3 +990,398 @@ parse_error::parse_error(error_category category, source_span span, std::string assert(span.begin <= span.end); } } // namespace cel + +#if CPP_LIBRARY_TESTING() +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(__APPLE__) +#include +#include +#include +#include +#endif + +namespace { +/// Collects independently owned tokens through the forward-only interface. +std::vector collect(std::string_view text) { + cel::parser_detail::lex_lexer lexer(text); + std::vector result; + while (!std::holds_alternative(lexer.current().value)) { + result.push_back(lexer.current()); + lexer.advance(); + } + result.push_back(lexer.current()); + return result; +} + +} // namespace + +TEST_CASE("bool specialization preserves exact and raw identifier names") { + auto t = collect("true false True true_ r#true _"); + REQUIRE(t.size() == 7); + CHECK(std::get(t[0].value)); + CHECK_FALSE(std::get(t[1].value)); + CHECK(std::get(t[2].value).spelling == "True"); + CHECK(std::get(t[3].value).spelling == "true_"); + CHECK(std::get(t[4].value).spelling == "r#true"); + CHECK(std::get(t[5].value).spelling == "_"); +} + +TEST_CASE("numbers retain scalar meaning and exact selector spelling") { + for (auto [text, expected] : + std::vector>{{"1", 1}, + {"1.25", 1.25}, + {"1f64", 1}, + {"2.5f64", 2.5}, + {"1e+2", 100}, + {"1_e+_2", 100}, + {"1_000", 1000}, + {"1.", 1}, + {"0xff", 255}, + {"0o_17", 15}, + {"0b_101_", 5}, + {"9007199254740993", 9007199254740992.0}}) { + INFO(text); + auto t = collect(text); + REQUIRE(t.size() == 2); + REQUIRE(std::holds_alternative(t[0].value)); + auto const& number = std::get(t[0].value); + CHECK(number.value == expected); + CHECK(number.spelling == text); + CHECK(t[0].span.begin == 0); + CHECK(t[0].span.end == text.size()); + } + auto t = collect(".0.1 1..2 1.foo 0.1e2 0f64"); + REQUIRE(t.size() == 11); + CHECK(std::get(t[0].value).spelling() == "."); + CHECK(std::get(t[1].value).spelling == "0.1"); + CHECK(std::get(t[1].value).form == + cel::parser_detail::numeric_form::decimal); + CHECK(std::get(t[3].value).spelling() == ".."); + CHECK(std::get(t[8].value).form == + cel::parser_detail::numeric_form::exponent); + CHECK(std::get(t[9].value).suffix == "f64"); +} + +TEST_CASE("exponent signs precede all exponent underscores") { + for (auto [text, expected] : + std::array{std::pair{"1e+_2f64", 100.0}, std::pair{"1e__2f64", 100.0}, + std::pair{"1e-__2f64", 0.01}, std::pair{"1.0E+__2f64", 100.0}}) { + INFO(std::string_view(text)); + auto t = collect(text); + REQUIRE(t.size() == 2); + REQUIRE(std::holds_alternative(t[0].value)); + auto const& number = std::get(t[0].value); + CHECK(number.value == expected); + CHECK(number.spelling == text); + CHECK(t[0].span == (cel::source_span{0, std::string_view(text).size()})); + } + for (auto text : {"1e_+2f64", "1e__-2f64", "1e_+_2f64", "1.0e_+2f64", "1E__+2f64", "1_e_+_2"}) { + INFO(std::string_view(text)); + auto t = collect(text); + REQUIRE(t.size() == 2); + REQUIRE(std::holds_alternative(t[0].value)); + auto const& error = std::get(t[0].value); + CHECK(error.category() == cel::error_category::malformed_input); + CHECK(error.span() == (cel::source_span{0, std::string_view(text).size()})); + } +} + +TEST_CASE("binary64 boundary conversion preserves Rust infinity and zero results") { + auto t = collect("1e9999 1e-9999 1.7976931348623157e308 " + "1.7976931348623159e308 5e-324 2e-324 0e9999"); + REQUIRE(t.size() == 8); + CHECK(std::isinf(std::get(t[0].value).value)); + CHECK(std::get(t[1].value).value == 0); + CHECK(std::get(t[2].value).value == + std::numeric_limits::max()); + CHECK(std::isinf(std::get(t[3].value).value)); + CHECK(std::get(t[4].value).value == + std::numeric_limits::denorm_min()); + CHECK(std::get(t[5].value).value == 0); + CHECK(std::get(t[6].value).value == 0); + auto huge = collect("0x" + std::string(1000, 'f')); + CHECK(std::isinf(std::get(huge[0].value).value)); + auto extremes = collect("0.0001e999999999999999999999 1000e-999999999999999999999"); + REQUIRE(extremes.size() == 3); + CHECK(std::isinf(std::get(extremes[0].value).value)); + CHECK(std::get(extremes[1].value).value == 0); +} + +#if defined(__APPLE__) +TEST_CASE("numeric conversion preserves the calling thread's floating-point environment") { + std::fenv_t saved; + REQUIRE(std::feholdexcept(&saved) == 0); + std::unique_ptr restore(&saved, std::fesetenv); + + for (const auto rounding : {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO}) { + INFO(rounding); + REQUIRE(std::fesetround(rounding) == 0); + REQUIRE(std::feclearexcept(FE_ALL_EXCEPT) == 0); + REQUIRE(std::feraiseexcept(FE_DIVBYZERO) == 0); + const auto flags = std::fetestexcept(FE_ALL_EXCEPT); + + const auto tokens = + collect("1.0000000000000001 0.99999999999999999 0x20000000000001 1e9999 1e-9999"); + CHECK(std::fegetround() == rounding); + CHECK(std::fetestexcept(FE_ALL_EXCEPT) == flags); + REQUIRE(tokens.size() == 6); + CHECK(std::get(tokens[0].value).value == 1.0); + CHECK(std::get(tokens[1].value).value == 1.0); + CHECK(std::get(tokens[2].value).value == + 9007199254740992.0); + CHECK(std::isinf(std::get(tokens[3].value).value)); + CHECK(std::get(tokens[4].value).value == 0.0); + } +} + +TEST_CASE("numeric conversion ignores the calling thread's numeric locale") { + using locale_type = std::remove_pointer_t; + std::unique_ptr locale( + newlocale(LC_NUMERIC_MASK, "de_DE.UTF-8", nullptr), freelocale); + REQUIRE(locale != nullptr); + const auto previous = uselocale(locale.get()); + REQUIRE(previous != nullptr); + const auto restore = [previous](locale_t current) { + uselocale(previous); + freelocale(current); + }; + std::unique_ptr active(locale.release(), restore); + + const auto tokens = collect("1.25 1_5e-1 0o17 0x20000000000001"); + REQUIRE(tokens.size() == 5); + CHECK(std::get(tokens[0].value).value == 1.25); + CHECK(std::get(tokens[1].value).value == 1.5); + CHECK(std::get(tokens[2].value).value == 15); + CHECK(std::get(tokens[3].value).value == + 9007199254740992.0); +} +#endif + +TEST_CASE("radix integers round ties without narrowing and retain exact spelling") { + constexpr std::array, 10> cases{{ + {"0b100000000000000000000000000000000000000000000000000001", 9007199254740992.0}, + {"0o400000000000000001", 9007199254740992.0}, + {"0x20000000000001", 9007199254740992.0}, + {"0b100000000000000000000000000000000000000000000000000011", 9007199254740996.0}, + {"0o400000000000000003", 9007199254740996.0}, + {"0x20000000000003", 9007199254740996.0}, + {"0b100000000000000000000000000000000000000000000000000000000000000000000000000000001", + 0x1p80}, + {"0o400000000000000000000000001", 0x1p80}, + {"0x100000000000000000001", 0x1p80}, + {"0o12_345", 5349.0}, + }}; + for (auto [text, expected] : cases) { + INFO(text); + const auto tokens = collect(text); + REQUIRE(tokens.size() == 2); + REQUIRE(std::holds_alternative(tokens[0].value)); + const auto& number = std::get(tokens[0].value); + CHECK(number.value == expected); + CHECK(number.spelling == text); + } +} + +TEST_CASE("joint compounds use maximal supported matching and full byte spans") { + for (auto text : + {"&&", "||", "==", "!=", "<=", ">=", "<<", ">>", "->", "=>", ":=", "..", "..="}) { + auto t = collect(text); + REQUIRE(t.size() == 2); + CHECK(std::get(t[0].value).spelling() == text); + CHECK(t[0].span.end == std::string_view(text).size()); + } + auto t = collect("& & &/**/ & &//x\n& .. = ..== +++ ::"); + REQUIRE(t.size() == 16); + CHECK(std::get(t[6].value).spelling() == ".."); + CHECK(std::get(t[8].value).spelling() == "..="); + CHECK(std::get(t[9].value).spelling() == "="); +} + +TEST_CASE("comments distinguish doc metadata and preserve nested contents") { + auto t = collect("//// ordinary\n/**/ /*** ordinary */ /// outer\r\n" + "//!inner\n/** block /*nested*/ text */ /*! inside */ true"); + REQUIRE(t.size() == 6); + CHECK(std::get(t[0].value).text == " outer"); + CHECK_FALSE(std::get(t[0].value).inner); + CHECK(std::get(t[1].value).inner); + CHECK(std::get(t[2].value).text == " block /*nested*/ text "); + CHECK(std::get(t[3].value).text == " inside "); + CHECK(std::get(t[4].value)); +} + +TEST_CASE("comment markers at EOF remain bounded") { + CHECK(collect("//").size() == 1); + auto t = collect("/*"); + REQUIRE(t.size() == 2); + CHECK(std::get(t[0].value).category() == + cel::error_category::malformed_input); +} + +TEST_CASE("Unicode identifiers and producer whitespace retain byte boundaries") { + auto t = collect("\xce\xb1\xcc\x81 " + "\xc2\xa0\xe2\x80\x8e\xe2\x80\x8f\xe6\x97\xa5\xe6\x9c\xac " + "\xf0\xbd\x80\x80"); + REQUIRE(t.size() == 4); + CHECK(std::get(t[0].value).spelling == "\xce\xb1\xcc\x81"); + CHECK(t[0].span.begin == 0); + CHECK(t[0].span.end == 4); + CHECK(std::get(t[1].value).spelling == + "\xe6\x97\xa5\xe6\x9c\xac"); + CHECK(t[1].span.begin == 13); + CHECK(t[1].span.end == 19); + CHECK(std::get(t[2].value).spelling == "\xf0\xbd\x80\x80"); +} + +TEST_CASE("diagnostics identify unsupported versus malformed input") { + for (auto text : {"1f32", "1u8", "1.0i32", "1\xe5\x90\x8d\xe5\xad\x97", "\"text\"", "'x'", + "b\"x\"", "r#\"x\"#", "br##\"x\"##", "c\"x\""}) { + INFO(text); + auto t = collect(text); + REQUIRE(t.size() == 2); + REQUIRE(std::holds_alternative(t[0].value)); + auto const& error = std::get(t[0].value); + CHECK(error.category() == cel::error_category::unsupported_literal); + CHECK(error.span().begin == 0); + CHECK(error.span().end == std::string_view(text).size()); + CHECK(error.span() == (cel::source_span{0, std::string_view(text).size()})); + CHECK((error.what()[0] != '\0')); + } + auto incomplete = collect("1e+"); + REQUIRE(incomplete.size() == 2); + auto const& error = std::get(incomplete[0].value); + CHECK(error.category() == cel::error_category::unsupported_literal); + CHECK(error.span().end == 2); + for (auto text : {"0x", "0b2", "\"unfinished", "/*unfinished", "///bare\rCR", "\xcc\x81", + "\xf0\x9f\x98\x80", "r#self"}) { + INFO(text); + auto t = collect(text); + REQUIRE(std::holds_alternative(t[t.size() - 2].value)); + CHECK(std::get(t[t.size() - 2].value).category() == + cel::error_category::malformed_input); + } +} + +TEST_CASE("malformed UTF8 locates the first invalid byte even in trivia") { + for (auto bytes : + {std::string("\x80", 1), std::string("\xc0\xaf", 2), std::string("\xed\xa0\x80", 3), + std::string("\xf4\x90\x80\x80", 4), std::string("\xe2\x82", 2)}) { + auto t = collect("/*" + bytes); + REQUIRE(t.size() == 2); + auto const& error = std::get(t[0].value); + CHECK(error.category() == cel::error_category::malformed_input); + CHECK(error.span().begin == 2); + CHECK(error.span().end == 3); + } +} + +TEST_CASE("delimiter checking handles deep valid and malformed input iteratively") { + auto t = collect("({[]})"); + REQUIRE(t.size() == 7); + CHECK(std::get(t[0].value).kind == + cel::parser_detail::delimiter::parenthesis); + CHECK(std::get(t[5].value).kind == + cel::parser_detail::delimiter::parenthesis); + for (auto text : {")", "([)]", "{"}) { + auto errors = collect(text); + auto const& error = std::get(errors[errors.size() - 2].value); + CHECK(error.category() == cel::error_category::delimiter_error); + } + std::string deep(50000, '('); + auto malformed = collect(deep); + CHECK(std::get(malformed[malformed.size() - 2].value).span().begin == 49999); + deep += std::string(50000, ')'); + CHECK(collect(deep).size() == 100001); + std::string comments; + for (int i = 0; i != 50000; ++i) + comments += "/*"; + for (int i = 0; i != 50000; ++i) + comments += "*/"; + CHECK(collect(comments).size() == 1); +} + +TEST_CASE("owned payload copies survive sources adapters and mutations") { + std::vector t; + { + std::string source = "identifier 1_2f64 ///text"; + t = collect(source); + source.assign(source.size(), 'x'); + } + auto copy = t; + std::get(copy[0].value).spelling = "changed"; + CHECK(std::get(t[0].value).spelling == "identifier"); + CHECK(std::get(t[1].value).spelling == "1_2f64"); + CHECK(std::get(t[2].value).text == "text"); + cel::parser_detail::lex_lexer lexer(std::string("temporary")); + CHECK(std::get(lexer.current().value).spelling == "temporary"); + std::string lazy_source = "alpha beta"; + cel::parser_detail::lex_lexer lazy(lazy_source); + lazy_source.assign(lazy_source.size(), 'x'); + lazy.advance(); + CHECK(std::get(lazy.current().value).spelling == "beta"); +} + +TEST_CASE("flattened producer cursor preserves current payload error and EOF laws") { + std::vector tokens{{{4, 5}, true}, + {{6, 7}, cel::parser_detail::identifier{"x"}}}; + cel::parser_detail::token_cursor cursor(tokens); + CHECK(std::get(cursor.current().value)); + cursor.advance(); + CHECK(std::get(cursor.current().value).spelling == "x"); + cursor.advance(); + CHECK(std::holds_alternative(cursor.current().value)); + CHECK(cursor.current().span.end == 7); + cursor.advance(); + CHECK(cursor.current().span.begin == 7); + cel::parser_detail::token_cursor empty(std::span{}); + CHECK(std::holds_alternative(empty.current().value)); + std::vector errors{ + {{2, 3}, cel::parse_error(cel::error_category::malformed_input, {2, 3}, "producer error")}, + {{4, 5}, true}}; + cel::parser_detail::token_cursor failed(errors); + CHECK(std::get(failed.current().value).span().begin == 2); + failed.advance(); + CHECK(std::holds_alternative(failed.current().value)); + cel::parser_detail::lex_lexer eof(" \n"); + CHECK(eof.current().span.begin == 2); + eof.advance(); + CHECK(eof.current().span.end == 2); + std::array explicit_end{ + cel::parser_detail::token{{8, 8}, cel::parser_detail::end_token{}}, + cel::parser_detail::token{{9, 10}, true}}; + cel::parser_detail::token_cursor terminal(explicit_end); + terminal.advance(); + CHECK(std::holds_alternative(terminal.current().value)); + CHECK(terminal.current().span.begin == 8); + std::array invisible{ + cel::parser_detail::token{ + {2, 5}, cel::parser_detail::open_delimiter{cel::parser_detail::delimiter::none}}, + cel::parser_detail::token{ + {2, 5}, cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::none}}}; + cel::parser_detail::token_cursor groups(invisible); + CHECK(std::get(groups.current().value).kind == + cel::parser_detail::delimiter::none); + groups.advance(); + CHECK(std::get(groups.current().value).kind == + cel::parser_detail::delimiter::none); + CHECK(groups.current().span == (cel::source_span{2, 5})); +} + +TEST_CASE("inline punctuation validates caller input and owns its bytes") { + std::string source = "..="; + cel::parser_detail::punctuation punct(source); + source.assign(3, 'x'); + CHECK(punct.spelling() == "..="); + for (auto invalid : {"", "....", "abc", "\xce\xb1"}) { + CHECK_THROWS_AS(cel::parser_detail::punctuation{invalid}, std::invalid_argument); + } +} +#endif diff --git a/src/type.cpp b/src/type.cpp index 28aa337..b7bfd1c 100644 --- a/src/type.cpp +++ b/src/type.cpp @@ -2,6 +2,7 @@ #include "type.hpp" #include "lookup_access.hpp" #include +#include namespace cel::parser_detail { namespace { @@ -156,12 +157,6 @@ class type_parser { } }; } // namespace -value_type parse_type(token_cursor& cursor, const op_lookup& lookup) { - return type_parser(cursor, lookup).parse(); -} -value_type parse_type(lex_lexer& cursor, const op_lookup& lookup) { - return type_parser(cursor, lookup).parse(); -} /// Parses a token prefix and publishes its exact successful source interval. value_type parse_type(token_cursor& cursor, const op_lookup& lookup, source_span& parsed_span) { return type_parser(cursor, lookup).parse(&parsed_span); @@ -170,6 +165,30 @@ value_type parse_type(token_cursor& cursor, const op_lookup& lookup, source_span value_type parse_type(lex_lexer& cursor, const op_lookup& lookup, source_span& parsed_span) { return type_parser(cursor, lookup).parse(&parsed_span); } +} // namespace cel::parser_detail + +#if CPP_LIBRARY_TESTING() +#include +#include +#include +#include + +namespace cel::parser_detail { +namespace { +namespace type_tests { +/// Parses one token prefix under the grammar, errors, ownership, and complexity in type.hpp. +value_type parse_type(token_cursor& cursor, const op_lookup& lookup) { + return type_parser(cursor, lookup).parse(); +} +/// Parses one text prefix under the grammar, errors, ownership, and complexity in type.hpp. +value_type parse_type(lex_lexer& cursor, const op_lookup& lookup) { + return type_parser(cursor, lookup).parse(); +} +/// Parses one complete type and rejects trailing input; follows the prefix grammar contract. +/// Throws parse_error(malformed_input) for input after the type and before terminal end. +/// Explicit end/error tokens follow token_cursor's contract; later tokens are ignored. +/// Returns an owned descriptor; tokens and lookup need not survive the call. +/// Complexity: O(tokens + name bytes + complete descriptor construction), O(nodes + 128) storage. value_type parse_type(std::span tokens, const op_lookup& lookup) { token_cursor cursor(tokens); auto type = parse_type(cursor, lookup); @@ -179,4 +198,136 @@ value_type parse_type(std::span tokens, const op_lookup& lookup) { "trailing type input"); return type; } +} // namespace type_tests +} // namespace +using type_tests::parse_type; } // namespace cel::parser_detail + +namespace { +/// Owns tokens collected from the accepted current/advance interface. +/// Complexity: O(source bytes), O(token payloads and count) storage. +std::vector tokens(std::string_view source) { + cel::parser_detail::lex_lexer lexer(source); + std::vector result; + while (!std::holds_alternative(lexer.current().value)) { + result.push_back(lexer.current()); + lexer.advance(); + } + result.push_back(lexer.current()); + return result; +} +/// Parses one complete type with source ownership outside the parser. +/// Complexity: O(source bytes + complete descriptor construction). +cel::value_type type(std::string_view source, const cel::op_lookup& lookup) { + auto input = tokens(source); + return cel::parser_detail::parse_type(input, lookup); +} +/// Provides a valid client leaf that is not an admitted callable parameter. +struct client { + double number; +}; +} // namespace + +TEST_CASE("type productions preserve nesting nominal identity and singleton commas") { + cel::op_lookup lookup; + lookup.register_type("Client"); + lookup.register_record("Record", + std::array{cel::record_field{"x", cel::value_type::leaf()}}); + CHECK(type("bool", lookup).same_shape(cel::value_type::leaf())); + CHECK(type("(f64)", lookup).same_shape(cel::value_type::leaf())); + CHECK(type("()", lookup).fields().empty()); + CHECK(type("(f64,)", lookup).fields().size() == 1); + auto nested = type("[((bool,), [Client], Record)]", lookup); + CHECK(nested.element().fields().size() == 3); + CHECK(nested.element().fields()[1].element().same_shape(cel::value_type::leaf())); + CHECK(nested.element().fields()[2].record_identity() == "Record"); + for (auto source : + {"(bool, f64,)", "[f64,]", "Fn((f64,), bool,)", "Fn((f64), bool)", "Fn((),)", "Fn()", + "bool f64", "[]", "(,)", "[f64)", "f32", "String", "usize", "Unknown", "bool(f64)"}) { + CHECK_THROWS_AS(type(source, lookup), cel::parse_error); + } +} + +TEST_CASE("Fn parameter admission is recursive while complete results remain unrestricted") { + cel::op_lookup lookup; + lookup.register_type("Client"); + auto fn = type("Fn((bool, [[(f64, bool)]]), Fn((), [Client]))", lookup); + CHECK(fn.parameters().size() == 2); + CHECK(fn.result().result().element().same_shape(cel::value_type::leaf())); + CHECK(type("Fn((), Client)", lookup).parameters().empty()); + for (auto source : {"Fn((Client,), bool)", "Fn(([Client],), bool)", "Fn((Fn((), bool),), bool)", + "Fn(([(Client, bool)],), f64)"}) { + CHECK_THROWS_AS(type(source, lookup), cel::parse_error); + } + CHECK(type("RangeInclusive(f64)", lookup).form() == cel::range_kind::range_inclusive); + CHECK(type("RangeFull()", lookup).form() == cel::range_kind::range_full); + CHECK_THROWS_AS(type("Range(bool)", lookup), cel::parse_error); + lookup.register_record("BuiltinRecord", + std::array{cel::record_field{ + "x", cel::value_type::array(cel::value_type::leaf())}}); + CHECK(type("Fn((BuiltinRecord, RangeInclusive(f64)), bool)", lookup).parameters().size() == 2); + lookup.register_record("ClientRecord", + std::array{cel::record_field{"x", cel::value_type::leaf()}}); + CHECK_THROWS_AS(type("Fn((ClientRecord,), bool)", lookup), cel::parse_error); + CHECK(type("Fn((), ClientRecord)", lookup).result().record_identity() == "ClientRecord"); + CHECK(type("Fn((), [Fn((), Client)])", lookup).result().element().kind() == + cel::type_kind::callable); +} + +TEST_CASE("inline type parsing leaves host token and errors retain exact byte spans") { + cel::op_lookup lookup; + cel::parser_detail::lex_lexer text_cursor("[f64], next"); + CHECK(cel::parser_detail::parse_type(text_cursor, lookup) + .element() + .same_shape(cel::value_type::leaf())); + CHECK(std::get(text_cursor.current().value).spelling() == ","); + auto input = tokens("[f64], next"); + cel::parser_detail::token_cursor cursor(input); + CHECK(cel::parser_detail::parse_type(cursor, lookup) + .element() + .same_shape(cel::value_type::leaf())); + CHECK(std::get(cursor.current().value).spelling() == ","); + try { + (void)type("[Unknown]", lookup); + FAIL("unknown type accepted"); + } catch (const cel::parse_error& error) { + CHECK(error.span() == cel::source_span{1, 8}); + } + + auto invalid = std::array{cel::parser_detail::token{ + {20, 21}, cel::parse_error(cel::error_category::malformed_input, {20, 21}, "producer")}}; + try { + (void)cel::parser_detail::parse_type(invalid, lookup); + FAIL("producer error accepted"); + } catch (const cel::parse_error& error) { + CHECK(error.span() == cel::source_span{20, 21}); + CHECK(std::string(error.what()) == "producer"); + } + const auto deep = std::string(1000, '[') + "f64" + std::string(1000, ']'); + CHECK(type(std::string(127, '[') + "f64" + std::string(127, ']'), lookup).kind() == + cel::type_kind::array); + try { + (void)type(deep, lookup); + FAIL("resource boundary ignored"); + } catch (const cel::parse_error& error) { + CHECK(error.category() == cel::error_category::resource_limit); + } +} + +TEST_CASE("type prefix span output excludes whitespace and publishes only on success") { + cel::op_lookup lookup; + cel::source_span parsed{90, 91}; + cel::parser_detail::lex_lexer source(" Fn((), [f64]) , next"); + CHECK(cel::parser_detail::parse_type(source, lookup, parsed).result().kind() == + cel::type_kind::array); + CHECK(parsed == cel::source_span{2, 15}); + CHECK(std::get(source.current().value).spelling() == ","); + const auto input = tokens(" [f64] , next"); + cel::parser_detail::token_cursor cursor(input); + CHECK(cel::parser_detail::parse_type(cursor, lookup, parsed).kind() == cel::type_kind::array); + CHECK(parsed == cel::source_span{2, 7}); + cel::parser_detail::lex_lexer invalid("[Unknown]"); + CHECK_THROWS_AS(cel::parser_detail::parse_type(invalid, lookup, parsed), cel::parse_error); + CHECK(parsed == cel::source_span{2, 7}); +} +#endif diff --git a/src/type.hpp b/src/type.hpp index 07a623e..da5a643 100644 --- a/src/type.hpp +++ b/src/type.hpp @@ -15,6 +15,9 @@ namespace cel::parser_detail { /// Callable parameters admit recursively eligible bool/f64 composites, not client leaves /// or nested callables; results admit any complete type. A callable type does not own code. /// Returns an owned descriptor that survives the cursor, token source, and lookup. +/// Publishes the consumed byte interval in parsed_span, excluding surrounding whitespace +/// and the following host token. External tokens supply these offsets without re-lexing. +/// Leaves parsed_span unchanged on failure. /// Throws source-located parse_error(malformed_input) for an expected type production, /// delimiter_error for a missing/mismatched close, type_error for unsupported names or /// ineligible callable types, and resource_limit beyond 128 active type productions. @@ -30,32 +33,10 @@ namespace cel::parser_detail { /// auto count = type.fields().size(); // 1; parsed is {0, 6}. /// auto comma = std::get(cursor.current().value).spelling(); // "," /// \endcode -value_type parse_type(token_cursor& cursor, const op_lookup& lookup); -/// Parses one type directly from the owned text lexer, following the inline grammar contract. -/// Leaves the following host token unconsumed without materializing a separate token array. -/// Throws the source diagnostics and resource errors documented by the token-cursor overload. -/// Complexity: O(lexer traversal + name bytes + complete descriptor construction) time, -/// O(nodes + 128) additional storage, excluding the lexer's owned source and payload. -/// Example: lex_lexer cursor("[f64], next"); auto type = parse_type(cursor, lookup). -value_type parse_type(lex_lexer& cursor, const op_lookup& lookup); -/// Parses one token type prefix and returns its exact consumed byte interval in parsed_span. -/// Follows the two-argument prefix overload's grammar, errors, ownership, and complexity. -/// Postcondition: parsed_span runs from the first consumed token's begin to the last one's end, -/// excluding surrounding whitespace and the following host token. -/// External tokens supply these offsets; parsing does not re-lex their source. -/// Leaves parsed_span unchanged if parsing fails; the cursor may have advanced. -/// Example: source_span span; auto type = parse_type(cursor, lookup, span). value_type parse_type(token_cursor& cursor, const op_lookup& lookup, source_span& parsed_span); /// Parses one text type prefix and returns its exact consumed interval without a token copy. /// Follows the token span-output overload's grammar, errors, ownership, and complexity. /// Example: lex_lexer c("[f64] , next"); source_span s; auto t = parse_type(c, lookup, s). value_type parse_type(lex_lexer& cursor, const op_lookup& lookup, source_span& parsed_span); -/// Parses one complete type and rejects trailing input; follows the inline grammar contract. -/// Throws parse_error(malformed_input) for input after the type and before terminal end. -/// Explicit end/error tokens follow token_cursor's contract; later tokens are ignored. -/// Returns an owned descriptor; tokens and lookup need not survive the call. -/// Complexity: O(tokens + name bytes + complete descriptor construction), O(nodes + 128) storage. -/// Example: auto type = parse_type(std::span(tokens), lookup). -value_type parse_type(std::span tokens, const op_lookup& lookup); } // namespace cel::parser_detail #endif diff --git a/src/unicode_data.hpp b/src/unicode_data.hpp deleted file mode 100644 index 8d0d6f9..0000000 --- a/src/unicode_data.hpp +++ /dev/null @@ -1,404 +0,0 @@ -// SPDX-License-Identifier: Unicode-3.0 -// Generated by tools/generate_unicode.py; Unicode 18.0.0. -// Input: https://www.unicode.org/Public/18.0.0/ucd/DerivedCoreProperties.txt -// SHA-256: 09c928886a178fcafd93c29e4bd59073a058e5a100b716d425cb563ab50f68c9 -#ifndef CEL_PARSER_UNICODE_DATA_HPP -#define CEL_PARSER_UNICODE_DATA_HPP -#include -#include -namespace cel::detail { -/// Stores an inclusive Unicode property interval. -struct unicode_range { - std::uint32_t first; - std::uint32_t last; -}; -/// Stores Unicode 18 XID_Start intervals in ascending order. -inline constexpr std::array xid_start{{ - {0x41, 0x5A}, {0x61, 0x7A}, {0xAA, 0xAA}, {0xB5, 0xB5}, - {0xBA, 0xBA}, {0xC0, 0xD6}, {0xD8, 0xF6}, {0xF8, 0x2C1}, - {0x2C6, 0x2D1}, {0x2E0, 0x2E4}, {0x2EC, 0x2EC}, {0x2EE, 0x2EE}, - {0x370, 0x374}, {0x376, 0x377}, {0x37B, 0x37D}, {0x37F, 0x37F}, - {0x386, 0x386}, {0x388, 0x38A}, {0x38C, 0x38C}, {0x38E, 0x3A1}, - {0x3A3, 0x3F5}, {0x3F7, 0x481}, {0x48A, 0x52F}, {0x531, 0x556}, - {0x558, 0x559}, {0x560, 0x588}, {0x58B, 0x58C}, {0x5D0, 0x5EA}, - {0x5EF, 0x5F2}, {0x620, 0x64A}, {0x66E, 0x66F}, {0x671, 0x6D3}, - {0x6D5, 0x6D5}, {0x6E5, 0x6E6}, {0x6EE, 0x6EF}, {0x6FA, 0x6FC}, - {0x6FF, 0x6FF}, {0x710, 0x710}, {0x712, 0x72F}, {0x74D, 0x7A5}, - {0x7B1, 0x7B1}, {0x7CA, 0x7EA}, {0x7F4, 0x7F5}, {0x7FA, 0x7FA}, - {0x800, 0x815}, {0x81A, 0x81A}, {0x824, 0x824}, {0x828, 0x828}, - {0x840, 0x858}, {0x860, 0x86A}, {0x870, 0x887}, {0x889, 0x88F}, - {0x8A0, 0x8C9}, {0x904, 0x939}, {0x93D, 0x93D}, {0x950, 0x950}, - {0x958, 0x961}, {0x971, 0x980}, {0x985, 0x98C}, {0x98F, 0x990}, - {0x993, 0x9A8}, {0x9AA, 0x9B0}, {0x9B2, 0x9B2}, {0x9B6, 0x9B9}, - {0x9BD, 0x9BD}, {0x9CE, 0x9CE}, {0x9DC, 0x9DD}, {0x9DF, 0x9E1}, - {0x9F0, 0x9F1}, {0x9FC, 0x9FC}, {0xA05, 0xA0A}, {0xA0F, 0xA10}, - {0xA13, 0xA28}, {0xA2A, 0xA30}, {0xA32, 0xA33}, {0xA35, 0xA36}, - {0xA38, 0xA39}, {0xA59, 0xA5C}, {0xA5E, 0xA5E}, {0xA72, 0xA74}, - {0xA85, 0xA8D}, {0xA8F, 0xA91}, {0xA93, 0xAA8}, {0xAAA, 0xAB0}, - {0xAB2, 0xAB3}, {0xAB5, 0xAB9}, {0xABD, 0xABD}, {0xAD0, 0xAD0}, - {0xAE0, 0xAE1}, {0xAF9, 0xAF9}, {0xB05, 0xB0C}, {0xB0F, 0xB10}, - {0xB13, 0xB28}, {0xB2A, 0xB30}, {0xB32, 0xB33}, {0xB35, 0xB39}, - {0xB3D, 0xB3D}, {0xB5C, 0xB5D}, {0xB5F, 0xB61}, {0xB71, 0xB71}, - {0xB83, 0xB83}, {0xB85, 0xB8A}, {0xB8E, 0xB90}, {0xB92, 0xB95}, - {0xB99, 0xB9A}, {0xB9C, 0xB9C}, {0xB9E, 0xB9F}, {0xBA3, 0xBA4}, - {0xBA8, 0xBAA}, {0xBAE, 0xBB9}, {0xBD0, 0xBD0}, {0xC05, 0xC0C}, - {0xC0E, 0xC10}, {0xC12, 0xC28}, {0xC2A, 0xC39}, {0xC3D, 0xC3D}, - {0xC58, 0xC5A}, {0xC5C, 0xC5D}, {0xC60, 0xC61}, {0xC80, 0xC80}, - {0xC85, 0xC8C}, {0xC8E, 0xC90}, {0xC92, 0xCA8}, {0xCAA, 0xCB3}, - {0xCB5, 0xCB9}, {0xCBD, 0xCBD}, {0xCDC, 0xCDE}, {0xCE0, 0xCE1}, - {0xCF1, 0xCF2}, {0xD04, 0xD0C}, {0xD0E, 0xD10}, {0xD12, 0xD3A}, - {0xD3D, 0xD3D}, {0xD4E, 0xD4E}, {0xD54, 0xD56}, {0xD5F, 0xD61}, - {0xD7A, 0xD7F}, {0xD85, 0xD96}, {0xD9A, 0xDB1}, {0xDB3, 0xDBB}, - {0xDBD, 0xDBD}, {0xDC0, 0xDC6}, {0xE01, 0xE30}, {0xE32, 0xE32}, - {0xE40, 0xE46}, {0xE81, 0xE82}, {0xE84, 0xE84}, {0xE86, 0xE8A}, - {0xE8C, 0xEA3}, {0xEA5, 0xEA5}, {0xEA7, 0xEB0}, {0xEB2, 0xEB2}, - {0xEBD, 0xEBD}, {0xEC0, 0xEC4}, {0xEC6, 0xEC6}, {0xEDC, 0xEDF}, - {0xF00, 0xF00}, {0xF40, 0xF47}, {0xF49, 0xF6C}, {0xF88, 0xF8C}, - {0x1000, 0x102A}, {0x103F, 0x103F}, {0x1050, 0x1055}, {0x105A, 0x105D}, - {0x1061, 0x1061}, {0x1065, 0x1066}, {0x106E, 0x1070}, {0x1075, 0x1081}, - {0x108E, 0x108E}, {0x10A0, 0x10C5}, {0x10C7, 0x10C7}, {0x10CD, 0x10CD}, - {0x10D0, 0x10FA}, {0x10FC, 0x1248}, {0x124A, 0x124D}, {0x1250, 0x1256}, - {0x1258, 0x1258}, {0x125A, 0x125D}, {0x1260, 0x1288}, {0x128A, 0x128D}, - {0x1290, 0x12B0}, {0x12B2, 0x12B5}, {0x12B8, 0x12BE}, {0x12C0, 0x12C0}, - {0x12C2, 0x12C5}, {0x12C8, 0x12D6}, {0x12D8, 0x1310}, {0x1312, 0x1315}, - {0x1318, 0x135A}, {0x1380, 0x138F}, {0x13A0, 0x13F5}, {0x13F8, 0x13FD}, - {0x1401, 0x166C}, {0x166F, 0x167F}, {0x1681, 0x169A}, {0x16A0, 0x16EA}, - {0x16EE, 0x16F8}, {0x1700, 0x1711}, {0x171F, 0x1731}, {0x1740, 0x1751}, - {0x1760, 0x176C}, {0x176E, 0x1770}, {0x1780, 0x17B3}, {0x17D7, 0x17D7}, - {0x17DC, 0x17DC}, {0x1820, 0x1878}, {0x1880, 0x18A8}, {0x18AA, 0x18AA}, - {0x18B0, 0x18F5}, {0x1900, 0x191E}, {0x1950, 0x196D}, {0x1970, 0x1974}, - {0x1980, 0x19AB}, {0x19B0, 0x19C9}, {0x1A00, 0x1A16}, {0x1A20, 0x1A54}, - {0x1AA7, 0x1AA7}, {0x1B05, 0x1B33}, {0x1B45, 0x1B4C}, {0x1B83, 0x1BA0}, - {0x1BAE, 0x1BAF}, {0x1BBA, 0x1BE5}, {0x1C00, 0x1C23}, {0x1C4D, 0x1C4F}, - {0x1C5A, 0x1C7D}, {0x1C80, 0x1C8A}, {0x1C90, 0x1CBA}, {0x1CBD, 0x1CBF}, - {0x1CE9, 0x1CEC}, {0x1CEE, 0x1CF3}, {0x1CF5, 0x1CF6}, {0x1CFA, 0x1CFA}, - {0x1D00, 0x1DBF}, {0x1E00, 0x1F15}, {0x1F18, 0x1F1D}, {0x1F20, 0x1F45}, - {0x1F48, 0x1F4D}, {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, {0x1F5B, 0x1F5B}, - {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4}, {0x1FB6, 0x1FBC}, - {0x1FBE, 0x1FBE}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, {0x1FD0, 0x1FD3}, - {0x1FD6, 0x1FDB}, {0x1FE0, 0x1FEC}, {0x1FF2, 0x1FF4}, {0x1FF6, 0x1FFC}, - {0x2071, 0x2071}, {0x207F, 0x207F}, {0x208F, 0x209F}, {0x2102, 0x2102}, - {0x2107, 0x2107}, {0x210A, 0x2113}, {0x2115, 0x2115}, {0x2118, 0x211D}, - {0x2124, 0x2124}, {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212A, 0x2139}, - {0x213C, 0x213F}, {0x2145, 0x2149}, {0x214E, 0x214E}, {0x2160, 0x2188}, - {0x2C00, 0x2CE4}, {0x2CEB, 0x2CEE}, {0x2CF2, 0x2CF3}, {0x2D00, 0x2D25}, - {0x2D27, 0x2D27}, {0x2D2D, 0x2D2D}, {0x2D30, 0x2D67}, {0x2D6F, 0x2D6F}, - {0x2D80, 0x2D96}, {0x2DA0, 0x2DA6}, {0x2DA8, 0x2DAE}, {0x2DB0, 0x2DB6}, - {0x2DB8, 0x2DBE}, {0x2DC0, 0x2DC6}, {0x2DC8, 0x2DCE}, {0x2DD0, 0x2DD6}, - {0x2DD8, 0x2DDE}, {0x3005, 0x3007}, {0x3021, 0x3029}, {0x3031, 0x3035}, - {0x3038, 0x303C}, {0x3041, 0x3096}, {0x309D, 0x309F}, {0x30A1, 0x30FA}, - {0x30FC, 0x30FF}, {0x3105, 0x312F}, {0x3131, 0x318E}, {0x31A0, 0x31BF}, - {0x31F0, 0x31FF}, {0x3400, 0x4DBF}, {0x4E00, 0xA48C}, {0xA4D0, 0xA4FD}, - {0xA500, 0xA60C}, {0xA610, 0xA61F}, {0xA62A, 0xA62B}, {0xA640, 0xA66E}, - {0xA67F, 0xA69D}, {0xA6A0, 0xA6EF}, {0xA717, 0xA71F}, {0xA722, 0xA788}, - {0xA78B, 0xA7DD}, {0xA7E2, 0xA7E2}, {0xA7F1, 0xA801}, {0xA803, 0xA805}, - {0xA807, 0xA80A}, {0xA80C, 0xA822}, {0xA840, 0xA873}, {0xA882, 0xA8B3}, - {0xA8F2, 0xA8F7}, {0xA8FB, 0xA8FB}, {0xA8FD, 0xA8FE}, {0xA90A, 0xA925}, - {0xA930, 0xA946}, {0xA960, 0xA97C}, {0xA984, 0xA9B2}, {0xA9CF, 0xA9CF}, - {0xA9E0, 0xA9E4}, {0xA9E6, 0xA9EF}, {0xA9FA, 0xA9FE}, {0xAA00, 0xAA28}, - {0xAA40, 0xAA42}, {0xAA44, 0xAA4B}, {0xAA60, 0xAA76}, {0xAA7A, 0xAA7A}, - {0xAA7E, 0xAAAF}, {0xAAB1, 0xAAB1}, {0xAAB5, 0xAAB6}, {0xAAB9, 0xAABD}, - {0xAAC0, 0xAAC0}, {0xAAC2, 0xAAC2}, {0xAADB, 0xAADD}, {0xAAE0, 0xAAEA}, - {0xAAF2, 0xAAF4}, {0xAB01, 0xAB06}, {0xAB09, 0xAB0E}, {0xAB11, 0xAB16}, - {0xAB20, 0xAB26}, {0xAB28, 0xAB2E}, {0xAB30, 0xAB5A}, {0xAB5C, 0xAB69}, - {0xAB6C, 0xAB6D}, {0xAB70, 0xABE2}, {0xAC00, 0xD7A3}, {0xD7B0, 0xD7C6}, - {0xD7CB, 0xD7FB}, {0xF900, 0xFA6D}, {0xFA70, 0xFAD9}, {0xFB00, 0xFB06}, - {0xFB13, 0xFB17}, {0xFB1D, 0xFB1D}, {0xFB1F, 0xFB28}, {0xFB2A, 0xFB36}, - {0xFB38, 0xFB3C}, {0xFB3E, 0xFB3E}, {0xFB40, 0xFB41}, {0xFB43, 0xFB44}, - {0xFB46, 0xFBB1}, {0xFBD3, 0xFC5D}, {0xFC64, 0xFD3D}, {0xFD50, 0xFD8F}, - {0xFD92, 0xFDC7}, {0xFDF0, 0xFDF9}, {0xFE71, 0xFE71}, {0xFE73, 0xFE73}, - {0xFE77, 0xFE77}, {0xFE79, 0xFE79}, {0xFE7B, 0xFE7B}, {0xFE7D, 0xFE7D}, - {0xFE7F, 0xFEFC}, {0xFF21, 0xFF3A}, {0xFF41, 0xFF5A}, {0xFF66, 0xFF9D}, - {0xFFA0, 0xFFBE}, {0xFFC2, 0xFFC7}, {0xFFCA, 0xFFCF}, {0xFFD2, 0xFFD7}, - {0xFFDA, 0xFFDC}, {0x10000, 0x1000B}, {0x1000D, 0x10026}, {0x10028, 0x1003A}, - {0x1003C, 0x1003D}, {0x1003F, 0x1004D}, {0x10050, 0x1005D}, {0x10080, 0x100FA}, - {0x10140, 0x10174}, {0x10280, 0x1029C}, {0x102A0, 0x102D0}, {0x10300, 0x1031F}, - {0x1032D, 0x1034A}, {0x10350, 0x10375}, {0x10380, 0x1039D}, {0x103A0, 0x103C3}, - {0x103C8, 0x103CF}, {0x103D1, 0x103D5}, {0x10400, 0x1049D}, {0x104B0, 0x104D3}, - {0x104D8, 0x104FB}, {0x10500, 0x10527}, {0x10530, 0x10563}, {0x10570, 0x1057A}, - {0x1057C, 0x1058A}, {0x1058C, 0x10592}, {0x10594, 0x10595}, {0x10597, 0x105A1}, - {0x105A3, 0x105B1}, {0x105B3, 0x105B9}, {0x105BB, 0x105BC}, {0x105C0, 0x105F3}, - {0x10600, 0x10736}, {0x10740, 0x10755}, {0x10760, 0x10767}, {0x10780, 0x10785}, - {0x10787, 0x107B0}, {0x107B2, 0x107BF}, {0x10800, 0x10805}, {0x10808, 0x10808}, - {0x1080A, 0x10835}, {0x10837, 0x10838}, {0x1083C, 0x1083C}, {0x1083F, 0x10855}, - {0x10860, 0x10876}, {0x10880, 0x1089E}, {0x108E0, 0x108F2}, {0x108F4, 0x108F5}, - {0x10900, 0x10915}, {0x10920, 0x10939}, {0x10940, 0x10959}, {0x10980, 0x109B7}, - {0x109BE, 0x109BF}, {0x10A00, 0x10A00}, {0x10A10, 0x10A13}, {0x10A15, 0x10A17}, - {0x10A19, 0x10A35}, {0x10A60, 0x10A7C}, {0x10A80, 0x10A9C}, {0x10AC0, 0x10AC7}, - {0x10AC9, 0x10AE4}, {0x10B00, 0x10B35}, {0x10B40, 0x10B55}, {0x10B60, 0x10B72}, - {0x10B80, 0x10B91}, {0x10C00, 0x10C48}, {0x10C80, 0x10CB2}, {0x10CC0, 0x10CF2}, - {0x10D00, 0x10D23}, {0x10D4A, 0x10D65}, {0x10D6F, 0x10D85}, {0x10E80, 0x10EA9}, - {0x10EB0, 0x10EB1}, {0x10EC2, 0x10EC7}, {0x10ED9, 0x10EEE}, {0x10F00, 0x10F1C}, - {0x10F27, 0x10F27}, {0x10F30, 0x10F45}, {0x10F70, 0x10F81}, {0x10FB0, 0x10FC4}, - {0x10FE0, 0x10FF6}, {0x11003, 0x11037}, {0x11071, 0x11072}, {0x11075, 0x11075}, - {0x11083, 0x110AF}, {0x110D0, 0x110E8}, {0x11103, 0x11126}, {0x11144, 0x11144}, - {0x11147, 0x11147}, {0x11150, 0x11172}, {0x11176, 0x11176}, {0x11183, 0x111B2}, - {0x111C1, 0x111C4}, {0x111DA, 0x111DA}, {0x111DC, 0x111DC}, {0x11200, 0x11211}, - {0x11213, 0x1122B}, {0x1123F, 0x11240}, {0x11280, 0x11286}, {0x11288, 0x11288}, - {0x1128A, 0x1128D}, {0x1128F, 0x1129D}, {0x1129F, 0x112A8}, {0x112B0, 0x112DE}, - {0x11305, 0x1130C}, {0x1130F, 0x11310}, {0x11313, 0x11328}, {0x1132A, 0x11330}, - {0x11332, 0x11333}, {0x11335, 0x11339}, {0x1133D, 0x1133D}, {0x11350, 0x11350}, - {0x1135D, 0x11361}, {0x11380, 0x11389}, {0x1138B, 0x1138B}, {0x1138E, 0x1138E}, - {0x11390, 0x113B5}, {0x113B7, 0x113B7}, {0x113D1, 0x113D1}, {0x113D3, 0x113D3}, - {0x11400, 0x11434}, {0x11447, 0x1144A}, {0x1145F, 0x11461}, {0x11480, 0x114AF}, - {0x114C4, 0x114C5}, {0x114C7, 0x114C7}, {0x11580, 0x115AE}, {0x115D8, 0x115DB}, - {0x11600, 0x1162F}, {0x11644, 0x11644}, {0x11680, 0x116AA}, {0x116B8, 0x116B8}, - {0x11700, 0x1171A}, {0x11740, 0x11746}, {0x11800, 0x1182B}, {0x118A0, 0x118DF}, - {0x118FF, 0x11906}, {0x11909, 0x11909}, {0x1190C, 0x11913}, {0x11915, 0x11916}, - {0x11918, 0x1192F}, {0x1193F, 0x1193F}, {0x11941, 0x11941}, {0x119A0, 0x119A7}, - {0x119AA, 0x119D0}, {0x119E1, 0x119E1}, {0x119E3, 0x119E3}, {0x11A00, 0x11A00}, - {0x11A0B, 0x11A32}, {0x11A3A, 0x11A3A}, {0x11A50, 0x11A50}, {0x11A5C, 0x11A89}, - {0x11A9D, 0x11A9D}, {0x11AB0, 0x11AF8}, {0x11B0A, 0x11B0A}, {0x11BC0, 0x11BE0}, - {0x11C00, 0x11C08}, {0x11C0A, 0x11C2E}, {0x11C40, 0x11C40}, {0x11C72, 0x11C8F}, - {0x11D00, 0x11D06}, {0x11D08, 0x11D09}, {0x11D0B, 0x11D30}, {0x11D46, 0x11D46}, - {0x11D60, 0x11D65}, {0x11D67, 0x11D68}, {0x11D6A, 0x11D89}, {0x11D98, 0x11D98}, - {0x11DB0, 0x11DDB}, {0x11DF1, 0x11DF1}, {0x11EE0, 0x11EF2}, {0x11F02, 0x11F02}, - {0x11F04, 0x11F10}, {0x11F12, 0x11F33}, {0x11FB0, 0x11FB0}, {0x12000, 0x12399}, - {0x12400, 0x1246F}, {0x12475, 0x12543}, {0x12550, 0x12686}, {0x12F90, 0x12FF0}, - {0x13000, 0x1342F}, {0x13441, 0x13446}, {0x13460, 0x143FA}, {0x14400, 0x14646}, - {0x16100, 0x1611D}, {0x16800, 0x16A38}, {0x16A40, 0x16A5E}, {0x16A70, 0x16ABE}, - {0x16AD0, 0x16AED}, {0x16B00, 0x16B2F}, {0x16B40, 0x16B43}, {0x16B63, 0x16B77}, - {0x16B7D, 0x16B8F}, {0x16D40, 0x16D6C}, {0x16E40, 0x16E7F}, {0x16EA0, 0x16EB8}, - {0x16EBB, 0x16ED3}, {0x16F00, 0x16F4A}, {0x16F50, 0x16F50}, {0x16F93, 0x16F9F}, - {0x16FE0, 0x16FE1}, {0x16FE3, 0x16FE3}, {0x16FF2, 0x16FF6}, {0x17000, 0x18CDA}, - {0x18CFF, 0x18D20}, {0x18D80, 0x18DF2}, {0x18E00, 0x19191}, {0x191A0, 0x191D2}, - {0x1AFF0, 0x1AFF3}, {0x1AFF5, 0x1AFFB}, {0x1AFFD, 0x1AFFE}, {0x1B000, 0x1B128}, - {0x1B132, 0x1B132}, {0x1B150, 0x1B152}, {0x1B155, 0x1B155}, {0x1B164, 0x1B168}, - {0x1B170, 0x1B2FB}, {0x1BC00, 0x1BC6A}, {0x1BC70, 0x1BC7C}, {0x1BC80, 0x1BC88}, - {0x1BC90, 0x1BC99}, {0x1D400, 0x1D454}, {0x1D456, 0x1D49C}, {0x1D49E, 0x1D49F}, - {0x1D4A2, 0x1D4A2}, {0x1D4A5, 0x1D4A6}, {0x1D4A9, 0x1D4AC}, {0x1D4AE, 0x1D4B9}, - {0x1D4BB, 0x1D4BB}, {0x1D4BD, 0x1D4C3}, {0x1D4C5, 0x1D505}, {0x1D507, 0x1D50A}, - {0x1D50D, 0x1D514}, {0x1D516, 0x1D51C}, {0x1D51E, 0x1D539}, {0x1D53B, 0x1D53E}, - {0x1D540, 0x1D544}, {0x1D546, 0x1D546}, {0x1D54A, 0x1D550}, {0x1D552, 0x1D6A6}, - {0x1D6A8, 0x1D6C0}, {0x1D6C2, 0x1D6DA}, {0x1D6DC, 0x1D6FA}, {0x1D6FC, 0x1D714}, - {0x1D716, 0x1D734}, {0x1D736, 0x1D74E}, {0x1D750, 0x1D76E}, {0x1D770, 0x1D788}, - {0x1D78A, 0x1D7A8}, {0x1D7AA, 0x1D7C2}, {0x1D7C4, 0x1D7CB}, {0x1DF00, 0x1DF81}, - {0x1DF90, 0x1DF96}, {0x1DFCD, 0x1DFFF}, {0x1E030, 0x1E06D}, {0x1E100, 0x1E12C}, - {0x1E137, 0x1E13D}, {0x1E14E, 0x1E14E}, {0x1E290, 0x1E2AD}, {0x1E2C0, 0x1E2EB}, - {0x1E4D0, 0x1E4EB}, {0x1E5D0, 0x1E5ED}, {0x1E5F0, 0x1E5F0}, {0x1E6C0, 0x1E6DE}, - {0x1E6E0, 0x1E6E2}, {0x1E6E4, 0x1E6E5}, {0x1E6E7, 0x1E6ED}, {0x1E6F0, 0x1E6F4}, - {0x1E6FE, 0x1E6FF}, {0x1E7E0, 0x1E7E6}, {0x1E7E8, 0x1E7EB}, {0x1E7ED, 0x1E7EE}, - {0x1E7F0, 0x1E7FE}, {0x1E800, 0x1E8C4}, {0x1E900, 0x1E943}, {0x1E94B, 0x1E94B}, - {0x1EE00, 0x1EE03}, {0x1EE05, 0x1EE1F}, {0x1EE21, 0x1EE22}, {0x1EE24, 0x1EE24}, - {0x1EE27, 0x1EE27}, {0x1EE29, 0x1EE32}, {0x1EE34, 0x1EE37}, {0x1EE39, 0x1EE39}, - {0x1EE3B, 0x1EE3B}, {0x1EE42, 0x1EE42}, {0x1EE47, 0x1EE47}, {0x1EE49, 0x1EE49}, - {0x1EE4B, 0x1EE4B}, {0x1EE4D, 0x1EE4F}, {0x1EE51, 0x1EE52}, {0x1EE54, 0x1EE54}, - {0x1EE57, 0x1EE57}, {0x1EE59, 0x1EE59}, {0x1EE5B, 0x1EE5B}, {0x1EE5D, 0x1EE5D}, - {0x1EE5F, 0x1EE5F}, {0x1EE61, 0x1EE62}, {0x1EE64, 0x1EE64}, {0x1EE67, 0x1EE6A}, - {0x1EE6C, 0x1EE72}, {0x1EE74, 0x1EE77}, {0x1EE79, 0x1EE7C}, {0x1EE7E, 0x1EE7E}, - {0x1EE80, 0x1EE89}, {0x1EE8B, 0x1EE9B}, {0x1EEA1, 0x1EEA3}, {0x1EEA5, 0x1EEA9}, - {0x1EEAB, 0x1EEBB}, {0x20000, 0x2A6DF}, {0x2A700, 0x2B81E}, {0x2B820, 0x2CEAD}, - {0x2CEB0, 0x2EBE0}, {0x2EBF0, 0x2EE5D}, {0x2F800, 0x2FA1D}, {0x30000, 0x3134A}, - {0x31350, 0x33479}, {0x3D000, 0x3FC3F}, -}}; -/// Stores Unicode 18 XID_Continue intervals in ascending order. -inline constexpr std::array xid_continue{{ - {0x30, 0x39}, {0x41, 0x5A}, {0x5F, 0x5F}, {0x61, 0x7A}, - {0xAA, 0xAA}, {0xB5, 0xB5}, {0xB7, 0xB7}, {0xBA, 0xBA}, - {0xC0, 0xD6}, {0xD8, 0xF6}, {0xF8, 0x2C1}, {0x2C6, 0x2D1}, - {0x2E0, 0x2E4}, {0x2EC, 0x2EC}, {0x2EE, 0x2EE}, {0x300, 0x374}, - {0x376, 0x377}, {0x37B, 0x37D}, {0x37F, 0x37F}, {0x386, 0x38A}, - {0x38C, 0x38C}, {0x38E, 0x3A1}, {0x3A3, 0x3F5}, {0x3F7, 0x481}, - {0x483, 0x487}, {0x48A, 0x52F}, {0x531, 0x556}, {0x558, 0x559}, - {0x560, 0x588}, {0x58B, 0x58C}, {0x591, 0x5BD}, {0x5BF, 0x5BF}, - {0x5C1, 0x5C2}, {0x5C4, 0x5C5}, {0x5C7, 0x5C9}, {0x5D0, 0x5EA}, - {0x5EF, 0x5F2}, {0x610, 0x61A}, {0x620, 0x669}, {0x66E, 0x6D3}, - {0x6D5, 0x6DC}, {0x6DF, 0x6E8}, {0x6EA, 0x6FC}, {0x6FF, 0x6FF}, - {0x710, 0x74A}, {0x74D, 0x7B1}, {0x7C0, 0x7F5}, {0x7FA, 0x7FA}, - {0x7FD, 0x7FD}, {0x800, 0x82D}, {0x840, 0x85B}, {0x860, 0x86A}, - {0x870, 0x887}, {0x889, 0x88F}, {0x897, 0x8E1}, {0x8E3, 0x963}, - {0x966, 0x96F}, {0x971, 0x983}, {0x985, 0x98C}, {0x98F, 0x990}, - {0x993, 0x9A8}, {0x9AA, 0x9B0}, {0x9B2, 0x9B2}, {0x9B6, 0x9B9}, - {0x9BC, 0x9C4}, {0x9C7, 0x9C8}, {0x9CB, 0x9CE}, {0x9D7, 0x9D7}, - {0x9DC, 0x9DD}, {0x9DF, 0x9E3}, {0x9E6, 0x9F1}, {0x9FC, 0x9FC}, - {0x9FE, 0x9FE}, {0xA01, 0xA03}, {0xA05, 0xA0A}, {0xA0F, 0xA10}, - {0xA13, 0xA28}, {0xA2A, 0xA30}, {0xA32, 0xA33}, {0xA35, 0xA36}, - {0xA38, 0xA39}, {0xA3C, 0xA3C}, {0xA3E, 0xA42}, {0xA47, 0xA48}, - {0xA4B, 0xA4D}, {0xA51, 0xA51}, {0xA59, 0xA5C}, {0xA5E, 0xA5E}, - {0xA66, 0xA75}, {0xA81, 0xA83}, {0xA85, 0xA8D}, {0xA8F, 0xA91}, - {0xA93, 0xAA8}, {0xAAA, 0xAB0}, {0xAB2, 0xAB3}, {0xAB5, 0xAB9}, - {0xABC, 0xAC5}, {0xAC7, 0xAC9}, {0xACB, 0xACD}, {0xAD0, 0xAD0}, - {0xAE0, 0xAE3}, {0xAE6, 0xAEF}, {0xAF9, 0xAFF}, {0xB01, 0xB03}, - {0xB05, 0xB0C}, {0xB0F, 0xB10}, {0xB13, 0xB28}, {0xB2A, 0xB30}, - {0xB32, 0xB33}, {0xB35, 0xB39}, {0xB3C, 0xB44}, {0xB47, 0xB48}, - {0xB4B, 0xB4D}, {0xB53, 0xB57}, {0xB5C, 0xB5D}, {0xB5F, 0xB63}, - {0xB66, 0xB6F}, {0xB71, 0xB71}, {0xB82, 0xB83}, {0xB85, 0xB8A}, - {0xB8E, 0xB90}, {0xB92, 0xB95}, {0xB99, 0xB9A}, {0xB9C, 0xB9C}, - {0xB9E, 0xB9F}, {0xBA3, 0xBA4}, {0xBA8, 0xBAA}, {0xBAE, 0xBB9}, - {0xBBE, 0xBC2}, {0xBC6, 0xBC8}, {0xBCA, 0xBCD}, {0xBD0, 0xBD0}, - {0xBD7, 0xBD7}, {0xBE6, 0xBEF}, {0xC00, 0xC0C}, {0xC0E, 0xC10}, - {0xC12, 0xC28}, {0xC2A, 0xC39}, {0xC3C, 0xC44}, {0xC46, 0xC48}, - {0xC4A, 0xC4D}, {0xC55, 0xC56}, {0xC58, 0xC5A}, {0xC5C, 0xC5D}, - {0xC60, 0xC63}, {0xC66, 0xC6F}, {0xC80, 0xC83}, {0xC85, 0xC8C}, - {0xC8E, 0xC90}, {0xC92, 0xCA8}, {0xCAA, 0xCB3}, {0xCB5, 0xCB9}, - {0xCBC, 0xCC4}, {0xCC6, 0xCC8}, {0xCCA, 0xCCD}, {0xCD5, 0xCD6}, - {0xCDC, 0xCDE}, {0xCE0, 0xCE3}, {0xCE6, 0xCEF}, {0xCF1, 0xCF3}, - {0xD00, 0xD0C}, {0xD0E, 0xD10}, {0xD12, 0xD44}, {0xD46, 0xD48}, - {0xD4A, 0xD4E}, {0xD54, 0xD57}, {0xD5F, 0xD63}, {0xD66, 0xD6F}, - {0xD7A, 0xD7F}, {0xD81, 0xD83}, {0xD85, 0xD96}, {0xD9A, 0xDB1}, - {0xDB3, 0xDBB}, {0xDBD, 0xDBD}, {0xDC0, 0xDC6}, {0xDCA, 0xDCA}, - {0xDCF, 0xDD4}, {0xDD6, 0xDD6}, {0xDD8, 0xDDF}, {0xDE6, 0xDEF}, - {0xDF2, 0xDF3}, {0xE01, 0xE3A}, {0xE40, 0xE4E}, {0xE50, 0xE59}, - {0xE81, 0xE82}, {0xE84, 0xE84}, {0xE86, 0xE8A}, {0xE8C, 0xEA3}, - {0xEA5, 0xEA5}, {0xEA7, 0xEBD}, {0xEC0, 0xEC4}, {0xEC6, 0xEC6}, - {0xEC8, 0xECE}, {0xED0, 0xED9}, {0xEDC, 0xEDF}, {0xF00, 0xF00}, - {0xF18, 0xF19}, {0xF20, 0xF29}, {0xF35, 0xF35}, {0xF37, 0xF37}, - {0xF39, 0xF39}, {0xF3E, 0xF47}, {0xF49, 0xF6C}, {0xF71, 0xF84}, - {0xF86, 0xF97}, {0xF99, 0xFBC}, {0xFC6, 0xFC6}, {0x1000, 0x1049}, - {0x1050, 0x109D}, {0x10A0, 0x10C5}, {0x10C7, 0x10C7}, {0x10CD, 0x10CD}, - {0x10D0, 0x10FA}, {0x10FC, 0x1248}, {0x124A, 0x124D}, {0x1250, 0x1256}, - {0x1258, 0x1258}, {0x125A, 0x125D}, {0x1260, 0x1288}, {0x128A, 0x128D}, - {0x1290, 0x12B0}, {0x12B2, 0x12B5}, {0x12B8, 0x12BE}, {0x12C0, 0x12C0}, - {0x12C2, 0x12C5}, {0x12C8, 0x12D6}, {0x12D8, 0x1310}, {0x1312, 0x1315}, - {0x1318, 0x135A}, {0x135D, 0x135F}, {0x1369, 0x1371}, {0x1380, 0x138F}, - {0x13A0, 0x13F5}, {0x13F8, 0x13FD}, {0x1401, 0x166C}, {0x166F, 0x167F}, - {0x1681, 0x169A}, {0x16A0, 0x16EA}, {0x16EE, 0x16F8}, {0x1700, 0x1715}, - {0x171F, 0x1734}, {0x1740, 0x1753}, {0x1760, 0x176C}, {0x176E, 0x1770}, - {0x1772, 0x1773}, {0x1780, 0x17D3}, {0x17D7, 0x17D7}, {0x17DC, 0x17DD}, - {0x17E0, 0x17E9}, {0x180B, 0x180D}, {0x180F, 0x1819}, {0x1820, 0x1878}, - {0x1880, 0x18AA}, {0x18B0, 0x18F5}, {0x1900, 0x191E}, {0x1920, 0x192B}, - {0x1930, 0x193B}, {0x1946, 0x196D}, {0x1970, 0x1974}, {0x1980, 0x19AB}, - {0x19B0, 0x19C9}, {0x19D0, 0x19DA}, {0x1A00, 0x1A1B}, {0x1A20, 0x1A5E}, - {0x1A60, 0x1A7C}, {0x1A7F, 0x1A89}, {0x1A90, 0x1A99}, {0x1AA7, 0x1AA7}, - {0x1AB0, 0x1ABD}, {0x1ABF, 0x1AF0}, {0x1B00, 0x1B4C}, {0x1B50, 0x1B59}, - {0x1B6B, 0x1B73}, {0x1B80, 0x1BF3}, {0x1C00, 0x1C37}, {0x1C40, 0x1C49}, - {0x1C4D, 0x1C7D}, {0x1C80, 0x1C8A}, {0x1C90, 0x1CBA}, {0x1CBD, 0x1CBF}, - {0x1CD0, 0x1CD2}, {0x1CD4, 0x1CFA}, {0x1D00, 0x1F15}, {0x1F18, 0x1F1D}, - {0x1F20, 0x1F45}, {0x1F48, 0x1F4D}, {0x1F50, 0x1F57}, {0x1F59, 0x1F59}, - {0x1F5B, 0x1F5B}, {0x1F5D, 0x1F5D}, {0x1F5F, 0x1F7D}, {0x1F80, 0x1FB4}, - {0x1FB6, 0x1FBC}, {0x1FBE, 0x1FBE}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, - {0x1FD0, 0x1FD3}, {0x1FD6, 0x1FDB}, {0x1FE0, 0x1FEC}, {0x1FF2, 0x1FF4}, - {0x1FF6, 0x1FFC}, {0x200C, 0x200D}, {0x203F, 0x2040}, {0x2054, 0x2054}, - {0x2071, 0x2071}, {0x207F, 0x207F}, {0x208F, 0x209F}, {0x20D0, 0x20DC}, - {0x20E1, 0x20E1}, {0x20E5, 0x20F0}, {0x2102, 0x2102}, {0x2107, 0x2107}, - {0x210A, 0x2113}, {0x2115, 0x2115}, {0x2118, 0x211D}, {0x2124, 0x2124}, - {0x2126, 0x2126}, {0x2128, 0x2128}, {0x212A, 0x2139}, {0x213C, 0x213F}, - {0x2145, 0x2149}, {0x214E, 0x214E}, {0x2160, 0x2188}, {0x2C00, 0x2CE4}, - {0x2CEB, 0x2CF3}, {0x2D00, 0x2D25}, {0x2D27, 0x2D27}, {0x2D2D, 0x2D2D}, - {0x2D30, 0x2D67}, {0x2D6F, 0x2D6F}, {0x2D7F, 0x2D96}, {0x2DA0, 0x2DA6}, - {0x2DA8, 0x2DAE}, {0x2DB0, 0x2DB6}, {0x2DB8, 0x2DBE}, {0x2DC0, 0x2DC6}, - {0x2DC8, 0x2DCE}, {0x2DD0, 0x2DD6}, {0x2DD8, 0x2DDE}, {0x2DE0, 0x2DFF}, - {0x3005, 0x3007}, {0x3021, 0x302F}, {0x3031, 0x3035}, {0x3038, 0x303C}, - {0x3041, 0x3096}, {0x3099, 0x309A}, {0x309D, 0x309F}, {0x30A1, 0x30FF}, - {0x3105, 0x312F}, {0x3131, 0x318E}, {0x31A0, 0x31BF}, {0x31F0, 0x31FF}, - {0x3400, 0x4DBF}, {0x4E00, 0xA48C}, {0xA4D0, 0xA4FD}, {0xA500, 0xA60C}, - {0xA610, 0xA62B}, {0xA640, 0xA66F}, {0xA674, 0xA67D}, {0xA67F, 0xA6F1}, - {0xA717, 0xA71F}, {0xA722, 0xA788}, {0xA78B, 0xA7DD}, {0xA7E2, 0xA7E2}, - {0xA7F1, 0xA827}, {0xA82C, 0xA82C}, {0xA840, 0xA873}, {0xA880, 0xA8C5}, - {0xA8D0, 0xA8D9}, {0xA8E0, 0xA8F7}, {0xA8FB, 0xA8FB}, {0xA8FD, 0xA92D}, - {0xA930, 0xA953}, {0xA960, 0xA97C}, {0xA980, 0xA9C0}, {0xA9CF, 0xA9D9}, - {0xA9E0, 0xA9FE}, {0xAA00, 0xAA36}, {0xAA40, 0xAA4D}, {0xAA50, 0xAA59}, - {0xAA60, 0xAA76}, {0xAA7A, 0xAAC2}, {0xAADB, 0xAADD}, {0xAAE0, 0xAAEF}, - {0xAAF2, 0xAAF6}, {0xAB01, 0xAB06}, {0xAB09, 0xAB0E}, {0xAB11, 0xAB16}, - {0xAB20, 0xAB26}, {0xAB28, 0xAB2E}, {0xAB30, 0xAB5A}, {0xAB5C, 0xAB69}, - {0xAB6C, 0xAB6D}, {0xAB70, 0xABEA}, {0xABEC, 0xABED}, {0xABF0, 0xABF9}, - {0xAC00, 0xD7A3}, {0xD7B0, 0xD7C6}, {0xD7CB, 0xD7FB}, {0xF900, 0xFA6D}, - {0xFA70, 0xFAD9}, {0xFB00, 0xFB06}, {0xFB13, 0xFB17}, {0xFB1D, 0xFB28}, - {0xFB2A, 0xFB36}, {0xFB38, 0xFB3C}, {0xFB3E, 0xFB3E}, {0xFB40, 0xFB41}, - {0xFB43, 0xFB44}, {0xFB46, 0xFBB1}, {0xFBD3, 0xFC5D}, {0xFC64, 0xFD3D}, - {0xFD50, 0xFD8F}, {0xFD92, 0xFDC7}, {0xFDF0, 0xFDF9}, {0xFE00, 0xFE0F}, - {0xFE20, 0xFE2F}, {0xFE33, 0xFE34}, {0xFE4D, 0xFE4F}, {0xFE71, 0xFE71}, - {0xFE73, 0xFE73}, {0xFE77, 0xFE77}, {0xFE79, 0xFE79}, {0xFE7B, 0xFE7B}, - {0xFE7D, 0xFE7D}, {0xFE7F, 0xFEFC}, {0xFF10, 0xFF19}, {0xFF21, 0xFF3A}, - {0xFF3F, 0xFF3F}, {0xFF41, 0xFF5A}, {0xFF65, 0xFFBE}, {0xFFC2, 0xFFC7}, - {0xFFCA, 0xFFCF}, {0xFFD2, 0xFFD7}, {0xFFDA, 0xFFDC}, {0x10000, 0x1000B}, - {0x1000D, 0x10026}, {0x10028, 0x1003A}, {0x1003C, 0x1003D}, {0x1003F, 0x1004D}, - {0x10050, 0x1005D}, {0x10080, 0x100FA}, {0x10140, 0x10174}, {0x101FD, 0x101FD}, - {0x10280, 0x1029C}, {0x102A0, 0x102D0}, {0x102E0, 0x102E0}, {0x10300, 0x1031F}, - {0x1032D, 0x1034A}, {0x10350, 0x1037A}, {0x10380, 0x1039D}, {0x103A0, 0x103C3}, - {0x103C8, 0x103CF}, {0x103D1, 0x103D5}, {0x10400, 0x1049D}, {0x104A0, 0x104A9}, - {0x104B0, 0x104D3}, {0x104D8, 0x104FB}, {0x10500, 0x10527}, {0x10530, 0x10563}, - {0x10570, 0x1057A}, {0x1057C, 0x1058A}, {0x1058C, 0x10592}, {0x10594, 0x10595}, - {0x10597, 0x105A1}, {0x105A3, 0x105B1}, {0x105B3, 0x105B9}, {0x105BB, 0x105BC}, - {0x105C0, 0x105F3}, {0x10600, 0x10736}, {0x10740, 0x10755}, {0x10760, 0x10767}, - {0x10780, 0x10785}, {0x10787, 0x107B0}, {0x107B2, 0x107BF}, {0x10800, 0x10805}, - {0x10808, 0x10808}, {0x1080A, 0x10835}, {0x10837, 0x10838}, {0x1083C, 0x1083C}, - {0x1083F, 0x10855}, {0x10860, 0x10876}, {0x10880, 0x1089E}, {0x108E0, 0x108F2}, - {0x108F4, 0x108F5}, {0x10900, 0x10915}, {0x10920, 0x10939}, {0x10940, 0x10959}, - {0x10980, 0x109B7}, {0x109BE, 0x109BF}, {0x10A00, 0x10A03}, {0x10A05, 0x10A06}, - {0x10A0C, 0x10A13}, {0x10A15, 0x10A17}, {0x10A19, 0x10A35}, {0x10A38, 0x10A3A}, - {0x10A3F, 0x10A3F}, {0x10A60, 0x10A7C}, {0x10A80, 0x10A9C}, {0x10AC0, 0x10AC7}, - {0x10AC9, 0x10AE6}, {0x10B00, 0x10B35}, {0x10B40, 0x10B55}, {0x10B60, 0x10B72}, - {0x10B80, 0x10B91}, {0x10C00, 0x10C48}, {0x10C80, 0x10CB2}, {0x10CC0, 0x10CF2}, - {0x10D00, 0x10D27}, {0x10D30, 0x10D39}, {0x10D40, 0x10D65}, {0x10D69, 0x10D6D}, - {0x10D6F, 0x10D85}, {0x10E80, 0x10EA9}, {0x10EAB, 0x10EAC}, {0x10EB0, 0x10EB1}, - {0x10EC2, 0x10EC7}, {0x10ECB, 0x10ECF}, {0x10ED9, 0x10EEE}, {0x10EF0, 0x10F1C}, - {0x10F27, 0x10F27}, {0x10F30, 0x10F50}, {0x10F70, 0x10F85}, {0x10FB0, 0x10FC4}, - {0x10FE0, 0x10FF6}, {0x11000, 0x11046}, {0x11066, 0x11075}, {0x1107F, 0x110BA}, - {0x110C2, 0x110C2}, {0x110D0, 0x110E8}, {0x110F0, 0x110F9}, {0x11100, 0x11134}, - {0x11136, 0x1113F}, {0x11144, 0x11147}, {0x11150, 0x11173}, {0x11176, 0x11176}, - {0x11180, 0x111C4}, {0x111C9, 0x111CC}, {0x111CE, 0x111DA}, {0x111DC, 0x111DC}, - {0x11200, 0x11211}, {0x11213, 0x11237}, {0x1123E, 0x11241}, {0x11280, 0x11286}, - {0x11288, 0x11288}, {0x1128A, 0x1128D}, {0x1128F, 0x1129D}, {0x1129F, 0x112A8}, - {0x112B0, 0x112EA}, {0x112F0, 0x112F9}, {0x11300, 0x11303}, {0x11305, 0x1130C}, - {0x1130F, 0x11310}, {0x11313, 0x11328}, {0x1132A, 0x11330}, {0x11332, 0x11333}, - {0x11335, 0x11339}, {0x1133B, 0x11344}, {0x11347, 0x11348}, {0x1134B, 0x1134D}, - {0x11350, 0x11350}, {0x11357, 0x11357}, {0x1135D, 0x11363}, {0x11366, 0x1136C}, - {0x11370, 0x11374}, {0x11380, 0x11389}, {0x1138B, 0x1138B}, {0x1138E, 0x1138E}, - {0x11390, 0x113B5}, {0x113B7, 0x113C0}, {0x113C2, 0x113C2}, {0x113C5, 0x113C5}, - {0x113C7, 0x113CA}, {0x113CC, 0x113D3}, {0x113E1, 0x113E2}, {0x11400, 0x1144A}, - {0x11450, 0x11459}, {0x1145E, 0x11461}, {0x11480, 0x114C5}, {0x114C7, 0x114C7}, - {0x114D0, 0x114D9}, {0x11580, 0x115B5}, {0x115B8, 0x115C0}, {0x115D8, 0x115DD}, - {0x11600, 0x11640}, {0x11644, 0x11644}, {0x11650, 0x11659}, {0x11680, 0x116B8}, - {0x116C0, 0x116C9}, {0x116D0, 0x116E3}, {0x11700, 0x1171A}, {0x1171D, 0x1172B}, - {0x11730, 0x11739}, {0x11740, 0x11746}, {0x11800, 0x1183A}, {0x118A0, 0x118E9}, - {0x118FF, 0x11906}, {0x11909, 0x11909}, {0x1190C, 0x11913}, {0x11915, 0x11916}, - {0x11918, 0x11935}, {0x11937, 0x11938}, {0x1193B, 0x11943}, {0x11950, 0x11959}, - {0x119A0, 0x119A7}, {0x119AA, 0x119D7}, {0x119DA, 0x119E1}, {0x119E3, 0x119E4}, - {0x11A00, 0x11A3E}, {0x11A47, 0x11A47}, {0x11A50, 0x11A99}, {0x11A9D, 0x11A9D}, - {0x11AB0, 0x11AF8}, {0x11B0A, 0x11B0A}, {0x11B60, 0x11B67}, {0x11BC0, 0x11BE0}, - {0x11BF0, 0x11BF9}, {0x11C00, 0x11C08}, {0x11C0A, 0x11C36}, {0x11C38, 0x11C40}, - {0x11C50, 0x11C59}, {0x11C72, 0x11C8F}, {0x11C92, 0x11CA7}, {0x11CA9, 0x11CB6}, - {0x11D00, 0x11D06}, {0x11D08, 0x11D09}, {0x11D0B, 0x11D36}, {0x11D3A, 0x11D3A}, - {0x11D3C, 0x11D3D}, {0x11D3F, 0x11D47}, {0x11D50, 0x11D59}, {0x11D60, 0x11D65}, - {0x11D67, 0x11D68}, {0x11D6A, 0x11D8E}, {0x11D90, 0x11D91}, {0x11D93, 0x11D98}, - {0x11DA0, 0x11DA9}, {0x11DB0, 0x11DDB}, {0x11DE0, 0x11DE9}, {0x11DF0, 0x11DF1}, - {0x11EE0, 0x11EF6}, {0x11F00, 0x11F10}, {0x11F12, 0x11F3A}, {0x11F3E, 0x11F42}, - {0x11F50, 0x11F5A}, {0x11FB0, 0x11FB0}, {0x12000, 0x12399}, {0x12400, 0x1246F}, - {0x12475, 0x12543}, {0x12550, 0x12686}, {0x12F90, 0x12FF0}, {0x13000, 0x1342F}, - {0x13440, 0x13455}, {0x13460, 0x143FA}, {0x14400, 0x14646}, {0x16100, 0x16139}, - {0x16800, 0x16A38}, {0x16A40, 0x16A5E}, {0x16A60, 0x16A69}, {0x16A70, 0x16ABE}, - {0x16AC0, 0x16AC9}, {0x16AD0, 0x16AED}, {0x16AF0, 0x16AF4}, {0x16B00, 0x16B36}, - {0x16B40, 0x16B43}, {0x16B50, 0x16B59}, {0x16B63, 0x16B77}, {0x16B7D, 0x16B8F}, - {0x16D40, 0x16D6C}, {0x16D70, 0x16D79}, {0x16E40, 0x16E7F}, {0x16EA0, 0x16EB8}, - {0x16EBB, 0x16ED3}, {0x16F00, 0x16F4A}, {0x16F4F, 0x16F87}, {0x16F8F, 0x16F9F}, - {0x16FE0, 0x16FE1}, {0x16FE3, 0x16FE4}, {0x16FF0, 0x16FF6}, {0x17000, 0x18CDA}, - {0x18CFF, 0x18D20}, {0x18D80, 0x18DF2}, {0x18E00, 0x19191}, {0x191A0, 0x191D2}, - {0x1AFF0, 0x1AFF3}, {0x1AFF5, 0x1AFFB}, {0x1AFFD, 0x1AFFE}, {0x1B000, 0x1B128}, - {0x1B132, 0x1B132}, {0x1B150, 0x1B152}, {0x1B155, 0x1B155}, {0x1B164, 0x1B168}, - {0x1B170, 0x1B2FB}, {0x1BC00, 0x1BC6A}, {0x1BC70, 0x1BC7C}, {0x1BC80, 0x1BC88}, - {0x1BC90, 0x1BC99}, {0x1BC9D, 0x1BC9E}, {0x1CCF0, 0x1CCF9}, {0x1CF00, 0x1CF2D}, - {0x1CF30, 0x1CF46}, {0x1D127, 0x1D128}, {0x1D165, 0x1D169}, {0x1D16D, 0x1D172}, - {0x1D17B, 0x1D182}, {0x1D185, 0x1D18B}, {0x1D1AA, 0x1D1AD}, {0x1D242, 0x1D244}, - {0x1D250, 0x1D252}, {0x1D25B, 0x1D25C}, {0x1D25F, 0x1D25F}, {0x1D280, 0x1D281}, - {0x1D400, 0x1D454}, {0x1D456, 0x1D49C}, {0x1D49E, 0x1D49F}, {0x1D4A2, 0x1D4A2}, - {0x1D4A5, 0x1D4A6}, {0x1D4A9, 0x1D4AC}, {0x1D4AE, 0x1D4B9}, {0x1D4BB, 0x1D4BB}, - {0x1D4BD, 0x1D4C3}, {0x1D4C5, 0x1D505}, {0x1D507, 0x1D50A}, {0x1D50D, 0x1D514}, - {0x1D516, 0x1D51C}, {0x1D51E, 0x1D539}, {0x1D53B, 0x1D53E}, {0x1D540, 0x1D544}, - {0x1D546, 0x1D546}, {0x1D54A, 0x1D550}, {0x1D552, 0x1D6A6}, {0x1D6A8, 0x1D6C0}, - {0x1D6C2, 0x1D6DA}, {0x1D6DC, 0x1D6FA}, {0x1D6FC, 0x1D714}, {0x1D716, 0x1D734}, - {0x1D736, 0x1D74E}, {0x1D750, 0x1D76E}, {0x1D770, 0x1D788}, {0x1D78A, 0x1D7A8}, - {0x1D7AA, 0x1D7C2}, {0x1D7C4, 0x1D7CB}, {0x1D7CE, 0x1D7FF}, {0x1DA00, 0x1DA36}, - {0x1DA3B, 0x1DA6C}, {0x1DA75, 0x1DA75}, {0x1DA84, 0x1DA84}, {0x1DA9B, 0x1DA9F}, - {0x1DAA1, 0x1DAAF}, {0x1DF00, 0x1DF81}, {0x1DF90, 0x1DF96}, {0x1DFCD, 0x1E006}, - {0x1E008, 0x1E018}, {0x1E01B, 0x1E021}, {0x1E023, 0x1E024}, {0x1E026, 0x1E02A}, - {0x1E030, 0x1E06D}, {0x1E08F, 0x1E08F}, {0x1E100, 0x1E12C}, {0x1E130, 0x1E13D}, - {0x1E140, 0x1E149}, {0x1E14E, 0x1E14E}, {0x1E290, 0x1E2AE}, {0x1E2C0, 0x1E2F9}, - {0x1E4D0, 0x1E4F9}, {0x1E5D0, 0x1E5FA}, {0x1E6C0, 0x1E6DE}, {0x1E6E0, 0x1E6F5}, - {0x1E6FE, 0x1E6FF}, {0x1E7E0, 0x1E7E6}, {0x1E7E8, 0x1E7EB}, {0x1E7ED, 0x1E7EE}, - {0x1E7F0, 0x1E7FE}, {0x1E800, 0x1E8C4}, {0x1E8D0, 0x1E8D6}, {0x1E900, 0x1E94B}, - {0x1E950, 0x1E959}, {0x1EE00, 0x1EE03}, {0x1EE05, 0x1EE1F}, {0x1EE21, 0x1EE22}, - {0x1EE24, 0x1EE24}, {0x1EE27, 0x1EE27}, {0x1EE29, 0x1EE32}, {0x1EE34, 0x1EE37}, - {0x1EE39, 0x1EE39}, {0x1EE3B, 0x1EE3B}, {0x1EE42, 0x1EE42}, {0x1EE47, 0x1EE47}, - {0x1EE49, 0x1EE49}, {0x1EE4B, 0x1EE4B}, {0x1EE4D, 0x1EE4F}, {0x1EE51, 0x1EE52}, - {0x1EE54, 0x1EE54}, {0x1EE57, 0x1EE57}, {0x1EE59, 0x1EE59}, {0x1EE5B, 0x1EE5B}, - {0x1EE5D, 0x1EE5D}, {0x1EE5F, 0x1EE5F}, {0x1EE61, 0x1EE62}, {0x1EE64, 0x1EE64}, - {0x1EE67, 0x1EE6A}, {0x1EE6C, 0x1EE72}, {0x1EE74, 0x1EE77}, {0x1EE79, 0x1EE7C}, - {0x1EE7E, 0x1EE7E}, {0x1EE80, 0x1EE89}, {0x1EE8B, 0x1EE9B}, {0x1EEA1, 0x1EEA3}, - {0x1EEA5, 0x1EEA9}, {0x1EEAB, 0x1EEBB}, {0x1FBF0, 0x1FBF9}, {0x20000, 0x2A6DF}, - {0x2A700, 0x2B81E}, {0x2B820, 0x2CEAD}, {0x2CEB0, 0x2EBE0}, {0x2EBF0, 0x2EE5D}, - {0x2F800, 0x2FA1D}, {0x30000, 0x3134A}, {0x31350, 0x33479}, {0x3D000, 0x3FC3F}, - {0xE0100, 0xE01EF}, -}}; -} // namespace cel::detail -#endif diff --git a/tests/cursor_copy_fail.cpp b/tests/cursor_copy_fail.cpp index b1f6aff..92fa413 100644 --- a/tests/cursor_copy_fail.cpp +++ b/tests/cursor_copy_fail.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSL-1.0 -#include "lexer.hpp" +#include "../src/lexer.hpp" #include /// Attempts to clone a forward-only cursor; compilation must fail. int main() { diff --git a/tests/expression_test.cpp b/tests/expression_test.cpp index f9af35b..4dc7418 100644 --- a/tests/expression_test.cpp +++ b/tests/expression_test.cpp @@ -1,6 +1,4 @@ // SPDX-License-Identifier: BSL-1.0 -#include "compiler.hpp" -#include "lookup_access.hpp" #include #include #include @@ -9,20 +7,9 @@ #include #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include +#include namespace { -/// Collects an external producer stream for the public borrowed-token boundary. -/// Complexity: O(source bytes + tokens) time and storage. -std::vector tokens(std::string_view source) { - cel::parser_detail::lex_lexer lexer(source); - std::vector result; - do { - result.push_back(lexer.current()); - if (std::holds_alternative(lexer.current().value)) break; - lexer.advance(); - } while (true); - return result; -} /// Compiles and executes text with a fresh caller stack. /// Complexity: O(compilation + execution). cel::value evaluate(cel::parser& parser, std::string_view text) { @@ -134,48 +121,6 @@ TEST_CASE("retained precedence associativity casts and IEEE numeric spellings") } } -TEST_CASE("numeric values require floating literal forms without integer coercion") { - cel::parser parser{cel::op_lookup{}}; - for (const auto& [text, span] : std::array{ - std::pair{"1", cel::source_span{0, 1}}, std::pair{"1 as f64", cel::source_span{0, 1}}, - std::pair{"1+2.0", cel::source_span{0, 1}}, std::pair{"1.0+1", cel::source_span{4, 5}}, - std::pair{"(|x:f64|x)(1)", cel::source_span{11, 12}}, - std::pair{"0x10", cel::source_span{0, 4}}, std::pair{"0b10", cel::source_span{0, 4}}, - std::pair{"0o10", cel::source_span{0, 4}}, std::pair{"0b1f64", cel::source_span{0, 6}}, - std::pair{"0o7_f64", cel::source_span{0, 7}}, - std::pair{"0x1f64", cel::source_span{0, 6}}}) { - CAPTURE(text); - error_at(parser, text, cel::error_category::unsupported_literal, span); - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, tokens(text)), - cel::parse_error); - } - CHECK(evaluate(parser, "1.0+2.0").as() == 3.0); - CHECK(evaluate(parser, "(|x:f64|x)(1.0)").as() == 1.0); - CHECK(evaluate(parser, "(1.0,2.0).0x1").as() == 2.0); -} - -TEST_CASE("decimal integer-form f64 literals produce floating values") { - cel::parser parser{cel::op_lookup{}}; - for (const auto& [text, expected] : std::array{ - std::pair{"1f64", 1.0}, std::pair{"0f64", 0.0}, std::pair{"1_f64", 1.0}, - std::pair{"1__f64", 1.0}, std::pair{"1_000f64", 1000.0}, - std::pair{"9007199254740993f64", 9007199254740992.0}, std::pair{"1e2f64", 100.0}, - std::pair{"1f64 + 2.0", 3.0}, std::pair{"-1f64", -1.0}, std::pair{"1f64 as f64", 1.0}, - std::pair{"(|x:f64|x)(1f64)", 1.0}}) { - CAPTURE(std::string_view(text)); - CHECK(evaluate(parser, text).as() == expected); - cel::raw_stack stack; - CHECK(cel::parser_detail::parser_access::parse_tokens(parser, tokens(text)) - .execute(stack, {}) - .as() == expected); - } - CHECK(std::signbit(evaluate(parser, "-0f64").as())); - for (auto text : {"1f64x", "1f64_", "1f640", "1f32", "1.0f64x", "(1.0,2.0).1f64"}) { - CAPTURE(text); - CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); - } -} - TEST_CASE("float exponent signs cannot follow underscores") { cel::parser parser{cel::op_lookup{}}; for (const auto& [text, expected] : @@ -190,20 +135,6 @@ TEST_CASE("float exponent signs cannot follow underscores") { } } -TEST_CASE("postfix brackets remain host input and are not core array indexing") { - cel::parser parser{cel::op_lookup{}}; - const auto input = tokens("[1.0][0.0]"); - CHECK_THROWS_AS(parser.parse_str("[1.0][0.0]"), cel::parse_error); - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, input), - cel::parse_error); - cel::parser_detail::token_cursor cursor(input); - const auto program = cel::parser_detail::parser_access::parse_expression(parser, cursor); - REQUIRE(std::holds_alternative(cursor.current().value)); - CHECK(cursor.current().span == cel::source_span{5, 6}); - cel::raw_stack stack; - CHECK(program.execute(stack, {}).at(0).as() == 1.0); -} - TEST_CASE("core lookup does not supply standard-library functions") { cel::parser parser{cel::op_lookup{}}; for (auto text : {"min(1.0,2.0)", "max(1.0,2.0)", "clamp(4.0,1.0,3.0)", "abs(-2.0)", @@ -267,32 +198,6 @@ TEST_CASE("complete expressions reject every bracket postfix form") { } } -TEST_CASE("all six range forms preserve complete type and endpoint order") { - cel::parser parser{cel::op_lookup{}}; - const auto forms = std::array{std::pair{"1.0 + 2.0..4.0 * 2.0", cel::range_kind::range}, - std::pair{"1.0..=3.0", cel::range_kind::range_inclusive}, - std::pair{"1.0..", cel::range_kind::range_from}, - std::pair{"..3.0", cel::range_kind::range_to}, - std::pair{"..=3.0", cel::range_kind::range_to_inclusive}, - std::pair{"..", cel::range_kind::range_full}}; - for (const auto& [text, kind] : forms) { - CAPTURE(text); - CHECK(evaluate(parser, text).type().form() == kind); - } - auto range = evaluate(parser, "1.0 + 2.0..4.0 * 2.0"); - CHECK(range.at(0).as() == 3); - CHECK(range.at(1).as() == 8); - for (auto text : {"..=", "1.0..=", "1.0..2.0..3.0", "true..false", "1.0==2.0..3.0==4.0"}) { - CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); - } - for (auto text : {"..else", "1.0..else", "..as", "1.0..as"}) { - const auto input = tokens(text); - cel::parser_detail::token_cursor cursor(input); - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_expression(parser, cursor), - cel::parse_error); - } -} - TEST_CASE("lazy branches compile both sides without executing callbacks") { std::vector trace; cel::op_lookup lookup; @@ -432,33 +337,6 @@ TEST_CASE( } } -TEST_CASE("independent closure scope isolation restores scopes after success and failure") { - cel::op_lookup lookup; - lookup.push_library_scope( - [](std::string_view name, cel::dyn_segment& b, std::size_t n, cel::source_span) { - if (name != "library" || n != 0) return false; - b.just(cel::value::from(7.0)); - return true; - }); - cel::parser_detail::lookup_access::push_scope( - lookup, [](std::string_view name, cel::dyn_segment& b, std::size_t n, cel::source_span) { - if (name != "ambient" || n != 0) return false; - b.just(cel::value::from(3.0)); - return true; - }); - cel::parser parser(std::move(lookup)); - CHECK(evaluate(parser, "ambient").as() == 3); - CHECK(evaluate(parser, "(|| library)()").as() == 7); - CHECK_THROWS_AS(parser.parse_str("|| ambient"), cel::parse_error); - CHECK(evaluate(parser, "ambient").as() == 3); - CHECK_THROWS_AS(parser.parse_str("|x:f64| || x"), cel::parse_error); - CHECK(evaluate(parser, "ambient").as() == 3); - CHECK(evaluate(parser, "(|ambient:f64| ambient)(9.0)").as() == 9); - CHECK(evaluate(parser, "ambient").as() == 3); - CHECK(evaluate(parser, "if true {ambient} else {0.0}").as() == 3); - CHECK(evaluate(parser, "(|ambient:bool| if ambient {1.0} else {2.0})(true)").as() == 1); -} - TEST_CASE("semantic record parameters custom members and explicit scalar call operations") { cel::op_lookup lookup; lookup.register_type("Alias"); @@ -535,97 +413,6 @@ TEST_CASE( CHECK(stack.pop()); } -TEST_CASE( - "text and token methods reject trailing input inline leaves host token diagnostics are owned") { - cel::parser parser{cel::op_lookup{}}; - auto input = tokens("1.0+2.0, host"); - cel::parser_detail::token_cursor cursor(input); - auto program = cel::parser_detail::parser_access::parse_expression(parser, cursor); - CHECK(std::get(cursor.current().value).spelling() == ","); - cel::raw_stack stack; - CHECK(program.execute(stack, {}).as() == 3); - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, input), - cel::parse_error); - CHECK(cel::parser_detail::parser_access::parse_tokens(parser, tokens("(1.0,2.0).1")) - .execute(stack, {}) - .as() == 2); - error_at(parser, "1.0 2.0", cel::error_category::malformed_input, {4, 7}); - error_at(parser, "[1.0,]", cel::error_category::malformed_input, {5, 6}); - error_at(parser, "(1.0]", cel::error_category::delimiter_error, {4, 5}); - error_at(parser, "missing", cel::error_category::lookup_error, {0, 7}); - error_at(parser, "[1.0,true]:[f64] ", cel::error_category::type_error, {0, 16}); - for (const auto& [text, expected] : - std::array{std::pair{"[]:(f64) , host", cel::source_span{3, 8}}, - std::pair{"[true]:([f64]) , host", cel::source_span{0, 14}}, - std::pair{"[[]:[bool]]:([[f64]]) , host", cel::source_span{0, 21}}}) { - CAPTURE(std::string_view(text)); - const auto annotated = tokens(text); - cel::parser_detail::token_cursor prefix(annotated); - try { - (void)cel::parser_detail::parser_access::parse_expression(parser, prefix); - FAIL("invalid annotation accepted"); - } catch (const cel::parse_error& error) { - CHECK(error.category() == cel::error_category::type_error); - CHECK(error.span() == expected); - } - CHECK(std::get(prefix.current().value).spelling() == ","); - } - auto invalid = std::array{cel::parser_detail::token{ - {20, 21}, - cel::parse_error(cel::error_category::unsupported_literal, {20, 21}, "producer")}}; - try { - (void)cel::parser_detail::parser_access::parse_tokens(parser, invalid); - FAIL("producer diagnostic ignored"); - } catch (const cel::parse_error& error) { - CHECK(error.category() == cel::error_category::unsupported_literal); - CHECK(error.span() == cel::source_span{20, 21}); - CHECK(std::string(error.what()) == "producer"); - } - const auto malformed = std::array{ - cel::parser_detail::token{ - {10, 11}, - cel::parser_detail::open_delimiter{cel::parser_detail::delimiter::parenthesis}}, - cel::parser_detail::token{{11, 14}, - cel::parser_detail::numeric_literal{ - 1, "1.0", "", cel::parser_detail::numeric_form::decimal}}, - cel::parser_detail::token{ - {14, 15}, cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::bracket}}}; - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, malformed), - cel::parse_error); - const auto invisible = std::array{ - cel::parser_detail::token{ - {0, 0}, cel::parser_detail::open_delimiter{cel::parser_detail::delimiter::none}}, - cel::parser_detail::token{ - {0, 0}, cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::none}}}; - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, invisible), - cel::parse_error); - auto host_close = tokens("1.0+2.0"); - host_close.back() = {{7, 8}, - cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::brace}}; - cel::parser_detail::token_cursor host(host_close); - CHECK(cel::parser_detail::parser_access::parse_expression(parser, host) - .execute(stack, {}) - .as() == 3); - CHECK(std::holds_alternative(host.current().value)); - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, host_close), - cel::parse_error); - const auto terminal = std::array{ - cel::parser_detail::token{{0, 3}, - cel::parser_detail::numeric_literal{ - 1, "1.0", "", cel::parser_detail::numeric_form::decimal}}, - cel::parser_detail::token{{3, 3}, cel::parser_detail::end_token{}}, - cel::parser_detail::token{{4, 5}, cel::parser_detail::identifier{"ignored"}}}; - CHECK(cel::parser_detail::parser_access::parse_tokens(parser, terminal) - .execute(stack, {}) - .as() == 1); - const auto external_suffix = std::array{cel::parser_detail::token{ - {0, 4}, - cel::parser_detail::numeric_literal{1, "1i32", "i32", - cel::parser_detail::numeric_form::integer}}}; - CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, external_suffix), - cel::parse_error); -} - TEST_CASE("recursive input has source resource diagnostics flat chains remain iterative") { cel::op_lookup lookup; lookup.register_op("step", [](double x) { return x; }); diff --git a/tests/lexer_copy_fail.cpp b/tests/lexer_copy_fail.cpp index 079e2c9..1f902f3 100644 --- a/tests/lexer_copy_fail.cpp +++ b/tests/lexer_copy_fail.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSL-1.0 -#include "lexer.hpp" +#include "../src/lexer.hpp" #include /// Attempts to clone a primed lexer; compilation must fail. int main() { diff --git a/tests/lookup_test.cpp b/tests/lookup_test.cpp index 4920998..915567a 100644 --- a/tests/lookup_test.cpp +++ b/tests/lookup_test.cpp @@ -1,5 +1,4 @@ // SPDX-License-Identifier: BSL-1.0 -#include "lookup_access.hpp" #include #include #include @@ -10,26 +9,14 @@ #include #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include +#include namespace { -/// Distinguishes equal-layout client operands by nominal identity. -struct first { - double number; -}; -/// Distinguishes a second client operand with the same layout. -struct second { - double number; -}; /// Supplies one adapter-backed nominal record for parser registration tests. struct adapted_point { double x; double y; }; -/// Supplies a same-layout second nominal record. -struct adapted_point_alias { - double x; - double y; -}; /// Supplies a second adapter for the same nominal identity. struct adapted_point_duplicate_name { double x; @@ -39,44 +26,6 @@ struct adapted_point_duplicate_name { struct adapted_unspellable_field { double value; }; -/// Marks an ordinary registered function independently of its operand overloads. -struct named_function {}; -/// Marks an independent installer's binding of the same function name. -struct other_marker {}; -/// Owns a copyable, nonmovable over-aligned registered callback. -struct alignas(256) copy_only_factor { - double factor; ///< Owns the multiplication factor. - /// Initializes the factor. - explicit copy_only_factor(double input) : factor(input) {} - /// Copies the factor independently. - copy_only_factor(const copy_only_factor&) = default; - /// Disallows move construction. - copy_only_factor(copy_only_factor&&) = delete; - /// Multiplies the operand by the owned factor. - double operator()(double input) const { return factor * input; } -}; -/// Marks a function with a valid over-aligned opaque client leaf. -struct alignas(256) aligned_marker { - double number; ///< Owns observable marker state. -}; -/// Evaluates a complete ordinary program through the public prepared boundary. -/// Complexity: O(compiled operations + native conversion + callback execution). -template -R evaluate(cel::dyn_segment builder) { - auto program = std::move(builder).finish(); - auto prepared = program.template prepare(); - cel::raw_stack stack; - return prepared.call(stack); -} -/// Emits source-ordered native operands, applies a name, and evaluates its result. -/// Complexity: O(arity + matching + compiled operations + conversion + callback execution). -template -R operation(const cel::op_lookup& lookup, std::string_view name, A... arguments) { - cel::dyn_segment builder; - (builder.just(cel::value::from(arguments)), ...); - cel::parser_detail::lookup_access::apply(lookup, name, builder, sizeof...(A), {10, 14}); - return evaluate(std::move(builder)); -} } // namespace namespace cel { @@ -101,27 +50,6 @@ struct record_adapter<::adapted_point> { } }; -template <> -struct record_adapter<::adapted_point_alias> { - /// Returns the canonical nominal descriptor for adapted_point_alias. - static value_type type() { - static const auto descriptor = value_type::record( - "AdapterPointAlias", std::array{record_field{"x", value_type::leaf()}, - record_field{"y", value_type::leaf()}}); - return descriptor; - } - /// Encodes one alias value in canonical field order. - static value to_value(const ::adapted_point_alias& source) { - return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); - } - /// Decodes one alias value after descriptor validation. - static ::adapted_point_alias from_value(const value& source) { - if (!source.type().same_shape(type())) - throw std::invalid_argument("wrong adapted point alias type"); - return {.x = source.field("x").as(), .y = source.field("y").as()}; - } -}; - template <> struct record_adapter<::adapted_point_duplicate_name> { /// Returns the same nominal identity as adapted_point. @@ -164,187 +92,6 @@ struct record_adapter<::adapted_unspellable_field> { }; } // namespace cel -TEST_CASE("structural registrations reject nontrivial adapters without reserving names") { - cel::op_lookup lookup; - CHECK_THROWS_AS(lookup.register_type>("array"), std::invalid_argument); - CHECK_THROWS_AS(lookup.register_type>("tuple"), std::invalid_argument); - CHECK_THROWS_AS(lookup.register_function("marker", std::vector{}), - std::invalid_argument); - CHECK_THROWS_AS(lookup.register_function("marker", std::tuple{1.0}), std::invalid_argument); - CHECK_FALSE(lookup.find_type("array")); - CHECK_FALSE(lookup.find_type("tuple")); - lookup.register_type("array"); - lookup.register_type("tuple"); - lookup.register_function("marker", named_function{}); - CHECK_NOTHROW(operation(lookup, "marker")); -} - -TEST_CASE("lookup owns independent copies of over-aligned lvalue callbacks and markers") { - cel::op_lookup lookup; - copy_only_factor callback(3.0); - lookup.register_op("scale", callback); - callback.factor = 99.0; - CHECK(operation(lookup, "scale", 2.0) == 6.0); - aligned_marker marker{7.0}; - lookup.register_function("aligned", marker); - marker.number = 99.0; - CHECK(operation(lookup, "aligned").number == 7.0); -} - -TEST_CASE("native extension registrations preserve nested structural descriptors and origins") { - using nested = std::tuple, std::vector>>; - cel::op_lookup lookup; - lookup.register_op("copy_nested", [](nested input) { return input; }); - const nested input{{}, {{true, first{4.0}}}}; - const auto copied = operation(lookup, "copy_nested", input); - CHECK(std::get<1>(std::get<1>(copied)[0]).number == 4.0); - lookup.register_function("measure_named", named_function{}); - lookup.register_op("measure_named", [](first input) { return input.number; }); - cel::dyn_segment builder; - builder.just(cel::value::from(true)); - const auto prefix = builder.snapshot(); - cel::parser_detail::lookup_access::apply(lookup, "measure_named", builder, 0, {}); - builder.just(cel::value::from(first{9.0})); - cel::parser_detail::lookup_access::apply(lookup, "()", builder, 2, {}); - CHECK(builder.origin_below(1) == prefix); - builder.make_tuple(2, {}); - const auto result = evaluate>(std::move(builder)); - CHECK(std::get<0>(result)); - CHECK(std::get<1>(result) == 9.0); -} - -TEST_CASE("exact registrations preserve overload identity and callback lifetime") { - cel::dyn_segment compiled; - std::weak_ptr lifetime; - { - cel::op_lookup lookup; - lookup.register_type("First"); - lookup.register_type("Second"); - auto state = std::make_shared(3.0); - lifetime = state; - lookup.register_op("measure", - [state](first x) { return x.number + *state; }); - lookup.register_op("measure", [](second x) { return x.number * 2.0; }); - CHECK(operation(lookup, "measure", second{4.0}) == 8.0); - compiled.just(cel::value::from(first{4.0})); - cel::parser_detail::lookup_access::apply(lookup, "measure", compiled, 1, {1, 8}); - CHECK_THROWS_AS((lookup.register_op("measure", [](first) { return true; })), - std::invalid_argument); - CHECK_THROWS_AS(lookup.register_type("First"), std::invalid_argument); - } - CHECK_FALSE(lifetime.expired()); - CHECK(evaluate(std::move(compiled)) == 7.0); - CHECK(lifetime.expired()); -} - -TEST_CASE("scopes are LIFO and isolated bodies retain libraries and registrations") { - cel::op_lookup lookup; - lookup.register_op("constant", [] { return 1.0; }); - lookup.push_library_scope( - [](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { - if (n != "library" || a != 0) return false; - b.just(cel::value::from(2.0)); - return true; - }); - cel::parser_detail::lookup_access::push_scope( - lookup, [](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { - if (n != "constant" || a != 0) return false; - b.just(cel::value::from(3.0)); - return true; - }); - cel::parser_detail::lookup_access::push_scope( - lookup, [](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { - if (n != "constant" || a != 0) return false; - b.just(cel::value::from(4.0)); - return true; - }); - CHECK(operation(lookup, "constant") == 4.0); - cel::parser_detail::lookup_access::pop_scope(lookup); - CHECK(operation(lookup, "constant") == 3.0); - auto saved = cel::parser_detail::lookup_access::isolate_scopes(lookup); - CHECK(operation(lookup, "constant") == 1.0); - CHECK(operation(lookup, "library") == 2.0); - cel::parser_detail::lookup_access::restore_scopes(lookup, std::move(saved)); - CHECK(operation(lookup, "constant") == 3.0); -} - -TEST_CASE("ordinary named markers retain first binding and direct member selectors") { - cel::op_lookup lookup; - CHECK_THROWS_AS(lookup.register_function("bad_marker", std::tuple{}), std::invalid_argument); - CHECK_THROWS_AS(operation>(lookup, "bad_marker"), cel::parse_error); - lookup.register_function("convert", named_function{}); - lookup.register_function("convert", other_marker{}); - CHECK_THROWS_AS(lookup.register_function("elsewhere", named_function{}), std::invalid_argument); - lookup.register_op("convert", [](double x) { return x + 1.0; }); - cel::dyn_segment secondary; - secondary.just(cel::value::from(other_marker{})); - secondary.just(cel::value::from(4.0)); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "()", secondary, 2, {}), - cel::parse_error); - cel::dyn_segment builder; - builder.just(cel::value::from(true)); // Preserve a prefix beneath marker and arguments. - cel::parser_detail::lookup_access::apply(lookup, "convert", builder, 0, {}); - CHECK(builder.operand_types(1)[0].same_shape(cel::value_type::leaf())); - builder.just(cel::value::from(4.0)); - cel::parser_detail::lookup_access::apply(lookup, "()", builder, 2, {}); - builder.make_tuple(2, {}); - CHECK(evaluate>(std::move(builder)) == std::tuple{true, 5.0}); - cel::dyn_segment member; - member.just(cel::value::from(5.0)); - cel::parser_detail::lookup_access::apply(lookup, "convert", member, 1, {}, - cel::parser_detail::lookup_selector::member); - CHECK(evaluate(std::move(member)) == 6.0); -} - -TEST_CASE("declined overloads never execute and selected emitter failures propagate") { - cel::op_lookup lookup; - std::size_t invoked = 0; - lookup.register_op("fail", [&invoked](first) { - ++invoked; - return 1.0; - }); - cel::dyn_segment builder; - builder.just(cel::value::from(second{2.0})); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "fail", builder, 1, {2, 6}), - cel::parse_error); - CHECK(invoked == 0); - CHECK(evaluate(std::move(builder)).number == 2.0); - lookup.register_operation( - "setup_failure", {}, cel::value_type::leaf(), - [](cel::dyn_segment&, cel::source_span) { throw std::logic_error("selected failure"); }); - CHECK_THROWS_WITH(operation(lookup, "setup_failure"), "selected failure"); - lookup.register_op("throwing", - []() -> double { throw std::runtime_error("callback"); }); - CHECK_THROWS_WITH(operation(lookup, "throwing"), "callback"); -} - -TEST_CASE("record adapter registration preserves nominal types and member calls") { - cel::op_lookup lookup; - lookup.register_record_type("AdapterPoint"); - lookup.register_record_type("AdapterPointAlias"); - std::size_t adapted_point_calls = 0; - lookup.register_op("sum", [&adapted_point_calls](adapted_point input) { - ++adapted_point_calls; - return input.x + input.y; - }); - cel::dyn_segment mismatch; - mismatch.just(cel::value::from(adapted_point_alias{.x = 1.0, .y = 2.0})); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "sum", mismatch, 1, {}), - cel::parse_error); - CHECK(adapted_point_calls == 0); - CHECK(evaluate(std::move(mismatch)).x == 1.0); - lookup.register_op( - "sum", [](adapted_point_alias input) { return input.x - input.y; }); - cel::parser parser(std::move(lookup)); - cel::raw_stack stack; - CHECK( - parser.parse_str("AdapterPoint { y: 2.0, x: 1.0 }.sum()").execute(stack, {}).as() == - 3.0); - CHECK(parser.parse_str("AdapterPointAlias { y: 2.0, x: 1.0 }.sum()") - .execute(stack, {}) - .as() == -1.0); -} - TEST_CASE("record adapter registration rejects duplicate CEL source names") { cel::op_lookup lookup; lookup.register_record_type("AdapterPoint"); @@ -440,313 +187,3 @@ TEST_CASE("record registration accepts spellable field identifiers") { .execute(stack, {}) .as() == 2.0); } - -TEST_CASE("nominal records and arbitrary nested registration use public runtime emitters") { - cel::op_lookup lookup; - const auto field = cel::record_field{ - "payload", cel::value_type::array(cel::value_type::array(cel::value_type::tuple(std::array{ - cel::value_type::leaf(), cel::value_type::leaf()})))}; - lookup.register_record("Record", std::array{field}); - CHECK_THROWS_AS(lookup.register_record("Record", {}), std::invalid_argument); - const auto found = lookup.find_type("Record"); - if (!found) throw std::logic_error("registered record missing"); - auto schema = *found; - CHECK(schema.record_identity() == "Record"); - CHECK(schema.fields()[0].same_shape(field.type)); - using nested = std::vector>>; - lookup.register_op("copy", [](nested input) { return input; }); - nested input{{{true, 3.0}}}; - CHECK(operation(lookup, "copy", input) == input); - lookup.register_operation( - "payload", std::array{schema}, field.type, - [](cel::dyn_segment& b, cel::source_span) { b.project_record("payload"); }); - cel::dyn_segment builder; - builder.just(cel::value::record(schema, std::array{cel::value::from(input)})); - cel::parser_detail::lookup_access::apply(lookup, "payload", builder, 1, {}, - cel::parser_detail::lookup_selector::member); - CHECK(evaluate(std::move(builder)) == input); - const auto different_name = cel::value_type::record("OtherRecord", std::array{field}); - const auto alternate_payload = cel::value::from(std::vector>{{true}}); - const auto different_fields = cel::value_type::record( - "Record", std::array{cel::record_field{"payload", alternate_payload.type()}}); - for (const auto& record : { - cel::value::record(different_name, std::array{cel::value::from(input)}), - cel::value::record(different_fields, std::array{alternate_payload}), - }) { - cel::dyn_segment wrong; - wrong.just(record); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "payload", wrong, 1, {}), - cel::parse_error); - const auto operands = wrong.operand_types(1); - const bool retained = operands.size() == 1 && operands[0].compatible_with(record.type()); - CHECK(retained); - } -} - -TEST_CASE("retained operators use IEEE arithmetic and partial comparisons") { - cel::op_lookup lookup; - CHECK(operation(lookup, "+", 2.0, 3.0) == 5.0); - CHECK(operation(lookup, "-", 2.0, 3.0) == -1.0); - CHECK(operation(lookup, "*", 2.0, 3.0) == 6.0); - CHECK(operation(lookup, "/", 8.0, 2.0) == 4.0); - CHECK(operation(lookup, "%", -5.0, 2.0) == -1.0); - CHECK(std::signbit(operation(lookup, "-", 0.0))); - CHECK_THROWS_AS(operation(lookup, "+", 1.0), cel::parse_error); - CHECK(std::isinf(operation(lookup, "/", 1.0, 0.0))); - CHECK(std::isnan(operation(lookup, "/", 0.0, 0.0))); - CHECK(std::isnan(operation(lookup, "%", 1.0, 0.0))); - CHECK(operation(lookup, "!", false)); - CHECK(operation(lookup, "==", true, true)); - CHECK(operation(lookup, "!=", true, false)); - const double nan = std::numeric_limits::quiet_NaN(); - for (auto name : {"==", "<", "<=", ">", ">="}) { - CHECK_FALSE(operation(lookup, name, nan, 1.0)); - } - CHECK(operation(lookup, "!=", nan, nan)); - CHECK(operation(lookup, "==", -0.0, 0.0)); - CHECK(operation(lookup, "<", 1.0, 2.0)); - CHECK_FALSE(operation(lookup, "<", 2.0, 1.0)); - CHECK(operation(lookup, "<=", 2.0, 2.0)); - CHECK(operation(lookup, ">", 2.0, 1.0)); - CHECK_FALSE(operation(lookup, ">", 1.0, 2.0)); - CHECK(operation(lookup, ">=", 2.0, 2.0)); - for (auto name : {"&", "|", "^", "<<", ">>", "round"}) { - CHECK_THROWS_AS(operation(lookup, name, 1.0, 2.0), cel::parse_error); - } - lookup.register_op("+", [](double a, double b) { return a - b; }); - CHECK(operation(lookup, "+", 2.0, 3.0) == -1.0); -} - -TEST_CASE("standard numeric names are not parser-provided operations") { - cel::op_lookup lookup; - for (auto name : {"min", "max", "clamp", "abs", "signum", "sqrt", "floor", "ceil", "trunc", - "fract", "round_ties_even"}) { - CAPTURE(name); - CHECK_THROWS_AS(operation(lookup, name, -3.0), cel::parse_error); - } -} - -TEST_CASE("owned names schemas and scope captures survive registration input destruction") { - cel::dyn_segment builder; - cel::dyn_segment move_only_program; - std::optional schema; - { - cel::op_lookup lookup; - std::string name = "owned"; - lookup.register_op(name, - [state = std::make_unique(8.0)] { return *state; }); - cel::parser_detail::lookup_access::apply(lookup, name, move_only_program, 0, {}); - name.assign("changed"); - CHECK(operation(lookup, "owned") == 8.0); - std::array fields{cel::record_field{"field", cel::value_type::leaf()}}; - lookup.register_record("Owner", fields); - fields[0].name.assign("replaced"); - schema = lookup.find_type("Owner"); - auto state = std::make_unique(9.0); - auto captured = std::shared_ptr(std::move(state)); - cel::parser_detail::lookup_access::push_scope( - lookup, - [captured](std::string_view n, cel::dyn_segment& b, std::size_t a, cel::source_span) { - if (n != "scoped" || a != 0) return false; - b.op([captured] { return *captured; }); - return true; - }); - cel::parser_detail::lookup_access::apply(lookup, "scoped", builder, 0, {}); - } - if (!schema) throw std::logic_error("owned record missing"); - CHECK(schema->field_names()[0] == "field"); - CHECK(evaluate(std::move(move_only_program)) == 8.0); - CHECK(evaluate(std::move(builder)) == 9.0); - cel::op_lookup lookup; - CHECK_THROWS_AS(lookup.register_type("f64"), std::invalid_argument); - CHECK_THROWS_AS(lookup.register_type("i32"), std::invalid_argument); - CHECK_THROWS_AS(lookup.register_type(""), std::invalid_argument); - CHECK_THROWS_AS(lookup.register_type>("NotLeaf"), std::invalid_argument); - const auto field = cel::record_field{"x", cel::value_type::leaf()}; - CHECK_THROWS_AS(lookup.register_record("Bad", std::array{field, field}), std::invalid_argument); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::push_scope(lookup, {}), - std::invalid_argument); -} - -TEST_CASE("structural signatures follow operations and records project complete schemas") { - cel::op_lookup lookup; - using input_type = std::tuple>>; - const auto tuple_type = cel::value::from(input_type{true, {{3.0, false}}}).type(); - const auto vector_type = tuple_type.fields()[1]; - lookup.register_structural_op( - "part", std::array{tuple_type}, vector_type, - [](cel::dyn_segment& b, cel::source_span) { b.project_tuple(1); }); - CHECK(operation>>(lookup, "part", - input_type{true, {{3.0, false}}}) == - std::vector>{{3.0, false}}); - lookup.register_op>, input_type>( - "part", [](input_type) { return std::vector>{{5.0, true}}; }); - CHECK(operation>>(lookup, "part", input_type{true, {}}) == - std::vector>{{5.0, true}}); - lookup.register_record("Nominal", std::array{cel::record_field{"part", vector_type}}); - const auto found = lookup.find_type("Nominal"); - if (!found) throw std::logic_error("registered record missing"); - const auto schema = *found; - const auto payload = cel::value::from(std::vector>{{2.0, true}}); - cel::dyn_segment builder; - builder.just(cel::value::record(schema, std::array{payload})); - cel::parser_detail::lookup_access::apply(lookup, "part", builder, 1, {}, - cel::parser_detail::lookup_selector::member); - CHECK(evaluate>>(std::move(builder)) == - std::vector>{{2.0, true}}); - lookup.register_operation( - "part", std::array{schema}, vector_type, [](cel::dyn_segment& b, cel::source_span) { - b.project_record("part"); - b.op>, std::vector>>( - [](std::vector>) { - return std::vector>{{7.0, false}}; - }); - }); - cel::dyn_segment shadowed; - shadowed.just(cel::value::record(schema, std::array{payload})); - cel::parser_detail::lookup_access::apply(lookup, "part", shadowed, 1, {}, - cel::parser_detail::lookup_selector::member); - CHECK(evaluate>>(std::move(shadowed)) == - std::vector>{{7.0, false}}); - CHECK_THROWS_AS(operation(lookup, "==", input_type{true, {}}, input_type{true, {}}), - cel::parse_error); -} - -TEST_CASE("callable dispatch accepts complete nested parameters and client results") { - using input_type = std::tuple>>; - cel::dyn_segment body; - body.push_argument(0, cel::value::from(input_type{false, {}}).type()); - body.op([](input_type x) { return first{std::get<1>(x)[0][0]}; }); - cel::callable function(std::move(body).finish(), - std::array{cel::value::from(input_type{false, {}}).type()}); - cel::dyn_segment builder; - { - cel::op_lookup lookup; - builder.just(function.to_value()); - builder.just(cel::value::from(input_type{true, {{6.0}}})); - cel::parser_detail::lookup_access::apply(lookup, "()", builder, 2, {}); - } - CHECK(evaluate(std::move(builder)).number == 6.0); - cel::dyn_segment member; - member.just(function.to_value()); - member.just(cel::value::from(input_type{true, {{6.0}}})); - cel::op_lookup lookup; - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply( - lookup, "()", member, 2, {}, cel::parser_detail::lookup_selector::member), - cel::parse_error); - cel::dyn_segment missing_argument; - missing_argument.just(function.to_value()); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "()", missing_argument, 1, {}), - cel::parse_error); - CHECK(missing_argument.operand_types(1)[0].compatible_with(function.type())); - cel::dyn_segment wrong_argument; - wrong_argument.just(function.to_value()); - wrong_argument.just(cel::value::from(true)); - try { - cel::parser_detail::lookup_access::apply(lookup, "()", wrong_argument, 2, {3, 9}); - FAIL("wrong callable argument admitted"); - } catch (const cel::parse_error& error) { - CHECK(error.category() == cel::error_category::lookup_error); - CHECK(error.span() == cel::source_span{3, 9}); - } - CHECK(wrong_argument.operand_types(2)[1].compatible_with(cel::value_type::leaf())); -} - -TEST_CASE("range emitters and casts preserve exact retained types and diagnostics") { - cel::op_lookup lookup; - cel::raw_stack stack; - constexpr std::array forms{std::pair{"range", cel::range_kind::range}, - std::pair{"range_inclusive", cel::range_kind::range_inclusive}, - std::pair{"range_from", cel::range_kind::range_from}, - std::pair{"range_to", cel::range_kind::range_to}, - std::pair{"range_to_inclusive", cel::range_kind::range_to_inclusive}, - std::pair{"range_full", cel::range_kind::range_full}}; - for (auto [name, kind] : forms) { - cel::dyn_segment builder; - const auto arity = - kind == cel::range_kind::range_full ? 0U : - kind == cel::range_kind::range || kind == cel::range_kind::range_inclusive ? 2U : - 1U; - if (arity > 0) builder.just(cel::value::from(-0.0)); - if (arity > 1) builder.just(cel::value::from(std::numeric_limits::infinity())); - cel::parser_detail::lookup_access::apply(lookup, name, builder, arity, {}); - auto value = std::move(builder).finish().execute(stack, {}); - const bool same_form = value.type().form() == kind; - const bool same_count = value.size() == arity; - CHECK(same_form); - CHECK(same_count); - if (arity > 0) CHECK(std::signbit(value.at(0).as())); - if (arity > 1) CHECK(std::isinf(value.at(1).as())); - } - cel::dyn_segment number; - number.just(cel::value::from(-0.0)); - cel::parser_detail::lookup_access::apply_cast(lookup, "f64", number, {2, 8}); - CHECK(std::signbit(evaluate(std::move(number)))); - cel::dyn_segment boolean; - boolean.just(cel::value::from(true)); - cel::parser_detail::lookup_access::apply_cast(lookup, "bool", boolean, {}); - CHECK(evaluate(std::move(boolean))); - lookup.register_type("AliasD"); - for (auto target : {"bool", "f32", "i32", "String", "AliasD"}) { - cel::dyn_segment invalid; - invalid.just(cel::value::from(3.0)); - try { - cel::parser_detail::lookup_access::apply_cast(lookup, target, invalid, {4, 11}); - FAIL("unsupported cast accepted"); - } catch (const cel::parse_error& error) { - CHECK(error.span() == cel::source_span{4, 11}); - } - CHECK(evaluate(std::move(invalid)) == 3.0); - } - cel::dyn_segment empty; - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply_cast(lookup, "f64", empty, {}), - cel::parse_error); - CHECK_THROWS_AS(operation(lookup, "range", true, false), cel::parse_error); -} - -TEST_CASE("zero-argument functions skip value scopes during direct operation selection") { - cel::op_lookup lookup; - lookup.register_function("zero", named_function{}); - lookup.register_op("zero", [] { return 2.0; }); - cel::parser_detail::lookup_access::push_scope( - lookup, - [](std::string_view name, cel::dyn_segment& builder, std::size_t arity, cel::source_span) { - if (name != "zero" || arity != 0) return false; - builder.just(cel::value::from(7.0)); - return true; - }); - CHECK(operation(lookup, "zero") == 7.0); - cel::dyn_segment builder; - cel::parser_detail::lookup_access::apply(lookup, "zero", builder, 0, {}, - cel::parser_detail::lookup_selector::ordinary, - cel::parser_detail::scope_selection::library_only); - cel::parser_detail::lookup_access::apply(lookup, "()", builder, 1, {}); - CHECK(evaluate(std::move(builder)) == 2.0); -} - -TEST_CASE("function marker retirement preserves zero-byte source unit results") { - cel::op_lookup lookup; - lookup.register_function("unit", named_function{}); - lookup.register_op>("unit", [] { return std::tuple{}; }); - cel::dyn_segment builder; - cel::parser_detail::lookup_access::apply(lookup, "unit", builder, 0, {}); - cel::parser_detail::lookup_access::apply(lookup, "()", builder, 1, {}); - CHECK(evaluate>(std::move(builder)) == std::tuple{}); -} - -TEST_CASE("registered descriptors distinguish semantic equality from ownership compatibility") { - cel::dyn_segment body; - body.just(cel::value::from(3.0)); - cel::callable function(std::move(body).finish(), {}); - auto declared = cel::value_type::callable({}, cel::value_type::leaf()); - CHECK(declared.same_shape(function.type())); - REQUIRE_FALSE(declared.compatible_with(function.type())); - cel::op_lookup lookup; - lookup.register_operation( - "test", std::array{declared}, cel::value_type::leaf(), - [](cel::dyn_segment&, cel::source_span) { FAIL("incompatible ownership selected"); }); - cel::dyn_segment builder; - builder.just(function.to_value()); - CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "test", builder, 1, {}), - cel::parse_error); -} diff --git a/tests/parity_driver_test.cpp b/tests/parity_driver_test.cpp index f0d6840..3406dab 100644 --- a/tests/parity_driver_test.cpp +++ b/tests/parity_driver_test.cpp @@ -3,6 +3,7 @@ #include #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include +#include using namespace cel::parity; TEST_CASE("unrelated execution exceptions fail instead of matching selected error fixtures") { diff --git a/tests/tests.cpp b/tests/tests.cpp deleted file mode 100644 index 93e9c60..0000000 --- a/tests/tests.cpp +++ /dev/null @@ -1,395 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#include "lexer.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include - -#if defined(__APPLE__) -#include -#include -#include -#include -#endif - -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include - -/// Collects independently owned tokens through the forward-only interface. -std::vector collect(std::string_view text) { - cel::parser_detail::lex_lexer lexer(text); - std::vector result; - while (!std::holds_alternative(lexer.current().value)) { - result.push_back(lexer.current()); - lexer.advance(); - } - result.push_back(lexer.current()); - return result; -} - -TEST_CASE("bool specialization preserves exact and raw identifier names") { - auto t = collect("true false True true_ r#true _"); - REQUIRE(t.size() == 7); - CHECK(std::get(t[0].value)); - CHECK_FALSE(std::get(t[1].value)); - CHECK(std::get(t[2].value).spelling == "True"); - CHECK(std::get(t[3].value).spelling == "true_"); - CHECK(std::get(t[4].value).spelling == "r#true"); - CHECK(std::get(t[5].value).spelling == "_"); -} - -TEST_CASE("numbers retain scalar meaning and exact selector spelling") { - for (auto [text, expected] : - std::vector>{{"1", 1}, - {"1.25", 1.25}, - {"1f64", 1}, - {"2.5f64", 2.5}, - {"1e+2", 100}, - {"1_e+_2", 100}, - {"1_000", 1000}, - {"1.", 1}, - {"0xff", 255}, - {"0o_17", 15}, - {"0b_101_", 5}, - {"9007199254740993", 9007199254740992.0}}) { - INFO(text); - auto t = collect(text); - REQUIRE(t.size() == 2); - REQUIRE(std::holds_alternative(t[0].value)); - auto const& number = std::get(t[0].value); - CHECK(number.value == expected); - CHECK(number.spelling == text); - CHECK(t[0].span.begin == 0); - CHECK(t[0].span.end == text.size()); - } - auto t = collect(".0.1 1..2 1.foo 0.1e2 0f64"); - REQUIRE(t.size() == 11); - CHECK(std::get(t[0].value).spelling() == "."); - CHECK(std::get(t[1].value).spelling == "0.1"); - CHECK(std::get(t[1].value).form == - cel::parser_detail::numeric_form::decimal); - CHECK(std::get(t[3].value).spelling() == ".."); - CHECK(std::get(t[8].value).form == - cel::parser_detail::numeric_form::exponent); - CHECK(std::get(t[9].value).suffix == "f64"); -} - -TEST_CASE("exponent signs precede all exponent underscores") { - for (auto [text, expected] : - std::array{std::pair{"1e+_2f64", 100.0}, std::pair{"1e__2f64", 100.0}, - std::pair{"1e-__2f64", 0.01}, std::pair{"1.0E+__2f64", 100.0}}) { - INFO(std::string_view(text)); - auto t = collect(text); - REQUIRE(t.size() == 2); - REQUIRE(std::holds_alternative(t[0].value)); - auto const& number = std::get(t[0].value); - CHECK(number.value == expected); - CHECK(number.spelling == text); - CHECK(t[0].span == (cel::source_span{0, std::string_view(text).size()})); - } - for (auto text : {"1e_+2f64", "1e__-2f64", "1e_+_2f64", "1.0e_+2f64", "1E__+2f64", "1_e_+_2"}) { - INFO(std::string_view(text)); - auto t = collect(text); - REQUIRE(t.size() == 2); - REQUIRE(std::holds_alternative(t[0].value)); - auto const& error = std::get(t[0].value); - CHECK(error.category() == cel::error_category::malformed_input); - CHECK(error.span() == (cel::source_span{0, std::string_view(text).size()})); - } -} - -TEST_CASE("binary64 boundary conversion preserves Rust infinity and zero results") { - auto t = collect("1e9999 1e-9999 1.7976931348623157e308 " - "1.7976931348623159e308 5e-324 2e-324 0e9999"); - REQUIRE(t.size() == 8); - CHECK(std::isinf(std::get(t[0].value).value)); - CHECK(std::get(t[1].value).value == 0); - CHECK(std::get(t[2].value).value == - std::numeric_limits::max()); - CHECK(std::isinf(std::get(t[3].value).value)); - CHECK(std::get(t[4].value).value == - std::numeric_limits::denorm_min()); - CHECK(std::get(t[5].value).value == 0); - CHECK(std::get(t[6].value).value == 0); - auto huge = collect("0x" + std::string(1000, 'f')); - CHECK(std::isinf(std::get(huge[0].value).value)); - auto extremes = collect("0.0001e999999999999999999999 1000e-999999999999999999999"); - REQUIRE(extremes.size() == 3); - CHECK(std::isinf(std::get(extremes[0].value).value)); - CHECK(std::get(extremes[1].value).value == 0); -} - -#if defined(__APPLE__) -TEST_CASE("numeric conversion preserves the calling thread's floating-point environment") { - std::fenv_t saved; - REQUIRE(std::feholdexcept(&saved) == 0); - std::unique_ptr restore(&saved, std::fesetenv); - - for (const auto rounding : {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO}) { - INFO(rounding); - REQUIRE(std::fesetround(rounding) == 0); - REQUIRE(std::feclearexcept(FE_ALL_EXCEPT) == 0); - REQUIRE(std::feraiseexcept(FE_DIVBYZERO) == 0); - const auto flags = std::fetestexcept(FE_ALL_EXCEPT); - - const auto tokens = - collect("1.0000000000000001 0.99999999999999999 0x20000000000001 1e9999 1e-9999"); - CHECK(std::fegetround() == rounding); - CHECK(std::fetestexcept(FE_ALL_EXCEPT) == flags); - REQUIRE(tokens.size() == 6); - CHECK(std::get(tokens[0].value).value == 1.0); - CHECK(std::get(tokens[1].value).value == 1.0); - CHECK(std::get(tokens[2].value).value == - 9007199254740992.0); - CHECK(std::isinf(std::get(tokens[3].value).value)); - CHECK(std::get(tokens[4].value).value == 0.0); - } -} - -TEST_CASE("numeric conversion ignores the calling thread's numeric locale") { - using locale_type = std::remove_pointer_t; - std::unique_ptr locale( - newlocale(LC_NUMERIC_MASK, "de_DE.UTF-8", nullptr), freelocale); - REQUIRE(locale != nullptr); - const auto previous = uselocale(locale.get()); - REQUIRE(previous != nullptr); - const auto restore = [previous](locale_t current) { - uselocale(previous); - freelocale(current); - }; - std::unique_ptr active(locale.release(), restore); - - const auto tokens = collect("1.25 1_5e-1 0o17 0x20000000000001"); - REQUIRE(tokens.size() == 5); - CHECK(std::get(tokens[0].value).value == 1.25); - CHECK(std::get(tokens[1].value).value == 1.5); - CHECK(std::get(tokens[2].value).value == 15); - CHECK(std::get(tokens[3].value).value == - 9007199254740992.0); -} -#endif - -TEST_CASE("radix integers round ties without narrowing and retain exact spelling") { - constexpr std::array, 10> cases{{ - {"0b100000000000000000000000000000000000000000000000000001", 9007199254740992.0}, - {"0o400000000000000001", 9007199254740992.0}, - {"0x20000000000001", 9007199254740992.0}, - {"0b100000000000000000000000000000000000000000000000000011", 9007199254740996.0}, - {"0o400000000000000003", 9007199254740996.0}, - {"0x20000000000003", 9007199254740996.0}, - {"0b100000000000000000000000000000000000000000000000000000000000000000000000000000001", - 0x1p80}, - {"0o400000000000000000000000001", 0x1p80}, - {"0x100000000000000000001", 0x1p80}, - {"0o12_345", 5349.0}, - }}; - for (auto [text, expected] : cases) { - INFO(text); - const auto tokens = collect(text); - REQUIRE(tokens.size() == 2); - REQUIRE(std::holds_alternative(tokens[0].value)); - const auto& number = std::get(tokens[0].value); - CHECK(number.value == expected); - CHECK(number.spelling == text); - } -} - -TEST_CASE("joint compounds use maximal supported matching and full byte spans") { - for (auto text : - {"&&", "||", "==", "!=", "<=", ">=", "<<", ">>", "->", "=>", ":=", "..", "..="}) { - auto t = collect(text); - REQUIRE(t.size() == 2); - CHECK(std::get(t[0].value).spelling() == text); - CHECK(t[0].span.end == std::string_view(text).size()); - } - auto t = collect("& & &/**/ & &//x\n& .. = ..== +++ ::"); - REQUIRE(t.size() == 16); - CHECK(std::get(t[6].value).spelling() == ".."); - CHECK(std::get(t[8].value).spelling() == "..="); - CHECK(std::get(t[9].value).spelling() == "="); -} - -TEST_CASE("comments distinguish doc metadata and preserve nested contents") { - auto t = collect("//// ordinary\n/**/ /*** ordinary */ /// outer\r\n" - "//!inner\n/** block /*nested*/ text */ /*! inside */ true"); - REQUIRE(t.size() == 6); - CHECK(std::get(t[0].value).text == " outer"); - CHECK_FALSE(std::get(t[0].value).inner); - CHECK(std::get(t[1].value).inner); - CHECK(std::get(t[2].value).text == " block /*nested*/ text "); - CHECK(std::get(t[3].value).text == " inside "); - CHECK(std::get(t[4].value)); -} - -TEST_CASE("comment markers at EOF remain bounded") { - CHECK(collect("//").size() == 1); - auto t = collect("/*"); - REQUIRE(t.size() == 2); - CHECK(std::get(t[0].value).category() == - cel::error_category::malformed_input); -} - -TEST_CASE("Unicode identifiers and producer whitespace retain byte boundaries") { - auto t = collect("\xce\xb1\xcc\x81 " - "\xc2\xa0\xe2\x80\x8e\xe2\x80\x8f\xe6\x97\xa5\xe6\x9c\xac " - "\xf0\xbd\x80\x80"); - REQUIRE(t.size() == 4); - CHECK(std::get(t[0].value).spelling == "\xce\xb1\xcc\x81"); - CHECK(t[0].span.begin == 0); - CHECK(t[0].span.end == 4); - CHECK(std::get(t[1].value).spelling == - "\xe6\x97\xa5\xe6\x9c\xac"); - CHECK(t[1].span.begin == 13); - CHECK(t[1].span.end == 19); - CHECK(std::get(t[2].value).spelling == "\xf0\xbd\x80\x80"); -} - -TEST_CASE("diagnostics identify unsupported versus malformed input") { - for (auto text : {"1f32", "1u8", "1.0i32", "1\xe5\x90\x8d\xe5\xad\x97", "\"text\"", "'x'", - "b\"x\"", "r#\"x\"#", "br##\"x\"##", "c\"x\""}) { - INFO(text); - auto t = collect(text); - REQUIRE(t.size() == 2); - REQUIRE(std::holds_alternative(t[0].value)); - auto const& error = std::get(t[0].value); - CHECK(error.category() == cel::error_category::unsupported_literal); - CHECK(error.span().begin == 0); - CHECK(error.span().end == std::string_view(text).size()); - CHECK(error.span() == (cel::source_span{0, std::string_view(text).size()})); - CHECK((error.what()[0] != '\0')); - } - auto incomplete = collect("1e+"); - REQUIRE(incomplete.size() == 2); - auto const& error = std::get(incomplete[0].value); - CHECK(error.category() == cel::error_category::unsupported_literal); - CHECK(error.span().end == 2); - for (auto text : {"0x", "0b2", "\"unfinished", "/*unfinished", "///bare\rCR", "\xcc\x81", - "\xf0\x9f\x98\x80", "r#self"}) { - INFO(text); - auto t = collect(text); - REQUIRE(std::holds_alternative(t[t.size() - 2].value)); - CHECK(std::get(t[t.size() - 2].value).category() == - cel::error_category::malformed_input); - } -} - -TEST_CASE("malformed UTF8 locates the first invalid byte even in trivia") { - for (auto bytes : - {std::string("\x80", 1), std::string("\xc0\xaf", 2), std::string("\xed\xa0\x80", 3), - std::string("\xf4\x90\x80\x80", 4), std::string("\xe2\x82", 2)}) { - auto t = collect("/*" + bytes); - REQUIRE(t.size() == 2); - auto const& error = std::get(t[0].value); - CHECK(error.category() == cel::error_category::malformed_input); - CHECK(error.span().begin == 2); - CHECK(error.span().end == 3); - } -} - -TEST_CASE("delimiter checking handles deep valid and malformed input iteratively") { - auto t = collect("({[]})"); - REQUIRE(t.size() == 7); - CHECK(std::get(t[0].value).kind == - cel::parser_detail::delimiter::parenthesis); - CHECK(std::get(t[5].value).kind == - cel::parser_detail::delimiter::parenthesis); - for (auto text : {")", "([)]", "{"}) { - auto errors = collect(text); - auto const& error = std::get(errors[errors.size() - 2].value); - CHECK(error.category() == cel::error_category::delimiter_error); - } - std::string deep(50000, '('); - auto malformed = collect(deep); - CHECK(std::get(malformed[malformed.size() - 2].value).span().begin == 49999); - deep += std::string(50000, ')'); - CHECK(collect(deep).size() == 100001); - std::string comments; - for (int i = 0; i != 50000; ++i) - comments += "/*"; - for (int i = 0; i != 50000; ++i) - comments += "*/"; - CHECK(collect(comments).size() == 1); -} - -TEST_CASE("owned payload copies survive sources adapters and mutations") { - std::vector t; - { - std::string source = "identifier 1_2f64 ///text"; - t = collect(source); - source.assign(source.size(), 'x'); - } - auto copy = t; - std::get(copy[0].value).spelling = "changed"; - CHECK(std::get(t[0].value).spelling == "identifier"); - CHECK(std::get(t[1].value).spelling == "1_2f64"); - CHECK(std::get(t[2].value).text == "text"); - cel::parser_detail::lex_lexer lexer(std::string("temporary")); - CHECK(std::get(lexer.current().value).spelling == "temporary"); - std::string lazy_source = "alpha beta"; - cel::parser_detail::lex_lexer lazy(lazy_source); - lazy_source.assign(lazy_source.size(), 'x'); - lazy.advance(); - CHECK(std::get(lazy.current().value).spelling == "beta"); -} - -TEST_CASE("flattened producer cursor preserves current payload error and EOF laws") { - std::vector tokens{{{4, 5}, true}, - {{6, 7}, cel::parser_detail::identifier{"x"}}}; - cel::parser_detail::token_cursor cursor(tokens); - CHECK(std::get(cursor.current().value)); - cursor.advance(); - CHECK(std::get(cursor.current().value).spelling == "x"); - cursor.advance(); - CHECK(std::holds_alternative(cursor.current().value)); - CHECK(cursor.current().span.end == 7); - cursor.advance(); - CHECK(cursor.current().span.begin == 7); - cel::parser_detail::token_cursor empty(std::span{}); - CHECK(std::holds_alternative(empty.current().value)); - std::vector errors{ - {{2, 3}, cel::parse_error(cel::error_category::malformed_input, {2, 3}, "producer error")}, - {{4, 5}, true}}; - cel::parser_detail::token_cursor failed(errors); - CHECK(std::get(failed.current().value).span().begin == 2); - failed.advance(); - CHECK(std::holds_alternative(failed.current().value)); - cel::parser_detail::lex_lexer eof(" \n"); - CHECK(eof.current().span.begin == 2); - eof.advance(); - CHECK(eof.current().span.end == 2); - std::array explicit_end{ - cel::parser_detail::token{{8, 8}, cel::parser_detail::end_token{}}, - cel::parser_detail::token{{9, 10}, true}}; - cel::parser_detail::token_cursor terminal(explicit_end); - terminal.advance(); - CHECK(std::holds_alternative(terminal.current().value)); - CHECK(terminal.current().span.begin == 8); - std::array invisible{ - cel::parser_detail::token{ - {2, 5}, cel::parser_detail::open_delimiter{cel::parser_detail::delimiter::none}}, - cel::parser_detail::token{ - {2, 5}, cel::parser_detail::close_delimiter{cel::parser_detail::delimiter::none}}}; - cel::parser_detail::token_cursor groups(invisible); - CHECK(std::get(groups.current().value).kind == - cel::parser_detail::delimiter::none); - groups.advance(); - CHECK(std::get(groups.current().value).kind == - cel::parser_detail::delimiter::none); - CHECK(groups.current().span == (cel::source_span{2, 5})); -} - -TEST_CASE("inline punctuation validates caller input and owns its bytes") { - std::string source = "..="; - cel::parser_detail::punctuation punct(source); - source.assign(3, 'x'); - CHECK(punct.spelling() == "..="); - for (auto invalid : {"", "....", "abc", "\xce\xb1"}) { - CHECK_THROWS_AS(cel::parser_detail::punctuation{invalid}, std::invalid_argument); - } -} diff --git a/tests/type_test.cpp b/tests/type_test.cpp deleted file mode 100644 index 8531e6a..0000000 --- a/tests/type_test.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#include "type.hpp" -#include -#include -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include - -namespace { -/// Owns tokens collected from the accepted current/advance interface. -/// Complexity: O(source bytes), O(token payloads and count) storage. -std::vector tokens(std::string_view source) { - cel::parser_detail::lex_lexer lexer(source); - std::vector result; - while (!std::holds_alternative(lexer.current().value)) { - result.push_back(lexer.current()); - lexer.advance(); - } - result.push_back(lexer.current()); - return result; -} -/// Parses one complete type with source ownership outside the parser. -/// Complexity: O(source bytes + complete descriptor construction). -cel::value_type type(std::string_view source, const cel::op_lookup& lookup) { - auto input = tokens(source); - return cel::parser_detail::parse_type(input, lookup); -} -/// Provides a valid client leaf that is not an admitted callable parameter. -struct client { - double number; -}; -} // namespace - -TEST_CASE("type productions preserve nesting nominal identity and singleton commas") { - cel::op_lookup lookup; - lookup.register_type("Client"); - lookup.register_record("Record", - std::array{cel::record_field{"x", cel::value_type::leaf()}}); - CHECK(type("bool", lookup).same_shape(cel::value_type::leaf())); - CHECK(type("(f64)", lookup).same_shape(cel::value_type::leaf())); - CHECK(type("()", lookup).fields().empty()); - CHECK(type("(f64,)", lookup).fields().size() == 1); - auto nested = type("[((bool,), [Client], Record)]", lookup); - CHECK(nested.element().fields().size() == 3); - CHECK(nested.element().fields()[1].element().same_shape(cel::value_type::leaf())); - CHECK(nested.element().fields()[2].record_identity() == "Record"); - for (auto source : - {"(bool, f64,)", "[f64,]", "Fn((f64,), bool,)", "Fn((f64), bool)", "Fn((),)", "Fn()", - "bool f64", "[]", "(,)", "[f64)", "f32", "String", "usize", "Unknown", "bool(f64)"}) { - CHECK_THROWS_AS(type(source, lookup), cel::parse_error); - } -} - -TEST_CASE("Fn parameter admission is recursive while complete results remain unrestricted") { - cel::op_lookup lookup; - lookup.register_type("Client"); - auto fn = type("Fn((bool, [[(f64, bool)]]), Fn((), [Client]))", lookup); - CHECK(fn.parameters().size() == 2); - CHECK(fn.result().result().element().same_shape(cel::value_type::leaf())); - CHECK(type("Fn((), Client)", lookup).parameters().empty()); - for (auto source : {"Fn((Client,), bool)", "Fn(([Client],), bool)", "Fn((Fn((), bool),), bool)", - "Fn(([(Client, bool)],), f64)"}) { - CHECK_THROWS_AS(type(source, lookup), cel::parse_error); - } - CHECK(type("RangeInclusive(f64)", lookup).form() == cel::range_kind::range_inclusive); - CHECK(type("RangeFull()", lookup).form() == cel::range_kind::range_full); - CHECK_THROWS_AS(type("Range(bool)", lookup), cel::parse_error); - lookup.register_record("BuiltinRecord", - std::array{cel::record_field{ - "x", cel::value_type::array(cel::value_type::leaf())}}); - CHECK(type("Fn((BuiltinRecord, RangeInclusive(f64)), bool)", lookup).parameters().size() == 2); - lookup.register_record("ClientRecord", - std::array{cel::record_field{"x", cel::value_type::leaf()}}); - CHECK_THROWS_AS(type("Fn((ClientRecord,), bool)", lookup), cel::parse_error); - CHECK(type("Fn((), ClientRecord)", lookup).result().record_identity() == "ClientRecord"); - CHECK(type("Fn((), [Fn((), Client)])", lookup).result().element().kind() == - cel::type_kind::callable); -} - -TEST_CASE("inline type parsing leaves host token and errors retain exact byte spans") { - cel::op_lookup lookup; - cel::parser_detail::lex_lexer text_cursor("[f64], next"); - CHECK(cel::parser_detail::parse_type(text_cursor, lookup) - .element() - .same_shape(cel::value_type::leaf())); - CHECK(std::get(text_cursor.current().value).spelling() == ","); - auto input = tokens("[f64], next"); - cel::parser_detail::token_cursor cursor(input); - CHECK(cel::parser_detail::parse_type(cursor, lookup) - .element() - .same_shape(cel::value_type::leaf())); - CHECK(std::get(cursor.current().value).spelling() == ","); - try { - (void)type("[Unknown]", lookup); - FAIL("unknown type accepted"); - } catch (const cel::parse_error& error) { - CHECK(error.span() == cel::source_span{1, 8}); - } - - auto invalid = std::array{cel::parser_detail::token{ - {20, 21}, cel::parse_error(cel::error_category::malformed_input, {20, 21}, "producer")}}; - try { - (void)cel::parser_detail::parse_type(invalid, lookup); - FAIL("producer error accepted"); - } catch (const cel::parse_error& error) { - CHECK(error.span() == cel::source_span{20, 21}); - CHECK(std::string(error.what()) == "producer"); - } - const auto deep = std::string(1000, '[') + "f64" + std::string(1000, ']'); - CHECK(type(std::string(127, '[') + "f64" + std::string(127, ']'), lookup).kind() == - cel::type_kind::array); - try { - (void)type(deep, lookup); - FAIL("resource boundary ignored"); - } catch (const cel::parse_error& error) { - CHECK(error.category() == cel::error_category::resource_limit); - } -} - -TEST_CASE("type prefix span output excludes whitespace and publishes only on success") { - cel::op_lookup lookup; - cel::source_span parsed{90, 91}; - cel::parser_detail::lex_lexer source(" Fn((), [f64]) , next"); - CHECK(cel::parser_detail::parse_type(source, lookup, parsed).result().kind() == - cel::type_kind::array); - CHECK(parsed == cel::source_span{2, 15}); - CHECK(std::get(source.current().value).spelling() == ","); - const auto input = tokens(" [f64] , next"); - cel::parser_detail::token_cursor cursor(input); - CHECK(cel::parser_detail::parse_type(cursor, lookup, parsed).kind() == cel::type_kind::array); - CHECK(parsed == cel::source_span{2, 7}); - cel::parser_detail::lex_lexer invalid("[Unknown]"); - CHECK_THROWS_AS(cel::parser_detail::parse_type(invalid, lookup, parsed), cel::parse_error); - CHECK(parsed == cel::source_span{2, 7}); -} diff --git a/tools/generate_unicode.py b/tools/generate_unicode.py index a5b3042..db0577b 100644 --- a/tools/generate_unicode.py +++ b/tools/generate_unicode.py @@ -31,25 +31,25 @@ def generate(): else: ranges.append(interval) output = [ - "// SPDX-License-Identifier: Unicode-3.0", + "// BEGIN GENERATED UNICODE DATA", + "// Unicode property data licensed under Unicode-3.0.", "// Generated by tools/generate_unicode.py; Unicode 18.0.0.", f"// Input: {URL}", f"// SHA-256: {hashlib.sha256(data).hexdigest()}", - "#ifndef CEL_PARSER_UNICODE_DATA_HPP", - "#define CEL_PARSER_UNICODE_DATA_HPP", - "#include ", - "#include ", - "namespace cel::detail {", "/// Stores an inclusive Unicode property interval.", "struct unicode_range { std::uint32_t first; std::uint32_t last; };", ] for prop, ranges in properties.items(): output += [f"/// Stores Unicode 18 {prop} intervals in ascending order.", - f"inline constexpr std::array {prop.lower()}{{{{"] + f"constexpr std::array {prop.lower()}{{{{"] output += [f" {{0x{lo:X}, 0x{hi:X}}}," for lo, hi in ranges] output += ["}};"] - output += ["} // namespace cel::detail", "#endif", ""] - Path("src/unicode_data.hpp").write_text("\n".join(output)) + output += ["// END GENERATED UNICODE DATA"] + path = Path("src/parser.cpp") + source = path.read_text() + start = source.index("// BEGIN GENERATED UNICODE DATA") + end = source.index("// END GENERATED UNICODE DATA", start) + len(output[-1]) + path.write_text(source[:start] + "\n".join(output) + source[end:]) print(f"Unicode 18 input SHA-256: {hashlib.sha256(data).hexdigest()}") print({prop: len(ranges) for prop, ranges in properties.items()}) diff --git a/tools/parity/driver.cpp b/tools/parity/driver.cpp index fe33035..7ff24d4 100644 --- a/tools/parity/driver.cpp +++ b/tools/parity/driver.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: BSL-1.0 +#include "../../src/lookup_access.hpp" #include "driver_support.hpp" -#include "lookup_access.hpp" #include #include #include