herb 0.11.1 → 0.11.2
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/Rakefile +4 -2
- data/config.yml +6 -0
- data/ext/herb/extconf.rb +8 -31
- data/ext/herb/nodes.c +75 -75
- data/ext/herb/parser_options_helpers.c +26 -0
- data/lib/herb/analysis/partial_index.rb +1 -1
- data/lib/herb/analysis/partial_resolution.rb +27 -0
- data/lib/herb/ast/helpers.rb +1 -1
- data/lib/herb/configuration.rb +11 -1
- data/lib/herb/dev/classifier.rb +1 -1
- data/lib/herb/engine/compiler.rb +5 -8
- data/lib/herb/engine/slots/dynamics_compiler.rb +53 -14
- data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
- data/lib/herb/engine/slots/visitor.rb +32 -4
- data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
- data/lib/herb/parser_options.rb +6 -3
- data/lib/herb/project.rb +19 -8
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -1
- data/sig/herb/analysis/partial_resolution.rbs +8 -0
- data/sig/herb/configuration.rbs +3 -0
- data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
- data/sig/herb/engine/slots/visitor.rbs +14 -0
- data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
- data/sig/herb/parser_options.rbs +6 -4
- data/sig/herb.rbs +2 -2
- data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
- data/src/analyze/action_view/generated_handlers.c +36 -36
- data/src/analyze/action_view/image_tag.c +7 -3
- data/src/analyze/action_view/javascript_include_tag.c +6 -3
- data/src/analyze/action_view/link_to.c +23 -23
- data/src/analyze/action_view/registry.c +7 -3
- data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
- data/src/analyze/action_view/tag_helpers.c +139 -90
- data/src/analyze/action_view/turbo_frame_tag.c +5 -4
- data/src/analyze/analyze.c +35 -19
- data/src/analyze/analyze_helpers.c +161 -188
- data/src/analyze/analyzed_ruby.c +8 -7
- data/src/analyze/control_type.c +29 -22
- data/src/analyze/herb_directives.c +16 -20
- data/src/analyze/iteration_nodes.c +69 -24
- data/src/analyze/parse_errors.c +32 -22
- data/src/analyze/postfix_conditionals.c +23 -13
- data/src/analyze/prism_annotate.c +29 -28
- data/src/analyze/render_nodes.c +51 -41
- data/src/analyze/strict_locals.c +14 -15
- data/src/analyze/ternary_conditionals.c +14 -10
- data/src/herb.c +10 -8
- data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
- data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
- data/src/include/analyze/action_view/tag_helpers.h +1 -1
- data/src/include/analyze/analyze.h +3 -2
- data/src/include/analyze/analyzed_ruby.h +4 -2
- data/src/include/analyze/helpers.h +6 -6
- data/src/include/herb.h +3 -2
- data/src/include/parser/parser_options.h +5 -0
- data/src/include/prism/prism_context.h +12 -12
- data/src/include/prism/prism_helpers.h +30 -0
- data/src/include/prism_version.h +11 -0
- data/src/include/version.h +1 -1
- data/src/parser/parser_helpers.c +1 -2
- data/src/parser.c +6 -7
- data/src/parser_options_defaults.c +1 -0
- data/src/prism/prism_helpers.c +84 -50
- data/src/prism/ruby_parser.c +20 -20
- data/templates/ext/herb/nodes.c.erb +5 -5
- data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
- data/templates/java/nodes.c.erb +6 -6
- data/templates/java/parser_options_helpers.c.erb +41 -2
- data/templates/java/parser_options_helpers.h.erb +2 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
- data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
- data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
- data/templates/lib/herb/parser_options.rb.erb +1 -1
- data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
- data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
- data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
- data/templates/src/include/parser/parser_options.h.erb +10 -0
- data/templates/src/include/prism_version.h.erb +17 -0
- data/templates/src/parser_options_defaults.c.erb +1 -1
- data/templates/template.rb +17 -2
- data/templates/wasm/nodes.cpp.erb +5 -5
- data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
- data/vendor/prism/Rakefile +76 -7
- data/vendor/prism/config.yml +174 -161
- data/vendor/prism/include/prism/arena.h +45 -0
- data/vendor/prism/include/prism/arena.hpp +42 -0
- data/vendor/prism/include/prism/ast.h +2738 -611
- data/vendor/prism/include/prism/ast.hpp +641 -0
- data/vendor/prism/include/prism/buffer.h +60 -0
- data/vendor/prism/include/prism/buffer.hpp +55 -0
- data/vendor/prism/include/prism/comments.h +72 -0
- data/vendor/prism/include/prism/compiler/accel.h +26 -0
- data/vendor/prism/include/prism/compiler/align.h +36 -0
- data/vendor/prism/include/prism/compiler/assume.h +25 -0
- data/vendor/prism/include/prism/compiler/branch.h +26 -0
- data/vendor/prism/include/prism/compiler/bswap.h +46 -0
- data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
- data/vendor/prism/include/prism/compiler/endianness.h +34 -0
- data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
- data/vendor/prism/include/prism/compiler/exported.h +24 -0
- data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
- data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
- data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
- data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
- data/vendor/prism/include/prism/compiler/format.h +27 -0
- data/vendor/prism/include/prism/compiler/inline.h +17 -0
- data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
- data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
- data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
- data/vendor/prism/include/prism/compiler/unused.h +18 -0
- data/vendor/prism/include/prism/constant_pool.h +106 -0
- data/vendor/prism/include/prism/diagnostic.h +55 -402
- data/vendor/prism/include/prism/errors_format.h +61 -0
- data/vendor/prism/include/prism/excludes.h +29 -0
- data/vendor/prism/include/prism/integer.h +41 -0
- data/vendor/prism/include/prism/internal/allocator.h +68 -0
- data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
- data/vendor/prism/include/prism/internal/arena.h +108 -0
- data/vendor/prism/include/prism/internal/bit.h +42 -0
- data/vendor/prism/include/prism/internal/buffer.h +94 -0
- data/vendor/prism/include/prism/internal/char.h +145 -0
- data/vendor/prism/include/prism/internal/comments.h +54 -0
- data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
- data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
- data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
- data/vendor/prism/include/prism/internal/integer.h +68 -0
- data/vendor/prism/include/prism/internal/isinf.h +16 -0
- data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
- data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
- data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
- data/vendor/prism/include/prism/internal/memchr.h +15 -0
- data/vendor/prism/include/prism/internal/node.h +42 -0
- data/vendor/prism/include/prism/internal/options.h +232 -0
- data/vendor/prism/include/prism/internal/parser.h +1015 -0
- data/vendor/prism/include/prism/internal/regexp.h +26 -0
- data/vendor/prism/include/prism/internal/serialize.h +39 -0
- data/vendor/prism/include/prism/internal/source.h +72 -0
- data/vendor/prism/include/prism/internal/static_literals.h +60 -0
- data/vendor/prism/include/prism/internal/stringy.h +30 -0
- data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
- data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
- data/vendor/prism/include/prism/internal/tokens.h +11 -0
- data/vendor/prism/include/prism/internal/xxh3.h +16 -0
- data/vendor/prism/include/prism/json.h +40 -0
- data/vendor/prism/include/prism/line_offset_list.h +69 -0
- data/vendor/prism/include/prism/magic_comments.h +53 -0
- data/vendor/prism/include/prism/node.h +59 -49
- data/vendor/prism/include/prism/node.hpp +272 -0
- data/vendor/prism/include/prism/node_type.hpp +38 -0
- data/vendor/prism/include/prism/options.h +154 -279
- data/vendor/prism/include/prism/options.hpp +43 -0
- data/vendor/prism/include/prism/parser.h +367 -870
- data/vendor/prism/include/prism/parser.hpp +274 -0
- data/vendor/prism/include/prism/prettyprint.h +14 -9
- data/vendor/prism/include/prism/serialize.h +123 -0
- data/vendor/prism/include/prism/source.h +163 -0
- data/vendor/prism/include/prism/stream.h +36 -0
- data/vendor/prism/include/prism/string_query.h +82 -0
- data/vendor/prism/include/prism/stringy.h +61 -0
- data/vendor/prism/include/prism/stringy.hpp +31 -0
- data/vendor/prism/include/prism/version.h +20 -3
- data/vendor/prism/include/prism.h +35 -320
- data/vendor/prism/include/prism.hpp +24 -0
- data/vendor/prism/src/arena.c +122 -0
- data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
- data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
- data/vendor/prism/src/comments.c +455 -0
- data/vendor/prism/src/constant_pool.c +406 -0
- data/vendor/prism/src/diagnostic.c +120 -68
- data/vendor/prism/src/encoding.c +8 -3
- data/vendor/prism/src/errors_format.c +519 -0
- data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
- data/vendor/prism/src/json.c +5733 -0
- data/vendor/prism/src/line_offset_list.c +100 -0
- data/vendor/prism/src/list.c +24 -0
- data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
- data/vendor/prism/src/node.c +3465 -7787
- data/vendor/prism/src/options.c +161 -54
- data/vendor/prism/src/parser.c +371 -0
- data/vendor/prism/src/prettyprint.c +421 -354
- data/vendor/prism/src/prism.c +8522 -7280
- data/vendor/prism/src/regexp.c +960 -45
- data/vendor/prism/src/serialize.c +2434 -2048
- data/vendor/prism/src/source.c +524 -0
- data/vendor/prism/src/static_literals.c +303 -360
- data/vendor/prism/src/string_query.c +180 -0
- data/vendor/prism/src/stringy.c +61 -0
- data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
- data/vendor/prism/src/strpbrk.c +447 -0
- data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
- data/vendor/prism/src/xxh3.c +292 -0
- data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
- data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
- data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
- data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
- data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
- data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
- data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
- data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
- data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
- data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
- data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
- data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
- data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
- data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
- data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
- data/vendor/prism/templates/src/json.c.erb +130 -0
- data/vendor/prism/templates/src/node.c.erb +79 -236
- data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
- data/vendor/prism/templates/src/serialize.c.erb +369 -183
- data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
- data/vendor/prism/templates/template.rb +193 -91
- metadata +100 -42
- data/vendor/prism/include/prism/defines.h +0 -260
- data/vendor/prism/include/prism/pack.h +0 -163
- data/vendor/prism/include/prism/regexp.h +0 -43
- data/vendor/prism/include/prism/static_literals.h +0 -121
- data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
- data/vendor/prism/include/prism/util/pm_char.h +0 -204
- data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
- data/vendor/prism/include/prism/util/pm_integer.h +0 -130
- data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
- data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
- data/vendor/prism/include/prism/util/pm_string.h +0 -200
- data/vendor/prism/src/pack.c +0 -509
- data/vendor/prism/src/util/pm_constant_pool.c +0 -342
- data/vendor/prism/src/util/pm_list.c +0 -49
- data/vendor/prism/src/util/pm_newline_list.c +0 -125
- data/vendor/prism/src/util/pm_string.c +0 -381
- data/vendor/prism/src/util/pm_strpbrk.c +0 -206
- data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
- data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
- data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
- data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
- data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
- data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
- data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
- data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
- data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
- data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file string_query.h
|
|
3
|
+
*
|
|
4
|
+
* Functions for querying properties of strings, such as whether they are valid
|
|
5
|
+
* local variable names, constant names, or method names.
|
|
6
|
+
*/
|
|
7
|
+
#ifndef PRISM_STRING_QUERY_H
|
|
8
|
+
#define PRISM_STRING_QUERY_H
|
|
9
|
+
|
|
10
|
+
#include "prism/compiler/exported.h"
|
|
11
|
+
#include "prism/compiler/nonnull.h"
|
|
12
|
+
|
|
13
|
+
#include <stddef.h>
|
|
14
|
+
#include <stdint.h>
|
|
15
|
+
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
extern "C" {
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents the results of a slice query.
|
|
22
|
+
*/
|
|
23
|
+
typedef enum {
|
|
24
|
+
/** Returned if the encoding given to a slice query was invalid. */
|
|
25
|
+
PM_STRING_QUERY_ERROR = -1,
|
|
26
|
+
|
|
27
|
+
/** Returned if the result of the slice query is false. */
|
|
28
|
+
PM_STRING_QUERY_FALSE,
|
|
29
|
+
|
|
30
|
+
/** Returned if the result of the slice query is true. */
|
|
31
|
+
PM_STRING_QUERY_TRUE
|
|
32
|
+
} pm_string_query_t;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check that the slice is a valid local variable name.
|
|
36
|
+
*
|
|
37
|
+
* @param source The source to check.
|
|
38
|
+
* @param length The length of the source.
|
|
39
|
+
* @param encoding_name The name of the encoding of the source.
|
|
40
|
+
* @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
41
|
+
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
42
|
+
*/
|
|
43
|
+
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_local(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check that the slice is a valid constant name.
|
|
47
|
+
*
|
|
48
|
+
* @param source The source to check.
|
|
49
|
+
* @param length The length of the source.
|
|
50
|
+
* @param encoding_name The name of the encoding of the source.
|
|
51
|
+
* @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
52
|
+
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
53
|
+
*/
|
|
54
|
+
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_constant(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Check that the slice is a valid method name.
|
|
58
|
+
*
|
|
59
|
+
* @param source The source to check.
|
|
60
|
+
* @param length The length of the source.
|
|
61
|
+
* @param encoding_name The name of the encoding of the source.
|
|
62
|
+
* @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
63
|
+
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
64
|
+
*/
|
|
65
|
+
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check that the slice is a keyword.
|
|
69
|
+
*
|
|
70
|
+
* @param source The source to check.
|
|
71
|
+
* @param length The length of the source.
|
|
72
|
+
* @param encoding_name The name of the encoding of the source.
|
|
73
|
+
* @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
74
|
+
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
75
|
+
*/
|
|
76
|
+
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_keyword(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
|
|
77
|
+
|
|
78
|
+
#ifdef __cplusplus
|
|
79
|
+
}
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
#endif
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file stringy.h
|
|
3
|
+
*
|
|
4
|
+
* A view of a sequence of bytes owned by someone else.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_STRINGY_H
|
|
7
|
+
#define PRISM_STRINGY_H
|
|
8
|
+
|
|
9
|
+
#include "prism/compiler/exported.h"
|
|
10
|
+
#include "prism/compiler/nonnull.h"
|
|
11
|
+
|
|
12
|
+
#include <stddef.h>
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A view of a sequence of bytes. The string does not own the bytes, so they
|
|
21
|
+
* must remain valid for as long as the string is in use.
|
|
22
|
+
*/
|
|
23
|
+
typedef struct {
|
|
24
|
+
/** A pointer to the start of the string. */
|
|
25
|
+
const uint8_t *source;
|
|
26
|
+
|
|
27
|
+
/** The length of the string in bytes of memory. */
|
|
28
|
+
size_t length;
|
|
29
|
+
} pm_string_t;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Initialize a string that views the given bytes. The bytes are not copied, so
|
|
33
|
+
* they must remain valid for as long as the string is in use.
|
|
34
|
+
*
|
|
35
|
+
* @param string The string to initialize.
|
|
36
|
+
* @param source The start of the bytes.
|
|
37
|
+
* @param length The number of bytes.
|
|
38
|
+
*/
|
|
39
|
+
PRISM_EXPORTED_FUNCTION void pm_string_init(pm_string_t *string, const uint8_t *source, size_t length) PRISM_NONNULL(1);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns the length associated with the string.
|
|
43
|
+
*
|
|
44
|
+
* @param string The string to get the length of.
|
|
45
|
+
* @returns The length of the string.
|
|
46
|
+
*/
|
|
47
|
+
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string) PRISM_NONNULL(1);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns the start pointer associated with the string.
|
|
51
|
+
*
|
|
52
|
+
* @param string The string to get the start pointer of.
|
|
53
|
+
* @returns The start pointer of the string.
|
|
54
|
+
*/
|
|
55
|
+
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string) PRISM_NONNULL(1);
|
|
56
|
+
|
|
57
|
+
#ifdef __cplusplus
|
|
58
|
+
}
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
#endif
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file stringy.hpp
|
|
3
|
+
*
|
|
4
|
+
* Access to the contents of strings from C++.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_STRINGY_HPP
|
|
7
|
+
#define PRISM_STRINGY_HPP
|
|
8
|
+
|
|
9
|
+
#include "prism/compiler/cplusplus.hpp"
|
|
10
|
+
#include "prism/compiler/lifetimebound.hpp"
|
|
11
|
+
|
|
12
|
+
#include "prism/stringy.h"
|
|
13
|
+
|
|
14
|
+
#include <string_view>
|
|
15
|
+
|
|
16
|
+
namespace prism {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The bytes of the given string.
|
|
20
|
+
*
|
|
21
|
+
* @param string The string to view.
|
|
22
|
+
* @return A view of the bytes of the string.
|
|
23
|
+
*/
|
|
24
|
+
[[nodiscard]] inline std::string_view
|
|
25
|
+
view(const pm_string_t &string PRISM_LIFETIMEBOUND) noexcept {
|
|
26
|
+
return std::string_view(reinterpret_cast<const char *>(pm_string_source(&string)), pm_string_length(&string));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#endif
|
|
@@ -6,15 +6,21 @@
|
|
|
6
6
|
#ifndef PRISM_VERSION_H
|
|
7
7
|
#define PRISM_VERSION_H
|
|
8
8
|
|
|
9
|
+
#include "prism/compiler/exported.h"
|
|
10
|
+
|
|
11
|
+
#ifdef __cplusplus
|
|
12
|
+
extern "C" {
|
|
13
|
+
#endif
|
|
14
|
+
|
|
9
15
|
/**
|
|
10
16
|
* The major version of the Prism library as an int.
|
|
11
17
|
*/
|
|
12
|
-
#define PRISM_VERSION_MAJOR
|
|
18
|
+
#define PRISM_VERSION_MAJOR 2
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* The minor version of the Prism library as an int.
|
|
16
22
|
*/
|
|
17
|
-
#define PRISM_VERSION_MINOR
|
|
23
|
+
#define PRISM_VERSION_MINOR 1
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* The patch version of the Prism library as an int.
|
|
@@ -24,6 +30,17 @@
|
|
|
24
30
|
/**
|
|
25
31
|
* The version of the Prism library as a constant string.
|
|
26
32
|
*/
|
|
27
|
-
#define PRISM_VERSION "1.
|
|
33
|
+
#define PRISM_VERSION "2.1.0"
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The prism version and the serialization format.
|
|
37
|
+
*
|
|
38
|
+
* @returns The prism version as a constant string.
|
|
39
|
+
*/
|
|
40
|
+
PRISM_EXPORTED_FUNCTION const char * pm_version(void);
|
|
41
|
+
|
|
42
|
+
#ifdef __cplusplus
|
|
43
|
+
}
|
|
44
|
+
#endif
|
|
28
45
|
|
|
29
46
|
#endif
|
|
@@ -6,306 +6,22 @@
|
|
|
6
6
|
#ifndef PRISM_H
|
|
7
7
|
#define PRISM_H
|
|
8
8
|
|
|
9
|
-
#include "prism/
|
|
10
|
-
#include "prism/util/pm_buffer.h"
|
|
11
|
-
#include "prism/util/pm_char.h"
|
|
12
|
-
#include "prism/util/pm_integer.h"
|
|
13
|
-
#include "prism/util/pm_memchr.h"
|
|
14
|
-
#include "prism/util/pm_strncasecmp.h"
|
|
15
|
-
#include "prism/util/pm_strpbrk.h"
|
|
9
|
+
#include "prism/arena.h"
|
|
16
10
|
#include "prism/ast.h"
|
|
11
|
+
#include "prism/buffer.h"
|
|
17
12
|
#include "prism/diagnostic.h"
|
|
13
|
+
#include "prism/errors_format.h"
|
|
14
|
+
#include "prism/json.h"
|
|
18
15
|
#include "prism/node.h"
|
|
19
16
|
#include "prism/options.h"
|
|
20
|
-
#include "prism/pack.h"
|
|
21
17
|
#include "prism/parser.h"
|
|
22
18
|
#include "prism/prettyprint.h"
|
|
23
|
-
#include "prism/
|
|
24
|
-
#include "prism/
|
|
19
|
+
#include "prism/serialize.h"
|
|
20
|
+
#include "prism/source.h"
|
|
21
|
+
#include "prism/stream.h"
|
|
22
|
+
#include "prism/string_query.h"
|
|
25
23
|
#include "prism/version.h"
|
|
26
24
|
|
|
27
|
-
#include <assert.h>
|
|
28
|
-
#include <errno.h>
|
|
29
|
-
#include <locale.h>
|
|
30
|
-
#include <math.h>
|
|
31
|
-
#include <stdarg.h>
|
|
32
|
-
#include <stdbool.h>
|
|
33
|
-
#include <stdint.h>
|
|
34
|
-
#include <stdio.h>
|
|
35
|
-
#include <stdlib.h>
|
|
36
|
-
#include <string.h>
|
|
37
|
-
|
|
38
|
-
#ifndef _WIN32
|
|
39
|
-
#include <strings.h>
|
|
40
|
-
#endif
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The prism version and the serialization format.
|
|
44
|
-
*
|
|
45
|
-
* @returns The prism version as a constant string.
|
|
46
|
-
*/
|
|
47
|
-
PRISM_EXPORTED_FUNCTION const char * pm_version(void);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Initialize a parser with the given start and end pointers.
|
|
51
|
-
*
|
|
52
|
-
* The resulting parser must eventually be freed with `pm_parser_free()`.
|
|
53
|
-
*
|
|
54
|
-
* @param parser The parser to initialize.
|
|
55
|
-
* @param source The source to parse.
|
|
56
|
-
* @param size The size of the source.
|
|
57
|
-
* @param options The optional options to use when parsing. These options must
|
|
58
|
-
* live for the whole lifetime of this parser.
|
|
59
|
-
*
|
|
60
|
-
* \public \memberof pm_parser
|
|
61
|
-
*/
|
|
62
|
-
PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options);
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Register a callback that will be called whenever prism changes the encoding
|
|
66
|
-
* it is using to parse based on the magic comment.
|
|
67
|
-
*
|
|
68
|
-
* @param parser The parser to register the callback with.
|
|
69
|
-
* @param callback The callback to register.
|
|
70
|
-
*
|
|
71
|
-
* \public \memberof pm_parser
|
|
72
|
-
*/
|
|
73
|
-
PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Free any memory associated with the given parser.
|
|
77
|
-
*
|
|
78
|
-
* This does not free the `pm_options_t` object that was used to initialize the
|
|
79
|
-
* parser.
|
|
80
|
-
*
|
|
81
|
-
* @param parser The parser to free.
|
|
82
|
-
*
|
|
83
|
-
* \public \memberof pm_parser
|
|
84
|
-
*/
|
|
85
|
-
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Initiate the parser with the given parser.
|
|
89
|
-
*
|
|
90
|
-
* @param parser The parser to use.
|
|
91
|
-
* @return The AST representing the source.
|
|
92
|
-
*
|
|
93
|
-
* \public \memberof pm_parser
|
|
94
|
-
*/
|
|
95
|
-
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser);
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* This function is used in pm_parse_stream() to retrieve a line of input from a
|
|
99
|
-
* stream. It closely mirrors that of fgets so that fgets can be used as the
|
|
100
|
-
* default implementation.
|
|
101
|
-
*/
|
|
102
|
-
typedef char * (pm_parse_stream_fgets_t)(char *string, int size, void *stream);
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* This function is used in pm_parse_stream to check whether a stream is EOF.
|
|
106
|
-
* It closely mirrors that of feof so that feof can be used as the
|
|
107
|
-
* default implementation.
|
|
108
|
-
*/
|
|
109
|
-
typedef int (pm_parse_stream_feof_t)(void *stream);
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Parse a stream of Ruby source and return the tree.
|
|
113
|
-
*
|
|
114
|
-
* @param parser The parser to use.
|
|
115
|
-
* @param buffer The buffer to use.
|
|
116
|
-
* @param stream The stream to parse.
|
|
117
|
-
* @param stream_fgets The function to use to read from the stream.
|
|
118
|
-
* @param stream_feof The function to use to determine if the stream has hit eof.
|
|
119
|
-
* @param options The optional options to use when parsing.
|
|
120
|
-
* @return The AST representing the source.
|
|
121
|
-
*
|
|
122
|
-
* \public \memberof pm_parser
|
|
123
|
-
*/
|
|
124
|
-
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, pm_parse_stream_feof_t *stream_feof, const pm_options_t *options);
|
|
125
|
-
|
|
126
|
-
// We optionally support serializing to a binary string. For systems that don't
|
|
127
|
-
// want or need this functionality, it can be turned off with the
|
|
128
|
-
// PRISM_EXCLUDE_SERIALIZATION define.
|
|
129
|
-
#ifndef PRISM_EXCLUDE_SERIALIZATION
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Parse and serialize the AST represented by the source that is read out of the
|
|
133
|
-
* given stream into to the given buffer.
|
|
134
|
-
*
|
|
135
|
-
* @param buffer The buffer to serialize to.
|
|
136
|
-
* @param stream The stream to parse.
|
|
137
|
-
* @param stream_fgets The function to use to read from the stream.
|
|
138
|
-
* @param stream_feof The function to use to tell if the stream has hit eof.
|
|
139
|
-
* @param data The optional data to pass to the parser.
|
|
140
|
-
*/
|
|
141
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_stream(pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, pm_parse_stream_feof_t *stream_feof, const char *data);
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Serialize the given list of comments to the given buffer.
|
|
145
|
-
*
|
|
146
|
-
* @param parser The parser to serialize.
|
|
147
|
-
* @param list The list of comments to serialize.
|
|
148
|
-
* @param buffer The buffer to serialize to.
|
|
149
|
-
*/
|
|
150
|
-
void pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer);
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Serialize the name of the encoding to the buffer.
|
|
154
|
-
*
|
|
155
|
-
* @param encoding The encoding to serialize.
|
|
156
|
-
* @param buffer The buffer to serialize to.
|
|
157
|
-
*/
|
|
158
|
-
void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer);
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Serialize the encoding, metadata, nodes, and constant pool.
|
|
162
|
-
*
|
|
163
|
-
* @param parser The parser to serialize.
|
|
164
|
-
* @param node The node to serialize.
|
|
165
|
-
* @param buffer The buffer to serialize to.
|
|
166
|
-
*/
|
|
167
|
-
void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Serialize the AST represented by the given node to the given buffer.
|
|
171
|
-
*
|
|
172
|
-
* @param parser The parser to serialize.
|
|
173
|
-
* @param node The node to serialize.
|
|
174
|
-
* @param buffer The buffer to serialize to.
|
|
175
|
-
*/
|
|
176
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Parse the given source to the AST and dump the AST to the given buffer.
|
|
180
|
-
*
|
|
181
|
-
* @param buffer The buffer to serialize to.
|
|
182
|
-
* @param source The source to parse.
|
|
183
|
-
* @param size The size of the source.
|
|
184
|
-
* @param data The optional data to pass to the parser.
|
|
185
|
-
*/
|
|
186
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Parse and serialize the comments in the given source to the given buffer.
|
|
190
|
-
*
|
|
191
|
-
* @param buffer The buffer to serialize to.
|
|
192
|
-
* @param source The source to parse.
|
|
193
|
-
* @param size The size of the source.
|
|
194
|
-
* @param data The optional data to pass to the parser.
|
|
195
|
-
*/
|
|
196
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Lex the given source and serialize to the given buffer.
|
|
200
|
-
*
|
|
201
|
-
* @param source The source to lex.
|
|
202
|
-
* @param size The size of the source.
|
|
203
|
-
* @param buffer The buffer to serialize to.
|
|
204
|
-
* @param data The optional data to pass to the lexer.
|
|
205
|
-
*/
|
|
206
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Parse and serialize both the AST and the tokens represented by the given
|
|
210
|
-
* source to the given buffer.
|
|
211
|
-
*
|
|
212
|
-
* @param buffer The buffer to serialize to.
|
|
213
|
-
* @param source The source to parse.
|
|
214
|
-
* @param size The size of the source.
|
|
215
|
-
* @param data The optional data to pass to the parser.
|
|
216
|
-
*/
|
|
217
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
|
|
218
|
-
|
|
219
|
-
#endif
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Parse the source and return true if it parses without errors or warnings.
|
|
223
|
-
*
|
|
224
|
-
* @param source The source to parse.
|
|
225
|
-
* @param size The size of the source.
|
|
226
|
-
* @param data The optional data to pass to the parser.
|
|
227
|
-
* @return True if the source parses without errors or warnings.
|
|
228
|
-
*/
|
|
229
|
-
PRISM_EXPORTED_FUNCTION bool pm_parse_success_p(const uint8_t *source, size_t size, const char *data);
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Returns a string representation of the given token type.
|
|
233
|
-
*
|
|
234
|
-
* @param token_type The token type to convert to a string.
|
|
235
|
-
* @return A string representation of the given token type.
|
|
236
|
-
*/
|
|
237
|
-
PRISM_EXPORTED_FUNCTION const char * pm_token_type_name(pm_token_type_t token_type);
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Returns the human name of the given token type.
|
|
241
|
-
*
|
|
242
|
-
* @param token_type The token type to convert to a human name.
|
|
243
|
-
* @return The human name of the given token type.
|
|
244
|
-
*/
|
|
245
|
-
const char * pm_token_type_human(pm_token_type_t token_type);
|
|
246
|
-
|
|
247
|
-
// We optionally support dumping to JSON. For systems that don't want or need
|
|
248
|
-
// this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
|
|
249
|
-
#ifndef PRISM_EXCLUDE_JSON
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Dump JSON to the given buffer.
|
|
253
|
-
*
|
|
254
|
-
* @param buffer The buffer to serialize to.
|
|
255
|
-
* @param parser The parser that parsed the node.
|
|
256
|
-
* @param node The node to serialize.
|
|
257
|
-
*/
|
|
258
|
-
PRISM_EXPORTED_FUNCTION void pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *node);
|
|
259
|
-
|
|
260
|
-
#endif
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Represents the results of a slice query.
|
|
264
|
-
*/
|
|
265
|
-
typedef enum {
|
|
266
|
-
/** Returned if the encoding given to a slice query was invalid. */
|
|
267
|
-
PM_STRING_QUERY_ERROR = -1,
|
|
268
|
-
|
|
269
|
-
/** Returned if the result of the slice query is false. */
|
|
270
|
-
PM_STRING_QUERY_FALSE,
|
|
271
|
-
|
|
272
|
-
/** Returned if the result of the slice query is true. */
|
|
273
|
-
PM_STRING_QUERY_TRUE
|
|
274
|
-
} pm_string_query_t;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Check that the slice is a valid local variable name.
|
|
278
|
-
*
|
|
279
|
-
* @param source The source to check.
|
|
280
|
-
* @param length The length of the source.
|
|
281
|
-
* @param encoding_name The name of the encoding of the source.
|
|
282
|
-
* @return PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
283
|
-
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
284
|
-
*/
|
|
285
|
-
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_local(const uint8_t *source, size_t length, const char *encoding_name);
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Check that the slice is a valid constant name.
|
|
289
|
-
*
|
|
290
|
-
* @param source The source to check.
|
|
291
|
-
* @param length The length of the source.
|
|
292
|
-
* @param encoding_name The name of the encoding of the source.
|
|
293
|
-
* @return PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
294
|
-
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
295
|
-
*/
|
|
296
|
-
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_constant(const uint8_t *source, size_t length, const char *encoding_name);
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Check that the slice is a valid method name.
|
|
300
|
-
*
|
|
301
|
-
* @param source The source to check.
|
|
302
|
-
* @param length The length of the source.
|
|
303
|
-
* @param encoding_name The name of the encoding of the source.
|
|
304
|
-
* @return PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
|
|
305
|
-
* the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
|
|
306
|
-
*/
|
|
307
|
-
PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint8_t *source, size_t length, const char *encoding_name);
|
|
308
|
-
|
|
309
25
|
/**
|
|
310
26
|
* @mainpage
|
|
311
27
|
*
|
|
@@ -328,27 +44,27 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
|
328
44
|
*
|
|
329
45
|
* @section parsing Parsing
|
|
330
46
|
*
|
|
331
|
-
* In order to parse Ruby code, the
|
|
332
|
-
*
|
|
47
|
+
* In order to parse Ruby code, the functions that you are going to want to use
|
|
48
|
+
* and be aware of are:
|
|
333
49
|
*
|
|
334
|
-
* * `
|
|
335
|
-
* * `
|
|
50
|
+
* * `pm_arena_new()` - create a new arena to hold all AST-lifetime allocations
|
|
51
|
+
* * `pm_parser_new()` - allocate and initialize a new parser
|
|
336
52
|
* * `pm_parse()` - parse and return the root node
|
|
337
|
-
* * `
|
|
338
|
-
* * `
|
|
53
|
+
* * `pm_parser_free()` - free the parser and its internal memory
|
|
54
|
+
* * `pm_arena_free()` - free all AST-lifetime memory
|
|
339
55
|
*
|
|
340
56
|
* Putting all of this together would look something like:
|
|
341
57
|
*
|
|
342
58
|
* ```c
|
|
343
59
|
* void parse(const uint8_t *source, size_t length) {
|
|
344
|
-
*
|
|
345
|
-
*
|
|
60
|
+
* pm_arena_t *arena = pm_arena_new();
|
|
61
|
+
* pm_parser_t *parser = pm_parser_new(arena, source, length, NULL);
|
|
346
62
|
*
|
|
347
|
-
* pm_node_t *root = pm_parse(
|
|
63
|
+
* pm_node_t *root = pm_parse(parser);
|
|
348
64
|
* printf("PARSED!\n");
|
|
349
65
|
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
66
|
+
* pm_parser_free(parser);
|
|
67
|
+
* pm_arena_free(arena);
|
|
352
68
|
* }
|
|
353
69
|
* ```
|
|
354
70
|
*
|
|
@@ -361,24 +77,23 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
|
361
77
|
* Prism provides the ability to serialize the AST and its related metadata into
|
|
362
78
|
* a binary format. This format is designed to be portable to different
|
|
363
79
|
* languages and runtimes so that you only need to make one FFI call in order to
|
|
364
|
-
* parse Ruby code. The
|
|
365
|
-
*
|
|
80
|
+
* parse Ruby code. The functions that you are going to want to use and be
|
|
81
|
+
* aware of are:
|
|
366
82
|
*
|
|
367
|
-
* * `
|
|
368
|
-
* * `pm_buffer_free()` - free the
|
|
369
|
-
* * `pm_serialize()` - serialize the AST into a buffer
|
|
83
|
+
* * `pm_buffer_new()` - create a new buffer
|
|
84
|
+
* * `pm_buffer_free()` - free the buffer and its internal memory
|
|
370
85
|
* * `pm_serialize_parse()` - parse and serialize the AST into a buffer
|
|
371
86
|
*
|
|
372
87
|
* Putting all of this together would look something like:
|
|
373
88
|
*
|
|
374
89
|
* ```c
|
|
375
90
|
* void serialize(const uint8_t *source, size_t length) {
|
|
376
|
-
* pm_buffer_t buffer =
|
|
91
|
+
* pm_buffer_t *buffer = pm_buffer_new();
|
|
377
92
|
*
|
|
378
|
-
* pm_serialize_parse(
|
|
93
|
+
* pm_serialize_parse(buffer, source, length, NULL);
|
|
379
94
|
* printf("SERIALIZED!\n");
|
|
380
95
|
*
|
|
381
|
-
* pm_buffer_free(
|
|
96
|
+
* pm_buffer_free(buffer);
|
|
382
97
|
* }
|
|
383
98
|
* ```
|
|
384
99
|
*
|
|
@@ -389,18 +104,18 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
|
389
104
|
*
|
|
390
105
|
* ```c
|
|
391
106
|
* void prettyprint(const uint8_t *source, size_t length) {
|
|
392
|
-
*
|
|
393
|
-
*
|
|
107
|
+
* pm_arena_t *arena = pm_arena_new();
|
|
108
|
+
* pm_parser_t *parser = pm_parser_new(arena, source, length, NULL);
|
|
394
109
|
*
|
|
395
|
-
* pm_node_t *root = pm_parse(
|
|
396
|
-
* pm_buffer_t buffer =
|
|
110
|
+
* pm_node_t *root = pm_parse(parser);
|
|
111
|
+
* pm_buffer_t *buffer = pm_buffer_new();
|
|
397
112
|
*
|
|
398
|
-
* pm_prettyprint(
|
|
399
|
-
* printf("%*.s\n", (int) buffer
|
|
113
|
+
* pm_prettyprint(buffer, parser, root);
|
|
114
|
+
* printf("%*.s\n", (int) pm_buffer_length(buffer), pm_buffer_value(buffer));
|
|
400
115
|
*
|
|
401
|
-
* pm_buffer_free(
|
|
402
|
-
*
|
|
403
|
-
*
|
|
116
|
+
* pm_buffer_free(buffer);
|
|
117
|
+
* pm_parser_free(parser);
|
|
118
|
+
* pm_arena_free(arena);
|
|
404
119
|
* }
|
|
405
120
|
* ```
|
|
406
121
|
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file prism.hpp
|
|
3
|
+
*
|
|
4
|
+
* The main header file for the C++ interface to the prism parser. It adds
|
|
5
|
+
* ownership, checked casts between node types, and callable-based iteration on
|
|
6
|
+
* top of the C API. It never wraps the C structs: every function in it takes
|
|
7
|
+
* and returns the same pm_*_t types that prism.h declares, so the two can be
|
|
8
|
+
* mixed freely. It requires C++17 or later.
|
|
9
|
+
*/
|
|
10
|
+
#ifndef PRISM_HPP
|
|
11
|
+
#define PRISM_HPP
|
|
12
|
+
|
|
13
|
+
#include "prism.h"
|
|
14
|
+
|
|
15
|
+
#include "prism/arena.hpp"
|
|
16
|
+
#include "prism/ast.hpp"
|
|
17
|
+
#include "prism/buffer.hpp"
|
|
18
|
+
#include "prism/node.hpp"
|
|
19
|
+
#include "prism/node_type.hpp"
|
|
20
|
+
#include "prism/options.hpp"
|
|
21
|
+
#include "prism/parser.hpp"
|
|
22
|
+
#include "prism/stringy.hpp"
|
|
23
|
+
|
|
24
|
+
#endif
|