Skip to content

Commit 5a2252e

Browse files
committed
Rename serialization APIs for consistency
1 parent f0aa8ad commit 5a2252e

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

include/prism.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,24 @@ void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buf
124124
PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
125125

126126
/**
127-
* Parse the given source to the AST and serialize the AST to the given buffer.
127+
* Parse the given source to the AST and dump the AST to the given buffer.
128128
*
129+
* @param buffer The buffer to serialize to.
129130
* @param source The source to parse.
130131
* @param size The size of the source.
131-
* @param buffer The buffer to serialize to.
132132
* @param data The optional data to pass to the parser.
133133
*/
134-
PRISM_EXPORTED_FUNCTION void pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data);
134+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
135135

136136
/**
137137
* Parse and serialize the comments in the given source to the given buffer.
138138
*
139+
* @param buffer The buffer to serialize to.
139140
* @param source The source to parse.
140141
* @param size The size of the source.
141-
* @param buffer The buffer to serialize to.
142142
* @param data The optional data to pass to the parser.
143143
*/
144-
PRISM_EXPORTED_FUNCTION void pm_parse_serialize_comments(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data);
144+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
145145

146146
/**
147147
* Lex the given source and serialize to the given buffer.
@@ -151,18 +151,18 @@ PRISM_EXPORTED_FUNCTION void pm_parse_serialize_comments(const uint8_t *source,
151151
* @param filepath The optional filepath to pass to the lexer.
152152
* @param buffer The buffer to serialize to.
153153
*/
154-
PRISM_EXPORTED_FUNCTION void pm_lex_serialize(const uint8_t *source, size_t size, const char *filepath, pm_buffer_t *buffer);
154+
PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
155155

156156
/**
157157
* Parse and serialize both the AST and the tokens represented by the given
158158
* source to the given buffer.
159159
*
160+
* @param buffer The buffer to serialize to.
160161
* @param source The source to parse.
161162
* @param size The size of the source.
162-
* @param buffer The buffer to serialize to.
163-
* @param metadata The optional metadata to pass to the parser.
163+
* @param data The optional data to pass to the parser.
164164
*/
165-
PRISM_EXPORTED_FUNCTION void pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata);
165+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
166166

167167
/**
168168
* Returns a string representation of the given token type.

lib/prism/ffi.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def self.load_exported_functions_from(header, *functions)
6969
load_exported_functions_from(
7070
"prism.h",
7171
"pm_version",
72-
"pm_parse_serialize",
73-
"pm_parse_serialize_comments",
74-
"pm_lex_serialize",
75-
"pm_parse_lex_serialize"
72+
"pm_serialize_parse",
73+
"pm_serialize_parse_comments",
74+
"pm_serialize_lex",
75+
"pm_serialize_parse_lex"
7676
)
7777

7878
load_exported_functions_from(
@@ -180,7 +180,7 @@ class << self
180180
# Mirror the Prism.dump API by using the serialization API.
181181
def dump(code, **options)
182182
LibRubyParser::PrismBuffer.with do |buffer|
183-
LibRubyParser.pm_parse_serialize(code, code.bytesize, buffer.pointer, dump_options(options))
183+
LibRubyParser.pm_serialize_parse(buffer.pointer, code, code.bytesize, dump_options(options))
184184
buffer.read
185185
end
186186
end
@@ -195,7 +195,7 @@ def dump_file(filepath, **options)
195195
# Mirror the Prism.lex API by using the serialization API.
196196
def lex(code, **options)
197197
LibRubyParser::PrismBuffer.with do |buffer|
198-
LibRubyParser.pm_lex_serialize(code, code.bytesize, dump_options(options), buffer.pointer)
198+
LibRubyParser.pm_serialize_lex(buffer.pointer, code, code.bytesize, dump_options(options))
199199
Serialize.load_tokens(Source.new(code), buffer.read)
200200
end
201201
end
@@ -224,7 +224,7 @@ def parse_file(filepath, **options)
224224
# Mirror the Prism.parse_comments API by using the serialization API.
225225
def parse_comments(code, **options)
226226
LibRubyParser::PrismBuffer.with do |buffer|
227-
LibRubyParser.pm_parse_serialize_comments(code, code.bytesize, buffer.pointer, dump_options(options))
227+
LibRubyParser.pm_serialize_parse_comments(buffer.pointer, code, code.bytesize, dump_options(options))
228228

229229
source = Source.new(code)
230230
loader = Serialize::Loader.new(source, buffer.read)
@@ -247,15 +247,15 @@ def parse_file_comments(filepath, **options)
247247
# Mirror the Prism.parse_lex API by using the serialization API.
248248
def parse_lex(code, **options)
249249
LibRubyParser::PrismBuffer.with do |buffer|
250-
LibRubyParser.pm_parse_lex_serialize(code, code.bytesize, buffer.pointer, dump_options(options))
250+
LibRubyParser.pm_serialize_parse_lex(buffer.pointer, code, code.bytesize, dump_options(options))
251251

252252
source = Source.new(code)
253253
loader = Serialize::Loader.new(source, buffer.read)
254254

255255
tokens = loader.load_tokens
256256
node, comments, magic_comments, errors, warnings = loader.load_nodes
257-
258257
tokens.each { |token,| token.value.force_encoding(loader.encoding) }
258+
259259
ParseResult.new([node, tokens], comments, magic_comments, errors, warnings, source)
260260
end
261261
end

src/prism.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16557,7 +16557,7 @@ pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1655716557
* buffer.
1655816558
*/
1655916559
PRISM_EXPORTED_FUNCTION void
16560-
pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data) {
16560+
pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
1656116561
pm_options_t options = { 0 };
1656216562
if (data != NULL) pm_options_read(&options, data);
1656316563

@@ -16579,7 +16579,7 @@ pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, cons
1657916579
* Parse and serialize the comments in the given source to the given buffer.
1658016580
*/
1658116581
PRISM_EXPORTED_FUNCTION void
16582-
pm_parse_serialize_comments(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data) {
16582+
pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
1658316583
pm_options_t options = { 0 };
1658416584
if (data != NULL) pm_options_read(&options, data);
1658516585

templates/src/serialize.c.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
287287
* Lex the given source and serialize to the given buffer.
288288
*/
289289
PRISM_EXPORTED_FUNCTION void
290-
pm_lex_serialize(const uint8_t *source, size_t size, const char *data, pm_buffer_t *buffer) {
290+
pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
291291
pm_options_t options = { 0 };
292292
if (data != NULL) pm_options_read(&options, data);
293293

@@ -321,7 +321,7 @@ pm_lex_serialize(const uint8_t *source, size_t size, const char *data, pm_buffer
321321
* source to the given buffer.
322322
*/
323323
PRISM_EXPORTED_FUNCTION void
324-
pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data) {
324+
pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
325325
pm_options_t options = { 0 };
326326
if (data != NULL) pm_options_read(&options, data);
327327

0 commit comments

Comments
 (0)