prism 2.0.0.rc1-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.
- checksums.yaml +7 -0
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +870 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +58 -0
- data/LICENSE.md +7 -0
- data/Makefile +145 -0
- data/README.md +81 -0
- data/config.yml +4752 -0
- data/docs/build_system.md +119 -0
- data/docs/configuration.md +69 -0
- data/docs/cruby_compilation.md +27 -0
- data/docs/design.md +53 -0
- data/docs/encoding.md +121 -0
- data/docs/fuzzing.md +81 -0
- data/docs/heredocs.md +36 -0
- data/docs/javascript.md +133 -0
- data/docs/local_variable_depth.md +229 -0
- data/docs/mapping.md +117 -0
- data/docs/parser_translation.md +24 -0
- data/docs/parsing_rules.md +22 -0
- data/docs/releasing.md +147 -0
- data/docs/relocation.md +32 -0
- data/docs/ripper_translation.md +63 -0
- data/docs/ruby_api.md +45 -0
- data/docs/ruby_parser_translation.md +19 -0
- data/docs/serialization.md +230 -0
- data/docs/testing.md +72 -0
- data/ext/prism/api_node.c +7005 -0
- data/ext/prism/extconf.rb +126 -0
- data/ext/prism/extension.c +1783 -0
- data/ext/prism/extension.h +19 -0
- data/include/prism/arena.h +37 -0
- data/include/prism/ast.h +10371 -0
- data/include/prism/buffer.h +52 -0
- data/include/prism/comments.h +55 -0
- data/include/prism/compiler/accel.h +24 -0
- data/include/prism/compiler/align.h +36 -0
- data/include/prism/compiler/assume.h +25 -0
- data/include/prism/compiler/exported.h +24 -0
- data/include/prism/compiler/fallthrough.h +22 -0
- data/include/prism/compiler/filesystem.h +32 -0
- data/include/prism/compiler/flex_array.h +19 -0
- data/include/prism/compiler/force_inline.h +21 -0
- data/include/prism/compiler/format.h +25 -0
- data/include/prism/compiler/inline.h +17 -0
- data/include/prism/compiler/nodiscard.h +22 -0
- data/include/prism/compiler/nonnull.h +18 -0
- data/include/prism/compiler/unused.h +18 -0
- data/include/prism/constant_pool.h +81 -0
- data/include/prism/diagnostic.h +93 -0
- data/include/prism/errors_format.h +53 -0
- data/include/prism/excludes.h +29 -0
- data/include/prism/integer.h +41 -0
- data/include/prism/internal/allocator.h +68 -0
- data/include/prism/internal/allocator_debug.h +88 -0
- data/include/prism/internal/arena.h +108 -0
- data/include/prism/internal/bit.h +42 -0
- data/include/prism/internal/buffer.h +91 -0
- data/include/prism/internal/char.h +145 -0
- data/include/prism/internal/comments.h +53 -0
- data/include/prism/internal/constant_pool.h +152 -0
- data/include/prism/internal/diagnostic.h +389 -0
- data/include/prism/internal/encoding.h +242 -0
- data/include/prism/internal/integer.h +68 -0
- data/include/prism/internal/isinf.h +16 -0
- data/include/prism/internal/line_offset_list.h +34 -0
- data/include/prism/internal/list.h +62 -0
- data/include/prism/internal/magic_comments.h +23 -0
- data/include/prism/internal/memchr.h +15 -0
- data/include/prism/internal/node.h +38 -0
- data/include/prism/internal/options.h +232 -0
- data/include/prism/internal/parser.h +984 -0
- data/include/prism/internal/regexp.h +26 -0
- data/include/prism/internal/serialize.h +39 -0
- data/include/prism/internal/source.h +72 -0
- data/include/prism/internal/static_literals.h +100 -0
- data/include/prism/internal/stringy.h +35 -0
- data/include/prism/internal/strncasecmp.h +18 -0
- data/include/prism/internal/strpbrk.h +33 -0
- data/include/prism/internal/tokens.h +11 -0
- data/include/prism/json.h +32 -0
- data/include/prism/line_offset_list.h +61 -0
- data/include/prism/magic_comments.h +35 -0
- data/include/prism/node.h +94 -0
- data/include/prism/options.h +354 -0
- data/include/prism/parser.h +404 -0
- data/include/prism/prettyprint.h +31 -0
- data/include/prism/serialize.h +115 -0
- data/include/prism/source.h +155 -0
- data/include/prism/stream.h +28 -0
- data/include/prism/string_query.h +63 -0
- data/include/prism/stringy.h +72 -0
- data/include/prism/version.h +38 -0
- data/include/prism.h +131 -0
- data/lib/prism/3.3/prism.so +0 -0
- data/lib/prism/3.4/prism.so +0 -0
- data/lib/prism/4.0/prism.so +0 -0
- data/lib/prism/compiler.rb +815 -0
- data/lib/prism/desugar_compiler.rb +463 -0
- data/lib/prism/dispatcher.rb +2383 -0
- data/lib/prism/dot_visitor.rb +4848 -0
- data/lib/prism/dsl.rb +1369 -0
- data/lib/prism/ffi.rb +740 -0
- data/lib/prism/inspect_visitor.rb +2425 -0
- data/lib/prism/lex_compat.rb +953 -0
- data/lib/prism/mutation_compiler.rb +780 -0
- data/lib/prism/node.rb +33204 -0
- data/lib/prism/node_ext.rb +504 -0
- data/lib/prism/node_find.rb +215 -0
- data/lib/prism/parse_result/errors.rb +72 -0
- data/lib/prism/parse_result/newlines.rb +423 -0
- data/lib/prism/parse_result.rb +1221 -0
- data/lib/prism/pattern.rb +314 -0
- data/lib/prism/polyfill/append_as_bytes.rb +15 -0
- data/lib/prism/polyfill/byteindex.rb +13 -0
- data/lib/prism/polyfill/scan_byte.rb +14 -0
- data/lib/prism/polyfill/unpack1.rb +14 -0
- data/lib/prism/polyfill/warn.rb +36 -0
- data/lib/prism/reflection.rb +427 -0
- data/lib/prism/relocation.rb +567 -0
- data/lib/prism/serialize.rb +5308 -0
- data/lib/prism/string_query.rb +46 -0
- data/lib/prism/translation/parser/builder.rb +70 -0
- data/lib/prism/translation/parser/compiler.rb +2226 -0
- data/lib/prism/translation/parser/lexer.rb +769 -0
- data/lib/prism/translation/parser.rb +376 -0
- data/lib/prism/translation/parser_current.rb +26 -0
- data/lib/prism/translation/parser_versions.rb +36 -0
- data/lib/prism/translation/ripper/filter.rb +53 -0
- data/lib/prism/translation/ripper/lexer.rb +133 -0
- data/lib/prism/translation/ripper/sexp.rb +118 -0
- data/lib/prism/translation/ripper/shim.rb +7 -0
- data/lib/prism/translation/ripper.rb +4278 -0
- data/lib/prism/translation/ruby_parser.rb +1721 -0
- data/lib/prism/translation.rb +20 -0
- data/lib/prism/visitor.rb +1440 -0
- data/lib/prism.rb +168 -0
- data/prism.gemspec +234 -0
- data/rbi/generated/prism/compiler.rbi +489 -0
- data/rbi/generated/prism/desugar_compiler.rbi +306 -0
- data/rbi/generated/prism/dispatcher.rbi +1138 -0
- data/rbi/generated/prism/dot_visitor.rbi +618 -0
- data/rbi/generated/prism/dsl.rbi +751 -0
- data/rbi/generated/prism/inspect_visitor.rbi +503 -0
- data/rbi/generated/prism/lex_compat.rbi +162 -0
- data/rbi/generated/prism/mutation_compiler.rbi +464 -0
- data/rbi/generated/prism/node.rbi +13681 -0
- data/rbi/generated/prism/node_ext.rbi +259 -0
- data/rbi/generated/prism/node_find.rbi +79 -0
- data/rbi/generated/prism/parse_result/errors.rbi +21 -0
- data/rbi/generated/prism/parse_result/newlines.rbi +208 -0
- data/rbi/generated/prism/parse_result.rbi +764 -0
- data/rbi/generated/prism/pattern.rbi +134 -0
- data/rbi/generated/prism/reflection.rbi +89 -0
- data/rbi/generated/prism/relocation.rbi +329 -0
- data/rbi/generated/prism/serialize.rbi +181 -0
- data/rbi/generated/prism/string_query.rbi +36 -0
- data/rbi/generated/prism/translation.rbi +7 -0
- data/rbi/generated/prism/visitor.rbi +650 -0
- data/rbi/generated/prism.rbi +86 -0
- data/rbi/prism/translation/parser.rbi +11 -0
- data/rbi/prism/translation/parser_versions.rbi +28 -0
- data/rbi/prism/translation/ripper.rbi +15 -0
- data/rbi/rubyvm/node_find.rbi +14 -0
- data/sig/generated/prism/compiler.rbs +492 -0
- data/sig/generated/prism/desugar_compiler.rbs +305 -0
- data/sig/generated/prism/dispatcher.rbs +1292 -0
- data/sig/generated/prism/dot_visitor.rbs +635 -0
- data/sig/generated/prism/dsl.rbs +928 -0
- data/sig/generated/prism/inspect_visitor.rbs +509 -0
- data/sig/generated/prism/lex_compat.rbs +166 -0
- data/sig/generated/prism/mutation_compiler.rbs +464 -0
- data/sig/generated/prism/node.rbs +20160 -0
- data/sig/generated/prism/node_ext.rbs +290 -0
- data/sig/generated/prism/node_find.rbs +90 -0
- data/sig/generated/prism/parse_result/errors.rbs +22 -0
- data/sig/generated/prism/parse_result/newlines.rbs +223 -0
- data/sig/generated/prism/parse_result.rbs +859 -0
- data/sig/generated/prism/pattern.rbs +156 -0
- data/sig/generated/prism/reflection.rbs +101 -0
- data/sig/generated/prism/relocation.rbs +428 -0
- data/sig/generated/prism/serialize.rbs +195 -0
- data/sig/generated/prism/string_query.rbs +36 -0
- data/sig/generated/prism/translation.rbs +8 -0
- data/sig/generated/prism/visitor.rbs +1111 -0
- data/sig/generated/prism.rbs +84 -0
- data/sig/manifest.yaml +2 -0
- data/src/arena.c +117 -0
- data/src/buffer.c +380 -0
- data/src/char.c +289 -0
- data/src/comments.c +454 -0
- data/src/constant_pool.c +406 -0
- data/src/diagnostic.c +886 -0
- data/src/encoding.c +5345 -0
- data/src/errors_format.c +519 -0
- data/src/integer.c +681 -0
- data/src/json.c +5733 -0
- data/src/line_offset_list.c +100 -0
- data/src/list.c +24 -0
- data/src/memchr.c +37 -0
- data/src/node.c +4515 -0
- data/src/options.c +451 -0
- data/src/parser.c +349 -0
- data/src/prettyprint.c +9024 -0
- data/src/prism.c +23739 -0
- data/src/regexp.c +1706 -0
- data/src/serialize.c +2309 -0
- data/src/source.c +518 -0
- data/src/static_literals.c +685 -0
- data/src/string_query.c +166 -0
- data/src/stringy.c +91 -0
- data/src/strncasecmp.c +37 -0
- data/src/strpbrk.c +447 -0
- data/src/tokens.c +724 -0
- metadata +259 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file parser.h
|
|
3
|
+
*
|
|
4
|
+
* The parser used to parse Ruby source.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_PARSER_H
|
|
7
|
+
#define PRISM_PARSER_H
|
|
8
|
+
|
|
9
|
+
#include "prism/compiler/nodiscard.h"
|
|
10
|
+
#include "prism/compiler/nonnull.h"
|
|
11
|
+
|
|
12
|
+
#include "prism/ast.h"
|
|
13
|
+
#include "prism/comments.h"
|
|
14
|
+
#include "prism/diagnostic.h"
|
|
15
|
+
#include "prism/line_offset_list.h"
|
|
16
|
+
#include "prism/magic_comments.h"
|
|
17
|
+
#include "prism/options.h"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The parser used to parse Ruby source.
|
|
21
|
+
*/
|
|
22
|
+
typedef struct pm_parser_t pm_parser_t;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Allocate and initialize a parser with the given start and end pointers.
|
|
26
|
+
*
|
|
27
|
+
* @param arena The arena to use for all AST-lifetime allocations. It is caller-
|
|
28
|
+
* owned and must outlive the parser.
|
|
29
|
+
* @param source The source to parse.
|
|
30
|
+
* @param size The size of the source.
|
|
31
|
+
* @param options The optional options to use when parsing. These options must
|
|
32
|
+
* live for the whole lifetime of this parser.
|
|
33
|
+
* @returns The initialized parser. It is the responsibility of the caller to
|
|
34
|
+
* free the parser with `pm_parser_free()`.
|
|
35
|
+
*/
|
|
36
|
+
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Free both the memory held by the given parser and the parser itself.
|
|
40
|
+
*
|
|
41
|
+
* @param parser The parser to free.
|
|
42
|
+
*/
|
|
43
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* When the encoding that is being used to parse the source is changed by prism,
|
|
47
|
+
* we provide the ability here to call out to a user-defined function.
|
|
48
|
+
*/
|
|
49
|
+
typedef void (*pm_encoding_changed_callback_t)(pm_parser_t *parser);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* This is the callback that is called when a token is lexed. It is passed
|
|
53
|
+
* the opaque data pointer, the parser, and the token that was lexed.
|
|
54
|
+
*/
|
|
55
|
+
typedef void (*pm_lex_callback_t)(pm_parser_t *parser, pm_token_t *token, void *data);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Register a callback that will be called whenever prism changes the encoding
|
|
59
|
+
* it is using to parse based on the magic comment.
|
|
60
|
+
*
|
|
61
|
+
* @param parser The parser to register the callback with.
|
|
62
|
+
* @param callback The callback to register.
|
|
63
|
+
*/
|
|
64
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_encoding_changed_callback_set(pm_parser_t *parser, pm_encoding_changed_callback_t callback) PRISM_NONNULL(1);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register a callback that will be called whenever a token is lexed.
|
|
68
|
+
*
|
|
69
|
+
* @param parser The parser to register the callback with.
|
|
70
|
+
* @param data The opaque data to pass to the callback when it is called.
|
|
71
|
+
* @param callback The callback to register.
|
|
72
|
+
*/
|
|
73
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_lex_callback_set(pm_parser_t *parser, pm_lex_callback_t callback, void *data) PRISM_NONNULL(1);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns the opaque data that is passed to the lex callback when it is called.
|
|
77
|
+
*
|
|
78
|
+
* @param parser The parser whose lex callback data we want to get.
|
|
79
|
+
* @returns The opaque data that is passed to the lex callback when it is called.
|
|
80
|
+
*/
|
|
81
|
+
PRISM_EXPORTED_FUNCTION void * pm_parser_lex_callback_data(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the raw pointer to the start of the source that is being parsed.
|
|
85
|
+
*
|
|
86
|
+
* @param parser the parser whose start pointer we want to get
|
|
87
|
+
* @returns the raw pointer to the start of the source that is being parsed
|
|
88
|
+
*/
|
|
89
|
+
PRISM_EXPORTED_FUNCTION const uint8_t * pm_parser_start(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the raw pointer to the end of the source that is being parsed.
|
|
93
|
+
*
|
|
94
|
+
* @param parser the parser whose end pointer we want to get
|
|
95
|
+
* @returns the raw pointer to the end of the source that is being parsed
|
|
96
|
+
*/
|
|
97
|
+
PRISM_EXPORTED_FUNCTION const uint8_t * pm_parser_end(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns the line that the parser was considered to have started on.
|
|
101
|
+
*
|
|
102
|
+
* @param parser the parser whose start line we want to get
|
|
103
|
+
* @returns the line that the parser was considered to have started on
|
|
104
|
+
*/
|
|
105
|
+
PRISM_EXPORTED_FUNCTION int32_t pm_parser_start_line(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returns the name of the encoding that is being used to parse the source.
|
|
109
|
+
*
|
|
110
|
+
* @param parser the parser whose encoding name we want to get
|
|
111
|
+
* @returns the name of the encoding that is being used to parse the source
|
|
112
|
+
*/
|
|
113
|
+
PRISM_EXPORTED_FUNCTION const char * pm_parser_encoding_name(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Returns the width of the character at the given pointer in the encoding that
|
|
117
|
+
* is being used to parse the source.
|
|
118
|
+
*
|
|
119
|
+
* @param parser the parser whose encoding we want to use
|
|
120
|
+
* @param start a pointer to the start of the character
|
|
121
|
+
* @param remaining the number of bytes remaining in the source
|
|
122
|
+
* @returns the width of the character in bytes
|
|
123
|
+
*/
|
|
124
|
+
PRISM_EXPORTED_FUNCTION size_t pm_parser_encoding_char_width(const pm_parser_t *parser, const uint8_t *start, ptrdiff_t remaining) PRISM_NONNULL(1, 2);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Returns whether or not the parser is using the US-ASCII encoding.
|
|
128
|
+
*
|
|
129
|
+
* @param parser the parser to check
|
|
130
|
+
* @returns true if the parser is using US-ASCII encoding, false otherwise
|
|
131
|
+
*/
|
|
132
|
+
PRISM_EXPORTED_FUNCTION bool pm_parser_encoding_us_ascii(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Returns the filepath that is being used to parse the source.
|
|
136
|
+
*
|
|
137
|
+
* @param parser the parser whose filepath we want to get
|
|
138
|
+
* @returns a pointer to the filepath string
|
|
139
|
+
*/
|
|
140
|
+
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_parser_filepath(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Find a constant in the parser's constant pool. Returns the id of the
|
|
144
|
+
* constant, or 0 if the constant is not found.
|
|
145
|
+
*
|
|
146
|
+
* @param parser the parser whose constant pool we want to search
|
|
147
|
+
* @param start a pointer to the start of the string to search for
|
|
148
|
+
* @param length the length of the string to search for
|
|
149
|
+
* @returns the id of the constant, or 0 if the constant is not found
|
|
150
|
+
*/
|
|
151
|
+
PRISM_EXPORTED_FUNCTION pm_constant_id_t pm_parser_constant_find(const pm_parser_t *parser, const uint8_t *start, size_t length) PRISM_NONNULL(1, 2);
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns the frozen string literal value of the parser, as determined by the
|
|
155
|
+
* frozen_string_literal magic comment or the option set on the parser.
|
|
156
|
+
*
|
|
157
|
+
* @param parser the parser whose frozen string literal value we want to get
|
|
158
|
+
* @returns -1 if disabled, 0 if unset, 1 if enabled
|
|
159
|
+
*/
|
|
160
|
+
PRISM_EXPORTED_FUNCTION int8_t pm_parser_frozen_string_literal(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns the line offsets that are associated with the given parser.
|
|
164
|
+
*
|
|
165
|
+
* @param parser the parser whose line offsets we want to get
|
|
166
|
+
* @returns the line offsets that are associated with the given parser
|
|
167
|
+
*/
|
|
168
|
+
PRISM_EXPORTED_FUNCTION const pm_line_offset_list_t * pm_parser_line_offsets(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns the location of the __DATA__ section that is associated with the
|
|
172
|
+
* given parser.
|
|
173
|
+
*
|
|
174
|
+
* @param parser the parser whose data location we want to get
|
|
175
|
+
* @returns the location of the __DATA__ section that is associated with the
|
|
176
|
+
* given parser. If it is unset, then the length will be set to 0.
|
|
177
|
+
*/
|
|
178
|
+
PRISM_EXPORTED_FUNCTION const pm_location_t * pm_parser_data_loc(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns whether the given parser is continuable, meaning that it could become
|
|
182
|
+
* valid if more input were appended, as opposed to being definitively invalid.
|
|
183
|
+
*
|
|
184
|
+
* @param parser the parser whose continuable status we want to get
|
|
185
|
+
* @returns whether the given parser is continuable
|
|
186
|
+
*/
|
|
187
|
+
PRISM_EXPORTED_FUNCTION bool pm_parser_continuable(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Returns the lex state of the parser. Note that this is an internal detail,
|
|
191
|
+
* and we are purposefully not returning an instance of the internal enum that
|
|
192
|
+
* we use to track this. This is only exposed because we need it for some very
|
|
193
|
+
* niche use cases. Most consumers should avoid this function.
|
|
194
|
+
*
|
|
195
|
+
* @param parser the parser whose lex state we want to get
|
|
196
|
+
* @returns the lex state of the parser
|
|
197
|
+
*/
|
|
198
|
+
PRISM_EXPORTED_FUNCTION int pm_parser_lex_state(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns the number of comments associated with the given parser.
|
|
202
|
+
*
|
|
203
|
+
* @param parser the parser whose comments we want to get the size of
|
|
204
|
+
* @returns the number of comments associated with the given parser
|
|
205
|
+
*/
|
|
206
|
+
PRISM_EXPORTED_FUNCTION size_t pm_parser_comments_size(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A callback function that can be used to process comments found while parsing.
|
|
210
|
+
*/
|
|
211
|
+
typedef void (*pm_comment_callback_t)(const pm_comment_t *comment, void *data);
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Iterates over the comments associated with the given parser and calls the
|
|
215
|
+
* given callback for each comment.
|
|
216
|
+
*
|
|
217
|
+
* @param parser the parser whose comments we want to iterate over
|
|
218
|
+
* @param callback the callback function to call for each comment. This function
|
|
219
|
+
* will be passed a pointer to the comment and the data parameter passed to
|
|
220
|
+
* this function.
|
|
221
|
+
* @param data the data to pass to the callback function for each comment. This
|
|
222
|
+
* can be NULL if no data needs to be passed to the callback function.
|
|
223
|
+
*/
|
|
224
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_comments_each(const pm_parser_t *parser, pm_comment_callback_t callback, void *data) PRISM_NONNULL(1);
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Returns the number of comments owned by the given node. This is 0 if the
|
|
228
|
+
* node owns no comments or if the attach_comments option was not set.
|
|
229
|
+
*
|
|
230
|
+
* @param parser the parser that produced the node
|
|
231
|
+
* @param node the node whose comments we want to count
|
|
232
|
+
* @returns the number of comments owned by the given node
|
|
233
|
+
*/
|
|
234
|
+
PRISM_EXPORTED_FUNCTION uint32_t pm_node_comments_size(const pm_parser_t *parser, const pm_node_t *node) PRISM_NONNULL(1, 2);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Returns the comment at the given index among the comments owned by the given
|
|
238
|
+
* node, which are ordered by start offset.
|
|
239
|
+
*
|
|
240
|
+
* @param parser the parser that produced the node
|
|
241
|
+
* @param node the node whose comment we want to get
|
|
242
|
+
* @param index the index of the comment among those owned by the node
|
|
243
|
+
* @returns the comment at the given index, or NULL if the index is out of range
|
|
244
|
+
*/
|
|
245
|
+
PRISM_EXPORTED_FUNCTION const pm_comment_t * pm_node_comment(const pm_parser_t *parser, const pm_node_t *node, uint32_t index) PRISM_NONNULL(1, 2);
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Returns the index, among the comments associated with the given parser, of
|
|
249
|
+
* the comment at the given index among the comment attachments. The attachments
|
|
250
|
+
* are every comment, grouped by owning node in order of node id and ordered by
|
|
251
|
+
* start offset within each node, so there are as many attachments as there are
|
|
252
|
+
* comments when the attach_comments option is set.
|
|
253
|
+
*
|
|
254
|
+
* @param parser the parser whose comment attachments we want to read
|
|
255
|
+
* @param index the index of the attachment
|
|
256
|
+
* @returns the index of the comment, or UINT32_MAX if the index is out of range
|
|
257
|
+
* or the attach_comments option was not set
|
|
258
|
+
*/
|
|
259
|
+
PRISM_EXPORTED_FUNCTION uint32_t pm_parser_comment_attachment(const pm_parser_t *parser, uint32_t index) PRISM_NONNULL(1);
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Returns the number of node ids that have a comment range, which is one more
|
|
263
|
+
* than the largest id of a node that owns a comment, or 0 if the
|
|
264
|
+
* attach_comments option was not set or there are no comments.
|
|
265
|
+
*
|
|
266
|
+
* @param parser the parser whose comment ranges we want to count
|
|
267
|
+
* @returns the number of comment ranges
|
|
268
|
+
*/
|
|
269
|
+
PRISM_EXPORTED_FUNCTION uint32_t pm_parser_comment_ranges_size(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns the range of comment attachments owned by the node with the given id.
|
|
273
|
+
*
|
|
274
|
+
* @param parser the parser that produced the node
|
|
275
|
+
* @param node_id the id of the node
|
|
276
|
+
* @returns the range of attachments owned by the node, whose length is 0 if the
|
|
277
|
+
* node owns no comments, the node id is out of range, or the
|
|
278
|
+
* attach_comments option was not set
|
|
279
|
+
*/
|
|
280
|
+
PRISM_EXPORTED_FUNCTION pm_comment_range_t pm_parser_comment_range(const pm_parser_t *parser, uint32_t node_id) PRISM_NONNULL(1);
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Returns the number of magic comments associated with the given parser.
|
|
284
|
+
*
|
|
285
|
+
* @param parser the parser whose magic comments we want to get the size of
|
|
286
|
+
* @returns the number of magic comments associated with the given parser
|
|
287
|
+
*/
|
|
288
|
+
PRISM_EXPORTED_FUNCTION size_t pm_parser_magic_comments_size(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* A callback function that can be used to process magic comments found while parsing.
|
|
292
|
+
*/
|
|
293
|
+
typedef void (*pm_magic_comment_callback_t)(const pm_magic_comment_t *magic_comment, void *data);
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Iterates over the magic comments associated with the given parser and calls the
|
|
297
|
+
* given callback for each magic comment.
|
|
298
|
+
*
|
|
299
|
+
* @param parser the parser whose magic comments we want to iterate over
|
|
300
|
+
* @param callback the callback function to call for each magic comment. This
|
|
301
|
+
* function will be passed a pointer to the magic comment and the data
|
|
302
|
+
* parameter passed to this function.
|
|
303
|
+
* @param data the data to pass to the callback function for each magic comment.
|
|
304
|
+
* This can be NULL if no data needs to be passed to the callback function.
|
|
305
|
+
*/
|
|
306
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_magic_comments_each(const pm_parser_t *parser, pm_magic_comment_callback_t callback, void *data) PRISM_NONNULL(1);
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Returns the number of errors associated with the given parser.
|
|
310
|
+
*
|
|
311
|
+
* @param parser the parser whose errors we want to get the size of
|
|
312
|
+
* @returns the number of errors associated with the given parser
|
|
313
|
+
*/
|
|
314
|
+
PRISM_EXPORTED_FUNCTION size_t pm_parser_errors_size(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Returns the number of warnings associated with the given parser.
|
|
318
|
+
*
|
|
319
|
+
* @param parser the parser whose warnings we want to get the size of
|
|
320
|
+
* @returns the number of warnings associated with the given parser
|
|
321
|
+
*/
|
|
322
|
+
PRISM_EXPORTED_FUNCTION size_t pm_parser_warnings_size(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* A callback function that can be used to process diagnostics found while
|
|
326
|
+
* parsing.
|
|
327
|
+
*/
|
|
328
|
+
typedef void (*pm_diagnostic_callback_t)(const pm_diagnostic_t *diagnostic, void *data);
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Iterates over the errors associated with the given parser and calls the
|
|
332
|
+
* given callback for each error.
|
|
333
|
+
*
|
|
334
|
+
* @param parser the parser whose errors we want to iterate over
|
|
335
|
+
* @param callback the callback function to call for each error. This function
|
|
336
|
+
* will be passed a pointer to the error and the data parameter passed to
|
|
337
|
+
* this function.
|
|
338
|
+
* @param data the data to pass to the callback function for each error. This
|
|
339
|
+
* can be NULL if no data needs to be passed to the callback function.
|
|
340
|
+
*/
|
|
341
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_errors_each(const pm_parser_t *parser, pm_diagnostic_callback_t callback, void *data) PRISM_NONNULL(1);
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Iterates over the warnings associated with the given parser and calls the
|
|
345
|
+
* given callback for each warning.
|
|
346
|
+
*
|
|
347
|
+
* @param parser the parser whose warnings we want to iterate over
|
|
348
|
+
* @param callback the callback function to call for each warning. This function
|
|
349
|
+
* will be passed a pointer to the warning and the data parameter passed to
|
|
350
|
+
* this function.
|
|
351
|
+
* @param data the data to pass to the callback function for each warning. This
|
|
352
|
+
* can be NULL if no data needs to be passed to the callback function.
|
|
353
|
+
*/
|
|
354
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_warnings_each(const pm_parser_t *parser, pm_diagnostic_callback_t callback, void *data) PRISM_NONNULL(1);
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Returns the number of constants in the constant pool associated with the
|
|
358
|
+
* given parser.
|
|
359
|
+
*
|
|
360
|
+
* @param parser the parser whose constant pool constants we want to get the
|
|
361
|
+
* size of
|
|
362
|
+
* @returns the number of constants in the constant pool associated with the
|
|
363
|
+
* given parser
|
|
364
|
+
*/
|
|
365
|
+
PRISM_EXPORTED_FUNCTION size_t pm_parser_constants_size(const pm_parser_t *parser) PRISM_NONNULL(1);
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* A callback function that can be used to process constants found while
|
|
369
|
+
* parsing.
|
|
370
|
+
*/
|
|
371
|
+
typedef void (*pm_constant_callback_t)(const pm_constant_t *constant, void *data);
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Iterates over the constants in the constant pool associated with the given
|
|
375
|
+
* parser and calls the given callback for each constant.
|
|
376
|
+
*
|
|
377
|
+
* @param parser the parser whose constants we want to iterate over
|
|
378
|
+
* @param callback the callback function to call for each constant. This function
|
|
379
|
+
* will be passed a pointer to the constant and the data parameter passed to
|
|
380
|
+
* this function.
|
|
381
|
+
* @param data the data to pass to the callback function for each constant. This
|
|
382
|
+
* can be NULL if no data needs to be passed to the callback function.
|
|
383
|
+
*/
|
|
384
|
+
PRISM_EXPORTED_FUNCTION void pm_parser_constants_each(const pm_parser_t *parser, pm_constant_callback_t callback, void *data) PRISM_NONNULL(1);
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Returns a pointer to the constant at the given id in the constant pool
|
|
388
|
+
* associated with the given parser.
|
|
389
|
+
*
|
|
390
|
+
* @param parser the parser whose constant pool we want to look up from
|
|
391
|
+
* @param constant_id the id of the constant to look up (1-based)
|
|
392
|
+
* @returns a pointer to the constant at the given id
|
|
393
|
+
*/
|
|
394
|
+
PRISM_EXPORTED_FUNCTION const pm_constant_t * pm_parser_constant(const pm_parser_t *parser, pm_constant_id_t constant_id) PRISM_NONNULL(1);
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Initiate the parser with the given parser.
|
|
398
|
+
*
|
|
399
|
+
* @param parser The parser to use.
|
|
400
|
+
* @returns The AST representing the source.
|
|
401
|
+
*/
|
|
402
|
+
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser) PRISM_NONNULL(1);
|
|
403
|
+
|
|
404
|
+
#endif
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file prettyprint.h
|
|
3
|
+
*
|
|
4
|
+
* An AST node pretty-printer.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_PRETTYPRINT_H
|
|
7
|
+
#define PRISM_PRETTYPRINT_H
|
|
8
|
+
|
|
9
|
+
#include "prism/excludes.h"
|
|
10
|
+
|
|
11
|
+
#ifndef PRISM_EXCLUDE_PRETTYPRINT
|
|
12
|
+
|
|
13
|
+
#include "prism/compiler/exported.h"
|
|
14
|
+
#include "prism/compiler/nonnull.h"
|
|
15
|
+
|
|
16
|
+
#include "prism/ast.h"
|
|
17
|
+
#include "prism/buffer.h"
|
|
18
|
+
#include "prism/parser.h"
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pretty-prints the AST represented by the given node to the given buffer.
|
|
22
|
+
*
|
|
23
|
+
* @param output_buffer The buffer to write the pretty-printed AST to.
|
|
24
|
+
* @param parser The parser that parsed the AST.
|
|
25
|
+
* @param node The root node of the AST to pretty-print.
|
|
26
|
+
*/
|
|
27
|
+
PRISM_EXPORTED_FUNCTION void pm_prettyprint(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm_node_t *node) PRISM_NONNULL(1, 2, 3);
|
|
28
|
+
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#endif
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file serialize.h
|
|
3
|
+
*
|
|
4
|
+
* The functions related to serializing the AST to a binary format.
|
|
5
|
+
*/
|
|
6
|
+
#ifndef PRISM_SERIALIZE_H
|
|
7
|
+
#define PRISM_SERIALIZE_H
|
|
8
|
+
|
|
9
|
+
#include "prism/excludes.h"
|
|
10
|
+
|
|
11
|
+
/* We optionally support serializing to a binary string. For systems that do not
|
|
12
|
+
* want or need this functionality, it can be turned off with the
|
|
13
|
+
* PRISM_EXCLUDE_SERIALIZATION define. */
|
|
14
|
+
#ifndef PRISM_EXCLUDE_SERIALIZATION
|
|
15
|
+
|
|
16
|
+
#include "prism/compiler/exported.h"
|
|
17
|
+
#include "prism/compiler/nonnull.h"
|
|
18
|
+
|
|
19
|
+
#include "prism/buffer.h"
|
|
20
|
+
#include "prism/errors_format.h"
|
|
21
|
+
#include "prism/parser.h"
|
|
22
|
+
#include "prism/source.h"
|
|
23
|
+
#include "prism/stream.h"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Serialize the AST represented by the given node to the given buffer.
|
|
27
|
+
*
|
|
28
|
+
* @param parser The parser to serialize.
|
|
29
|
+
* @param node The node to serialize.
|
|
30
|
+
* @param buffer The buffer to serialize to.
|
|
31
|
+
*/
|
|
32
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) PRISM_NONNULL(1, 2, 3);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parse the given source to the AST and dump the AST to the given buffer.
|
|
36
|
+
*
|
|
37
|
+
* @param buffer The buffer to serialize to.
|
|
38
|
+
* @param source The source to parse.
|
|
39
|
+
* @param size The size of the source.
|
|
40
|
+
* @param data The optional data to pass to the parser.
|
|
41
|
+
*/
|
|
42
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) PRISM_NONNULL(1, 2);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Parse and serialize the AST represented by the given source into the given
|
|
46
|
+
* buffer.
|
|
47
|
+
*
|
|
48
|
+
* @param buffer The buffer to serialize to.
|
|
49
|
+
* @param source The source to parse.
|
|
50
|
+
* @param data The optional data to pass to the parser.
|
|
51
|
+
*/
|
|
52
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_stream(pm_buffer_t *buffer, pm_source_t *source, const char *data) PRISM_NONNULL(1, 2);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Parse and serialize the comments in the given source to the given buffer.
|
|
56
|
+
*
|
|
57
|
+
* @param buffer The buffer to serialize to.
|
|
58
|
+
* @param source The source to parse.
|
|
59
|
+
* @param size The size of the source.
|
|
60
|
+
* @param data The optional data to pass to the parser.
|
|
61
|
+
*/
|
|
62
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) PRISM_NONNULL(1, 2);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Lex the given source and serialize to the given buffer.
|
|
66
|
+
*
|
|
67
|
+
* @param source The source to lex.
|
|
68
|
+
* @param size The size of the source.
|
|
69
|
+
* @param buffer The buffer to serialize to.
|
|
70
|
+
* @param data The optional data to pass to the lexer.
|
|
71
|
+
*/
|
|
72
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) PRISM_NONNULL(1, 2);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse and serialize both the AST and the tokens represented by the given
|
|
76
|
+
* source to the given buffer.
|
|
77
|
+
*
|
|
78
|
+
* @param buffer The buffer to serialize to.
|
|
79
|
+
* @param source The source to parse.
|
|
80
|
+
* @param size The size of the source.
|
|
81
|
+
* @param data The optional data to pass to the parser.
|
|
82
|
+
*/
|
|
83
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) PRISM_NONNULL(1, 2);
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Parse the source and return true if it parses without errors or warnings.
|
|
87
|
+
*
|
|
88
|
+
* @param source The source to parse.
|
|
89
|
+
* @param size The size of the source.
|
|
90
|
+
* @param data The optional data to pass to the parser.
|
|
91
|
+
* @returns True if the source parses without errors or warnings.
|
|
92
|
+
*/
|
|
93
|
+
PRISM_EXPORTED_FUNCTION bool pm_serialize_parse_success_p(const uint8_t *source, size_t size, const char *data) PRISM_NONNULL(1);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parse the given source and format any errors that are encountered into the
|
|
97
|
+
* given buffer using the given format type. If the source parses without any
|
|
98
|
+
* errors, then -1 is returned and the buffer is left empty. Otherwise, the
|
|
99
|
+
* name of the encoding of the source is written to the buffer, followed by a
|
|
100
|
+
* null byte, followed by the formatted errors, and the error level of the
|
|
101
|
+
* error with the highest precedence is returned.
|
|
102
|
+
*
|
|
103
|
+
* @param buffer The buffer to write the encoding name and formatted errors to.
|
|
104
|
+
* @param source The source to parse.
|
|
105
|
+
* @param size The size of the source.
|
|
106
|
+
* @param data The optional data to pass to the parser.
|
|
107
|
+
* @param format_type The type of formatting to use when formatting the errors.
|
|
108
|
+
* @returns The error level of the error with the highest precedence, or -1 if
|
|
109
|
+
* the source parsed without errors.
|
|
110
|
+
*/
|
|
111
|
+
PRISM_EXPORTED_FUNCTION int8_t pm_serialize_parse_errors_format(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data, pm_errors_format_type_t format_type) PRISM_NONNULL(1, 2);
|
|
112
|
+
|
|
113
|
+
#endif
|
|
114
|
+
|
|
115
|
+
#endif
|