summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-11-02 14:13:28 -0400
committerKevin Newton <kddnewton@gmail.com>2023-11-03 10:13:49 -0400
commit649659119490eb8df75a05f85f0ae8be78e42bed (patch)
tree2a512116c742fa8c5038b60791b4abcd8a7144d6
parent05f5c545d232554b6ffb183d6948ad37f46df53b (diff)
[ruby/prism] Rename serialization APIs for consistency
https://github.com/ruby/prism/commit/5a2252e3ac
-rw-r--r--lib/prism/ffi.rb18
-rw-r--r--prism/prism.c4
-rw-r--r--prism/prism.h18
-rw-r--r--prism/templates/src/serialize.c.erb4
4 files changed, 22 insertions, 22 deletions
diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb
index 61ece6a641..cc84d00f14 100644
--- a/lib/prism/ffi.rb
+++ b/lib/prism/ffi.rb
@@ -69,10 +69,10 @@ module Prism
load_exported_functions_from(
"prism.h",
"pm_version",
- "pm_parse_serialize",
- "pm_parse_serialize_comments",
- "pm_lex_serialize",
- "pm_parse_lex_serialize"
+ "pm_serialize_parse",
+ "pm_serialize_parse_comments",
+ "pm_serialize_lex",
+ "pm_serialize_parse_lex"
)
load_exported_functions_from(
@@ -180,7 +180,7 @@ module Prism
# Mirror the Prism.dump API by using the serialization API.
def dump(code, **options)
LibRubyParser::PrismBuffer.with do |buffer|
- LibRubyParser.pm_parse_serialize(code, code.bytesize, buffer.pointer, dump_options(options))
+ LibRubyParser.pm_serialize_parse(buffer.pointer, code, code.bytesize, dump_options(options))
buffer.read
end
end
@@ -195,7 +195,7 @@ module Prism
# Mirror the Prism.lex API by using the serialization API.
def lex(code, **options)
LibRubyParser::PrismBuffer.with do |buffer|
- LibRubyParser.pm_lex_serialize(code, code.bytesize, dump_options(options), buffer.pointer)
+ LibRubyParser.pm_serialize_lex(buffer.pointer, code, code.bytesize, dump_options(options))
Serialize.load_tokens(Source.new(code), buffer.read)
end
end
@@ -224,7 +224,7 @@ module Prism
# Mirror the Prism.parse_comments API by using the serialization API.
def parse_comments(code, **options)
LibRubyParser::PrismBuffer.with do |buffer|
- LibRubyParser.pm_parse_serialize_comments(code, code.bytesize, buffer.pointer, dump_options(options))
+ LibRubyParser.pm_serialize_parse_comments(buffer.pointer, code, code.bytesize, dump_options(options))
source = Source.new(code)
loader = Serialize::Loader.new(source, buffer.read)
@@ -247,15 +247,15 @@ module Prism
# Mirror the Prism.parse_lex API by using the serialization API.
def parse_lex(code, **options)
LibRubyParser::PrismBuffer.with do |buffer|
- LibRubyParser.pm_parse_lex_serialize(code, code.bytesize, buffer.pointer, dump_options(options))
+ LibRubyParser.pm_serialize_parse_lex(buffer.pointer, code, code.bytesize, dump_options(options))
source = Source.new(code)
loader = Serialize::Loader.new(source, buffer.read)
tokens = loader.load_tokens
node, comments, magic_comments, errors, warnings = loader.load_nodes
-
tokens.each { |token,| token.value.force_encoding(loader.encoding) }
+
ParseResult.new([node, tokens], comments, magic_comments, errors, warnings, source)
end
end
diff --git a/prism/prism.c b/prism/prism.c
index 2c04860de1..9d2fd6d6f7 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -16557,7 +16557,7 @@ pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
* buffer.
*/
PRISM_EXPORTED_FUNCTION void
-pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data) {
+pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
pm_options_t options = { 0 };
if (data != NULL) pm_options_read(&options, data);
@@ -16579,7 +16579,7 @@ pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, cons
* Parse and serialize the comments in the given source to the given buffer.
*/
PRISM_EXPORTED_FUNCTION void
-pm_parse_serialize_comments(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data) {
+pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
pm_options_t options = { 0 };
if (data != NULL) pm_options_read(&options, data);
diff --git a/prism/prism.h b/prism/prism.h
index e2c5d06418..2f7208929b 100644
--- a/prism/prism.h
+++ b/prism/prism.h
@@ -124,24 +124,24 @@ void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buf
PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
/**
- * Parse the given source to the AST and serialize the AST to the given buffer.
+ * Parse the given source to the AST and dump the AST to the given buffer.
*
+ * @param buffer The buffer to serialize to.
* @param source The source to parse.
* @param size The size of the source.
- * @param buffer The buffer to serialize to.
* @param data The optional data to pass to the parser.
*/
-PRISM_EXPORTED_FUNCTION void pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data);
+PRISM_EXPORTED_FUNCTION void pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
/**
* Parse and serialize the comments in the given source to the given buffer.
*
+ * @param buffer The buffer to serialize to.
* @param source The source to parse.
* @param size The size of the source.
- * @param buffer The buffer to serialize to.
* @param data The optional data to pass to the parser.
*/
-PRISM_EXPORTED_FUNCTION void pm_parse_serialize_comments(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data);
+PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
/**
* 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,
* @param filepath The optional filepath to pass to the lexer.
* @param buffer The buffer to serialize to.
*/
-PRISM_EXPORTED_FUNCTION void pm_lex_serialize(const uint8_t *source, size_t size, const char *filepath, pm_buffer_t *buffer);
+PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
/**
* Parse and serialize both the AST and the tokens represented by the given
* source to the given buffer.
*
+ * @param buffer The buffer to serialize to.
* @param source The source to parse.
* @param size The size of the source.
- * @param buffer The buffer to serialize to.
- * @param metadata The optional metadata to pass to the parser.
+ * @param data The optional data to pass to the parser.
*/
-PRISM_EXPORTED_FUNCTION void pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata);
+PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
/**
* Returns a string representation of the given token type.
diff --git a/prism/templates/src/serialize.c.erb b/prism/templates/src/serialize.c.erb
index b8e93df6fb..9b0722c257 100644
--- a/prism/templates/src/serialize.c.erb
+++ b/prism/templates/src/serialize.c.erb
@@ -287,7 +287,7 @@ serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
* Lex the given source and serialize to the given buffer.
*/
PRISM_EXPORTED_FUNCTION void
-pm_lex_serialize(const uint8_t *source, size_t size, const char *data, pm_buffer_t *buffer) {
+pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
pm_options_t options = { 0 };
if (data != NULL) pm_options_read(&options, data);
@@ -321,7 +321,7 @@ pm_lex_serialize(const uint8_t *source, size_t size, const char *data, pm_buffer
* source to the given buffer.
*/
PRISM_EXPORTED_FUNCTION void
-pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *data) {
+pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data) {
pm_options_t options = { 0 };
if (data != NULL) pm_options_read(&options, data);