prism 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +172 -0
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +62 -0
  5. data/LICENSE.md +7 -0
  6. data/Makefile +84 -0
  7. data/README.md +89 -0
  8. data/config.yml +2481 -0
  9. data/docs/build_system.md +74 -0
  10. data/docs/building.md +22 -0
  11. data/docs/configuration.md +60 -0
  12. data/docs/design.md +53 -0
  13. data/docs/encoding.md +117 -0
  14. data/docs/fuzzing.md +93 -0
  15. data/docs/heredocs.md +36 -0
  16. data/docs/mapping.md +117 -0
  17. data/docs/ripper.md +36 -0
  18. data/docs/ruby_api.md +25 -0
  19. data/docs/serialization.md +181 -0
  20. data/docs/testing.md +55 -0
  21. data/ext/prism/api_node.c +4725 -0
  22. data/ext/prism/api_pack.c +256 -0
  23. data/ext/prism/extconf.rb +136 -0
  24. data/ext/prism/extension.c +626 -0
  25. data/ext/prism/extension.h +18 -0
  26. data/include/prism/ast.h +1932 -0
  27. data/include/prism/defines.h +45 -0
  28. data/include/prism/diagnostic.h +231 -0
  29. data/include/prism/enc/pm_encoding.h +95 -0
  30. data/include/prism/node.h +41 -0
  31. data/include/prism/pack.h +141 -0
  32. data/include/prism/parser.h +418 -0
  33. data/include/prism/regexp.h +19 -0
  34. data/include/prism/unescape.h +48 -0
  35. data/include/prism/util/pm_buffer.h +51 -0
  36. data/include/prism/util/pm_char.h +91 -0
  37. data/include/prism/util/pm_constant_pool.h +78 -0
  38. data/include/prism/util/pm_list.h +67 -0
  39. data/include/prism/util/pm_memchr.h +14 -0
  40. data/include/prism/util/pm_newline_list.h +61 -0
  41. data/include/prism/util/pm_state_stack.h +24 -0
  42. data/include/prism/util/pm_string.h +61 -0
  43. data/include/prism/util/pm_string_list.h +25 -0
  44. data/include/prism/util/pm_strpbrk.h +29 -0
  45. data/include/prism/version.h +4 -0
  46. data/include/prism.h +82 -0
  47. data/lib/prism/compiler.rb +465 -0
  48. data/lib/prism/debug.rb +157 -0
  49. data/lib/prism/desugar_compiler.rb +206 -0
  50. data/lib/prism/dispatcher.rb +2051 -0
  51. data/lib/prism/dsl.rb +750 -0
  52. data/lib/prism/ffi.rb +251 -0
  53. data/lib/prism/lex_compat.rb +838 -0
  54. data/lib/prism/mutation_compiler.rb +718 -0
  55. data/lib/prism/node.rb +14540 -0
  56. data/lib/prism/node_ext.rb +55 -0
  57. data/lib/prism/node_inspector.rb +68 -0
  58. data/lib/prism/pack.rb +185 -0
  59. data/lib/prism/parse_result/comments.rb +172 -0
  60. data/lib/prism/parse_result/newlines.rb +60 -0
  61. data/lib/prism/parse_result.rb +266 -0
  62. data/lib/prism/pattern.rb +239 -0
  63. data/lib/prism/ripper_compat.rb +174 -0
  64. data/lib/prism/serialize.rb +662 -0
  65. data/lib/prism/visitor.rb +470 -0
  66. data/lib/prism.rb +64 -0
  67. data/prism.gemspec +113 -0
  68. data/src/diagnostic.c +287 -0
  69. data/src/enc/pm_big5.c +52 -0
  70. data/src/enc/pm_euc_jp.c +58 -0
  71. data/src/enc/pm_gbk.c +61 -0
  72. data/src/enc/pm_shift_jis.c +56 -0
  73. data/src/enc/pm_tables.c +507 -0
  74. data/src/enc/pm_unicode.c +2324 -0
  75. data/src/enc/pm_windows_31j.c +56 -0
  76. data/src/node.c +2633 -0
  77. data/src/pack.c +493 -0
  78. data/src/prettyprint.c +2136 -0
  79. data/src/prism.c +14587 -0
  80. data/src/regexp.c +580 -0
  81. data/src/serialize.c +1899 -0
  82. data/src/token_type.c +349 -0
  83. data/src/unescape.c +637 -0
  84. data/src/util/pm_buffer.c +103 -0
  85. data/src/util/pm_char.c +272 -0
  86. data/src/util/pm_constant_pool.c +252 -0
  87. data/src/util/pm_list.c +41 -0
  88. data/src/util/pm_memchr.c +33 -0
  89. data/src/util/pm_newline_list.c +134 -0
  90. data/src/util/pm_state_stack.c +19 -0
  91. data/src/util/pm_string.c +200 -0
  92. data/src/util/pm_string_list.c +29 -0
  93. data/src/util/pm_strncasecmp.c +17 -0
  94. data/src/util/pm_strpbrk.c +66 -0
  95. metadata +138 -0
