Ruby: prism/prism.h File Reference

Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)

Functions
prism.h File Reference

The main header file for the prism parser. More...

`#include "prism/defines.h"`
`#include "prism/util/pm_buffer.h"`
`#include "prism/util/pm_char.h"`
`#include "prism/util/pm_memchr.h"`
`#include "prism/util/pm_strncasecmp.h"`
`#include "prism/util/pm_strpbrk.h"`
`#include "prism/ast.h"`
`#include "prism/diagnostic.h"`
`#include "prism/node.h"`
`#include "prism/options.h"`
`#include "prism/pack.h"`
`#include "prism/parser.h"`
`#include "prism/prettyprint.h"`
`#include "prism/regexp.h"`
`#include "prism/version.h"`
`#include <assert.h>`
`#include <errno.h>`
`#include <stdarg.h>`
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <strings.h>`

Go to the source code of this file.

## Functions
PRISM_EXPORTED_FUNCTION const char * | pm_version (void)
| The prism version and the serialization format.
PRISM_EXPORTED_FUNCTION void | pm_parser_init (pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options)
| Initialize a parser with the given start and end pointers.
PRISM_EXPORTED_FUNCTION void | pm_parser_register_encoding_changed_callback (pm_parser_t *parser, pm_encoding_changed_callback_t callback)
| Register a callback that will be called whenever prism changes the encoding it is using to parse based on the magic comment.
PRISM_EXPORTED_FUNCTION void | pm_parser_free (pm_parser_t *parser)
| Free any memory associated with the given parser.
PRISM_EXPORTED_FUNCTION pm_node_t * | pm_parse (pm_parser_t *parser)
| Initiate the parser with the given parser.
void | pm_serialize_comment_list (pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer)
| Serialize the given list of comments to the given buffer.
void | pm_serialize_encoding (const pm_encoding_t *encoding, pm_buffer_t *buffer)
| Serialize the name of the encoding to the buffer.
void | pm_serialize_content (pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
| Serialize the encoding, metadata, nodes, and constant pool.
PRISM_EXPORTED_FUNCTION void | pm_serialize (pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
| Serialize the AST represented by the given node to the given buffer.
PRISM_EXPORTED_FUNCTION void | pm_serialize_parse (pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data)
| Parse the given source to the AST and dump the AST to the given buffer.
PRISM_EXPORTED_FUNCTION void | pm_serialize_parse_comments (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.
PRISM_EXPORTED_FUNCTION void | pm_serialize_lex (pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data)
| Lex the given source and serialize to the given buffer.
PRISM_EXPORTED_FUNCTION void | pm_serialize_parse_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.
PRISM_EXPORTED_FUNCTION bool | pm_parse_success_p (const uint8_t *source, size_t size, const char *data)
| Parse the source and return true if it parses without errors or warnings.
PRISM_EXPORTED_FUNCTION const char * | pm_token_type_to_str (pm_token_type_t token_type)
| Returns a string representation of the given token type.

## Detailed Description

The main header file for the prism parser.

Definition in file prism.h.

## Function Documentation

## ◆ pm_parse()

PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse | ( | pm_parser_t * | parser | ) |

Initiate the parser with the given parser.

Parameters

  parser | The parser to use.

Returns
  The AST representing the source.

Initiate the parser with the given parser.

Definition at line 17411 of file prism.c.

## ◆ pm_parse_success_p()

PRISM_EXPORTED_FUNCTION bool pm_parse_success_p | ( | const uint8_t * | source,
|  | size_t | size,
|  | const char * | data )

Parse the source and return true if it parses without errors or warnings.

Parameters

  source | The source to parse.
  size | The size of the source.
  data | The optional data to pass to the parser.

Returns
  True if the source parses without errors or warnings.

Definition at line 2077 of file serialize.c.

Referenced by pm_parse_success_p().

## ◆ pm_parser_free()

PRISM_EXPORTED_FUNCTION void pm_parser_free | ( | pm_parser_t * | parser | ) |

Free any memory associated with the given parser.

Parameters

  parser | The parser to free.

Definition at line 17384 of file prism.c.

## ◆ pm_parser_init()

PRISM_EXPORTED_FUNCTION void pm_parser_init | ( | pm_parser_t * | parser,
|  | const uint8_t * | source,
|  | size_t | size,
|  | const pm_options_t * | options )

Initialize a parser with the given start and end pointers.

Parameters

  parser | The parser to initialize.
  source | The source to parse.
  size | The size of the source.
  options | The optional options to use when parsing.

Definition at line 17206 of file prism.c.

## ◆ pm_parser_register_encoding_changed_callback()

PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback | ( | pm_parser_t * | parser,
|  | pm_encoding_changed_callback_t | callback )

Register a callback that will be called whenever prism changes the encoding it is using to parse based on the magic comment.

Parameters

  parser | The parser to register the callback with.
  callback | The callback to register.

Definition at line 17346 of file prism.c.

## ◆ pm_serialize()

PRISM_EXPORTED_FUNCTION void pm_serialize | ( | pm_parser_t * | parser,
|  | pm_node_t * | node,
|  | pm_buffer_t * | buffer )

Serialize the AST represented by the given node to the given buffer.

Parameters

  parser | The parser to serialize.
  node | The node to serialize.
  buffer | The buffer to serialize to.

Definition at line 17428 of file prism.c.

## ◆ pm_serialize_comment_list()

void pm_serialize_comment_list | ( | pm_parser_t * | parser,
|  | pm_list_t * | list,
|  | pm_buffer_t * | buffer )

Serialize the given list of comments to the given buffer.

Parameters

  parser | The parser to serialize.
  list | The list of comments to serialize.
  buffer | The buffer to serialize to.

Definition at line 1858 of file serialize.c.

Referenced by pm_serialize_comment_list(), pm_serialize_content(), pm_serialize_lex(), and pm_serialize_parse_comments().

## ◆ pm_serialize_content()

void pm_serialize_content | ( | pm_parser_t * | parser,
|  | pm_node_t * | node,
|  | pm_buffer_t * | buffer )

Serialize the encoding, metadata, nodes, and constant pool.

Parameters

  parser | The parser to serialize.
  node | The node to serialize.
  buffer | The buffer to serialize to.

Definition at line 1934 of file serialize.c.

Referenced by pm_serialize(), pm_serialize_content(), and pm_serialize_parse().

## ◆ pm_serialize_encoding()

void pm_serialize_encoding | ( | const pm_encoding_t * | encoding,
|  | pm_buffer_t * | buffer )

Serialize the name of the encoding to the buffer.

Parameters

  encoding | The encoding to serialize.
  buffer | The buffer to serialize to.

Definition at line 1923 of file serialize.c.

Referenced by pm_serialize_content(), pm_serialize_encoding(), pm_serialize_lex(), and pm_serialize_parse_comments().

## ◆ pm_serialize_lex()

PRISM_EXPORTED_FUNCTION void pm_serialize_lex | ( | pm_buffer_t * | buffer,
|  | const uint8_t * | source,
|  | size_t | size,
|  | const char * | data )

Lex the given source and serialize to the given buffer.

Parameters

  source | The source to lex.
  size | The size of the source.
  buffer | The buffer to serialize to.
  data | The optional data to pass to the lexer.

Definition at line 2014 of file serialize.c.

Referenced by pm_serialize_lex().

## ◆ pm_serialize_parse()

PRISM_EXPORTED_FUNCTION void pm_serialize_parse | ( | pm_buffer_t * | buffer,
|  | const uint8_t * | source,
|  | size_t | size,
|  | const char * | data )

Parse the given source to the AST and dump the AST to the given buffer.

Parameters

  buffer | The buffer to serialize to.
  source | The source to parse.
  size | The size of the source.
  data | The optional data to pass to the parser.

Parse the given source to the AST and dump the AST to the given buffer.

Definition at line 17439 of file prism.c.

## ◆ pm_serialize_parse_comments()

PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments | ( | 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.

Parameters

  buffer | The buffer to serialize to.
  source | The source to parse.
  size | The size of the source.
  data | The optional data to pass to the parser.

Definition at line 17461 of file prism.c.

## ◆ pm_serialize_parse_lex()

PRISM_EXPORTED_FUNCTION void pm_serialize_parse_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.

Parameters

  buffer | The buffer to serialize to.
  source | The source to parse.
  size | The size of the source.
  data | The optional data to pass to the parser.

Definition at line 2050 of file serialize.c.

Referenced by pm_serialize_parse_lex().

## ◆ pm_token_type_to_str()

PRISM_EXPORTED_FUNCTION const char * pm_token_type_to_str | ( | pm_token_type_t | token_type | ) |

Returns a string representation of the given token type.

Parameters

  token_type | The token type to convert to a string.

Returns
  A string representation of the given token type.

Definition at line 16 of file token_type.c.

Referenced by pm_token_type_to_str().

## ◆ pm_version()

PRISM_EXPORTED_FUNCTION const char * pm_version | ( | void |  | ) |

The prism version and the serialization format.

Returns
  The prism version as a constant string.

Definition at line 7 of file prism.c.