prism 2.0.0.rc2-x86_64-linux-gnu → 2.0.0-x86_64-linux-gnu

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -2
  3. data/docs/serialization.md +19 -6
  4. data/ext/prism/api_node.c +80 -80
  5. data/ext/prism/extension.c +34 -67
  6. data/ext/prism/extension.h +1 -1
  7. data/include/prism/arena.h +8 -0
  8. data/include/prism/arena.hpp +42 -0
  9. data/include/prism/ast.h +11 -1
  10. data/include/prism/ast.hpp +641 -0
  11. data/include/prism/buffer.h +8 -0
  12. data/include/prism/buffer.hpp +55 -0
  13. data/include/prism/comments.h +17 -0
  14. data/include/prism/compiler/branch.h +26 -0
  15. data/include/prism/compiler/cplusplus.hpp +16 -0
  16. data/include/prism/compiler/exceptions.hpp +17 -0
  17. data/include/prism/compiler/format.h +2 -0
  18. data/include/prism/compiler/lifetimebound.hpp +25 -0
  19. data/include/prism/constant_pool.h +25 -0
  20. data/include/prism/diagnostic.h +18 -0
  21. data/include/prism/errors_format.h +8 -0
  22. data/include/prism/internal/node.h +8 -4
  23. data/include/prism/internal/stringy.h +1 -6
  24. data/include/prism/json.h +8 -0
  25. data/include/prism/line_offset_list.h +8 -0
  26. data/include/prism/magic_comments.h +18 -0
  27. data/include/prism/node.h +55 -10
  28. data/include/prism/node.hpp +272 -0
  29. data/include/prism/node_type.hpp +38 -0
  30. data/include/prism/options.h +10 -1
  31. data/include/prism/options.hpp +43 -0
  32. data/include/prism/parser.h +72 -64
  33. data/include/prism/parser.hpp +274 -0
  34. data/include/prism/prettyprint.h +8 -0
  35. data/include/prism/serialize.h +8 -0
  36. data/include/prism/source.h +8 -0
  37. data/include/prism/stream.h +8 -0
  38. data/include/prism/string_query.h +8 -0
  39. data/include/prism/stringy.h +16 -27
  40. data/include/prism/stringy.hpp +31 -0
  41. data/include/prism/version.h +9 -1
  42. data/include/prism.h +0 -8
  43. data/include/prism.hpp +24 -0
  44. data/lib/prism/3.3/prism.so +0 -0
  45. data/lib/prism/3.4/prism.so +0 -0
  46. data/lib/prism/4.0/prism.so +0 -0
  47. data/lib/prism/serialize.rb +2549 -3281
  48. data/prism.gemspec +14 -1
  49. data/rbi/generated/prism/node.rbi +736 -0
  50. data/rbi/generated/prism/serialize.rbi +6 -5
  51. data/sig/generated/prism/node.rbs +736 -0
  52. data/sig/generated/prism/serialize.rbs +7 -5
  53. data/src/comments.c +2 -2
  54. data/src/diagnostic.c +8 -0
  55. data/src/node.c +216 -368
  56. data/src/options.c +7 -13
  57. data/src/parser.c +52 -48
  58. data/src/prism.c +175 -194
  59. data/src/regexp.c +0 -1
  60. data/src/serialize.c +2300 -1950
  61. data/src/source.c +8 -2
  62. data/src/stringy.c +3 -33
  63. metadata +14 -1
@@ -12,6 +12,10 @@
12
12
 
13
13
  #include <stddef.h>
14
14
 
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
15
19
  /**
16
20
  * A wrapper around a contiguous block of allocated memory.
17
21
  */
@@ -49,4 +53,8 @@ PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer) PRISM_
49
53
  */
50
54
  PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer) PRISM_NONNULL(1);
51
55
 