@@ -0,0 +1,78 @@
1
+ // The constant pool is a data structure that stores a set of strings. Each
2
+ // string is assigned a unique id, which can be used to compare strings for
3
+ // equality. This comparison ends up being much faster than strcmp, since it
4
+ // only requires a single integer comparison.
5
+
6
+ #ifndef PRISM_CONSTANT_POOL_H
7
+ #define PRISM_CONSTANT_POOL_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <assert.h>
12
+ #include <stdbool.h>
13
+ #include <stdint.h>
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+
17
+ typedef uint32_t pm_constant_id_t;
18
+
19
+ typedef struct {
20
+ pm_constant_id_t *ids;
21
+ size_t size;
22
+ size_t capacity;
23
+ } pm_constant_id_list_t;
24
+
25
+ // Initialize a list of constant ids.
26
+ void pm_constant_id_list_init(pm_constant_id_list_t *list);
27
+
28
+ // Append a constant id to a list of constant ids. Returns false if any
29
+ // potential reallocations fail.
30
+ bool pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id);
31
+
32
+ // Checks if the current constant id list includes the given constant id.
33
+ bool
34
+ pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id);
35
+
36
+ // Get the memory size of a list of constant ids.
37
+ size_t pm_constant_id_list_memsize(pm_constant_id_list_t *list);
38
+
39
+ // Free the memory associated with a list of constant ids.
40
+ void pm_constant_id_list_free(pm_constant_id_list_t *list);
41
+
42
+ typedef struct {
43
+ unsigned int id: 31;
44
+ bool owned: 1;
45
+ uint32_t hash;
46
+ } pm_constant_pool_bucket_t;
47
+
48
+ typedef struct {
49
+ const uint8_t *start;
50
+ size_t length;
51
+ } pm_constant_t;
52
+
53
+ typedef struct {
54
+ pm_constant_pool_bucket_t *buckets;
55
+ pm_constant_t *constants;
56
+ uint32_t size;
57
+ uint32_t capacity;
58
+ } pm_constant_pool_t;
59
+
60
+ // Define an empty constant pool.
61
+ #define PM_CONSTANT_POOL_EMPTY ((pm_constant_pool_t) { .buckets = NULL, .constants = NULL, .size = 0, .capacity = 0 })
62
+
63
+ // Initialize a new constant pool with a given capacity.
64
+ bool pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity);
65
+
66
+ // Insert a constant into a constant pool that is a slice of a source string.
67
+ // Returns the id of the constant, or 0 if any potential calls to resize fail.
68
+ pm_constant_id_t pm_constant_pool_insert_shared(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
69
+
70
+ // Insert a constant into a constant pool from memory that is now owned by the
71
+ // constant pool. Returns the id of the constant, or 0 if any potential calls to
72
+ // resize fail.
73
+ pm_constant_id_t pm_constant_pool_insert_owned(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
74
+
75
+ // Free the memory associated with a constant pool.
76
+ void pm_constant_pool_free(pm_constant_pool_t *pool);
77
+
78
+ #endif
@@ -0,0 +1,67 @@
1
+ // This struct represents an abstract linked list that provides common
2
+ // functionality. It is meant to be used any time a linked list is necessary to
3
+ // store data.
4
+ //
5
+ // The linked list itself operates off a set of pointers. Because the pointers
6
+ // are not necessarily sequential, they can be of any size. We use this fact to
7
+ // allow the consumer of this linked list to extend the node struct to include
8
+ // any data they want. This is done by using the pm_list_node_t as the first
9
+ // member of the struct.
10
+ //
11
+ // For example, if we want to store a list of integers, we can do the following:
12
+ //
13
+ // typedef struct {
14
+ // pm_list_node_t node;
15
+ // int value;
16
+ // } pm_int_node_t;
17
+ //
18
+ // pm_list_t list = PM_LIST_EMPTY;
19
+ // pm_int_node_t *node = malloc(sizeof(pm_int_node_t));
20
+ // node->value = 5;
21
+ //
22
+ // pm_list_append(&list, &node->node);
23
+ //
24
+ // The pm_list_t struct is used to represent the overall linked list. It
25
+ // contains a pointer to the head and tail of the list. This allows for easy
26
+ // iteration and appending of new nodes.
27
+
28
+ #ifndef PRISM_LIST_H
29
+ #define PRISM_LIST_H
30
+
31
+ #include "prism/defines.h"
32
+
33
+ #include <stdbool.h>
34
+ #include <stddef.h>
35
+ #include <stdint.h>
36
+ #include <stdlib.h>
37
+
38
+ // This represents a node in the linked list.
39
+ typedef struct pm_list_node {
40
+ struct pm_list_node *next;
41
+ } pm_list_node_t;
42
+
43
+ // This represents the overall linked list. It keeps a pointer to the head and
44
+ // tail so that iteration is easy and pushing new nodes is easy.
45
+ typedef struct {
46
+ size_t size;
47
+ pm_list_node_t *head;
48
+ pm_list_node_t *tail;
49
+ } pm_list_t;
50
+
51
+ // This represents an empty list. It's used to initialize a stack-allocated list
52
+ // as opposed to a method call.
53
+ #define PM_LIST_EMPTY ((pm_list_t) { .size = 0, .head = NULL, .tail = NULL })
54
+
55
+ // Returns true if the given list is empty.
56
+ PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
57
+
58
+ // Returns the size of the list.
59
+ PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
60
+
61
+ // Append a node to the given list.
62
+ void pm_list_append(pm_list_t *list, pm_list_node_t *node);
63
+
64
+ // Deallocate the internal state of the given list.
65
+ PRISM_EXPORTED_FUNCTION void pm_list_free(pm_list_t *list);
66
+
67
+ #endif
@@ -0,0 +1,14 @@
1
+ #ifndef PRISM_MEMCHR_H
2
+ #define PRISM_MEMCHR_H
3
+
4
+ #include "prism/defines.h"
5
+ #include "prism/enc/pm_encoding.h"
6
+
7
+ #include <stddef.h>
8
+
9
+ // We need to roll our own memchr to handle cases where the encoding changes and
10
+ // we need to search for a character in a buffer that could be the trailing byte
11
+ // of a multibyte character.
12
+ void * pm_memchr(const void *source, int character, size_t number, bool encoding_changed, pm_encoding_t *encoding);
13
+
14
+ #endif
@@ -0,0 +1,61 @@
1
+ // When compiling the syntax tree, it's necessary to know the line and column
2
+ // of many nodes. This is necessary to support things like error messages,
3
+ // tracepoints, etc.
4
+ //
5
+ // It's possible that we could store the start line, start column, end line, and
6
+ // end column on every node in addition to the offsets that we already store,
7
+ // but that would be quite a lot of memory overhead.
8
+
9
+ #ifndef PRISM_NEWLINE_LIST_H
10
+ #define PRISM_NEWLINE_LIST_H
11
+
12
+ #include "prism/defines.h"
13
+
14
+ #include <assert.h>
15
+ #include <stdbool.h>
16
+ #include <stddef.h>
17
+ #include <stdlib.h>
18
+
19
+ // A list of offsets of newlines in a string. The offsets are assumed to be
20
+ // sorted/inserted in ascending order.
21
+ typedef struct {
22
+ const uint8_t *start;
23
+
24
+ size_t *offsets;
25
+ size_t size;
26
+ size_t capacity;
27
+
28
+ size_t last_offset;
29
+ size_t last_index;
30
+ } pm_newline_list_t;
31
+
32
+ // A line and column in a string.
33
+ typedef struct {
34
+ size_t line;
35
+ size_t column;
36
+ } pm_line_column_t;
37
+
38
+ #define PM_NEWLINE_LIST_EMPTY ((pm_newline_list_t) { \
39
+ .start = NULL, .offsets = NULL, .size = 0, .capacity = 0, .last_offset = 0, .last_index = 0 \
40
+ })
41
+
42
+ // Initialize a new newline list with the given capacity. Returns true if the
43
+ // allocation of the offsets succeeds, otherwise returns false.
44
+ bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
45
+
46
+ // Append a new offset to the newline list. Returns true if the reallocation of
47
+ // the offsets succeeds (if one was necessary), otherwise returns false.
48
+ bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor);
49
+
50
+ // Conditionally append a new offset to the newline list, if the value passed in is a newline.
51
+ bool pm_newline_list_check_append(pm_newline_list_t *list, const uint8_t *cursor);
52
+
53
+ // Returns the line and column of the given offset. If the offset is not in the
54
+ // list, the line and column of the closest offset less than the given offset
55
+ // are returned.
56
+ pm_line_column_t pm_newline_list_line_column(pm_newline_list_t *list, const uint8_t *cursor);
57
+
58
+ // Free the internal memory allocated for the newline list.
59
+ void pm_newline_list_free(pm_newline_list_t *list);
60
+
61
+ #endif
@@ -0,0 +1,24 @@
1
+ #ifndef PRISM_STATE_STACK_H
2
+ #define PRISM_STATE_STACK_H
3
+
4
+ #include "prism/defines.h"
5
+
6
+ #include <stdbool.h>
7
+ #include <stdint.h>
8
+
9
+ // A struct that represents a stack of bools.
10
+ typedef uint32_t pm_state_stack_t;
11
+
12
+ // Initializes the state stack to an empty stack.
13
+ #define PM_STATE_STACK_EMPTY ((pm_state_stack_t) 0)
14
+
15
+ // Pushes a value onto the stack.
16
+ void pm_state_stack_push(pm_state_stack_t *stack, bool value);
17
+
18
+ // Pops a value off the stack.
19
+ void pm_state_stack_pop(pm_state_stack_t *stack);
20
+
21
+ // Returns the value at the top of the stack.
22
+ bool pm_state_stack_p(pm_state_stack_t *stack);
23
+
24
+ #endif
@@ -0,0 +1,61 @@
1
+ #ifndef PRISM_STRING_H
2
+ #define PRISM_STRING_H
3
+
4
+ #include "prism/defines.h"
5
+
6
+ #include <assert.h>
7
+ #include <stdbool.h>
8
+ #include <stddef.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ // This struct represents a string value.
13
+ typedef struct {
14
+ enum { PM_STRING_SHARED, PM_STRING_OWNED, PM_STRING_CONSTANT, PM_STRING_MAPPED } type;
15
+ const uint8_t *source;
16
+ size_t length;
17
+ } pm_string_t;
18
+
19
+ #define PM_EMPTY_STRING ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 })
20
+
21
+ // Initialize a shared string that is based on initial input.
22
+ void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end);
23
+
24
+ // Initialize an owned string that is responsible for freeing allocated memory.
25
+ void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length);
26
+
27
+ // Initialize a constant string that doesn't own its memory source.
28
+ void pm_string_constant_init(pm_string_t *string, const char *source, size_t length);
29
+
30
+ // Read the file indicated by the filepath parameter into source and load its
31
+ // contents and size into the given pm_string_t.
32
+ // The given pm_string_t should be freed using pm_string_free() when it is no longer used.
33
+ //
34
+ // We want to use demand paging as much as possible in order to avoid having to
35
+ // read the entire file into memory (which could be detrimental to performance
36
+ // for large files). This means that if we're on windows we'll use
37
+ // `MapViewOfFile`, on POSIX systems that have access to `mmap` we'll use
38
+ // `mmap`, and on other POSIX systems we'll use `read`.
39
+ PRISM_EXPORTED_FUNCTION bool pm_string_mapped_init(pm_string_t *string, const char *filepath);
40
+
41
+ // Returns the memory size associated with the string.
42
+ size_t pm_string_memsize(const pm_string_t *string);
43
+
44
+ // Ensure the string is owned. If it is not, then reinitialize it as owned and
45
+ // copy over the previous source.
46
+ void pm_string_ensure_owned(pm_string_t *string);
47
+
48
+ // Returns the length associated with the string.
49
+ PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string);
50
+
51
+ // Returns the start pointer associated with the string.
52
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string);
53
+
54
+ // Free the associated memory of the given string.
55
+ PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string);
56
+
57
+ // Returns the size of the pm_string_t struct. This is necessary to allocate the
58
+ // correct amount of memory in the FFI backend.
59
+ PRISM_EXPORTED_FUNCTION size_t pm_string_sizeof(void);
60
+
61
+ #endif // PRISM_STRING_H
@@ -0,0 +1,25 @@
1
+ #ifndef PRISM_STRING_LIST_H
2
+ #define PRISM_STRING_LIST_H
3
+
4
+ #include "prism/defines.h"
5
+ #include "prism/util/pm_string.h"
6
+
7
+ #include <stddef.h>
8
+ #include <stdlib.h>
9
+
10
+ typedef struct {
11
+ pm_string_t *strings;
12
+ size_t length;
13
+ size_t capacity;
14
+ } pm_string_list_t;
15
+
16
+ // Initialize a pm_string_list_t with its default values.
17
+ PRISM_EXPORTED_FUNCTION void pm_string_list_init(pm_string_list_t *string_list);
18
+
19
+ // Append a pm_string_t to the given string list.
20
+ void pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string);
21
+
22
+ // Free the memory associated with the string list.
23
+ PRISM_EXPORTED_FUNCTION void pm_string_list_free(pm_string_list_t *string_list);
24
+
25
+ #endif
@@ -0,0 +1,29 @@
1
+ #ifndef PRISM_STRPBRK_H
2
+ #define PRISM_STRPBRK_H
3
+
4
+ #include "prism/defines.h"
5
+ #include "prism/parser.h"
6
+
7
+ #include <stddef.h>
8
+ #include <string.h>
9
+
10
+ // Here we have rolled our own version of strpbrk. The standard library strpbrk
11
+ // has undefined behavior when the source string is not null-terminated. We want
12
+ // to support strings that are not null-terminated because pm_parse does not
13
+ // have the contract that the string is null-terminated. (This is desirable
14
+ // because it means the extension can call pm_parse with the result of a call to
15
+ // mmap).
16
+ //
17
+ // The standard library strpbrk also does not support passing a maximum length
18
+ // to search. We want to support this for the reason mentioned above, but we
19
+ // also don't want it to stop on null bytes. Ruby actually allows null bytes
20
+ // within strings, comments, regular expressions, etc. So we need to be able to
21
+ // skip past them.
22
+ //
23
+ // Finally, we want to support encodings wherein the charset could contain
24
+ // characters that are trailing bytes of multi-byte characters. For example, in
25
+ // Shift-JIS, the backslash character can be a trailing byte. In that case we
26
+ // need to take a slower path and iterate one multi-byte character at a time.
27
+ const uint8_t * pm_strpbrk(pm_parser_t *parser, const uint8_t *source, const uint8_t *charset, ptrdiff_t length);
28
+
29
+ #endif
@@ -0,0 +1,4 @@
1
+ #define PRISM_VERSION_MAJOR 0
2
+ #define PRISM_VERSION_MINOR 13
3
+ #define PRISM_VERSION_PATCH 0
4
+ #define PRISM_VERSION "0.13.0"
data/include/prism.h ADDED
@@ -0,0 +1,82 @@
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