yarp 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -8
  3. data/CONTRIBUTING.md +2 -2
  4. data/Makefile +5 -5
  5. data/README.md +11 -12
  6. data/config.yml +6 -2
  7. data/docs/build_system.md +21 -21
  8. data/docs/building.md +4 -4
  9. data/docs/configuration.md +25 -21
  10. data/docs/design.md +2 -2
  11. data/docs/encoding.md +17 -17
  12. data/docs/fuzzing.md +4 -4
  13. data/docs/heredocs.md +3 -3
  14. data/docs/mapping.md +94 -94
  15. data/docs/ripper.md +4 -4
  16. data/docs/ruby_api.md +11 -11
  17. data/docs/serialization.md +17 -16
  18. data/docs/testing.md +6 -6
  19. data/ext/prism/api_node.c +4725 -0
  20. data/ext/{yarp → prism}/api_pack.c +82 -82
  21. data/ext/{yarp → prism}/extconf.rb +13 -13
  22. data/ext/{yarp → prism}/extension.c +175 -168
  23. data/ext/prism/extension.h +18 -0
  24. data/include/prism/ast.h +1932 -0
  25. data/include/prism/defines.h +45 -0
  26. data/include/prism/diagnostic.h +231 -0
  27. data/include/{yarp/enc/yp_encoding.h → prism/enc/pm_encoding.h} +40 -40
  28. data/include/prism/node.h +41 -0
  29. data/include/prism/pack.h +141 -0
  30. data/include/{yarp → prism}/parser.h +143 -142
  31. data/include/prism/regexp.h +19 -0
  32. data/include/prism/unescape.h +48 -0
  33. data/include/prism/util/pm_buffer.h +51 -0
  34. data/include/{yarp/util/yp_char.h → prism/util/pm_char.h} +20 -20
  35. data/include/{yarp/util/yp_constant_pool.h → prism/util/pm_constant_pool.h} +26 -22
  36. data/include/{yarp/util/yp_list.h → prism/util/pm_list.h} +21 -21
  37. data/include/prism/util/pm_memchr.h +14 -0
  38. data/include/{yarp/util/yp_newline_list.h → prism/util/pm_newline_list.h} +11 -11
  39. data/include/prism/util/pm_state_stack.h +24 -0
  40. data/include/{yarp/util/yp_string.h → prism/util/pm_string.h} +20 -20
  41. data/include/prism/util/pm_string_list.h +25 -0
  42. data/include/{yarp/util/yp_strpbrk.h → prism/util/pm_strpbrk.h} +7 -7
  43. data/include/prism/version.h +4 -0
  44. data/include/prism.h +82 -0
  45. data/lib/prism/compiler.rb +465 -0
  46. data/lib/prism/debug.rb +157 -0
  47. data/lib/{yarp/desugar_visitor.rb → prism/desugar_compiler.rb} +4 -2
  48. data/lib/prism/dispatcher.rb +2051 -0
  49. data/lib/prism/dsl.rb +750 -0
  50. data/lib/{yarp → prism}/ffi.rb +66 -67
  51. data/lib/{yarp → prism}/lex_compat.rb +40 -43
  52. data/lib/{yarp/mutation_visitor.rb → prism/mutation_compiler.rb} +3 -3
  53. data/lib/{yarp → prism}/node.rb +2012 -2593
  54. data/lib/prism/node_ext.rb +55 -0
  55. data/lib/prism/node_inspector.rb +68 -0
  56. data/lib/{yarp → prism}/pack.rb +1 -1
  57. data/lib/{yarp → prism}/parse_result/comments.rb +1 -1
  58. data/lib/{yarp → prism}/parse_result/newlines.rb +1 -1
  59. data/lib/prism/parse_result.rb +266 -0
  60. data/lib/{yarp → prism}/pattern.rb +14 -14
  61. data/lib/{yarp → prism}/ripper_compat.rb +5 -5
  62. data/lib/{yarp → prism}/serialize.rb +12 -7
  63. data/lib/prism/visitor.rb +470 -0
  64. data/lib/prism.rb +64 -0
  65. data/lib/yarp.rb +2 -614
  66. data/src/diagnostic.c +213 -208
  67. data/src/enc/pm_big5.c +52 -0
  68. data/src/enc/pm_euc_jp.c +58 -0
  69. data/src/enc/{yp_gbk.c → pm_gbk.c} +16 -16
  70. data/src/enc/pm_shift_jis.c +56 -0
  71. data/src/enc/{yp_tables.c → pm_tables.c} +69 -69
  72. data/src/enc/{yp_unicode.c → pm_unicode.c} +40 -40
  73. data/src/enc/pm_windows_31j.c +56 -0
  74. data/src/node.c +1293 -1233
  75. data/src/pack.c +247 -247
  76. data/src/prettyprint.c +1479 -1479
  77. data/src/{yarp.c → prism.c} +5205 -5083
  78. data/src/regexp.c +132 -132
  79. data/src/serialize.c +1121 -1121
  80. data/src/token_type.c +169 -167
  81. data/src/unescape.c +106 -87
  82. data/src/util/pm_buffer.c +103 -0
  83. data/src/util/{yp_char.c → pm_char.c} +72 -72
  84. data/src/util/{yp_constant_pool.c → pm_constant_pool.c} +85 -64
  85. data/src/util/{yp_list.c → pm_list.c} +10 -10
  86. data/src/util/{yp_memchr.c → pm_memchr.c} +6 -4
  87. data/src/util/{yp_newline_list.c → pm_newline_list.c} +21 -21
  88. data/src/util/{yp_state_stack.c → pm_state_stack.c} +4 -4
  89. data/src/util/{yp_string.c → pm_string.c} +38 -38
  90. data/src/util/pm_string_list.c +29 -0
  91. data/src/util/{yp_strncasecmp.c → pm_strncasecmp.c} +1 -1
  92. data/src/util/{yp_strpbrk.c → pm_strpbrk.c} +8 -8
  93. data/yarp.gemspec +68 -59
  94. metadata +70 -61
  95. data/ext/yarp/api_node.c +0 -4728
  96. data/ext/yarp/extension.h +0 -18
  97. data/include/yarp/ast.h +0 -1929
  98. data/include/yarp/defines.h +0 -45
  99. data/include/yarp/diagnostic.h +0 -226
  100. data/include/yarp/node.h +0 -42
  101. data/include/yarp/pack.h +0 -141
  102. data/include/yarp/regexp.h +0 -19
  103. data/include/yarp/unescape.h +0 -44
  104. data/include/yarp/util/yp_buffer.h +0 -51
  105. data/include/yarp/util/yp_memchr.h +0 -14
  106. data/include/yarp/util/yp_state_stack.h +0 -24
  107. data/include/yarp/util/yp_string_list.h +0 -25
  108. data/include/yarp/version.h +0 -4
  109. data/include/yarp.h +0 -82
  110. data/src/enc/yp_big5.c +0 -52
  111. data/src/enc/yp_euc_jp.c +0 -58
  112. data/src/enc/yp_shift_jis.c +0 -56
  113. data/src/enc/yp_windows_31j.c +0 -56
  114. data/src/util/yp_buffer.c +0 -101
  115. data/src/util/yp_string_list.c +0 -29
