From c52170d4c301ace973f1d5314f565ae6fb7d0dcb Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 5 Jan 2026 22:14:31 +0000 Subject: [PATCH 01/43] Inital try at a git artifact downloader. --- build/ab.py | 23 +++++++++++++++++++++-- build/utils.py | 15 +++++++++++++++ dep/build.py | 27 +++++++++++++++++++++++++++ src/gui2/build.py | 12 +----------- 4 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 dep/build.py diff --git a/build/ab.py b/build/ab.py index 6261a2b0..655f9e2d 100644 --- a/build/ab.py +++ b/build/ab.py @@ -30,6 +30,7 @@ outputTargets = set() commandsDb = [] belatedErrors = [] +atexits = [] RE_FORMAT_SPEC = re.compile( r"(?:(?P[\s\S])?(?P[<>=^]))?" @@ -563,7 +564,14 @@ def add_belated_error(msg): belatedErrors += [msg] -def emit_rule(self, ins, outs, cmds=[], label=None): +def add_atexit(cb): + global atexits + atexits += [cb] + + +def emit_rule( + self, ins, outs, cmds=[], label=None, sandbox=True, generator=False +): name = self.name fins = [self.templateexpand(f) for f in set(filenamesof(ins))] fouts = [self.templateexpand(f) for f in filenamesof(outs)] @@ -581,7 +589,8 @@ def emit_rule(self, ins, outs, cmds=[], label=None): os.makedirs(self.dir, exist_ok=True) rule = [] - if G.AB_SANDBOX == "yes": + sandbox = sandbox and (G.AB_SANDBOX == "yes") + if sandbox: sandbox = join(self.dir, "sandbox") emit(f"rm -rf {sandbox}", into=rule) emit( @@ -621,6 +630,9 @@ def emit_rule(self, ins, outs, cmds=[], label=None): ) if label: emit(" description=", label) + if generator: + emit(" generator=true") + emit("build", name, ":phony", *fouts) else: assert len(cmds) == 0, "rules with no outputs cannot have commands" @@ -638,6 +650,8 @@ def simplerule( deps: Targets = [], commands=[], add_to_commanddb=False, + sandbox=True, + generator=False, label="RULE", ): self.ins = ins @@ -676,6 +690,8 @@ def simplerule( outs=outs, label=self.templateexpand("$[label] $[name]") if label else None, cmds=cs, + sandbox=sandbox, + generator=generator, ) @@ -768,6 +784,9 @@ def main(): print(s) sys.exit(1) + for cb in atexits: + cb() + with open(outputdir + "/build.targets", "wt") as fp: fp.write("ninja-targets =") fp.write(substituteGlobalVariables(" ".join(outputTargets))) diff --git a/build/utils.py b/build/utils.py index 224cae40..a793ad9f 100644 --- a/build/utils.py +++ b/build/utils.py @@ -7,6 +7,9 @@ getcwd, error, simplerule, + add_atexit, + targets, + emit, G, ) from os.path import relpath, splitext, join, basename, isfile, normpath @@ -125,6 +128,18 @@ def shell(cmd): return r.decode("utf-8").strip() +def add_wildcard_dependency(dep, pattern, exclude="."): + def cb(): + yesre = _glob_to_re(pattern) + nore = _glob_to_re(exclude) + for t in targets.values(): + for o in t.outs: + if (type(o) == str) and yesre.match(o) and not nore.match(o): + emit("build", o, ":phony", dep.name) + + add_atexit(cb) + + @Rule def objectify(self, name, src: Target, symbol): simplerule( diff --git a/dep/build.py b/dep/build.py new file mode 100644 index 00000000..bdca1216 --- /dev/null +++ b/dep/build.py @@ -0,0 +1,27 @@ +from build.pkg import package +from build.c import clibrary +from build.git import git_repository + +package( + name="md4c_lib", + package="md4c", + fallback=clibrary( + name="md4c_fallback_lib", + srcs=[ + "dep/md4c/src/entity.c", + "dep/md4c/src/entity.h", + "dep/md4c/src/md4c-html.h", + "dep/md4c/src/md4c.c", + "dep/md4c/src/md4c.h", + ], + hdrs={"md4c.h": "dep/md4c/src/md4c.h"}, + deps=[ + git_repository( + name="md4c_repo", + url="https://github.com/mity/md4c", + branch="master", + path="dep/md4c", + ) + ], + ), +) diff --git a/src/gui2/build.py b/src/gui2/build.py index 62b3d368..d2ec4676 100644 --- a/src/gui2/build.py +++ b/src/gui2/build.py @@ -54,16 +54,6 @@ def sources_from(path, except_for=[]): ), ) -package( - name="md4c_lib", - package="md4c", - fallback=clibrary( - name="md4c_fallback_lib", - srcs=sources_from("dep/md4c/src"), - hdrs={"md4c.h": "dep/md4c/src/md4c.h"}, - ), -) - package( name="cli11_lib", package="CLI11", @@ -424,7 +414,7 @@ def plugin(name, id, srcs, hdrs, romfsdir, deps): ), hdrs=headers_from("dep/imhex/plugins/ui/include"), romfsdir="dep/imhex/plugins/ui/romfs", - deps=[".+libimhex", ".+fonts-plugin", ".+md4c_lib"], + deps=[".+libimhex", ".+fonts-plugin", "dep+md4c_lib"], ) plugin( From 3b302d4f85b522a31ddac577b45cd135c46118ee Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 5 Jan 2026 22:24:11 +0000 Subject: [PATCH 02/43] Lexy is now downloaded on-the-fly. --- dep/build.py | 138 ++ dep/lexy/LICENSE | 23 - dep/lexy/README.adoc | 175 --- dep/lexy/UPSTREAM.md | 2 - dep/lexy/build.py | 13 - dep/lexy/include/lexy/_detail/any_ref.hpp | 68 - dep/lexy/include/lexy/_detail/assert.hpp | 51 - .../include/lexy/_detail/buffer_builder.hpp | 160 -- dep/lexy/include/lexy/_detail/code_point.hpp | 368 ----- dep/lexy/include/lexy/_detail/config.hpp | 199 --- dep/lexy/include/lexy/_detail/detect.hpp | 35 - .../include/lexy/_detail/integer_sequence.hpp | 64 - dep/lexy/include/lexy/_detail/invoke.hpp | 70 - dep/lexy/include/lexy/_detail/iterator.hpp | 244 ---- dep/lexy/include/lexy/_detail/lazy_init.hpp | 246 ---- .../include/lexy/_detail/memory_resource.hpp | 152 -- dep/lexy/include/lexy/_detail/nttp_string.hpp | 147 -- .../include/lexy/_detail/stateless_lambda.hpp | 72 - dep/lexy/include/lexy/_detail/std.hpp | 98 -- dep/lexy/include/lexy/_detail/string_view.hpp | 212 --- dep/lexy/include/lexy/_detail/swar.hpp | 251 ---- dep/lexy/include/lexy/_detail/tuple.hpp | 119 -- dep/lexy/include/lexy/_detail/type_name.hpp | 130 -- .../include/lexy/_detail/unicode_database.hpp | 83 -- dep/lexy/include/lexy/action/base.hpp | 275 ---- dep/lexy/include/lexy/action/match.hpp | 90 -- dep/lexy/include/lexy/action/parse.hpp | 191 --- .../include/lexy/action/parse_as_tree.hpp | 217 --- dep/lexy/include/lexy/action/scan.hpp | 98 -- dep/lexy/include/lexy/action/trace.hpp | 506 ------- dep/lexy/include/lexy/action/validate.hpp | 320 ---- dep/lexy/include/lexy/callback.hpp | 23 - dep/lexy/include/lexy/callback/adapter.hpp | 168 --- dep/lexy/include/lexy/callback/aggregate.hpp | 72 - dep/lexy/include/lexy/callback/base.hpp | 91 -- dep/lexy/include/lexy/callback/bind.hpp | 385 ----- dep/lexy/include/lexy/callback/bit_cast.hpp | 80 - .../include/lexy/callback/composition.hpp | 120 -- dep/lexy/include/lexy/callback/constant.hpp | 33 - dep/lexy/include/lexy/callback/container.hpp | 511 ------- dep/lexy/include/lexy/callback/fold.hpp | 92 -- dep/lexy/include/lexy/callback/forward.hpp | 51 - dep/lexy/include/lexy/callback/integer.hpp | 44 - dep/lexy/include/lexy/callback/noop.hpp | 34 - dep/lexy/include/lexy/callback/object.hpp | 98 -- dep/lexy/include/lexy/callback/string.hpp | 210 --- dep/lexy/include/lexy/code_point.hpp | 306 ---- dep/lexy/include/lexy/dsl.hpp | 68 - dep/lexy/include/lexy/dsl/any.hpp | 52 - dep/lexy/include/lexy/dsl/ascii.hpp | 514 ------- dep/lexy/include/lexy/dsl/base.hpp | 273 ---- dep/lexy/include/lexy/dsl/bits.hpp | 152 -- dep/lexy/include/lexy/dsl/bom.hpp | 47 - dep/lexy/include/lexy/dsl/brackets.hpp | 117 -- dep/lexy/include/lexy/dsl/branch.hpp | 147 -- dep/lexy/include/lexy/dsl/byte.hpp | 399 ----- dep/lexy/include/lexy/dsl/capture.hpp | 143 -- dep/lexy/include/lexy/dsl/case_folding.hpp | 303 ---- dep/lexy/include/lexy/dsl/char_class.hpp | 611 -------- dep/lexy/include/lexy/dsl/choice.hpp | 161 --- dep/lexy/include/lexy/dsl/code_point.hpp | 212 --- dep/lexy/include/lexy/dsl/combination.hpp | 153 -- dep/lexy/include/lexy/dsl/context_counter.hpp | 304 ---- dep/lexy/include/lexy/dsl/context_flag.hpp | 153 -- .../include/lexy/dsl/context_identifier.hpp | 178 --- dep/lexy/include/lexy/dsl/delimited.hpp | 471 ------ dep/lexy/include/lexy/dsl/digit.hpp | 652 --------- dep/lexy/include/lexy/dsl/effect.hpp | 69 - dep/lexy/include/lexy/dsl/eof.hpp | 76 - dep/lexy/include/lexy/dsl/error.hpp | 128 -- dep/lexy/include/lexy/dsl/expression.hpp | 601 -------- dep/lexy/include/lexy/dsl/flags.hpp | 141 -- dep/lexy/include/lexy/dsl/follow.hpp | 122 -- dep/lexy/include/lexy/dsl/identifier.hpp | 414 ------ dep/lexy/include/lexy/dsl/if.hpp | 49 - dep/lexy/include/lexy/dsl/integer.hpp | 566 -------- dep/lexy/include/lexy/dsl/list.hpp | 448 ------ dep/lexy/include/lexy/dsl/literal.hpp | 625 -------- dep/lexy/include/lexy/dsl/lookahead.hpp | 140 -- dep/lexy/include/lexy/dsl/loop.hpp | 124 -- dep/lexy/include/lexy/dsl/member.hpp | 99 -- dep/lexy/include/lexy/dsl/newline.hpp | 85 -- dep/lexy/include/lexy/dsl/operator.hpp | 333 ----- dep/lexy/include/lexy/dsl/option.hpp | 120 -- dep/lexy/include/lexy/dsl/parse_as.hpp | 156 -- dep/lexy/include/lexy/dsl/parse_tree_node.hpp | 251 ---- dep/lexy/include/lexy/dsl/peek.hpp | 180 --- dep/lexy/include/lexy/dsl/position.hpp | 83 -- dep/lexy/include/lexy/dsl/production.hpp | 249 ---- dep/lexy/include/lexy/dsl/punctuator.hpp | 46 - dep/lexy/include/lexy/dsl/recover.hpp | 344 ----- dep/lexy/include/lexy/dsl/repeat.hpp | 182 --- dep/lexy/include/lexy/dsl/return.hpp | 24 - dep/lexy/include/lexy/dsl/scan.hpp | 519 ------- dep/lexy/include/lexy/dsl/separator.hpp | 139 -- dep/lexy/include/lexy/dsl/sequence.hpp | 125 -- dep/lexy/include/lexy/dsl/sign.hpp | 47 - dep/lexy/include/lexy/dsl/subgrammar.hpp | 109 -- dep/lexy/include/lexy/dsl/symbol.hpp | 543 ------- dep/lexy/include/lexy/dsl/terminator.hpp | 114 -- dep/lexy/include/lexy/dsl/times.hpp | 68 - dep/lexy/include/lexy/dsl/token.hpp | 225 --- dep/lexy/include/lexy/dsl/unicode.hpp | 497 ------- dep/lexy/include/lexy/dsl/until.hpp | 157 -- dep/lexy/include/lexy/dsl/whitespace.hpp | 319 ---- dep/lexy/include/lexy/encoding.hpp | 333 ----- dep/lexy/include/lexy/error.hpp | 270 ---- dep/lexy/include/lexy/grammar.hpp | 381 ----- dep/lexy/include/lexy/input/argv_input.hpp | 215 --- dep/lexy/include/lexy/input/base.hpp | 148 -- dep/lexy/include/lexy/input/buffer.hpp | 507 ------- dep/lexy/include/lexy/input/file.hpp | 138 -- dep/lexy/include/lexy/input/lexeme_input.hpp | 66 - .../include/lexy/input/parse_tree_input.hpp | 184 --- dep/lexy/include/lexy/input/range_input.hpp | 59 - dep/lexy/include/lexy/input/string_input.hpp | 115 -- dep/lexy/include/lexy/input_location.hpp | 483 ------- dep/lexy/include/lexy/lexeme.hpp | 107 -- dep/lexy/include/lexy/parse_tree.hpp | 1284 ----------------- dep/lexy/include/lexy/token.hpp | 285 ---- dep/lexy/include/lexy/visualize.hpp | 708 --------- .../include/lexy_ext/compiler_explorer.hpp | 60 - .../include/lexy_ext/parse_tree_algorithm.hpp | 281 ---- .../include/lexy_ext/parse_tree_doctest.hpp | 195 --- dep/lexy/include/lexy_ext/report_error.hpp | 381 ----- dep/lexy/include/lexy_ext/shell.hpp | 422 ------ lib/data/build.py | 2 +- 127 files changed, 139 insertions(+), 27247 deletions(-) delete mode 100644 dep/lexy/LICENSE delete mode 100644 dep/lexy/README.adoc delete mode 100644 dep/lexy/UPSTREAM.md delete mode 100644 dep/lexy/build.py delete mode 100644 dep/lexy/include/lexy/_detail/any_ref.hpp delete mode 100644 dep/lexy/include/lexy/_detail/assert.hpp delete mode 100644 dep/lexy/include/lexy/_detail/buffer_builder.hpp delete mode 100644 dep/lexy/include/lexy/_detail/code_point.hpp delete mode 100644 dep/lexy/include/lexy/_detail/config.hpp delete mode 100644 dep/lexy/include/lexy/_detail/detect.hpp delete mode 100644 dep/lexy/include/lexy/_detail/integer_sequence.hpp delete mode 100644 dep/lexy/include/lexy/_detail/invoke.hpp delete mode 100644 dep/lexy/include/lexy/_detail/iterator.hpp delete mode 100644 dep/lexy/include/lexy/_detail/lazy_init.hpp delete mode 100644 dep/lexy/include/lexy/_detail/memory_resource.hpp delete mode 100644 dep/lexy/include/lexy/_detail/nttp_string.hpp delete mode 100644 dep/lexy/include/lexy/_detail/stateless_lambda.hpp delete mode 100644 dep/lexy/include/lexy/_detail/std.hpp delete mode 100644 dep/lexy/include/lexy/_detail/string_view.hpp delete mode 100644 dep/lexy/include/lexy/_detail/swar.hpp delete mode 100644 dep/lexy/include/lexy/_detail/tuple.hpp delete mode 100644 dep/lexy/include/lexy/_detail/type_name.hpp delete mode 100644 dep/lexy/include/lexy/_detail/unicode_database.hpp delete mode 100644 dep/lexy/include/lexy/action/base.hpp delete mode 100644 dep/lexy/include/lexy/action/match.hpp delete mode 100644 dep/lexy/include/lexy/action/parse.hpp delete mode 100644 dep/lexy/include/lexy/action/parse_as_tree.hpp delete mode 100644 dep/lexy/include/lexy/action/scan.hpp delete mode 100644 dep/lexy/include/lexy/action/trace.hpp delete mode 100644 dep/lexy/include/lexy/action/validate.hpp delete mode 100644 dep/lexy/include/lexy/callback.hpp delete mode 100644 dep/lexy/include/lexy/callback/adapter.hpp delete mode 100644 dep/lexy/include/lexy/callback/aggregate.hpp delete mode 100644 dep/lexy/include/lexy/callback/base.hpp delete mode 100644 dep/lexy/include/lexy/callback/bind.hpp delete mode 100644 dep/lexy/include/lexy/callback/bit_cast.hpp delete mode 100644 dep/lexy/include/lexy/callback/composition.hpp delete mode 100644 dep/lexy/include/lexy/callback/constant.hpp delete mode 100644 dep/lexy/include/lexy/callback/container.hpp delete mode 100644 dep/lexy/include/lexy/callback/fold.hpp delete mode 100644 dep/lexy/include/lexy/callback/forward.hpp delete mode 100644 dep/lexy/include/lexy/callback/integer.hpp delete mode 100644 dep/lexy/include/lexy/callback/noop.hpp delete mode 100644 dep/lexy/include/lexy/callback/object.hpp delete mode 100644 dep/lexy/include/lexy/callback/string.hpp delete mode 100644 dep/lexy/include/lexy/code_point.hpp delete mode 100644 dep/lexy/include/lexy/dsl.hpp delete mode 100644 dep/lexy/include/lexy/dsl/any.hpp delete mode 100644 dep/lexy/include/lexy/dsl/ascii.hpp delete mode 100644 dep/lexy/include/lexy/dsl/base.hpp delete mode 100644 dep/lexy/include/lexy/dsl/bits.hpp delete mode 100644 dep/lexy/include/lexy/dsl/bom.hpp delete mode 100644 dep/lexy/include/lexy/dsl/brackets.hpp delete mode 100644 dep/lexy/include/lexy/dsl/branch.hpp delete mode 100644 dep/lexy/include/lexy/dsl/byte.hpp delete mode 100644 dep/lexy/include/lexy/dsl/capture.hpp delete mode 100644 dep/lexy/include/lexy/dsl/case_folding.hpp delete mode 100644 dep/lexy/include/lexy/dsl/char_class.hpp delete mode 100644 dep/lexy/include/lexy/dsl/choice.hpp delete mode 100644 dep/lexy/include/lexy/dsl/code_point.hpp delete mode 100644 dep/lexy/include/lexy/dsl/combination.hpp delete mode 100644 dep/lexy/include/lexy/dsl/context_counter.hpp delete mode 100644 dep/lexy/include/lexy/dsl/context_flag.hpp delete mode 100644 dep/lexy/include/lexy/dsl/context_identifier.hpp delete mode 100644 dep/lexy/include/lexy/dsl/delimited.hpp delete mode 100644 dep/lexy/include/lexy/dsl/digit.hpp delete mode 100644 dep/lexy/include/lexy/dsl/effect.hpp delete mode 100644 dep/lexy/include/lexy/dsl/eof.hpp delete mode 100644 dep/lexy/include/lexy/dsl/error.hpp delete mode 100644 dep/lexy/include/lexy/dsl/expression.hpp delete mode 100644 dep/lexy/include/lexy/dsl/flags.hpp delete mode 100644 dep/lexy/include/lexy/dsl/follow.hpp delete mode 100644 dep/lexy/include/lexy/dsl/identifier.hpp delete mode 100644 dep/lexy/include/lexy/dsl/if.hpp delete mode 100644 dep/lexy/include/lexy/dsl/integer.hpp delete mode 100644 dep/lexy/include/lexy/dsl/list.hpp delete mode 100644 dep/lexy/include/lexy/dsl/literal.hpp delete mode 100644 dep/lexy/include/lexy/dsl/lookahead.hpp delete mode 100644 dep/lexy/include/lexy/dsl/loop.hpp delete mode 100644 dep/lexy/include/lexy/dsl/member.hpp delete mode 100644 dep/lexy/include/lexy/dsl/newline.hpp delete mode 100644 dep/lexy/include/lexy/dsl/operator.hpp delete mode 100644 dep/lexy/include/lexy/dsl/option.hpp delete mode 100644 dep/lexy/include/lexy/dsl/parse_as.hpp delete mode 100644 dep/lexy/include/lexy/dsl/parse_tree_node.hpp delete mode 100644 dep/lexy/include/lexy/dsl/peek.hpp delete mode 100644 dep/lexy/include/lexy/dsl/position.hpp delete mode 100644 dep/lexy/include/lexy/dsl/production.hpp delete mode 100644 dep/lexy/include/lexy/dsl/punctuator.hpp delete mode 100644 dep/lexy/include/lexy/dsl/recover.hpp delete mode 100644 dep/lexy/include/lexy/dsl/repeat.hpp delete mode 100644 dep/lexy/include/lexy/dsl/return.hpp delete mode 100644 dep/lexy/include/lexy/dsl/scan.hpp delete mode 100644 dep/lexy/include/lexy/dsl/separator.hpp delete mode 100644 dep/lexy/include/lexy/dsl/sequence.hpp delete mode 100644 dep/lexy/include/lexy/dsl/sign.hpp delete mode 100644 dep/lexy/include/lexy/dsl/subgrammar.hpp delete mode 100644 dep/lexy/include/lexy/dsl/symbol.hpp delete mode 100644 dep/lexy/include/lexy/dsl/terminator.hpp delete mode 100644 dep/lexy/include/lexy/dsl/times.hpp delete mode 100644 dep/lexy/include/lexy/dsl/token.hpp delete mode 100644 dep/lexy/include/lexy/dsl/unicode.hpp delete mode 100644 dep/lexy/include/lexy/dsl/until.hpp delete mode 100644 dep/lexy/include/lexy/dsl/whitespace.hpp delete mode 100644 dep/lexy/include/lexy/encoding.hpp delete mode 100644 dep/lexy/include/lexy/error.hpp delete mode 100644 dep/lexy/include/lexy/grammar.hpp delete mode 100644 dep/lexy/include/lexy/input/argv_input.hpp delete mode 100644 dep/lexy/include/lexy/input/base.hpp delete mode 100644 dep/lexy/include/lexy/input/buffer.hpp delete mode 100644 dep/lexy/include/lexy/input/file.hpp delete mode 100644 dep/lexy/include/lexy/input/lexeme_input.hpp delete mode 100644 dep/lexy/include/lexy/input/parse_tree_input.hpp delete mode 100644 dep/lexy/include/lexy/input/range_input.hpp delete mode 100644 dep/lexy/include/lexy/input/string_input.hpp delete mode 100644 dep/lexy/include/lexy/input_location.hpp delete mode 100644 dep/lexy/include/lexy/lexeme.hpp delete mode 100644 dep/lexy/include/lexy/parse_tree.hpp delete mode 100644 dep/lexy/include/lexy/token.hpp delete mode 100644 dep/lexy/include/lexy/visualize.hpp delete mode 100644 dep/lexy/include/lexy_ext/compiler_explorer.hpp delete mode 100644 dep/lexy/include/lexy_ext/parse_tree_algorithm.hpp delete mode 100644 dep/lexy/include/lexy_ext/parse_tree_doctest.hpp delete mode 100644 dep/lexy/include/lexy_ext/report_error.hpp delete mode 100644 dep/lexy/include/lexy_ext/shell.hpp diff --git a/dep/build.py b/dep/build.py index bdca1216..993bd732 100644 --- a/dep/build.py +++ b/dep/build.py @@ -25,3 +25,141 @@ ], ), ) + +clibrary( + name="lexy_lib", + hdrs={ + h: f"dep/lexy/include/{h}" + for h in [ + "lexy_ext/parse_tree_algorithm.hpp", + "lexy_ext/report_error.hpp", + "lexy_ext/parse_tree_doctest.hpp", + "lexy_ext/compiler_explorer.hpp", + "lexy_ext/shell.hpp", + "lexy/callback/constant.hpp", + "lexy/callback/object.hpp", + "lexy/callback/composition.hpp", + "lexy/callback/aggregate.hpp", + "lexy/callback/forward.hpp", + "lexy/callback/integer.hpp", + "lexy/callback/string.hpp", + "lexy/callback/bit_cast.hpp", + "lexy/callback/bind.hpp", + "lexy/callback/fold.hpp", + "lexy/callback/adapter.hpp", + "lexy/callback/container.hpp", + "lexy/callback/noop.hpp", + "lexy/callback/base.hpp", + "lexy/error.hpp", + "lexy/_detail/type_name.hpp", + "lexy/_detail/assert.hpp", + "lexy/_detail/swar.hpp", + "lexy/_detail/tuple.hpp", + "lexy/_detail/code_point.hpp", + "lexy/_detail/unicode_database.hpp", + "lexy/_detail/integer_sequence.hpp", + "lexy/_detail/any_ref.hpp", + "lexy/_detail/memory_resource.hpp", + "lexy/_detail/iterator.hpp", + "lexy/_detail/config.hpp", + "lexy/_detail/stateless_lambda.hpp", + "lexy/_detail/lazy_init.hpp", + "lexy/_detail/nttp_string.hpp", + "lexy/_detail/detect.hpp", + "lexy/_detail/string_view.hpp", + "lexy/_detail/buffer_builder.hpp", + "lexy/_detail/invoke.hpp", + "lexy/_detail/std.hpp", + "lexy/code_point.hpp", + "lexy/parse_tree.hpp", + "lexy/grammar.hpp", + "lexy/encoding.hpp", + "lexy/input_location.hpp", + "lexy/lexeme.hpp", + "lexy/dsl/capture.hpp", + "lexy/dsl/case_folding.hpp", + "lexy/dsl/literal.hpp", + "lexy/dsl/context_identifier.hpp", + "lexy/dsl/error.hpp", + "lexy/dsl/whitespace.hpp", + "lexy/dsl/flags.hpp", + "lexy/dsl/subgrammar.hpp", + "lexy/dsl/code_point.hpp", + "lexy/dsl/sign.hpp", + "lexy/dsl/member.hpp", + "lexy/dsl/if.hpp", + "lexy/dsl/symbol.hpp", + "lexy/dsl/branch.hpp", + "lexy/dsl/follow.hpp", + "lexy/dsl/repeat.hpp", + "lexy/dsl/ascii.hpp", + "lexy/dsl/combination.hpp", + "lexy/dsl/return.hpp", + "lexy/dsl/integer.hpp", + "lexy/dsl/production.hpp", + "lexy/dsl/until.hpp", + "lexy/dsl/brackets.hpp", + "lexy/dsl/sequence.hpp", + "lexy/dsl/char_class.hpp", + "lexy/dsl/lookahead.hpp", + "lexy/dsl/loop.hpp", + "lexy/dsl/unicode.hpp", + "lexy/dsl/context_counter.hpp", + "lexy/dsl/choice.hpp", + "lexy/dsl/parse_as.hpp", + "lexy/dsl/byte.hpp", + "lexy/dsl/digit.hpp", + "lexy/dsl/punctuator.hpp", + "lexy/dsl/recover.hpp", + "lexy/dsl/times.hpp", + "lexy/dsl/bits.hpp", + "lexy/dsl/option.hpp", + "lexy/dsl/identifier.hpp", + "lexy/dsl/context_flag.hpp", + "lexy/dsl/operator.hpp", + "lexy/dsl/token.hpp", + "lexy/dsl/any.hpp", + "lexy/dsl/separator.hpp", + "lexy/dsl/peek.hpp", + "lexy/dsl/newline.hpp", + "lexy/dsl/parse_tree_node.hpp", + "lexy/dsl/expression.hpp", + "lexy/dsl/delimited.hpp", + "lexy/dsl/effect.hpp", + "lexy/dsl/position.hpp", + "lexy/dsl/scan.hpp", + "lexy/dsl/list.hpp", + "lexy/dsl/base.hpp", + "lexy/dsl/bom.hpp", + "lexy/dsl/terminator.hpp", + "lexy/dsl/eof.hpp", + "lexy/dsl.hpp", + "lexy/visualize.hpp", + "lexy/callback.hpp", + "lexy/token.hpp", + "lexy/action/parse_as_tree.hpp", + "lexy/action/parse.hpp", + "lexy/action/trace.hpp", + "lexy/action/match.hpp", + "lexy/action/validate.hpp", + "lexy/action/scan.hpp", + "lexy/action/base.hpp", + "lexy/input/buffer.hpp", + "lexy/input/lexeme_input.hpp", + "lexy/input/argv_input.hpp", + "lexy/input/file.hpp", + "lexy/input/string_input.hpp", + "lexy/input/parse_tree_input.hpp", + "lexy/input/range_input.hpp", + "lexy/input/base.hpp", + ] + }, + deps=[ + git_repository( + name="lexy_repo", + url="https://github.com/foonathan/lexy", + branch="v2025.05.0", + path="dep/lexy", + ) + ], +) diff --git a/dep/lexy/LICENSE b/dep/lexy/LICENSE deleted file mode 100644 index 36b7cd93..00000000 --- a/dep/lexy/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/dep/lexy/README.adoc b/dep/lexy/README.adoc deleted file mode 100644 index 6bc88487..00000000 --- a/dep/lexy/README.adoc +++ /dev/null @@ -1,175 +0,0 @@ -= lexy - -ifdef::env-github[] -image:https://img.shields.io/endpoint?url=https%3A%2F%2Fwww.jonathanmueller.dev%2Fproject%2Flexy%2Findex.json[Project Status,link=https://www.jonathanmueller.dev/project/] -image:https://github.com/foonathan/lexy/workflows/Main%20CI/badge.svg[Build Status] -image:https://img.shields.io/badge/try_it_online-blue[Playground,link=https://lexy.foonathan.net/playground] -endif::[] - -lexy is a parser combinator library for {cpp}17 and onwards. -It allows you to write a parser by specifying it in a convenient {cpp} DSL, -which gives you all the flexibility and control of a handwritten parser without any of the manual work. - -ifdef::env-github[] -*Documentation*: https://lexy.foonathan.net/[lexy.foonathan.net] -endif::[] - -.IPv4 address parser --- -ifndef::env-github[] -[.godbolt-example] -.+++{{< svg "icons/play.svg" >}}+++ -endif::[] -[source,cpp] ----- -namespace dsl = lexy::dsl; - -// Parse an IPv4 address into a `std::uint32_t`. -struct ipv4_address -{ - // What is being matched. - static constexpr auto rule = []{ - // Match a sequence of (decimal) digits and convert it into a std::uint8_t. - auto octet = dsl::integer; - - // Match four of them separated by periods. - return dsl::times<4>(octet, dsl::sep(dsl::period)) + dsl::eof; - }(); - - // How the matched output is being stored. - static constexpr auto value - = lexy::callback([](std::uint8_t a, std::uint8_t b, std::uint8_t c, std::uint8_t d) { - return (a << 24) | (b << 16) | (c << 8) | d; - }); -}; ----- --- - -== Features - -Full control:: - * *Describe the parser, not some abstract grammar*: - Unlike parser generators that use some table driven magic for parsing, lexy's grammar is just syntax sugar for a hand-written recursive descent parser. - The parsing algorithm does exactly what you've instructed it to do -- no more ambiguities or weird shift/reduce errors! - * *No implicit backtracking or lookahead*: - It will only backtrack when you say it should, and only lookahead when and how far you want it. - Don't worry about rules that have side-effects, they won't be executed unnecessarily thanks to the user-specified lookahead conditions. - https://lexy.foonathan.net/playground?example=peek[Try it online]. - * *Escape hatch for manual parsing*: - Sometimes you want to parse something that can't be expressed easily with lexy's facilities. - Don't worry, you can integrate a hand-written parser into the grammar at any point. - https://lexy.foonathan.net/playground/?example=scan[Try it online]. - * *Tracing*: - Figure out why the grammar isn't working the way you want it to. - https://lexy.foonathan.net/playground/?example=trace&mode=trace[Try it online]. - -Easily integrated:: - * *A pure {cpp} DSL*: - No need to use an external grammar file; embed the grammar directly in your {cpp} project using operator overloading and functions. - * *Bring your own data structures*: - You can directly store results into your own types and have full control over all heap allocations. - * *Fully `constexpr` parsing*: - You want to parse a string literal at compile-time? You can do so. - * *Minimal standard library dependencies*: - The core parsing library only depends on fundamental headers such as `` or ``; no big includes like `` or ``. - * *Header-only core library* (by necessity, not by choice -- it's `constexpr` after all). - -ifdef::env-github[Designed for text::] -ifndef::env-github[Designed for text (e.g. {{< github-example json >}}, {{< github-example xml >}}, {{< github-example email >}}) ::] - * *Unicode support*: parse UTF-8, UTF-16, or UTF-32, and access the Unicode character database to query char classes or perform case folding. - https://lexy.foonathan.net/playground?example=identifier-unicode[Try it online]. - * *Convenience*: - Built-in rules for parsing nested structures, quotes and escape sequences. - https://lexy.foonathan.net/playground?example=parenthesized[Try it online]. - * *Automatic whitespace skipping*: - No need to manually handle whitespace or comments. - https://lexy.foonathan.net/playground/?example=whitespace_comment[Try it online]. - -ifdef::env-github[Designed for programming languages::] -ifndef::env-github[Designed for programming languages (e.g. {{< github-example calculator >}}, {{< github-example shell >}})::] - * *Keyword and identifier parsing*: - Reserve a set of keywords that won't be matched as regular identifiers. - https://lexy.foonathan.net/playground/?example=reserved_identifier[Try it online]. - * *Operator parsing*: - Parse unary/binary operators with different precedences and associativity, including chained comparisons `a < b < c`. - https://lexy.foonathan.net/playground/?example=expr[Try it online]. - * *Automatic error recovery*: - Log an error, recover, and continue parsing! - https://lexy.foonathan.net/playground/?example=recover[Try it online]. - -ifdef::env-github[Designed for binary input::] -ifndef::env-github[Designed for binary input (e.g. {{< github-example protobuf >}})::] - * *Bytes*: Rules for parsing `N` bytes or Nbit big/little endian integer. - * *Bits*: Rules for parsing individual bit patterns. - * *Blobs*: Rules for parsing TLV formats. - -== FAQ - -Why should I use lexy over XYZ?:: - lexy is closest to other PEG parsers. - However, they usually do more implicit backtracking, which can hurt performance and you need to be very careful with rules that have side-effects. - This is not the case for lexy, where backtracking is controlled using branch conditions. - lexy also gives you a lot of control over error reporting, supports error recovery, special support for operator precedence parsing, and other advanced features. - - http://boost-spirit.com/home/[Boost.Spirit]::: - The main difference: it is not a Boost library. - In addition, Boost.Spirit is quite old and doesn't support e.g. non-common ranges as input. - Boost.Spirit also eagerly creates attributes from the rules, which can lead to nested tuples/variants while lexy uses callbacks which enables zero-copy parsing directly into your own data structure. - However, lexy's grammar is more verbose and designed to parser bigger grammars instead of the small one-off rules that Boost.Spirit is good at. - https://github.com/taocpp/PEGTL[PEGTL]::: - PEGTL is very similar and was a big inspiration. - The biggest difference is that lexy uses an operator based DSL instead of inheriting from templated classes as PEGTL does; - depending on your preference this can be an advantage or disadvantage. - Hand-written Parsers::: - Writing a handwritten parser is more manual work and error prone. - lexy automates that away without having to sacrifice control. - You can use it to quickly prototype a parser and then slowly replace more and more with a handwritten parser over time; - mixing a hand-written parser and a lexy grammar works seamlessly. - -How bad are the compilation times?:: -They're not as bad as you might expect (in debug mode, that is). -+ -The example JSON parser compiles in about 2s on my machine. -If we remove all the lexy specific parts and just benchmark the time it takes for the compiler to process the datastructure (and stdlib includes), -that takes about 700ms. -If we validate JSON only instead of parsing it, so remove the data structures and keep only the lexy specific parts, we're looking at about 840ms. -+ -Keep in mind, that you can fully isolate lexy in a single translation unit that only needs to be touched when you change the parser. -You can also split a lexy grammar into multiple translation units using the `dsl::subgrammar` rule. - -How bad are the {cpp} error messages if you mess something up?:: - They're certainly worse than the error message lexy gives you. - The big problem here is that the first line gives you the error, followed by dozens of template instantiations, which end at your `lexy::parse` call. - Besides providing an external tool to filter those error messages, there is nothing I can do about that. - -How fast is it?:: - Benchmarks are available in the `benchmarks/` directory. - A sample result of the JSON validator benchmark which compares the example JSON parser with various other implementations is available https://lexy.foonathan.net/benchmark_json/[here]. - -Why is it called lexy?:: - I previously had a tokenizer library called foonathan/lex. - I've tried adding a parser to it, but found that the line between pure tokenization and parsing has become increasingly blurred. - lexy is a re-imagination on of the parser I've added to foonathan/lex, and I've simply kept a similar name. - -ifdef::env-github[] -== Documentation - -The documentation, including tutorials, reference documentation, and an interactive playground can be found at https://lexy.foonathan.net/[lexy.foonathan.net]. - -A minimal `CMakeLists.txt` that uses lexy can look like this: - -.`CMakeLists.txt` -```cmake -project(lexy-example) - -include(FetchContent) -FetchContent_Declare(lexy URL https://lexy.foonathan.net/download/lexy-src.zip) -FetchContent_MakeAvailable(lexy) - -add_executable(lexy_example) -target_sources(lexy_example PRIVATE main.cpp) -target_link_libraries(lexy_example PRIVATE foonathan::lexy) -``` - -endif::[] - diff --git a/dep/lexy/UPSTREAM.md b/dep/lexy/UPSTREAM.md deleted file mode 100644 index d98ae327..00000000 --- a/dep/lexy/UPSTREAM.md +++ /dev/null @@ -1,2 +0,0 @@ -This is a heavily truncated copy of https://github.com/foonathan/lexy, commit -20926cf. \ No newline at end of file diff --git a/dep/lexy/build.py b/dep/lexy/build.py deleted file mode 100644 index aac156eb..00000000 --- a/dep/lexy/build.py +++ /dev/null @@ -1,13 +0,0 @@ -from build.c import cxxlibrary -from build.utils import glob - -cxxlibrary( - name="lexy", - srcs=[], - hdrs={ - h: f"./include/{h}" - for h in glob( - ["**/*.hpp"], dir="dep/lexy/include", relative_to="dep/lexy/include" - ) - }, -) diff --git a/dep/lexy/include/lexy/_detail/any_ref.hpp b/dep/lexy/include/lexy/_detail/any_ref.hpp deleted file mode 100644 index f873198c..00000000 --- a/dep/lexy/include/lexy/_detail/any_ref.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2020-2025 Jonathan Müller and lexy contributors -// SPDX-License-Identifier: BSL-1.0 - -#ifndef LEXY_DETAIL_ANY_REF_HPP_INCLUDED -#define LEXY_DETAIL_ANY_REF_HPP_INCLUDED - -#include - -// Essentially a void*, but we can cast it in a constexpr context. -// The cost is an extra layer of indirection. - -namespace lexy::_detail -{ -template -class any_holder; - -// Store a pointer to this instead of a void*. -class any_base -{ -public: - any_base(const any_base&) = delete; - any_base& operator=(const any_base&) = delete; - - template - constexpr T& get() noexcept - { - return static_cast*>(this)->get(); - } - template - constexpr const T& get() const noexcept - { - return static_cast*>(this)->get(); - } - -private: - constexpr any_base() = default; - ~any_base() = default; - - template - friend class any_holder; -}; - -using any_ref = any_base*; -using any_cref = const any_base*; - -// Need to store the object in here. -template -class any_holder : public any_base -{ -public: - constexpr explicit any_holder(T&& obj) : _obj(LEXY_MOV(obj)) {} - - constexpr T& get() noexcept - { - return _obj; - } - constexpr const T& get() const noexcept - { - return _obj; - } - -private: - T _obj; -}; -} // namespace lexy::_detail - -#endif // LEXY_DETAIL_ANY_REF_HPP_INCLUDED - diff --git a/dep/lexy/include/lexy/_detail/assert.hpp b/dep/lexy/include/lexy/_detail/assert.hpp deleted file mode 100644 index dae510e0..00000000 --- a/dep/lexy/include/lexy/_detail/assert.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2020-2025 Jonathan Müller and lexy contributors -// SPDX-License-Identifier: BSL-1.0 - -#ifndef LEXY_DETAIL_ASSERT_HPP_INCLUDED -#define LEXY_DETAIL_ASSERT_HPP_INCLUDED - -#include - -#ifndef LEXY_ENABLE_ASSERT - -// By default, enable assertions if NDEBUG is not defined. - -# if NDEBUG -# define LEXY_ENABLE_ASSERT 0 -# else -# define LEXY_ENABLE_ASSERT 1 -# endif - -#endif - -#if LEXY_ENABLE_ASSERT - -// We want assertions: use assert() if that's available, otherwise abort. -// We don't use assert() directly as that's not constexpr. - -# if NDEBUG - -# include -# define LEXY_PRECONDITION(Expr) ((Expr) ? void(0) : std::abort()) -# define LEXY_ASSERT(Expr, Msg) ((Expr) ? void(0) : std::abort()) - -# else - -# include - -# define LEXY_PRECONDITION(Expr) ((Expr) ? void(0) : assert(Expr)) -# define LEXY_ASSERT(Expr, Msg) ((Expr) ? void(0) : assert((Expr) && (Msg))) - -# endif - -#else - -// We don't want assertions. - -# define LEXY_PRECONDITION(Expr) static_cast(sizeof(Expr)) -# define LEXY_ASSERT(Expr, Msg) static_cast(sizeof(Expr)) - -#endif - -#endif // LEXY_DETAIL_ASSERT_HPP_INCLUDED - diff --git a/dep/lexy/include/lexy/_detail/buffer_builder.hpp b/dep/lexy/include/lexy/_detail/buffer_builder.hpp deleted file mode 100644 index f0f5b17f..00000000 --- a/dep/lexy/include/lexy/_detail/buffer_builder.hpp +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2020-2025 Jonathan Müller and lexy contributors -// SPDX-License-Identifier: BSL-1.0 - -#ifndef LEXY_DETAIL_BUFFER_BUILDER_HPP_INCLUDED -#define LEXY_DETAIL_BUFFER_BUILDER_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace lexy::_detail -{ -// Builds a buffer: it has a read are and a write area. -// The characters in the read area are already valid and can be read. -// The characters in the write area are not valid, but can be written too. -template -class buffer_builder -{ - static_assert(std::is_trivial_v); - - static constexpr std::size_t total_size_bytes = 1024; - static constexpr std::size_t stack_buffer_size - = (total_size_bytes - 3 * sizeof(T*)) / sizeof(T); - static constexpr auto growth_factor = 2; - -public: - buffer_builder() noexcept : _data(_stack_buffer), _read_size(0), _write_size(stack_buffer_size) - { - static_assert(sizeof(*this) == total_size_bytes, "invalid buffer size calculation"); - } - - ~buffer_builder() noexcept - { - // Free memory if we allocated any. - if (_data != _stack_buffer) - ::operator delete(_data); - } - - buffer_builder(const buffer_builder&) = delete; - buffer_builder& operator=(const buffer_builder&) = delete; - - // The total capacity: read + write. - std::size_t capacity() const noexcept - { - return _read_size + _write_size; - } - - // The read area. - const T* read_data() const noexcept - { - return _data; - } - std::size_t read_size() const noexcept - { - return _read_size; - } - - // The write area. - T* write_data() noexcept - { - return _data + _read_size; - } - std::size_t write_size() const noexcept - { - return _write_size; - } - - // Clears the read area. - void clear() noexcept - { - _write_size += _read_size; - _read_size = 0; - } - - // Takes the first n characters of the write area and appends them to the read area. - void commit(std::size_t n) noexcept - { - LEXY_PRECONDITION(n <= _write_size); - _read_size += n; - _write_size -= n; - } - - // Increases the write area, invalidates all pointers. - void grow() - { - const auto cur_cap = capacity(); - const auto new_cap = growth_factor * cur_cap; - - // Allocate new memory. - auto memory = static_cast(::operator new(new_cap * sizeof(T))); - // Copy the read area into the new memory. - std::memcpy(memory, _data, _read_size); - - // Release the old memory, if there was any. - if (_data != _stack_buffer) - ::operator delete(_data); - - // Update for the new area. - _data = memory; - // _read_size hasn't been changed - _write_size = new_cap - _read_size; - } - - //=== iterator ===// - // Stable iterator over the memory. - class stable_iterator : public forward_iterator_base - { - public: - constexpr stable_iterator() = default; - - explicit constexpr stable_iterator(const _detail::buffer_builder& buffer, - std::size_t idx) noexcept - : _buffer(&buffer), _idx(idx) - {} - - constexpr const T& deref() const noexcept - { - LEXY_PRECONDITION(_idx != _buffer->read_size()); - return _buffer->read_data()[_idx]; - } - - constexpr void increment() noexcept - { - LEXY_PRECONDITION(_idx != _buffer->read_size()); - ++_idx; - } - - constexpr bool equal(stable_iterator rhs) const noexcept - { - if (!_buffer || !rhs._buffer) - return !_buffer && !rhs._buffer; - else - { - LEXY_PRECONDITION(_buffer == rhs._buffer); - return _idx == rhs._idx; - } - } - - constexpr std::size_t index() const noexcept - { - return _idx; - } - - private: - const _detail::buffer_builder* _buffer = nullptr; - std::size_t _idx = 0; - }; - -private: - T* _data; - std::size_t _read_size; - std::size_t _write_size; - T _stack_buffer[stack_buffer_size]; -}; -} // namespace lexy::_detail - -#endif // LEXY_DETAIL_BUFFER_BUILDER_HPP_INCLUDED - diff --git a/dep/lexy/include/lexy/_detail/code_point.hpp b/dep/lexy/include/lexy/_detail/code_point.hpp deleted file mode 100644 index 88e7aa0b..00000000 --- a/dep/lexy/include/lexy/_detail/code_point.hpp +++ /dev/null @@ -1,368 +0,0 @@ -// Copyright (C) 2020-2025 Jonathan Müller and lexy contributors -// SPDX-License-Identifier: BSL-1.0 - -#ifndef LEXY_DETAIL_CODE_POINT_HPP_INCLUDED -#define LEXY_DETAIL_CODE_POINT_HPP_INCLUDED - -#include - -//=== encoding ===// -namespace lexy::_detail -{ -template -constexpr std::size_t encode_code_point(char32_t cp, typename Encoding::char_type* buffer, - std::size_t size) -{ - if constexpr (std::is_same_v) - { - LEXY_PRECONDITION(size >= 1); - - *buffer = char(cp); - return 1; - } - else if constexpr (std::is_same_v // - || std::is_same_v) - { - using char_type = typename Encoding::char_type; - // Taken from http://www.herongyang.com/Unicode/UTF-8-UTF-8-Encoding-Algorithm.html. - if (cp <= 0x7F) - { - LEXY_PRECONDITION(size >= 1); - - buffer[0] = char_type(cp); - return 1; - } - else if (cp <= 0x07'FF) - { - LEXY_PRECONDITION(size >= 2); - - auto first = (cp >> 6) & 0x1F; - auto second = (cp >> 0) & 0x3F; - - buffer[0] = char_type(0xC0 | first); - buffer[1] = char_type(0x80 | second); - return 2; - } - else if (cp <= 0xFF'FF) - { - LEXY_PRECONDITION(size >= 3); - - auto first = (cp >> 12) & 0x0F; - auto second = (cp >> 6) & 0x3F; - auto third = (cp >> 0) & 0x3F; - - buffer[0] = char_type(0xE0 | first); - buffer[1] = char_type(0x80 | second); - buffer[2] = char_type(0x80 | third); - return 3; - } - else - { - LEXY_PRECONDITION(size >= 4); - - auto first = (cp >> 18) & 0x07; - auto second = (cp >> 12) & 0x3F; - auto third = (cp >> 6) & 0x3F; - auto fourth = (cp >> 0) & 0x3F; - - buffer[0] = char_type(0xF0 | first); - buffer[1] = char_type(0x80 | second); - buffer[2] = char_type(0x80 | third); - buffer[3] = char_type(0x80 | fourth); - return 4; - } - } - else if constexpr (std::is_same_v) - { - if (cp <= 0xFF'FF) - { - LEXY_PRECONDITION(size >= 1); - - buffer[0] = char16_t(cp); - return 1; - } - else - { - // Algorithm implemented from - // https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF. - LEXY_PRECONDITION(size >= 2); - - auto u_prime = cp - 0x1'0000; - auto high_ten_bits = u_prime >> 10; - auto low_ten_bits = u_prime & 0b0000'0011'1111'1111; - - buffer[0] = char16_t(0xD800 + high_ten_bits); - buffer[1] = char16_t(0xDC00 + low_ten_bits); - return 2; - } - } - else if constexpr (std::is_same_v) - { - LEXY_PRECONDITION(size >= 1); - - *buffer = cp; - return 1; - } - else - { - static_assert(lexy::_detail::error, - "cannot encode a code point in this encoding"); - (void)cp; - (void)buffer; - (void)size; - return 0; - } -} -} // namespace lexy::_detail - -//=== parsing ===// -namespace lexy::_detail -{ -enum class cp_error -{ - success, - eof, - leads_with_trailing, - missing_trailing, - surrogate, - overlong_sequence, - out_of_range, -}; - -template -struct cp_result -{ - char32_t cp; - cp_error error; - typename Reader::marker end; -}; - -template -constexpr cp_result parse_code_point(Reader reader) -{ - if constexpr (std::is_same_v) - { - if (reader.peek() == Reader::encoding::eof()) - return {{}, cp_error::eof, reader.current()}; - - auto cur = reader.peek(); - reader.bump(); - - auto cp = static_cast(cur); - if (cp <= 0x7F) - return {cp, cp_error::success, reader.current()}; - else - return {cp, cp_error::out_of_range, reader.current()}; - } - else if constexpr (std::is_same_v // - || std::is_same_v) - { - using uchar_t = unsigned char; - constexpr auto payload_lead1 = 0b0111'1111; - constexpr auto payload_lead2 = 0b0001'1111; - constexpr auto payload_lead3 = 0b0000'1111; - constexpr auto payload_lead4 = 0b0000'0111; - constexpr auto payload_cont = 0b0011'1111; - - constexpr auto pattern_lead1 = 0b0 << 7; - constexpr auto pattern_lead2 = 0b110 << 5; - constexpr auto pattern_lead3 = 0b1110 << 4; - constexpr auto pattern_lead4 = 0b11110 << 3; - constexpr auto pattern_cont = 0b10 << 6; - - auto first = uchar_t(reader.peek()); - if ((first & ~payload_lead1) == pattern_lead1) - { - // ASCII character. - reader.bump(); - return {first, cp_error::success, reader.current()}; - } - else if ((first & ~payload_cont) == pattern_cont) - { - return {{}, cp_error::leads_with_trailing, reader.current()}; - } - else if ((first & ~payload_lead2) == pattern_lead2) - { - reader.bump(); - - auto second = uchar_t(reader.peek()); - if ((second & ~payload_cont) != pattern_cont) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - auto result = char32_t(first & payload_lead2); - result <<= 6; - result |= char32_t(second & payload_cont); - - // C0 and C1 are overlong ASCII. - if (first == 0xC0 || first == 0xC1) - return {result, cp_error::overlong_sequence, reader.current()}; - else - return {result, cp_error::success, reader.current()}; - } - else if ((first & ~payload_lead3) == pattern_lead3) - { - reader.bump(); - - auto second = uchar_t(reader.peek()); - if ((second & ~payload_cont) != pattern_cont) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - auto third = uchar_t(reader.peek()); - if ((third & ~payload_cont) != pattern_cont) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - auto result = char32_t(first & payload_lead3); - result <<= 6; - result |= char32_t(second & payload_cont); - result <<= 6; - result |= char32_t(third & payload_cont); - - auto cp = result; - if (0xD800 <= cp && cp <= 0xDFFF) - return {cp, cp_error::surrogate, reader.current()}; - else if (first == 0xE0 && second < 0xA0) - return {cp, cp_error::overlong_sequence, reader.current()}; - else - return {cp, cp_error::success, reader.current()}; - } - else if ((first & ~payload_lead4) == pattern_lead4) - { - reader.bump(); - - auto second = uchar_t(reader.peek()); - if ((second & ~payload_cont) != pattern_cont) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - auto third = uchar_t(reader.peek()); - if ((third & ~payload_cont) != pattern_cont) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - auto fourth = uchar_t(reader.peek()); - if ((fourth & ~payload_cont) != pattern_cont) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - auto result = char32_t(first & payload_lead4); - result <<= 6; - result |= char32_t(second & payload_cont); - result <<= 6; - result |= char32_t(third & payload_cont); - result <<= 6; - result |= char32_t(fourth & payload_cont); - - auto cp = result; - if (cp > 0x10'FFFF) - return {cp, cp_error::out_of_range, reader.current()}; - else if (first == 0xF0 && second < 0x90) - return {cp, cp_error::overlong_sequence, reader.current()}; - else - return {cp, cp_error::success, reader.current()}; - } - else // FE or FF - { - return {{}, cp_error::eof, reader.current()}; - } - } - else if constexpr (std::is_same_v) - { - constexpr auto payload1 = 0b0000'0011'1111'1111; - constexpr auto payload2 = payload1; - - constexpr auto pattern1 = 0b110110 << 10; - constexpr auto pattern2 = 0b110111 << 10; - - if (reader.peek() == Reader::encoding::eof()) - return {{}, cp_error::eof, reader.current()}; - - auto first = char16_t(reader.peek()); - if ((first & ~payload1) == pattern1) - { - reader.bump(); - if (reader.peek() == Reader::encoding::eof()) - return {{}, cp_error::missing_trailing, reader.current()}; - - auto second = char16_t(reader.peek()); - if ((second & ~payload2) != pattern2) - return {{}, cp_error::missing_trailing, reader.current()}; - reader.bump(); - - // We've got a valid code point. - auto result = char32_t(first & payload1); - result <<= 10; - result |= char32_t(second & payload2); - result |= 0x10000; - return {result, cp_error::success, reader.current()}; - } - else if ((first & ~payload2) == pattern2) - { - return {{}, cp_error::leads_with_trailing, reader.current()}; - } - else - { - // Single code unit code point; always valid. - reader.bump(); - return {first, cp_error::success, reader.current()}; - } - } - else if constexpr (std::is_same_v) - { - if (reader.peek() == Reader::encoding::eof()) - return {{}, cp_error::eof, reader.current()}; - - auto cur = reader.peek(); - reader.bump(); - - auto cp = cur; - if (cp > 0x10'FFFF) - return {cp, cp_error::out_of_range, reader.current()}; - else if (0xD800 <= cp && cp <= 0xDFFF) - return {cp, cp_error::surrogate, reader.current()}; - else - return {cp, cp_error::success, reader.current()}; - } - else - { - static_assert(lexy::_detail::error, - "no known code point for this encoding"); - return {}; - } -} - -template -constexpr void recover_code_point(Reader& reader, cp_result result) -{ - switch (result.error) - { - case cp_error::success: - // Consume the entire code point. - reader.reset(result.end); - break; - case cp_error::eof: - // We don't need to do anything to "recover" from EOF. - break; - - case cp_error::leads_with_trailing: - // Invalid code unit, consume to recover. - LEXY_PRECONDITION(result.end.position() == reader.position()); - reader.bump(); - break; - - case cp_error::missing_trailing: - case cp_error::surrogate: - case cp_error::out_of_range: - case cp_error::overlong_sequence: - // Consume all the invalid code units to recover. - reader.reset(result.end); - break; - } -} -} // namespace lexy::_detail - -#endif // LEXY_DETAIL_CODE_POINT_HPP_INCLUDED - diff --git a/dep/lexy/include/lexy/_detail/config.hpp b/dep/lexy/include/lexy/_detail/config.hpp deleted file mode 100644 index 84a69da5..00000000 --- a/dep/lexy/include/lexy/_detail/config.hpp +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright (C) 2020-2025 Jonathan Müller and lexy contributors -// SPDX-License-Identifier: BSL-1.0 - -#ifndef LEXY_DETAIL_CONFIG_HPP_INCLUDED -#define LEXY_DETAIL_CONFIG_HPP_INCLUDED - -#include -#include - -#if defined(LEXY_USER_CONFIG_HEADER) -# include LEXY_USER_CONFIG_HEADER -#elif defined(__has_include) -# if __has_include() -# include -# elif __has_include("lexy_user_config.hpp") -# include "lexy_user_config.hpp" -# endif -#endif - -#ifndef LEXY_HAS_UNICODE_DATABASE -# define LEXY_HAS_UNICODE_DATABASE 0 -#endif - -#ifndef LEXY_EXPERIMENTAL -# define LEXY_EXPERIMENTAL 0 -#endif - -//=== utility traits===// -#define LEXY_MOV(...) static_cast&&>(__VA_ARGS__) -#define LEXY_FWD(...) static_cast(__VA_ARGS__) - -#define LEXY_DECLVAL(...) lexy::_detail::declval<__VA_ARGS__>() - -#define LEXY_DECAY_DECLTYPE(...) std::decay_t - -/// Creates a new type from the instantiation of a template. -/// This is used to shorten type names. -#define LEXY_INSTANTIATION_NEWTYPE(Name, Templ, ...) \ - struct Name : Templ<__VA_ARGS__> \ - { \ - using Templ<__VA_ARGS__>::Templ; \ - } - -namespace lexy::_detail -{ -template -constexpr bool error = false; - -template -std::add_rvalue_reference_t declval(); - -template -constexpr void swap(T& lhs, T& rhs) noexcept -{ - T tmp = LEXY_MOV(lhs); - lhs = LEXY_MOV(rhs); - rhs = LEXY_MOV(tmp); -} - -template -constexpr bool is_decayed_same = std::is_same_v, std::decay_t>; - -template -using type_or = std::conditional_t, Fallback, T>; -} // namespace lexy::_detail - -//=== NTTP ===// -#ifndef LEXY_HAS_NTTP -// See https://github.com/foonathan/lexy/issues/15. -# if __cpp_nontype_template_parameter_class >= 201806 || __cpp_nontype_template_args >= 201911 -# define LEXY_HAS_NTTP 1 -# else -# define LEXY_HAS_NTTP 0 -# endif -#endif - -#if LEXY_HAS_NTTP -# define LEXY_NTTP_PARAM auto -#else -# define LEXY_NTTP_PARAM const auto& -#endif - -//=== consteval ===// -#ifndef LEXY_HAS_CONSTEVAL -# if defined(_MSC_VER) && !defined(__clang__) -// Currently can't handle returning strings from consteval, check back later. -# define LEXY_HAS_CONSTEVAL 0 -# elif __cpp_consteval -# define LEXY_HAS_CONSTEVAL 1 -# else -# define LEXY_HAS_CONSTEVAL 0 -# endif -#endif - -#if LEXY_HAS_CONSTEVAL -# define LEXY_CONSTEVAL consteval -#else -# define LEXY_CONSTEVAL constexpr -#endif - -//=== constexpr ===// -#ifndef LEXY_HAS_CONSTEXPR_DTOR -# if __cpp_constexpr_dynamic_alloc -# define LEXY_HAS_CONSTEXPR_DTOR 1 -# else -# define LEXY_HAS_CONSTEXPR_DTOR 0 -# endif -#endif - -#if LEXY_HAS_CONSTEXPR_DTOR -# define LEXY_CONSTEXPR_DTOR constexpr -#else -# define LEXY_CONSTEXPR_DTOR -#endif - -//=== char8_t ===// -#ifndef LEXY_HAS_CHAR8_T -# if __cpp_char8_t -# define LEXY_HAS_CHAR8_T 1 -# else -# define LEXY_HAS_CHAR8_T 0 -# endif -#endif - -#if LEXY_HAS_CHAR8_T - -# define LEXY_CHAR_OF_u8 char8_t -# define LEXY_CHAR8_T char8_t -# define LEXY_CHAR8_STR(Str) u8##Str - -#else - -namespace lexy -{ -using _char8_t = unsigned char; -} // namespace lexy - -# define LEXY_CHAR_OF_u8 char -# define LEXY_CHAR8_T ::lexy::_char8_t -# define LEXY_CHAR8_STR(Str) \ - LEXY_NTTP_STRING(::lexy::_detail::type_string, u8##Str)::c_str - -#endif - -//=== endianness ===// -#ifndef LEXY_IS_LITTLE_ENDIAN -# if defined(__BYTE_ORDER__) -# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define LEXY_IS_LITTLE_ENDIAN 1 -# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define LEXY_IS_LITTLE_ENDIAN 0 -# else -# error "unsupported byte order" -# endif -# elif defined(_MSC_VER) -# define LEXY_IS_LITTLE_ENDIAN 1 -# else -# error "unknown endianness" -# endif -#endif - -//=== force inline ===// -#ifndef LEXY_FORCE_INLINE -# if defined(__has_cpp_attribute) -# if __has_cpp_attribute(gnu::always_inline) -# define LEXY_FORCE_INLINE [[gnu::always_inline]] -# endif -# endif -# -# ifndef LEXY_FORCE_INLINE -# define LEXY_FORCE_INLINE inline -# endif -#endif - -//=== empty_member ===// -#ifndef LEXY_EMPTY_MEMBER - -# if defined(__has_cpp_attribute) -# if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 11 -// GCC <= 11 has buggy support, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101040 -# define LEXY_HAS_EMPTY_MEMBER 0 -# elif __has_cpp_attribute(no_unique_address) -# define LEXY_HAS_EMPTY_MEMBER 1 -# endif -# endif -# ifndef LEXY_HAS_EMPTY_MEMBER -# define LEXY_HAS_EMPTY_MEMBER 0 -# endif - -# if LEXY_HAS_EMPTY_MEMBER -# define LEXY_EMPTY_MEMBER [[no_unique_address]] -# else -# define LEXY_EMPTY_MEMBER -# endif - -#endif - -#endif // LEXY_DETAIL_CONFIG_HPP_INCLUDED - diff --git a/dep/lexy/include/lexy/_detail/detect.hpp b/dep/lexy/include/lexy/_detail/detect.hpp deleted file mode 100644 index aa987a0e..00000000 --- a/dep/lexy/include/lexy/_detail/detect.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2020-2025 Jonathan Müller and lexy contributors -// SPDX-License-Identifier: BSL-1.0 - -#ifndef LEXY_DETAIL_DETECT_HPP_INCLUDED -#define LEXY_DETAIL_DETECT_HPP_INCLUDED - -#include - -namespace lexy::_detail -{ -template -using void_t = void; - -template