Skip to content

Commit

Permalink
Rename serialization APIs for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Nov 3, 2023
1 parent f0aa8ad commit 5a2252e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
18 changes: 9 additions & 9 deletions include/prism.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
18 changes: 9 additions & 9 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def self.load_exported_functions_from(header, *functions)
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(
Expand Down Expand Up @@ -180,7 +180,7 @@ class << self
# 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
Expand All @@ -195,7 +195,7 @@ def dump_file(filepath, **options)
# 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
Expand Down Expand Up @@ -224,7 +224,7 @@ def parse_file(filepath, **options)
# 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)
Expand All @@ -247,15 +247,15 @@ def parse_file_comments(filepath, **options)
# 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
Expand Down
4 changes: 2 additions & 2 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions templates/src/serialize.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5a2252e

Please sign in to comment.