@@ -1,45 +0,0 @@
1
- #ifndef YARP_DEFINES_H
2
- #define YARP_DEFINES_H
3
-
4
- // This file should be included first by any *.h or *.c in YARP
5
-
6
- #include <ctype.h>
7
- #include <stdarg.h>
8
- #include <stddef.h>
9
- #include <stdint.h>
10
- #include <stdio.h>
11
- #include <string.h>
12
-
13
- // YP_EXPORTED_FUNCTION
14
- #ifndef YP_EXPORTED_FUNCTION
15
- # ifdef YP_EXPORT_SYMBOLS
16
- # ifdef _WIN32
17
- # define YP_EXPORTED_FUNCTION __declspec(dllexport) extern
18
- # else
19
- # define YP_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
20
- # endif
21
- # else
22
- # define YP_EXPORTED_FUNCTION
23
- # endif
24
- #endif
25
-
26
- // YP_ATTRIBUTE_UNUSED
27
- #if defined(__GNUC__)
28
- # define YP_ATTRIBUTE_UNUSED __attribute__((unused))
29
- #else
30
- # define YP_ATTRIBUTE_UNUSED
31
- #endif
32
-
33
- // inline
34
- #if defined(_MSC_VER) && !defined(inline)
35
- # define inline __inline
36
- #endif
37
-
38
- // Windows versions before 2015 use _snprintf
39
- #if defined(_MSC_VER) && (_MSC_VER < 1900)
40
- # define snprintf _snprintf
41
- #endif
42
-
43
- int yp_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length);
44
-
45
- #endif
@@ -1,226 +0,0 @@
1
- #ifndef YARP_DIAGNOSTIC_H
2
- #define YARP_DIAGNOSTIC_H
3
-
4
- #include "yarp/defines.h"
5
- #include "yarp/util/yp_list.h"
6
-
7
- #include <stdbool.h>
8
- #include <stdlib.h>
9
- #include <assert.h>
10
-
11
- // This struct represents a diagnostic found during parsing.
12
- typedef struct {
13
- yp_list_node_t node;
14
- const uint8_t *start;
15
- const uint8_t *end;
16
- const char *message;
17
- } yp_diagnostic_t;
18
-
19
- typedef enum {
20
- YP_ERR_ALIAS_ARGUMENT,
21
- YP_ERR_AMPAMPEQ_MULTI_ASSIGN,
22
- YP_ERR_ARGUMENT_AFTER_BLOCK,
23
- YP_ERR_ARGUMENT_BARE_HASH,
24
- YP_ERR_ARGUMENT_BLOCK_MULTI,
25
- YP_ERR_ARGUMENT_FORMAL_CLASS,
26
- YP_ERR_ARGUMENT_FORMAL_CONSTANT,
27
- YP_ERR_ARGUMENT_FORMAL_GLOBAL,
28
- YP_ERR_ARGUMENT_FORMAL_IVAR,
29
- YP_ERR_ARGUMENT_NO_FORWARDING_AMP,
30
- YP_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
31
- YP_ERR_ARGUMENT_NO_FORWARDING_STAR,
32
- YP_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT,
33
- YP_ERR_ARGUMENT_SPLAT_AFTER_SPLAT,
34
- YP_ERR_ARGUMENT_TERM_PAREN,
35
- YP_ERR_ARGUMENT_UNEXPECTED_BLOCK,
36
- YP_ERR_ARRAY_ELEMENT,
37
- YP_ERR_ARRAY_EXPRESSION,
38
- YP_ERR_ARRAY_EXPRESSION_AFTER_STAR,
39
- YP_ERR_ARRAY_SEPARATOR,
40
- YP_ERR_ARRAY_TERM,
41
- YP_ERR_BEGIN_LONELY_ELSE,
42
- YP_ERR_BEGIN_TERM,
43
- YP_ERR_BEGIN_UPCASE_BRACE,
44
- YP_ERR_BEGIN_UPCASE_TERM,
45
- YP_ERR_BLOCK_PARAM_LOCAL_VARIABLE,
46
- YP_ERR_BLOCK_PARAM_PIPE_TERM,
47
- YP_ERR_BLOCK_TERM_BRACE,
48
- YP_ERR_BLOCK_TERM_END,
49
- YP_ERR_CANNOT_PARSE_EXPRESSION,
50
- YP_ERR_CANNOT_PARSE_STRING_PART,
51
- YP_ERR_CASE_EXPRESSION_AFTER_CASE,
52
- YP_ERR_CASE_EXPRESSION_AFTER_WHEN,
53
- YP_ERR_CASE_MISSING_CONDITIONS,
54
- YP_ERR_CASE_TERM,
55
- YP_ERR_CLASS_IN_METHOD,
56
- YP_ERR_CLASS_NAME,
57
- YP_ERR_CLASS_SUPERCLASS,
58
- YP_ERR_CLASS_TERM,
59
- YP_ERR_CONDITIONAL_ELSIF_PREDICATE,
60
- YP_ERR_CONDITIONAL_IF_PREDICATE,
61
- YP_ERR_CONDITIONAL_TERM,
62
- YP_ERR_CONDITIONAL_TERM_ELSE,
63
- YP_ERR_CONDITIONAL_UNLESS_PREDICATE,
64
- YP_ERR_CONDITIONAL_UNTIL_PREDICATE,
65
- YP_ERR_CONDITIONAL_WHILE_PREDICATE,
66
- YP_ERR_CONSTANT_PATH_COLON_COLON_CONSTANT,
67
- YP_ERR_DEF_ENDLESS,
68
- YP_ERR_DEF_ENDLESS_SETTER,
69
- YP_ERR_DEF_NAME,
70
- YP_ERR_DEF_NAME_AFTER_RECEIVER,
71
- YP_ERR_DEF_PARAMS_TERM,
72
- YP_ERR_DEF_PARAMS_TERM_PAREN,
73
- YP_ERR_DEF_RECEIVER,
74
- YP_ERR_DEF_RECEIVER_TERM,
75
- YP_ERR_DEF_TERM,
76
- YP_ERR_DEFINED_EXPRESSION,
77
- YP_ERR_EMBDOC_TERM,
78
- YP_ERR_EMBEXPR_END,
79
- YP_ERR_EMBVAR_INVALID,
80
- YP_ERR_END_UPCASE_BRACE,
81
- YP_ERR_END_UPCASE_TERM,
82
- YP_ERR_ESCAPE_INVALID_CONTROL,
83
- YP_ERR_ESCAPE_INVALID_CONTROL_REPEAT,
84
- YP_ERR_ESCAPE_INVALID_HEXADECIMAL,
85
- YP_ERR_ESCAPE_INVALID_META,
86
- YP_ERR_ESCAPE_INVALID_META_REPEAT,
87
- YP_ERR_ESCAPE_INVALID_UNICODE,
88
- YP_ERR_ESCAPE_INVALID_UNICODE_CM_FLAGS,
89
- YP_ERR_ESCAPE_INVALID_UNICODE_LITERAL,
90
- YP_ERR_ESCAPE_INVALID_UNICODE_LONG,
91
- YP_ERR_ESCAPE_INVALID_UNICODE_TERM,
92
- YP_ERR_EXPECT_ARGUMENT,
93
- YP_ERR_EXPECT_EOL_AFTER_STATEMENT,
94
- YP_ERR_EXPECT_EXPRESSION_AFTER_AMPAMPEQ,
95
- YP_ERR_EXPECT_EXPRESSION_AFTER_PIPEPIPEEQ,
96
- YP_ERR_EXPECT_EXPRESSION_AFTER_COMMA,
97
- YP_ERR_EXPECT_EXPRESSION_AFTER_EQUAL,
98
- YP_ERR_EXPECT_EXPRESSION_AFTER_LESS_LESS,
99
- YP_ERR_EXPECT_EXPRESSION_AFTER_LPAREN,
100
- YP_ERR_EXPECT_EXPRESSION_AFTER_QUESTION,
101
- YP_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR,
102
- YP_ERR_EXPECT_EXPRESSION_AFTER_SPLAT,
103
- YP_ERR_EXPECT_EXPRESSION_AFTER_SPLAT_HASH,
104
- YP_ERR_EXPECT_EXPRESSION_AFTER_STAR,
105
- YP_ERR_EXPECT_IDENT_REQ_PARAMETER,
106
- YP_ERR_EXPECT_LPAREN_REQ_PARAMETER,
107
- YP_ERR_EXPECT_RBRACKET,
108
- YP_ERR_EXPECT_RPAREN,
109
- YP_ERR_EXPECT_RPAREN_AFTER_MULTI,
110
- YP_ERR_EXPECT_RPAREN_REQ_PARAMETER,
111
- YP_ERR_EXPECT_STRING_CONTENT,
112
- YP_ERR_EXPECT_WHEN_DELIMITER,
113
- YP_ERR_EXPRESSION_BARE_HASH,
114
- YP_ERR_FOR_COLLECTION,
115
- YP_ERR_FOR_IN,
116
- YP_ERR_FOR_INDEX,
117
- YP_ERR_FOR_TERM,
118
- YP_ERR_HASH_EXPRESSION_AFTER_LABEL,
119
- YP_ERR_HASH_KEY,
120
- YP_ERR_HASH_ROCKET,
121
- YP_ERR_HASH_TERM,
122
- YP_ERR_HASH_VALUE,
123
- YP_ERR_HEREDOC_TERM,
124
- YP_ERR_INCOMPLETE_QUESTION_MARK,
125
- YP_ERR_INCOMPLETE_VARIABLE_CLASS,
126
- YP_ERR_INCOMPLETE_VARIABLE_INSTANCE,
127
- YP_ERR_INVALID_ENCODING_MAGIC_COMMENT,
128
- YP_ERR_INVALID_FLOAT_EXPONENT,
129
- YP_ERR_INVALID_NUMBER_BINARY,
130
- YP_ERR_INVALID_NUMBER_DECIMAL,
131
- YP_ERR_INVALID_NUMBER_HEXADECIMAL,
132
- YP_ERR_INVALID_NUMBER_OCTAL,
133
- YP_ERR_INVALID_NUMBER_UNDERSCORE,
134
- YP_ERR_INVALID_PERCENT,
135
- YP_ERR_INVALID_TOKEN,
136
- YP_ERR_INVALID_VARIABLE_GLOBAL,
137
- YP_ERR_LAMBDA_OPEN,
138
- YP_ERR_LAMBDA_TERM_BRACE,
139
- YP_ERR_LAMBDA_TERM_END,
140
- YP_ERR_LIST_I_LOWER_ELEMENT,
141
- YP_ERR_LIST_I_LOWER_TERM,
142
- YP_ERR_LIST_I_UPPER_ELEMENT,
143
- YP_ERR_LIST_I_UPPER_TERM,
144
- YP_ERR_LIST_W_LOWER_ELEMENT,
145
- YP_ERR_LIST_W_LOWER_TERM,
146
- YP_ERR_LIST_W_UPPER_ELEMENT,
147
- YP_ERR_LIST_W_UPPER_TERM,
148
- YP_ERR_MALLOC_FAILED,
149
- YP_ERR_MODULE_IN_METHOD,
150
- YP_ERR_MODULE_NAME,
151
- YP_ERR_MODULE_TERM,
152
- YP_ERR_MULTI_ASSIGN_MULTI_SPLATS,
153
- YP_ERR_NOT_EXPRESSION,
154
- YP_ERR_NUMBER_LITERAL_UNDERSCORE,
155
- YP_ERR_NUMBERED_PARAMETER_NOT_ALLOWED,
156
- YP_ERR_NUMBERED_PARAMETER_OUTER_SCOPE,
157
- YP_ERR_OPERATOR_MULTI_ASSIGN,
158
- YP_ERR_OPERATOR_WRITE_BLOCK,
159
- YP_ERR_PARAMETER_ASSOC_SPLAT_MULTI,
160
- YP_ERR_PARAMETER_BLOCK_MULTI,
161
- YP_ERR_PARAMETER_NAME_REPEAT,
162
- YP_ERR_PARAMETER_NO_DEFAULT,
163
- YP_ERR_PARAMETER_NO_DEFAULT_KW,
164
- YP_ERR_PARAMETER_NUMBERED_RESERVED,
165
- YP_ERR_PARAMETER_ORDER,
166
- YP_ERR_PARAMETER_SPLAT_MULTI,
167
- YP_ERR_PARAMETER_STAR,
168
- YP_ERR_PARAMETER_WILD_LOOSE_COMMA,
169
- YP_ERR_PATTERN_EXPRESSION_AFTER_BRACKET,
170
- YP_ERR_PATTERN_EXPRESSION_AFTER_HROCKET,
171
- YP_ERR_PATTERN_EXPRESSION_AFTER_COMMA,
172
- YP_ERR_PATTERN_EXPRESSION_AFTER_IN,
173
- YP_ERR_PATTERN_EXPRESSION_AFTER_KEY,
174
- YP_ERR_PATTERN_EXPRESSION_AFTER_PAREN,
175
- YP_ERR_PATTERN_EXPRESSION_AFTER_PIN,
176
- YP_ERR_PATTERN_EXPRESSION_AFTER_PIPE,
177
- YP_ERR_PATTERN_EXPRESSION_AFTER_RANGE,
178
- YP_ERR_PATTERN_HASH_KEY,
179
- YP_ERR_PATTERN_HASH_KEY_LABEL,
180
- YP_ERR_PATTERN_IDENT_AFTER_HROCKET,
181
- YP_ERR_PATTERN_LABEL_AFTER_COMMA,
182
- YP_ERR_PATTERN_REST,
183
- YP_ERR_PATTERN_TERM_BRACE,
184
- YP_ERR_PATTERN_TERM_BRACKET,
185
- YP_ERR_PATTERN_TERM_PAREN,
186
- YP_ERR_PIPEPIPEEQ_MULTI_ASSIGN,
187
- YP_ERR_REGEXP_TERM,
188
- YP_ERR_RESCUE_EXPRESSION,
189
- YP_ERR_RESCUE_MODIFIER_VALUE,
190
- YP_ERR_RESCUE_TERM,
191
- YP_ERR_RESCUE_VARIABLE,
192
- YP_ERR_RETURN_INVALID,
193
- YP_ERR_STRING_CONCATENATION,
194
- YP_ERR_STRING_INTERPOLATED_TERM,
195
- YP_ERR_STRING_LITERAL_TERM,
196
- YP_ERR_SYMBOL_INVALID,
197
- YP_ERR_SYMBOL_TERM_DYNAMIC,
198
- YP_ERR_SYMBOL_TERM_INTERPOLATED,
199
- YP_ERR_TERNARY_COLON,
200
- YP_ERR_TERNARY_EXPRESSION_FALSE,
201
- YP_ERR_TERNARY_EXPRESSION_TRUE,
202
- YP_ERR_UNARY_RECEIVER_BANG,
203
- YP_ERR_UNARY_RECEIVER_MINUS,
204
- YP_ERR_UNARY_RECEIVER_PLUS,
205
- YP_ERR_UNARY_RECEIVER_TILDE,
206
- YP_ERR_UNDEF_ARGUMENT,
207
- YP_ERR_UNTIL_TERM,
208
- YP_ERR_WHILE_TERM,
209
- YP_ERR_WRITE_TARGET_READONLY,
210
- YP_ERR_WRITE_TARGET_UNEXPECTED,
211
- YP_ERR_XSTRING_TERM,
212
- YP_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS,
213
- YP_WARN_AMBIGUOUS_FIRST_ARGUMENT_PLUS,
214
- YP_WARN_AMBIGUOUS_PREFIX_STAR,
215
- YP_WARN_AMBIGUOUS_SLASH,
216
- /* This must be the last member. */
217
- YP_DIAGNOSTIC_ID_LEN,
218
- } yp_diagnostic_id_t;
219
-
220
- // Append a diagnostic to the given list of diagnostics.
221
- bool yp_diagnostic_list_append(yp_list_t *list, const uint8_t *start, const uint8_t *end, yp_diagnostic_id_t diag_id);
222
-
223
- // Deallocate the internal state of the given diagnostic list.
224
- void yp_diagnostic_list_free(yp_list_t *list);
225
-
226
- #endif
data/include/yarp/node.h DELETED
@@ -1,42 +0,0 @@
1
- #ifndef YARP_NODE_H
2
- #define YARP_NODE_H
3
-
4
- #include "yarp/defines.h"
5
- #include "yarp/parser.h"
6
-
7
- // Append a new node onto the end of the node list.
8
- void yp_node_list_append(yp_node_list_t *list, yp_node_t *node);
9
-
10
- // Clear the node but preserves the location.
11
- void yp_node_clear(yp_node_t *node);
12
-
13
- // Deallocate a node and all of its children.
14
- YP_EXPORTED_FUNCTION void yp_node_destroy(yp_parser_t *parser, struct yp_node *node);
15
-
16
- // This struct stores the information gathered by the yp_node_memsize function.
17
- // It contains both the memory footprint and additionally metadata about the
18
- // shape of the tree.
19
- typedef struct {
20
- size_t memsize;
21
- size_t node_count;
22
- } yp_memsize_t;
23
-
24
- // Calculates the memory footprint of a given node.
25
- YP_EXPORTED_FUNCTION void yp_node_memsize(yp_node_t *node, yp_memsize_t *memsize);
26
-
27
- // Returns a string representation of the given node type.
28
- YP_EXPORTED_FUNCTION const char * yp_node_type_to_str(yp_node_type_t node_type);
29
-
30
- #define YP_EMPTY_NODE_LIST ((yp_node_list_t) { .nodes = NULL, .size = 0, .capacity = 0 })
31
-
32
- #endif // YARP_NODE_H
33
-
34
- // ScopeNodes are helper nodes, and will never
35
- // be part of the AST. We manually declare them
36
- // here to avoid generating them
37
- typedef struct yp_scope_node {
38
- yp_node_t base;
39
- struct yp_parameters_node *parameters;
40
- yp_node_t *body;
41
- yp_constant_id_list_t locals;
42
- } yp_scope_node_t;
data/include/yarp/pack.h DELETED
@@ -1,141 +0,0 @@
1
- #ifndef YARP_PACK_H
2
- #define YARP_PACK_H
3
-
4
- #include "yarp/defines.h"
5
-
6
- #include <stdint.h>
7
- #include <stdlib.h>
8
-
9
- typedef enum yp_pack_version {
10
- YP_PACK_VERSION_3_2_0
11
- } yp_pack_version;
12
-
13
- typedef enum yp_pack_variant {
14
- YP_PACK_VARIANT_PACK,
15
- YP_PACK_VARIANT_UNPACK
16
- } yp_pack_variant;
17
-
18
- typedef enum yp_pack_type {
19
- YP_PACK_SPACE,
20
- YP_PACK_COMMENT,
21
- YP_PACK_INTEGER,
22
- YP_PACK_UTF8,
23
- YP_PACK_BER,
24
- YP_PACK_FLOAT,
25
- YP_PACK_STRING_SPACE_PADDED,
26
- YP_PACK_STRING_NULL_PADDED,
27
- YP_PACK_STRING_NULL_TERMINATED,
28
- YP_PACK_STRING_MSB,
29
- YP_PACK_STRING_LSB,
30
- YP_PACK_STRING_HEX_HIGH,
31
- YP_PACK_STRING_HEX_LOW,
32
- YP_PACK_STRING_UU,
33
- YP_PACK_STRING_MIME,
34
- YP_PACK_STRING_BASE64,
35
- YP_PACK_STRING_FIXED,
36
- YP_PACK_STRING_POINTER,
37
- YP_PACK_MOVE,
38
- YP_PACK_BACK,
39
- YP_PACK_NULL,
40
- YP_PACK_END
41
- } yp_pack_type;
42
-
43
- typedef enum yp_pack_signed {
44
- YP_PACK_UNSIGNED,
45
- YP_PACK_SIGNED,
46
- YP_PACK_SIGNED_NA
47
- } yp_pack_signed;
48
-
49
- typedef enum yp_pack_endian {
50
- YP_PACK_AGNOSTIC_ENDIAN,
51
- YP_PACK_LITTLE_ENDIAN, // aka 'VAX', or 'V'
52
- YP_PACK_BIG_ENDIAN, // aka 'network', or 'N'
53
- YP_PACK_NATIVE_ENDIAN,
54
- YP_PACK_ENDIAN_NA
55
- } yp_pack_endian;
56
-
57
- typedef enum yp_pack_size {
58
- YP_PACK_SIZE_SHORT,
59
- YP_PACK_SIZE_INT,
60
- YP_PACK_SIZE_LONG,
61
- YP_PACK_SIZE_LONG_LONG,
62
- YP_PACK_SIZE_8,
63
- YP_PACK_SIZE_16,
64
- YP_PACK_SIZE_32,
65
- YP_PACK_SIZE_64,
66
- YP_PACK_SIZE_P,
67
- YP_PACK_SIZE_NA
68
- } yp_pack_size;
69
-
70
- typedef enum yp_pack_length_type {
71
- YP_PACK_LENGTH_FIXED,
72
- YP_PACK_LENGTH_MAX,
73
- YP_PACK_LENGTH_RELATIVE, // special case for unpack @*
74
- YP_PACK_LENGTH_NA
75
- } yp_pack_length_type;
76
-
77
- typedef enum yp_pack_encoding {
78
- YP_PACK_ENCODING_START,
79
- YP_PACK_ENCODING_ASCII_8BIT,
80
- YP_PACK_ENCODING_US_ASCII,
81
- YP_PACK_ENCODING_UTF_8
82
- } yp_pack_encoding;
83
-
84
- typedef enum yp_pack_result {
85
- YP_PACK_OK,
86
- YP_PACK_ERROR_UNSUPPORTED_DIRECTIVE,
87
- YP_PACK_ERROR_UNKNOWN_DIRECTIVE,
88
- YP_PACK_ERROR_LENGTH_TOO_BIG,
89
- YP_PACK_ERROR_BANG_NOT_ALLOWED,
90
- YP_PACK_ERROR_DOUBLE_ENDIAN
91
- } yp_pack_result;
92
-
93
- // Parse a single directive from a pack or unpack format string.
94
- //
95
- // Parameters:
96
- // - [in] yp_pack_version version the version of Ruby
97
- // - [in] yp_pack_variant variant pack or unpack
98
- // - [in out] const char **format the start of the next directive to parse
99
- // on calling, and advanced beyond the parsed directive on return, or as
100
- // much of it as was consumed until an error was encountered
101
- // - [in] const char *format_end the end of the format string
102
- // - [out] yp_pack_type *type the type of the directive
103
- // - [out] yp_pack_signed *signed_type
104
- // whether the value is signed
105
- // - [out] yp_pack_endian *endian the endianness of the value
106
- // - [out] yp_pack_size *size the size of the value
107
- // - [out] yp_pack_length_type *length_type
108
- // what kind of length is specified
109
- // - [out] size_t *length the length of the directive
110
- // - [in out] yp_pack_encoding *encoding
111
- // takes the current encoding of the string
112
- // which would result from parsing the whole format string, and returns a
113
- // possibly changed directive - the encoding should be
114
- // YP_PACK_ENCODING_START when yp_pack_parse is called for the first
115
- // directive in a format string
116
- //
117
- // Return:
118
- // - YP_PACK_OK on success
119
- // - YP_PACK_ERROR_* on error
120
- //
121
- // Notes:
122
- // Consult Ruby documentation for the meaning of directives.
123
- YP_EXPORTED_FUNCTION yp_pack_result
124
- yp_pack_parse(
125
- yp_pack_variant variant_arg,
126
- const char **format,
127
- const char *format_end,
128
- yp_pack_type *type,
129
- yp_pack_signed *signed_type,
130
- yp_pack_endian *endian,
131
- yp_pack_size *size,
132
- yp_pack_length_type *length_type,
133
- uint64_t *length,
134
- yp_pack_encoding *encoding
135
- );
136
-
137
- // YARP abstracts sizes away from the native system - this converts an abstract
138
- // size to a native size.
139
- YP_EXPORTED_FUNCTION size_t yp_size_to_native(yp_pack_size size);
140
-
141
- #endif
@@ -1,19 +0,0 @@
1
- #ifndef YARP_REGEXP_H
2
- #define YARP_REGEXP_H
3
-
4
- #include "yarp/defines.h"
5
- #include "yarp/parser.h"
6
- #include "yarp/enc/yp_encoding.h"
7
- #include "yarp/util/yp_memchr.h"
8
- #include "yarp/util/yp_string_list.h"
9
- #include "yarp/util/yp_string.h"
10
-
11
- #include <stdbool.h>
12
- #include <stddef.h>
13
- #include <string.h>
14
-
15
- // Parse a regular expression and extract the names of all of the named capture
16
- // groups.
17
- YP_EXPORTED_FUNCTION bool yp_regexp_named_capture_group_names(const uint8_t *source, size_t size, yp_string_list_t *named_captures, bool encoding_changed, yp_encoding_t *encoding);
18
-
19
- #endif
@@ -1,44 +0,0 @@
1
- #ifndef YARP_UNESCAPE_H
2
- #define YARP_UNESCAPE_H
3
-
4
- #include "yarp/defines.h"
5
- #include "yarp/diagnostic.h"
6
- #include "yarp/parser.h"
7
- #include "yarp/util/yp_char.h"
8
- #include "yarp/util/yp_list.h"
9
- #include "yarp/util/yp_memchr.h"
10
- #include "yarp/util/yp_string.h"
11
-
12
- #include <assert.h>
13
- #include <stdbool.h>
14
- #include <stdint.h>
15
- #include <string.h>
16
-
17
- // The type of unescape we are performing.
18
- typedef enum {
19
- // When we're creating a string inside of a list literal like %w, we
20
- // shouldn't escape anything.
21
- YP_UNESCAPE_NONE,
22
-
23
- // When we're unescaping a single-quoted string, we only need to unescape
24
- // single quotes and backslashes.
25
- YP_UNESCAPE_MINIMAL,
26
-
27
- // When we're unescaping a double-quoted string, we need to unescape all
28
- // escapes.
29
- YP_UNESCAPE_ALL
30
- } yp_unescape_type_t;
31
-
32
- // Unescape the contents of the given token into the given string using the given unescape mode.
33
- YP_EXPORTED_FUNCTION void yp_unescape_manipulate_string(yp_parser_t *parser, yp_string_t *string, yp_unescape_type_t unescape_type);
34
- void yp_unescape_manipulate_char_literal(yp_parser_t *parser, yp_string_t *string, yp_unescape_type_t unescape_type);
35
-
36
- // Accepts a source string and a type of unescaping and returns the unescaped version.
37
- // The caller must yp_string_free(result); after calling this function.
38
- YP_EXPORTED_FUNCTION bool yp_unescape_string(const uint8_t *start, size_t length, yp_unescape_type_t unescape_type, yp_string_t *result);
39
-
40
- // Returns the number of bytes that encompass the first escape sequence in the
41
- // given string.
42
- size_t yp_unescape_calculate_difference(yp_parser_t *parser, const uint8_t *value, yp_unescape_type_t unescape_type, bool expect_single_codepoint);
43
-
44
- #endif
@@ -1,51 +0,0 @@
1
- #ifndef YARP_BUFFER_H
2
- #define YARP_BUFFER_H
3
-
4
- #include "yarp/defines.h"
5
-
6
- #include <assert.h>
7
- #include <stdbool.h>
8
- #include <stdint.h>
9
- #include <stdlib.h>
10
- #include <string.h>
11
-
12
- // A yp_buffer_t is a simple memory buffer that stores data in a contiguous
13
- // block of memory. It is used to store the serialized representation of a
14
- // YARP tree.
15
- typedef struct {
16
- char *value;
17
- size_t length;
18
- size_t capacity;
19
- } yp_buffer_t;
20
-
21
- // Return the size of the yp_buffer_t struct.
22
- YP_EXPORTED_FUNCTION size_t yp_buffer_sizeof(void);
23
-
24
- // Initialize a yp_buffer_t with its default values.
25
- YP_EXPORTED_FUNCTION bool yp_buffer_init(yp_buffer_t *buffer);
26
-
27
- // Return the value of the buffer.
28
- YP_EXPORTED_FUNCTION char * yp_buffer_value(yp_buffer_t *buffer);
29
-
30
- // Return the length of the buffer.
31
- YP_EXPORTED_FUNCTION size_t yp_buffer_length(yp_buffer_t *buffer);
32
-
33
- // Append the given amount of space as zeroes to the buffer.
34
- void yp_buffer_append_zeroes(yp_buffer_t *buffer, size_t length);
35
-
36
- // Append a string to the buffer.
37
- void yp_buffer_append_str(yp_buffer_t *buffer, const char *value, size_t length);
38
-
39
- // Append a list of bytes to the buffer.
40
- void yp_buffer_append_bytes(yp_buffer_t *buffer, const uint8_t *value, size_t length);
41
-
42
- // Append a single byte to the buffer.
43
- void yp_buffer_append_u8(yp_buffer_t *buffer, uint8_t value);
44
-
45
- // Append a 32-bit unsigned integer to the buffer.
46
- void yp_buffer_append_u32(yp_buffer_t *buffer, uint32_t value);
47
-
48
- // Free the memory associated with the buffer.
49
- YP_EXPORTED_FUNCTION void yp_buffer_free(yp_buffer_t *buffer);
50
-
51
- #endif
@@ -1,14 +0,0 @@
1
- #ifndef YP_MEMCHR_H
2
- #define YP_MEMCHR_H
3
-
4
- #include "yarp/defines.h"
5
- #include "yarp/enc/yp_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 * yp_memchr(const void *source, int character, size_t number, bool encoding_changed, yp_encoding_t *encoding);
13
-
14
- #endif
@@ -1,24 +0,0 @@
1
- #ifndef YP_STATE_STACK_H
2
- #define YP_STATE_STACK_H
3
-
4
- #include "yarp/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 yp_state_stack_t;
11
-
12
- // Initializes the state stack to an empty stack.
13
- #define YP_STATE_STACK_EMPTY ((yp_state_stack_t) 0)
14
-
15
- // Pushes a value onto the stack.
16
- void yp_state_stack_push(yp_state_stack_t *stack, bool value);
17
-
18
- // Pops a value off the stack.
19
- void yp_state_stack_pop(yp_state_stack_t *stack);
20
-
21
- // Returns the value at the top of the stack.
22
- bool yp_state_stack_p(yp_state_stack_t *stack);
23
-
24
- #endif
@@ -1,25 +0,0 @@
1
- #ifndef YARP_STRING_LIST_H
2
- #define YARP_STRING_LIST_H
3
-
4
- #include "yarp/defines.h"
5
- #include "yarp/util/yp_string.h"
6
-
7
- #include <stddef.h>
8
- #include <stdlib.h>
9
-
10
- typedef struct {
11
- yp_string_t *strings;
12
- size_t length;
13
- size_t capacity;
14
- } yp_string_list_t;
15
-
16
- // Initialize a yp_string_list_t with its default values.
17
- YP_EXPORTED_FUNCTION void yp_string_list_init(yp_string_list_t *string_list);
18
-
19
- // Append a yp_string_t to the given string list.
20
- void yp_string_list_append(yp_string_list_t *string_list, yp_string_t *string);
21
-
22
- // Free the memory associated with the string list.
23
- YP_EXPORTED_FUNCTION void yp_string_list_free(yp_string_list_t *string_list);
24
-
25
- #endif
@@ -1,4 +0,0 @@
1
- #define YP_VERSION_MAJOR 0
2
- #define YP_VERSION_MINOR 12
3
- #define YP_VERSION_PATCH 0
4
- #define YP_VERSION "0.12.0"