56
+ #ifdef __cplusplus
57
+ }
58
+ #endif
59
+
52
60
  #endif
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @file buffer.hpp
3
+ *
4
+ * Ownership of buffers from C++, and access to their contents.
5
+ */
6
+ #ifndef PRISM_BUFFER_HPP
7
+ #define PRISM_BUFFER_HPP
8
+
9
+ #include "prism/compiler/cplusplus.hpp"
10
+ #include "prism/compiler/lifetimebound.hpp"
11
+
12
+ #include "prism/buffer.h"
13
+
14
+ #include <memory>
15
+ #include <string_view>
16
+
17
+ namespace prism {
18
+
19
+ /** Frees a buffer with pm_buffer_free. */
20
+ struct buffer_deleter {
21
+ /**
22
+ * Frees the given buffer.
23
+ *
24
+ * @param buffer The buffer to free.
25
+ */
26
+ void operator()(pm_buffer_t *buffer) const noexcept { pm_buffer_free(buffer); }
27
+ };
28
+
29
+ /** An owned buffer. */
30
+ using unique_buffer = std::unique_ptr<pm_buffer_t, buffer_deleter>;
31
+
32
+ /**
33
+ * Allocate a new empty buffer. Allocation failure aborts, so this never throws.
34
+ *
35
+ * @return A unique_buffer managing the newly allocated buffer.
36
+ */
37
+ [[nodiscard]] inline unique_buffer
38
+ make_buffer() noexcept {
39
+ return unique_buffer(pm_buffer_new());
40
+ }
41
+
42
+ /**
43
+ * The bytes written to the given buffer so far.
44
+ *
45
+ * @param buffer The buffer to view.
46
+ * @return A string_view of the contents of the buffer.
47
+ */
48
+ [[nodiscard]] inline std::string_view
49
+ view(const pm_buffer_t *buffer PRISM_LIFETIMEBOUND) noexcept {
50
+ return std::string_view(pm_buffer_value(buffer), pm_buffer_length(buffer));
51
+ }
52
+
53
+ }
54
+
55
+ #endif
@@ -14,6 +14,10 @@
14
14
 
15
15
  #include <stddef.h>
16
16
 
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
17
21
  /** This is the type of a comment that we've found while parsing. */
