Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)
prism.h
Go to the documentation of this file.
1
6#ifndef PRISM_H
7#define PRISM_H
8
9#include "prism/defines.h"
11#include "prism/util/pm_char.h"
15#include "prism/ast.h"
16#include "prism/diagnostic.h"
17#include "prism/node.h"
18#include "prism/options.h"
19#include "prism/pack.h"
20#include "prism/parser.h"
21#include "prism/prettyprint.h"
22#include "prism/regexp.h"
23#include "prism/version.h"
24
25#include <assert.h>
26#include <errno.h>
27#include <stdarg.h>
28#include <stdbool.h>
29#include <stdint.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34#ifndef _WIN32
35#include <strings.h>
36#endif
37
43PRISM_EXPORTED_FUNCTION const char * pm_version(void);
44
53PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options);
54
63
70
78
87
94void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer);
95
103void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
104
113
122PRISM_EXPORTED_FUNCTION void pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
123
132PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
133
142PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
143
153PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
154
163PRISM_EXPORTED_FUNCTION bool pm_parse_success_p(const uint8_t *source, size_t size, const char *data);
164
172
272#endif
The abstract syntax tree.
enum pm_token_type pm_token_type_t
This enum represents every type of token in the Ruby source.
A list of diagnostics generated during parsing.
The options that can be passed to parsing.
A pack template string parser.
The parser used to parse Ruby source.
void(* pm_encoding_changed_callback_t)(pm_parser_t *parser)
When the encoding that is being used to parse the source is changed by prism, we provide the ability ...
Definition parser.h:425
A wrapper around a contiguous block of allocated memory.
Functions for working with characters and strings.
A custom memchr implementation.
A custom strncasecmp implementation.
A custom strpbrk implementation.
An AST node pretty-printer.
Macro definitions used throughout the prism library.
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition defines.h:32
Functions related to nodes in the AST.
The version of the Prism library.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser)
Initiate the parser with the given parser.
Definition prism.c:17411
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 base...
Definition prism.c:17346
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.
Definition serialize.c:2014
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser)
Free any memory associated with the given parser.
Definition prism.c:17384
void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer)
Serialize the encoding, metadata, nodes, and constant pool.
Definition serialize.c:1934
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.
Definition serialize.c:2050
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.
Definition prism.c:17428
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.
Definition prism.c:17461
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.
Definition prism.c:17439
void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer)
Serialize the name of the encoding to the buffer.
Definition serialize.c:1923
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.
Definition token_type.c:16
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.
Definition prism.c:17206
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.
Definition serialize.c:2077
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.
Definition serialize.c:1858
PRISM_EXPORTED_FUNCTION const char * pm_version(void)
The prism version and the serialization format.
Definition prism.c:7
A regular expression parser.
Defines old _.
C99 shim for <stdbool.h>
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
Definition pm_buffer.h:21
This struct defines the functions necessary to implement the encoding interface so we can determine h...
Definition encoding.h:23
This represents the overall linked list.
Definition pm_list.h:55
This is the base structure that represents a node in the syntax tree.
Definition ast.h:1061
The options that can be passed to the parser.
Definition options.h:30
This struct represents the overall parser.
Definition parser.h:489