|
| 1 | +#ifndef PRISM_H |
| 2 | +#define PRISM_H |
| 3 | + |
| 4 | +#include "prism/defines.h" |
| 5 | +#include "prism/ast.h" |
| 6 | +#include "prism/diagnostic.h" |
| 7 | +#include "prism/node.h" |
| 8 | +#include "prism/pack.h" |
| 9 | +#include "prism/parser.h" |
| 10 | +#include "prism/regexp.h" |
| 11 | +#include "prism/unescape.h" |
| 12 | +#include "prism/util/pm_buffer.h" |
| 13 | +#include "prism/util/pm_char.h" |
| 14 | +#include "prism/util/pm_memchr.h" |
| 15 | +#include "prism/util/pm_strpbrk.h" |
| 16 | +#include "prism/version.h" |
| 17 | + |
| 18 | +#include <assert.h> |
| 19 | +#include <errno.h> |
| 20 | +#include <stdarg.h> |
| 21 | +#include <stdbool.h> |
| 22 | +#include <stdint.h> |
| 23 | +#include <stdio.h> |
| 24 | +#include <stdlib.h> |
| 25 | +#include <string.h> |
| 26 | + |
| 27 | +#ifndef _WIN32 |
| 28 | +#include <strings.h> |
| 29 | +#endif |
| 30 | + |
| 31 | +void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer); |
| 32 | + |
| 33 | +void pm_print_node(pm_parser_t *parser, pm_node_t *node); |
| 34 | + |
| 35 | +void pm_parser_metadata(pm_parser_t *parser, const char *metadata); |
| 36 | + |
| 37 | +// Generate a scope node from the given node. |
| 38 | +void pm_scope_node_init(pm_node_t *node, pm_scope_node_t *dest); |
| 39 | + |
| 40 | +// The prism version and the serialization format. |
| 41 | +PRISM_EXPORTED_FUNCTION const char * pm_version(void); |
| 42 | + |
| 43 | +// Initialize a parser with the given start and end pointers. |
| 44 | +PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const char *filepath); |
| 45 | + |
| 46 | +// Register a callback that will be called whenever prism changes the encoding it |
| 47 | +// is using to parse based on the magic comment. |
| 48 | +PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback); |
| 49 | + |
| 50 | +// Register a callback that will be called when prism encounters a magic comment |
| 51 | +// with an encoding referenced that it doesn't understand. The callback should |
| 52 | +// return NULL if it also doesn't understand the encoding or it should return a |
| 53 | +// pointer to a pm_encoding_t struct that contains the functions necessary to |
| 54 | +// parse identifiers. |
| 55 | +PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_decode_callback(pm_parser_t *parser, pm_encoding_decode_callback_t callback); |
| 56 | + |
| 57 | +// Free any memory associated with the given parser. |
| 58 | +PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser); |
| 59 | + |
| 60 | +// Parse the Ruby source associated with the given parser and return the tree. |
| 61 | +PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser); |
| 62 | + |
| 63 | +// Pretty-prints the AST represented by the given node to the given buffer. |
| 64 | +PRISM_EXPORTED_FUNCTION void pm_prettyprint(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer); |
| 65 | + |
| 66 | +// Serialize the AST represented by the given node to the given buffer. |
| 67 | +PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer); |
| 68 | + |
| 69 | +// Parse the given source to the AST and serialize the AST to the given buffer. |
| 70 | +PRISM_EXPORTED_FUNCTION void pm_parse_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata); |
| 71 | + |
| 72 | +// Lex the given source and serialize to the given buffer. |
| 73 | +PRISM_EXPORTED_FUNCTION void pm_lex_serialize(const uint8_t *source, size_t size, const char *filepath, pm_buffer_t *buffer); |
| 74 | + |
| 75 | +// Parse and serialize both the AST and the tokens represented by the given |
| 76 | +// source to the given buffer. |
| 77 | +PRISM_EXPORTED_FUNCTION void pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata); |
| 78 | + |
| 79 | +// Returns a string representation of the given token type. |
| 80 | +PRISM_EXPORTED_FUNCTION const char * pm_token_type_to_str(pm_token_type_t token_type); |
| 81 | + |
| 82 | +#endif |
0 commit comments