18
22
  typedef enum {
19
23
  PM_COMMENT_INLINE,
@@ -52,4 +56,17 @@ PRISM_EXPORTED_FUNCTION pm_location_t pm_comment_location(const pm_comment_t *co
52
56
  */
53
57
  PRISM_EXPORTED_FUNCTION pm_comment_type_t pm_comment_type(const pm_comment_t *comment) PRISM_NONNULL(1);
54
58
 
59
+ /**
60
+ * Returns the comment that follows the given comment among the comments
61
+ * associated with the parser that found it.
62
+ *
63
+ * @param comment the comment whose successor we want to get
64
+ * @returns the next comment, or NULL if the given comment is the last one
65
+ */
66
+ PRISM_EXPORTED_FUNCTION const pm_comment_t * pm_comment_next(const pm_comment_t *comment) PRISM_NONNULL(1);
67
+
68
+ #ifdef __cplusplus
69
+ }
70
+ #endif
71
+
55
72
  #endif
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file compiler/branch.h
3
+ */
4
+ #ifndef PRISM_COMPILER_BRANCH_H
5
+ #define PRISM_COMPILER_BRANCH_H
6
+
7
+ /**
8
+ * Branch prediction hints. These tell the compiler which side of a branch to
9
+ * predicate the fast path through, so it can lay out instructions to favour
10
+ * that side and steer the static branch predictor.
11
+ */
12
+ #if defined(__GNUC__) || defined(__clang__)
13
+ /** The compiler should predicate that this branch will be taken. */
14
+ #define PRISM_LIKELY(x) __builtin_expect(!!(x), 1)
15
+
16
+ /** The compiler should predicate that this branch will not be taken. */
17
+ #define PRISM_UNLIKELY(x) __builtin_expect(!!(x), 0)
18
+ #else
19
+ /** Void because this platform does not support branch prediction hints. */
20
+ #define PRISM_LIKELY(x) (x)
21
+
22
+ /** Void because this platform does not support branch prediction hints. */
23
+ #define PRISM_UNLIKELY(x) (x)
24
+ #endif
25
+
26
+ #endif
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file compiler/cplusplus.hpp
3
+ */
4
+ #ifndef PRISM_COMPILER_CPLUSPLUS_HPP
5
+ #define PRISM_COMPILER_CPLUSPLUS_HPP
6
+
7
+ /**
8
+ * The C++ interface relies on C++17 for inline variables, std::string_view,
9
+ * std::void_t, and std::is_invocable_r_v. MSVC reports __cplusplus as 199711L
10
+ * unless /Zc:__cplusplus is passed, so its own _MSVC_LANG is checked as well.
11
+ */
12
+ #if !defined(__cplusplus) || ((__cplusplus < 201703L) && (!defined(_MSVC_LANG) || (_MSVC_LANG < 201703L)))
13
+ # error "the prism C++ interface requires C++17 or later"
14
+ #endif
15
+
16
+ #endif
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @file compiler/exceptions.hpp
3
+ */
4
+ #ifndef PRISM_COMPILER_EXCEPTIONS_HPP
5
+ #define PRISM_COMPILER_EXCEPTIONS_HPP
6
+
7
+ /**
8
+ * Defined when C++ exceptions are enabled, so that code which catches them can
9
+ * still compile in builds that disable them, such as with -fno-exceptions.
10
+ * __cpp_exceptions is the standard feature test macro, and older versions of
11
+ * GCC and MSVC define __EXCEPTIONS and _CPPUNWIND instead.
12
+ */
13
+ #if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
14
+ # define PRISM_HAS_EXCEPTIONS
15
+ #endif
16
+
17
+ #endif
@@ -4,6 +4,8 @@
4
4
  #ifndef PRISM_COMPILER_FORMAT_H
5
5
  #define PRISM_COMPILER_FORMAT_H
6
6
 
7
+ #include <stdio.h>
8
+
7
9
  /**
8
10
  * Certain compilers support specifying that a function accepts variadic
9
11
  * parameters that look like printf format strings to provide a better developer
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @file compiler/lifetimebound.hpp
3
+ */
4
+ #ifndef PRISM_COMPILER_LIFETIMEBOUND_HPP
5
+ #define PRISM_COMPILER_LIFETIMEBOUND_HPP
6
+
7
+ /**
8
+ * Mark a parameter that the return value points into, so that the compiler
9
+ * warns if a temporary is passed and the return value outlives it. If it is
10
+ * placed after the qualifiers of a member function, it marks the object
11
+ * instead.
12
+ */
13
+ #if defined(__has_cpp_attribute)
14
+ # if __has_cpp_attribute(clang::lifetimebound)
15
+ # define PRISM_LIFETIMEBOUND [[clang::lifetimebound]]
16
+ # elif __has_cpp_attribute(msvc::lifetimebound)
17
+ # define PRISM_LIFETIMEBOUND [[msvc::lifetimebound]]
18
+ # endif
19
+ #endif
20
+
21
+ #ifndef PRISM_LIFETIMEBOUND
22
+ # define PRISM_LIFETIMEBOUND
23
+ #endif
24
+
25
+ #endif
@@ -11,6 +11,7 @@
11
11
  #define PRISM_CONSTANT_POOL_H
12
12
 
13
13
  #include "prism/compiler/exported.h"
14
+ #include "prism/compiler/inline.h"
14
15
  #include "prism/compiler/nodiscard.h"
15
16
  #include "prism/compiler/nonnull.h"
16
17
 
@@ -19,11 +20,31 @@
19
20
  #include <stddef.h>
20
21
  #include <stdint.h>
21
22
 
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
22
27
  /**
23
28
  * A constant id is a unique identifier for a constant in the constant pool.
24
29
  */
25
30
  typedef uint32_t pm_constant_id_t;
26
31
 
32
+ /**
33
+ * Returns the index of the constant with the given id among the constants of
34
+ * the parser that produced it. The indices run from 0 to one less than
35
+ * pm_parser_constants_size, so they can index a cache with one entry per
36
+ * constant that was filled using pm_parser_constant_at.
37
+ *
38
+ * @param constant_id the id of the constant. Optional constant fields on nodes
39
+ * hold 0 when they are absent, which is not a valid id, so check for it
40
+ * before calling this function.
41
+ * @returns the index of the constant
42
+ */
43
+ static PRISM_INLINE size_t
44
+ pm_constant_id_index(pm_constant_id_t constant_id) {
45
+ return (size_t) constant_id - 1;
46
+ }
47
+
27
48
  /**
28
49
  * A list of constant IDs. Usually used to represent a set of locals.
29
50
  */
@@ -78,4 +99,8 @@ PRISM_EXPORTED_FUNCTION void pm_constant_id_list_init(pm_constant_id_list_t *lis
78
99
  */
79
100
  PRISM_EXPORTED_FUNCTION void pm_constant_id_list_append(pm_arena_t *arena, pm_constant_id_list_t *list, pm_constant_id_t id) PRISM_NONNULL(1, 2);
80
101
 
102
+ #ifdef __cplusplus
103
+ }
104
+ #endif
105
+
81
106
  #endif
@@ -12,6 +12,10 @@
12
12
 
13
13
  #include "prism/ast.h"
14
14
 
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
15
19
  /**
16
20
  * An opaque pointer to a diagnostic generated during parsing.
17
21
  */
@@ -90,4 +94,18 @@ PRISM_EXPORTED_FUNCTION pm_error_level_t pm_diagnostic_error_level(const pm_diag
90
94
  */
91
95
  PRISM_EXPORTED_FUNCTION pm_warning_level_t pm_diagnostic_warning_level(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
92
96
 
97
+ /**
98
+ * Get the diagnostic that follows the given diagnostic among the errors or the
99
+ * warnings of the parser that produced it.
100
+ *
101
+ * @param diagnostic The diagnostic to get the successor of.
102
+ * @returns The next diagnostic of the same kind, or NULL if the given
103
+ * diagnostic is the last one.
104
+ */
105
+ PRISM_EXPORTED_FUNCTION const pm_diagnostic_t * pm_diagnostic_next(const pm_diagnostic_t *diagnostic) PRISM_NONNULL(1);
106
+
107
+ #ifdef __cplusplus
108
+ }
109
+ #endif
110
+
93
111
  #endif
@@ -14,6 +14,10 @@
14
14
  #include "prism/diagnostic.h"
15
15
  #include "prism/parser.h"
16
16
 
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
17
21
  /** The type of formatting to use when formatting errors. */
18
22
  typedef enum {
19
23
  /** Format errors in a plain format with no colors or styles. Typically
@@ -50,4 +54,8 @@ typedef enum {
50
54
  */
51
55
  PRISM_EXPORTED_FUNCTION pm_error_level_t pm_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type) PRISM_NONNULL(1, 2);
52
56
 
57
+ #ifdef __cplusplus
58
+ }
59
+ #endif
60
+
53
61
  #endif
@@ -14,14 +14,18 @@
14
14
  #define PM_LOCATION_END(location_) ((location_)->start + (location_)->length)
15
15
 
16
16
  /*
17
- * Slow path for pm_node_list_append: grow the list and append the node.
18
- * Do not call directly — use pm_node_list_append instead.
17
+ * Slow path for pm_node_list_append_inline: grow the list and append the node.
18
+ * Do not call directly — use pm_node_list_append_inline instead.
19
19
  */
20
20
  void pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
21
21
 
22
- /* Append a new node onto the end of the node list. */
22
+ /*
23
+ * Append a new node onto the end of the node list, handling the common case
24
+ * inline and growing the list through pm_node_list_append_slow. This is the
25
+ * version for prism's own code; others call the exported pm_node_list_append.
26
+ */
23
27
  static PRISM_FORCE_INLINE void
24
- pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
28
+ pm_node_list_append_inline(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
25
29
  if (list->size < list->capacity) {
26
30
  list->nodes[list->size++] = node;
27
31
  } else {
@@ -12,7 +12,7 @@ static const uint8_t empty_source[] = "";
12
12
  * Defines an empty string. This is useful for initializing a string that will
13
13
  * be filled in later.
14
14
  */
15
- #define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = empty_source, .length = 0 })
15
+ #define PM_STRING_EMPTY ((pm_string_t) { .source = empty_source, .length = 0 })
16
16
 
17
17
  /*
18
18
  * Initialize a shared string that is based on initial input.
@@ -27,9 +27,4 @@ void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint
27
27
  */
28
28
  int pm_string_compare(const pm_string_t *left, const pm_string_t *right);
29
29
 
30
- /*
31
- * Free the associated memory of the given string.
32
- */
33
- void pm_string_cleanup(pm_string_t *string);
34
-
35
30
  #endif
data/include/prism/json.h CHANGED
@@ -18,6 +18,10 @@
18
18
  #include "prism/buffer.h"
19
19
  #include "prism/parser.h"
20
20
 
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
21
25
  /**
22
26
  * Dump JSON to the given buffer.
23
27
  *
@@ -27,6 +31,10 @@
27
31
  */
28
32
  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
33
 
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
30
38
  #endif
31
39
 
32
40
  #endif
@@ -20,6 +20,10 @@
20
20
  #include <stddef.h>
21
21
  #include <stdint.h>
22
22
 
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
23
27
  /**
24
28
  * A list of offsets of the start of lines in a string. The offsets are assumed
25
29
  * to be sorted/inserted in ascending order.
@@ -58,4 +62,8 @@ typedef struct {
58
62
  */
59
63
  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
64
 
65
+ #ifdef __cplusplus
66
+ }
67
+ #endif
68
+
61
69
  #endif
@@ -13,6 +13,10 @@
13
13
 
14
14
  #include <stddef.h>
15
15
 
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
16
20
  /** An opaque pointer to a magic comment found while parsing. */
17
21
  typedef struct pm_magic_comment_t pm_magic_comment_t;
18
22
 
@@ -32,4 +36,18 @@ PRISM_EXPORTED_FUNCTION pm_location_t pm_magic_comment_key(const pm_magic_commen
32
36
  */
33
37
  PRISM_EXPORTED_FUNCTION pm_location_t pm_magic_comment_value(const pm_magic_comment_t *magic_comment) PRISM_NONNULL(1);
34
38
 
39
+ /**
40
+ * Returns the magic comment that follows the given magic comment among the
41
+ * magic comments associated with the parser that found it.
42
+ *
43
+ * @param magic_comment the magic comment whose successor we want to get
44
+ * @returns the next magic comment, or NULL if the given magic comment is the
45
+ * last one
46
+ */
47
+ PRISM_EXPORTED_FUNCTION const pm_magic_comment_t * pm_magic_comment_next(const pm_magic_comment_t *magic_comment) PRISM_NONNULL(1);
48
+
49
+ #ifdef __cplusplus
50
+ }
51
+ #endif
52
+
35
53
  #endif
data/include/prism/node.h CHANGED
@@ -11,6 +11,10 @@
11
11
 
12
12
  #include "prism/ast.h"
13
13
 
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
14
18
  /**
15
19
  * Loop through each node in the node list, writing each node to the given
16
20
  * pm_node_t pointer.
@@ -18,6 +22,18 @@
18
22
  #define PM_NODE_LIST_FOREACH(list, index, node) \
19
23
  for (size_t index = 0; index < (list)->size && ((node) = (list)->nodes[index]); index++)
20
24
 
25
+ /**
26
+ * Append a node to the end of a node list. If the list is full, its storage is
27
+ * grown by allocating from the given arena, so the arena must live as long as
28
+ * the list does. For a list in a parsed tree, that is the arena that was passed
29
+ * to pm_parser_new.
30
+ *
31
+ * @param arena The arena to allocate the list's storage from.
32
+ * @param list The list to append to.
33
+ * @param node The node to append.
34
+ */
35
+ PRISM_EXPORTED_FUNCTION void pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) PRISM_NONNULL(1, 2, 3);
36
+
21
37
  /**
22
38
  * Returns a string representation of the given node type.
23
39
  *
@@ -26,20 +42,41 @@
26
42
  */
27
43
  PRISM_EXPORTED_FUNCTION const char * pm_node_type(pm_node_type_t node_type);
28
44
 
45
+ /**
46
+ * The value returned by a visitor callback, which determines where the walk
47
+ * goes next.
48
+ */
49
+ typedef enum {
50
+ /** Continue the walk without visiting this node's children. */
51
+ PM_VISIT_SKIP,
52
+
53
+ /** Continue the walk by visiting this node's children. */
54
+ PM_VISIT_DESCEND,
55
+
56
+ /** End the walk without visiting any more nodes. */
57
+ PM_VISIT_STOP
58
+ } pm_visit_result_t;
59
+
60
+ /**
61
+ * A callback that is called for each node visited by pm_visit_node and
62
+ * pm_visit_child_nodes. The data parameter is the opaque pointer that was
63
+ * passed to the function that started the walk.
64
+ */
65
+ typedef pm_visit_result_t (*pm_visit_callback_t)(const pm_node_t *node, void *data);
66
+
29
67
  /**
30
68
  * 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.
69
+ * callback function will be called for each node in the subtree, and its
70
+ * return value determines whether the walk visits that node's children, skips
71
+ * them, or stops entirely. The data parameter is treated as an opaque pointer
72
+ * and is passed to the visitor callback for consumers to use as they see fit.
36
73
  *
37
74
  * As an example:
38
75
  *
39
76
  * ```c
40
77
  * #include "prism.h"
41
78
  *
42
- * bool visit(const pm_node_t *node, void *data) {
79
+ * pm_visit_result_t visit(const pm_node_t *node, void *data) {
43
80
  * size_t *indent = (size_t *) data;
44
81
  * for (size_t i = 0; i < *indent * 2; i++) putc(' ', stdout);
45
82
  * printf("%s\n", pm_node_type(node->type));
@@ -48,7 +85,7 @@ PRISM_EXPORTED_FUNCTION const char * pm_node_type(pm_node_type_t node_type);
48
85
  * size_t *next_data = &next_indent;
49
86
  * pm_visit_child_nodes(node, visit, next_data);
50
87
  *
51
- * return false;
88
+ * return PM_VISIT_SKIP;
52
89
  * }
53
90
  *
54
91
  * int main(void) {
@@ -77,18 +114,26 @@ PRISM_EXPORTED_FUNCTION const char * pm_node_type(pm_node_type_t node_type);
77
114
  * @param node The root node to start visiting from.
78
115
  * @param visitor The callback to call for each node in the subtree.
79
116
  * @param data An opaque pointer that is passed to the visitor callback.
117
+ * @returns false if the visitor stopped the walk by returning PM_VISIT_STOP,
118
+ * true otherwise.
80
119
  */
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);
120
+ PRISM_EXPORTED_FUNCTION bool pm_visit_node(const pm_node_t *node, pm_visit_callback_t visitor, void *data) PRISM_NONNULL(1);
82
121
 
83
122
  /**
84
123
  * Visit the children of the given node with the given callback. This is the
85
124
  * default behavior for walking the tree that is called from pm_visit_node if
86
- * the callback returns true.
125
+ * the callback returns PM_VISIT_DESCEND.
87
126
  *
88
127
  * @param node The node to visit the children of.
89
128
  * @param visitor The callback to call for each child node.
90
129
  * @param data An opaque pointer that is passed to the visitor callback.
130
+ * @returns false if the visitor stopped the walk by returning PM_VISIT_STOP,
131
+ * true otherwise.
91
132
  */
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);
133
+ PRISM_EXPORTED_FUNCTION bool pm_visit_child_nodes(const pm_node_t *node, pm_visit_callback_t visitor, void *data) PRISM_NONNULL(1);
134
+
135
+ #ifdef __cplusplus
136
+ }
137
+ #endif
93
138
 
94
139
  #endif