debase-ruby_core_source 4.0.1 → 4.1.0.preview1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/addr2line.h +22 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/builtin.h +127 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/build_assert/build_assert.h +40 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/check_type/check_type.h +63 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/container_of/container_of.h +142 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/list/list.h +791 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/str/str.h +17 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/constant.h +53 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/darray.h +295 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/debug_counter.h +428 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/dln.h +33 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/encindex.h +70 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/eval_intern.h +356 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/hrtime.h +237 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/id.h +365 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/id_table.h +74 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/insns.inc +315 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/insns_info.inc +11637 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/array.h +158 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/basic_operators.h +67 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/bignum.h +249 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/bits.h +647 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/box.h +103 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/class.h +797 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/cmdlineopt.h +64 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/compar.h +30 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/compile.h +34 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/compilers.h +104 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/complex.h +29 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/concurrent_set.h +21 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/cont.h +33 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/coverage.h +51 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/dir.h +16 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/enc.h +19 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/encoding.h +40 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/enum.h +18 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/enumerator.h +21 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/error.h +287 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/eval.h +43 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/file.h +40 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/fixnum.h +185 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/gc.h +411 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/hash.h +220 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/imemo.h +302 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/inits.h +54 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/io.h +167 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/io_buffer.h +36 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/jit.h +23 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/load.h +20 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/loadpath.h +16 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/marshal.h +17 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/math.h +23 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/missing.h +19 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/numeric.h +326 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/object.h +88 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/objspace.h +24 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/parse.h +131 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/proc.h +34 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/process.h +124 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/ractor.h +9 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/random.h +17 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/range.h +46 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/rational.h +92 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/re.h +87 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/ruby_parser.h +109 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/sanitizers.h +346 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/scheduler.h +7 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/serial.h +23 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/set.h +20 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/set_table.h +77 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/signal.h +25 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/simd.h +18 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/st.h +32 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/static_assert.h +16 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/string.h +240 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/struct.h +120 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/symbol.h +46 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/thread.h +108 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/time.h +34 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/transcode.h +23 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/util.h +27 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/variable.h +81 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/vm.h +144 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/vm_map.h +95 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/warnings.h +16 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal.h +106 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/iseq.h +439 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/known_errors.inc +1419 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/method.h +279 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/node.h +122 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/node_name.inc +224 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/optinsn.inc +128 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/optunifs.inc +41 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parse.h +246 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_bits.h +647 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_node.h +32 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_st.h +161 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_value.h +116 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/arena.h +37 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/ast.h +10371 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/buffer.h +52 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/comments.h +43 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/accel.h +19 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/align.h +36 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/assume.h +25 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/exported.h +24 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/fallthrough.h +22 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/filesystem.h +32 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/flex_array.h +19 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/force_inline.h +21 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/format.h +25 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/inline.h +17 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nodiscard.h +22 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nonnull.h +18 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/unused.h +18 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/constant_pool.h +81 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/diagnostic.h +93 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/errors_format.h +53 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/excludes.h +29 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/extension.h +19 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/integer.h +41 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/allocator.h +68 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/allocator_debug.h +88 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/arena.h +108 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/bit.h +42 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/buffer.h +91 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/char.h +139 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/comments.h +20 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/constant_pool.h +152 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/diagnostic.h +389 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/encoding.h +242 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/integer.h +68 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/isinf.h +16 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/line_offset_list.h +34 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/list.h +62 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/magic_comments.h +23 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/memchr.h +15 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/node.h +32 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/options.h +224 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/parser.h +971 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/regexp.h +42 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/serialize.h +39 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/source.h +72 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/static_literals.h +100 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/stringy.h +35 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/strncasecmp.h +18 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/strpbrk.h +33 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/tokens.h +11 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/json.h +32 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/line_offset_list.h +61 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/magic_comments.h +35 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/node.h +94 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/options.h +335 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/parser.h +348 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/prettyprint.h +31 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/prism.h +131 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/serialize.h +115 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/source.h +155 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/stream.h +28 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/string_query.h +63 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/stringy.h +72 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/version.h +38 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism_compile.h +204 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism_xallocator.h +6 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/probes_helper.h +42 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ractor_core.h +421 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/regenc.h +261 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/regint.h +983 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/regparse.h +371 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/revision.h +5 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ruby_assert.h +14 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ruby_atomic.h +115 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/rubyparser.h +1389 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/shape.h +733 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/siphash.h +48 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/symbol.h +116 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_none.h +25 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_pthread.h +63 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_sched.h +271 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_win32.h +48 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/timev.h +58 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/transcode_data.h +138 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/variable.h +26 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/version.h +69 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm.inc +6457 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_call_iseq_optimized.inc +244 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_callinfo.h +688 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_core.h +2509 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_debug.h +124 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_exec.h +202 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_insnhelper.h +280 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_opts.h +65 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_sync.h +160 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vmtc.inc +302 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/yjit.h +87 -0
- data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/zjit.h +221 -0
- data/lib/debase/ruby_core_source/version.rb +1 -1
- metadata +2930 -2724
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_REGEXP_H
|
|
2
|
+
#define PRISM_INTERNAL_REGEXP_H
|
|
3
|
+
|
|
4
|
+
#include "prism/ast.h"
|
|
5
|
+
#include "prism/internal/constant_pool.h"
|
|
6
|
+
#include "prism/parser.h"
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Accumulation state for named capture groups found during regexp parsing.
|
|
10
|
+
* The caller initializes this with the call node and passes it to
|
|
11
|
+
* pm_regexp_parse. The regexp parser populates match and names as groups
|
|
12
|
+
* are found.
|
|
13
|
+
*/
|
|
14
|
+
typedef struct {
|
|
15
|
+
/* The call node wrapping the regular expression node (for =~). */
|
|
16
|
+
pm_call_node_t *call;
|
|
17
|
+
|
|
18
|
+
/* The match write node being built, or NULL if no captures found yet. */
|
|
19
|
+
pm_match_write_node_t *match;
|
|
20
|
+
|
|
21
|
+
/* The set of capture names found so far (for deduplication). */
|
|
22
|
+
pm_constant_id_set_t names;
|
|
23
|
+
} pm_regexp_name_data_t;
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Callback invoked by pm_regexp_parse() for each named capture group found.
|
|
27
|
+
*/
|
|
28
|
+
typedef void (*pm_regexp_name_callback_t)(pm_parser_t *parser, const pm_string_t *name, bool shared, pm_regexp_name_data_t *data);
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Parse a regular expression, validate its encoding, and optionally extract
|
|
32
|
+
* named capture groups. Returns the encoding flags to set on the node.
|
|
33
|
+
*/
|
|
34
|
+
PRISM_EXPORTED_FUNCTION pm_node_flags_t pm_regexp_parse(pm_parser_t *parser, pm_regular_expression_node_t *node, pm_regexp_name_callback_t name_callback, pm_regexp_name_data_t *name_data);
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Parse an interpolated regular expression for named capture groups only.
|
|
38
|
+
* No encoding validation is performed.
|
|
39
|
+
*/
|
|
40
|
+
void pm_regexp_parse_named_captures(pm_parser_t *parser, const uint8_t *source, size_t size, bool shared, bool extended_mode, pm_regexp_name_callback_t name_callback, pm_regexp_name_data_t *name_data);
|
|
41
|
+
|
|
42
|
+
#endif
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_SERIALIZE_H
|
|
2
|
+
#define PRISM_INTERNAL_SERIALIZE_H
|
|
3
|
+
|
|
4
|
+
#include "prism/internal/encoding.h"
|
|
5
|
+
#include "prism/internal/list.h"
|
|
6
|
+
|
|
7
|
+
#include "prism/ast.h"
|
|
8
|
+
#include "prism/buffer.h"
|
|
9
|
+
#include "prism/excludes.h"
|
|
10
|
+
#include "prism/parser.h"
|
|
11
|
+
|
|
12
|
+
/* We optionally support serializing to a binary string. For systems that do not
|
|
13
|
+
* want or need this functionality, it can be turned off with the
|
|
14
|
+
* PRISM_EXCLUDE_SERIALIZATION define. */
|
|
15
|
+
#ifndef PRISM_EXCLUDE_SERIALIZATION
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Serialize the given list of offsets to the given buffer.
|
|
19
|
+
*/
|
|
20
|
+
void pm_serialize_line_offset_list(pm_line_offset_list_t *list, pm_buffer_t *buffer);
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Serialize the given list of comments to the given buffer.
|
|
24
|
+
*/
|
|
25
|
+
void pm_serialize_comment_list(pm_list_t *list, pm_buffer_t *buffer);
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Serialize the name of the encoding to the buffer.
|
|
29
|
+
*/
|
|
30
|
+
void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer);
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Serialize the encoding, metadata, nodes, and constant pool.
|
|
34
|
+
*/
|
|
35
|
+
void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
|
|
36
|
+
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#endif
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_SOURCE_H
|
|
2
|
+
#define PRISM_INTERNAL_SOURCE_H
|
|
3
|
+
|
|
4
|
+
#include "prism/source.h"
|
|
5
|
+
#include "prism/buffer.h"
|
|
6
|
+
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* The type of source, which determines cleanup behavior.
|
|
11
|
+
*/
|
|
12
|
+
typedef enum {
|
|
13
|
+
/* Wraps existing constant memory, no cleanup. */
|
|
14
|
+
PM_SOURCE_CONSTANT,
|
|
15
|
+
|
|
16
|
+
/* Wraps existing shared memory (non-owning slice), no cleanup. */
|
|
17
|
+
PM_SOURCE_SHARED,
|
|
18
|
+
|
|
19
|
+
/* Owns a heap-allocated buffer, freed on cleanup. */
|
|
20
|
+
PM_SOURCE_OWNED,
|
|
21
|
+
|
|
22
|
+
/* Memory-mapped file, unmapped on cleanup. */
|
|
23
|
+
PM_SOURCE_MAPPED,
|
|
24
|
+
|
|
25
|
+
/* Stream source backed by a pm_buffer_t. */
|
|
26
|
+
PM_SOURCE_STREAM
|
|
27
|
+
} pm_source_type_t;
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* The internal representation of a source.
|
|
31
|
+
*/
|
|
32
|
+
struct pm_source_t {
|
|
33
|
+
/* A pointer to the start of the source data. */
|
|
34
|
+
const uint8_t *source;
|
|
35
|
+
|
|
36
|
+
/* The length of the source data in bytes. */
|
|
37
|
+
size_t length;
|
|
38
|
+
|
|
39
|
+
/* The type of the source. */
|
|
40
|
+
pm_source_type_t type;
|
|
41
|
+
|
|
42
|
+
/* Stream-specific data, only used for PM_SOURCE_STREAM sources. */
|
|
43
|
+
struct {
|
|
44
|
+
/* The buffer that holds the accumulated stream data. */
|
|
45
|
+
pm_buffer_t *buffer;
|
|
46
|
+
|
|
47
|
+
/* The stream object to read from. */
|
|
48
|
+
void *stream;
|
|
49
|
+
|
|
50
|
+
/* The function to use to read from the stream. */
|
|
51
|
+
pm_source_stream_fgets_t *fgets;
|
|
52
|
+
|
|
53
|
+
/* The function to use to check if the stream is at EOF. */
|
|
54
|
+
pm_source_stream_feof_t *feof;
|
|
55
|
+
|
|
56
|
+
/* Whether the stream has reached EOF. */
|
|
57
|
+
bool eof;
|
|
58
|
+
} stream;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* Read from a stream into the source's internal buffer. This is used by
|
|
63
|
+
* pm_parse_stream to incrementally read the source.
|
|
64
|
+
*/
|
|
65
|
+
bool pm_source_stream_read(pm_source_t *source);
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Returns whether the stream source has reached EOF.
|
|
69
|
+
*/
|
|
70
|
+
bool pm_source_stream_eof(const pm_source_t *source);
|
|
71
|
+
|
|
72
|
+
#endif
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_STATIC_LITERALS_H
|
|
2
|
+
#define PRISM_INTERNAL_STATIC_LITERALS_H
|
|
3
|
+
|
|
4
|
+
#include "prism/internal/encoding.h"
|
|
5
|
+
|
|
6
|
+
#include "prism/ast.h"
|
|
7
|
+
#include "prism/buffer.h"
|
|
8
|
+
#include "prism/line_offset_list.h"
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* An internal hash table for a set of nodes.
|
|
12
|
+
*/
|
|
13
|
+
typedef struct {
|
|
14
|
+
/* The array of nodes in the hash table. */
|
|
15
|
+
pm_node_t **nodes;
|
|
16
|
+
|
|
17
|
+
/* The size of the hash table. */
|
|
18
|
+
uint32_t size;
|
|
19
|
+
|
|
20
|
+
/* The space that has been allocated in the hash table. */
|
|
21
|
+
uint32_t capacity;
|
|
22
|
+
} pm_node_hash_t;
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Certain sets of nodes (hash keys and when clauses) check for duplicate nodes
|
|
26
|
+
* to alert the user of potential issues. To do this, we keep a set of the nodes
|
|
27
|
+
* that have been seen so far, and compare whenever we find a new node.
|
|
28
|
+
*
|
|
29
|
+
* We bucket the nodes based on their type to minimize the number of comparisons
|
|
30
|
+
* that need to be performed.
|
|
31
|
+
*/
|
|
32
|
+
typedef struct {
|
|
33
|
+
/*
|
|
34
|
+
* This is the set of IntegerNode and SourceLineNode instances.
|
|
35
|
+
*/
|
|
36
|
+
pm_node_hash_t integer_nodes;
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
* This is the set of FloatNode instances.
|
|
40
|
+
*/
|
|
41
|
+
pm_node_hash_t float_nodes;
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* This is the set of RationalNode and ImaginaryNode instances.
|
|
45
|
+
*/
|
|
46
|
+
pm_node_hash_t number_nodes;
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* This is the set of StringNode and SourceFileNode instances.
|
|
50
|
+
*/
|
|
51
|
+
pm_node_hash_t string_nodes;
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* This is the set of RegularExpressionNode instances.
|
|
55
|
+
*/
|
|
56
|
+
pm_node_hash_t regexp_nodes;
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* This is the set of SymbolNode instances.
|
|
60
|
+
*/
|
|
61
|
+
pm_node_hash_t symbol_nodes;
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* A pointer to the last TrueNode instance that was inserted, or NULL.
|
|
65
|
+
*/
|
|
66
|
+
pm_node_t *true_node;
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* A pointer to the last FalseNode instance that was inserted, or NULL.
|
|
70
|
+
*/
|
|
71
|
+
pm_node_t *false_node;
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* A pointer to the last NilNode instance that was inserted, or NULL.
|
|
75
|
+
*/
|
|
76
|
+
pm_node_t *nil_node;
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* A pointer to the last SourceEncodingNode instance that was inserted, or
|
|
80
|
+
* NULL.
|
|
81
|
+
*/
|
|
82
|
+
pm_node_t *source_encoding_node;
|
|
83
|
+
} pm_static_literals_t;
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Add a node to the set of static literals.
|
|
87
|
+
*/
|
|
88
|
+
pm_node_t * pm_static_literals_add(const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const pm_encoding_t *encoding, pm_static_literals_t *literals, pm_node_t *node, bool replace);
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* Free the internal memory associated with the given static literals set.
|
|
92
|
+
*/
|
|
93
|
+
void pm_static_literals_free(pm_static_literals_t *literals);
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* Create a string-based representation of the given static literal.
|
|
97
|
+
*/
|
|
98
|
+
void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const pm_encoding_t *encoding, const pm_node_t *node);
|
|
99
|
+
|
|
100
|
+
#endif
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_STRINGY_H
|
|
2
|
+
#define PRISM_INTERNAL_STRINGY_H
|
|
3
|
+
|
|
4
|
+
#include "prism/stringy.h"
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Backing storage for an empty string.
|
|
8
|
+
*/
|
|
9
|
+
static const uint8_t empty_source[] = "";
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Defines an empty string. This is useful for initializing a string that will
|
|
13
|
+
* be filled in later.
|
|
14
|
+
*/
|
|
15
|
+
#define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = empty_source, .length = 0 })
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Initialize a shared string that is based on initial input.
|
|
19
|
+
*/
|
|
20
|
+
void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end);
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* Compare the underlying lengths and bytes of two strings. Returns 0 if the
|
|
24
|
+
* strings are equal, a negative number if the left string is less than the
|
|
25
|
+
* right string, and a positive number if the left string is greater than the
|
|
26
|
+
* right string.
|
|
27
|
+
*/
|
|
28
|
+
int pm_string_compare(const pm_string_t *left, const pm_string_t *right);
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Free the associated memory of the given string.
|
|
32
|
+
*/
|
|
33
|
+
void pm_string_cleanup(pm_string_t *string);
|
|
34
|
+
|
|
35
|
+
#endif
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_STRNCASECMP_H
|
|
2
|
+
#define PRISM_INTERNAL_STRNCASECMP_H
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Compare two strings, ignoring case, up to the given length. Returns 0 if the
|
|
9
|
+
* strings are equal, a negative number if string1 is less than string2, or a
|
|
10
|
+
* positive number if string1 is greater than string2.
|
|
11
|
+
*
|
|
12
|
+
* Note that this is effectively our own implementation of strncasecmp, but it's
|
|
13
|
+
* not available on all of the platforms we want to support so we're rolling it
|
|
14
|
+
* here.
|
|
15
|
+
*/
|
|
16
|
+
int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length);
|
|
17
|
+
|
|
18
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifndef PRISM_INTERNAL_STRPBRK_H
|
|
2
|
+
#define PRISM_INTERNAL_STRPBRK_H
|
|
3
|
+
|
|
4
|
+
#include "prism/parser.h"
|
|
5
|
+
|
|
6
|
+
/* The maximum number of bytes in a strpbrk charset. */
|
|
7
|
+
#define PM_STRPBRK_CACHE_SIZE 16
|
|
8
|
+
|
|
9
|
+
#include <stddef.h>
|
|
10
|
+
#include <stdint.h>
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Here we have rolled our own version of strpbrk. The standard library strpbrk
|
|
14
|
+
* has undefined behavior when the source string is not null-terminated. We want
|
|
15
|
+
* to support strings that are not null-terminated because pm_parse does not
|
|
16
|
+
* have the contract that the string is null-terminated. (This is desirable
|
|
17
|
+
* because it means the extension can call pm_parse with the result of a call to
|
|
18
|
+
* mmap).
|
|
19
|
+
*
|
|
20
|
+
* The standard library strpbrk also does not support passing a maximum length
|
|
21
|
+
* to search. We want to support this for the reason mentioned above, but we
|
|
22
|
+
* also don't want it to stop on null bytes. Ruby actually allows null bytes
|
|
23
|
+
* within strings, comments, regular expressions, etc. So we need to be able to
|
|
24
|
+
* skip past them.
|
|
25
|
+
*
|
|
26
|
+
* Finally, we want to support encodings wherein the charset could contain
|
|
27
|
+
* characters that are trailing bytes of multi-byte characters. For example, in
|
|
28
|
+
* Shift-JIS, the backslash character can be a trailing byte. In that case we
|
|
29
|
+
* need to take a slower path and iterate one multi-byte character at a time.
|
|
30
|
+
*/
|
|
31
|
+
const uint8_t * pm_strpbrk(pm_parser_t *parser, const uint8_t *source, const uint8_t *charset, ptrdiff_t length, bool validate);
|
|
32
|
+
|
|
33
|
+
#endif
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file json.h
|
|
3
|
+
*/
|
|
4
|
+
#ifndef PRISM_JSON_H
|
|
5
|
+
#define PRISM_JSON_H
|
|
6
|
+
|
|
7
|
+
#include "prism/excludes.h"
|
|
8
|
+
|
|
9
|
+
/* We optionally support dumping to JSON. For systems that don't want or need
|
|
10
|
+
* this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
|
|
11
|
+
*/
|
|
12
|
+
#ifndef PRISM_EXCLUDE_JSON
|
|
13
|
+
|
|
14
|
+
#include "prism/compiler/exported.h"
|
|
15
|
+
#include "prism/compiler/nonnull.h"
|
|
16
|
+
|
|
17
|
+
#include "prism/ast.h"
|
|
18
|
+
#include "prism/buffer.h"
|
|
19
|
+
#include "prism/parser.h"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Dump JSON to the given buffer.
|
|
23
|
+
*
|
|
24
|
+
* @param buffer The buffer to serialize to.
|
|
25
|
+
* @param parser The parser that parsed the node.
|
|
26
|
+
* @param node The node to serialize.
|
|
27
|
+
*/
|
|
28
|
+
PRISM_EXPORTED_FUNCTION void pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *node) PRISM_NONNULL(1, 2, 3);
|
|
29
|
+
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#endif
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file line_offset_list.h
|
|
3
|
+
*
|
|
4
|
+
* A list of byte offsets of newlines in a string.
|
|
5
|
+
*
|
|
6
|
+
* When compiling the syntax tree, it's necessary to know the line and column
|
|
7
|
+
* of many nodes. This is necessary to support things like error messages,
|
|
8
|
+
* tracepoints, etc.
|
|
9
|
+
*
|
|
10
|
+
* It's possible that we could store the start line, start column, end line, and
|
|
11
|
+
* end column on every node in addition to the offsets that we already store,
|
|
12
|
+
* but that would be quite a lot of memory overhead.
|
|
13
|
+
*/
|
|
14
|
+
#ifndef PRISM_LINE_OFFSET_LIST_H
|
|
15
|
+
#define PRISM_LINE_OFFSET_LIST_H
|
|
16
|
+
|
|
17
|
+
#include "prism/compiler/exported.h"
|
|
18
|
+
#include "prism/compiler/nonnull.h"
|
|
19
|
+
|
|
20
|
+
#include <stddef.h>
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A list of offsets of the start of lines in a string. The offsets are assumed
|
|
25
|
+
* to be sorted/inserted in ascending order.
|
|
26
|
+
*/
|
|
27
|
+
typedef struct {
|
|
28
|
+
/** The number of offsets in the list. */
|
|
29
|
+
size_t size;
|
|
30
|
+
|
|
31
|
+
/** The capacity of the list that has been allocated. */
|
|
32
|
+
size_t capacity;
|
|
33
|
+
|
|
34
|
+
/** The list of offsets. */
|
|
35
|
+
uint32_t *offsets;
|
|
36
|
+
} pm_line_offset_list_t;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A line and column in a string.
|
|
40
|
+
*/
|
|
41
|
+
typedef struct {
|
|
42
|
+
/** The line number. */
|
|
43
|
+
int32_t line;
|
|
44
|
+
|
|
45
|
+
/** The column in bytes. */
|
|
46
|
+
uint32_t column;
|
|
47
|
+
} pm_line_column_t;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns the line and column of the given offset. If the offset is not in the
|
|
51
|
+
* list, the line and column of the closest offset less than the given offset
|
|
52
|
+
* are returned.
|
|
53
|
+
*
|
|
54
|
+
* @param list The list to search.
|
|
55
|
+
* @param cursor The offset to search for.
|
|
56
|
+
* @param start_line The line to start counting from.
|
|
57
|
+
* @returns The line and column of the given offset.
|
|
58
|
+
*/
|
|
59
|
+
PRISM_EXPORTED_FUNCTION pm_line_column_t pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) PRISM_NONNULL(1);
|
|
60
|
+
|
|
61
|
+
#endif
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file magic_comments.h
|
|
3
|
+
*
|
|
4
|
+
* Types and functions related to magic comments found during parsing.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_MAGIC_COMMENTS_H
|
|
7
|
+
#define PRISM_MAGIC_COMMENTS_H
|
|
8
|
+
|
|
9
|
+
#include "prism/compiler/exported.h"
|
|
10
|
+
#include "prism/compiler/nonnull.h"
|
|
11
|
+
|
|
12
|
+
#include "prism/ast.h"
|
|
13
|
+
|
|
14
|
+
#include <stddef.h>
|
|
15
|
+
|
|
16
|
+
/** An opaque pointer to a magic comment found while parsing. */
|
|
17
|
+
typedef struct pm_magic_comment_t pm_magic_comment_t;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns the location of the key associated with the given magic comment.
|
|
21
|
+
*
|
|
22
|
+
* @param magic_comment the magic comment whose key location we want to get
|
|
23
|
+
* @returns the location of the key associated with the given magic comment
|
|
24
|
+
*/
|
|
25
|
+
PRISM_EXPORTED_FUNCTION pm_location_t pm_magic_comment_key(const pm_magic_comment_t *magic_comment) PRISM_NONNULL(1);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the location of the value associated with the given magic comment.
|
|
29
|
+
*
|
|
30
|
+
* @param magic_comment the magic comment whose value location we want to get
|
|
31
|
+
* @returns the location of the value associated with the given magic comment
|
|
32
|
+
*/
|
|
33
|
+
PRISM_EXPORTED_FUNCTION pm_location_t pm_magic_comment_value(const pm_magic_comment_t *magic_comment) PRISM_NONNULL(1);
|
|
34
|
+
|
|
35
|
+
#endif
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file node.h
|
|
3
|
+
*
|
|
4
|
+
* Functions related to nodes in the AST.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_NODE_H
|
|
7
|
+
#define PRISM_NODE_H
|
|
8
|
+
|
|
9
|
+
#include "prism/compiler/exported.h"
|
|
10
|
+
#include "prism/compiler/nonnull.h"
|
|
11
|
+
|
|
12
|
+
#include "prism/ast.h"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Loop through each node in the node list, writing each node to the given
|
|
16
|
+
* pm_node_t pointer.
|
|
17
|
+
*/
|
|
18
|
+
#define PM_NODE_LIST_FOREACH(list, index, node) \
|
|
19
|
+
for (size_t index = 0; index < (list)->size && ((node) = (list)->nodes[index]); index++)
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns a string representation of the given node type.
|
|
23
|
+
*
|
|
24
|
+
* @param node_type The node type to convert to a string.
|
|
25
|
+
* @returns A string representation of the given node type.
|
|
26
|
+
*/
|
|
27
|
+
PRISM_EXPORTED_FUNCTION const char * pm_node_type(pm_node_type_t node_type);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Visit each of the nodes in this subtree using the given visitor callback. The
|
|
31
|
+
* callback function will be called for each node in the subtree. If it returns
|
|
32
|
+
* false, then that node's children will not be visited. If it returns true,
|
|
33
|
+
* then the children will be visited. The data parameter is treated as an opaque
|
|
34
|
+
* pointer and is passed to the visitor callback for consumers to use as they
|
|
35
|
+
* see fit.
|
|
36
|
+
*
|
|
37
|
+
* As an example:
|
|
38
|
+
*
|
|
39
|
+
* ```c
|
|
40
|
+
* #include "prism.h"
|
|
41
|
+
*
|
|
42
|
+
* bool visit(const pm_node_t *node, void *data) {
|
|
43
|
+
* size_t *indent = (size_t *) data;
|
|
44
|
+
* for (size_t i = 0; i < *indent * 2; i++) putc(' ', stdout);
|
|
45
|
+
* printf("%s\n", pm_node_type(node->type));
|
|
46
|
+
*
|
|
47
|
+
* size_t next_indent = *indent + 1;
|
|
48
|
+
* size_t *next_data = &next_indent;
|
|
49
|
+
* pm_visit_child_nodes(node, visit, next_data);
|
|
50
|
+
*
|
|
51
|
+
* return false;
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* int main(void) {
|
|
55
|
+
* const char *source = "1 + 2; 3 + 4";
|
|
56
|
+
* size_t size = strlen(source);
|
|
57
|
+
*
|
|
58
|
+
* pm_arena_t *arena = pm_arena_new();
|
|
59
|
+
* pm_options_t *options = pm_options_new();
|
|
60
|
+
*
|
|
61
|
+
* pm_parser_t *parser = pm_parser_new(arena, (const uint8_t *) source, size, options);
|
|
62
|
+
*
|
|
63
|
+
* size_t indent = 0;
|
|
64
|
+
* pm_node_t *node = pm_parse(parser);
|
|
65
|
+
*
|
|
66
|
+
* size_t *data = &indent;
|
|
67
|
+
* pm_visit_node(node, visit, data);
|
|
68
|
+
*
|
|
69
|
+
* pm_parser_free(parser);
|
|
70
|
+
* pm_options_free(options);
|
|
71
|
+
* pm_arena_free(arena);
|
|
72
|
+
*
|
|
73
|
+
* return EXIT_SUCCESS;
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @param node The root node to start visiting from.
|
|
78
|
+
* @param visitor The callback to call for each node in the subtree.
|
|
79
|
+
* @param data An opaque pointer that is passed to the visitor callback.
|
|
80
|
+
*/
|
|
81
|
+
PRISM_EXPORTED_FUNCTION void pm_visit_node(const pm_node_t *node, bool (*visitor)(const pm_node_t *node, void *data), void *data) PRISM_NONNULL(1);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Visit the children of the given node with the given callback. This is the
|
|
85
|
+
* default behavior for walking the tree that is called from pm_visit_node if
|
|
86
|
+
* the callback returns true.
|
|
87
|
+
*
|
|
88
|
+
* @param node The node to visit the children of.
|
|
89
|
+
* @param visitor The callback to call for each child node.
|
|
90
|
+
* @param data An opaque pointer that is passed to the visitor callback.
|
|
91
|
+
*/
|
|
92
|
+
PRISM_EXPORTED_FUNCTION void pm_visit_child_nodes(const pm_node_t *node, bool (*visitor)(const pm_node_t *node, void *data), void *data) PRISM_NONNULL(1);
|
|
93
|
+
|
|
94
|
+
#endif
|