prism 0.16.0 → 0.17.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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/Makefile +6 -0
  4. data/README.md +1 -1
  5. data/config.yml +50 -35
  6. data/docs/fuzzing.md +1 -1
  7. data/docs/serialization.md +28 -29
  8. data/ext/prism/api_node.c +802 -770
  9. data/ext/prism/api_pack.c +20 -9
  10. data/ext/prism/extension.c +464 -162
  11. data/ext/prism/extension.h +1 -1
  12. data/include/prism/ast.h +3173 -763
  13. data/include/prism/defines.h +32 -9
  14. data/include/prism/diagnostic.h +36 -3
  15. data/include/prism/enc/pm_encoding.h +118 -28
  16. data/include/prism/node.h +38 -13
  17. data/include/prism/options.h +204 -0
  18. data/include/prism/pack.h +44 -33
  19. data/include/prism/parser.h +445 -200
  20. data/include/prism/prettyprint.h +12 -1
  21. data/include/prism/regexp.h +16 -2
  22. data/include/prism/util/pm_buffer.h +94 -16
  23. data/include/prism/util/pm_char.h +162 -48
  24. data/include/prism/util/pm_constant_pool.h +126 -32
  25. data/include/prism/util/pm_list.h +68 -38
  26. data/include/prism/util/pm_memchr.h +18 -3
  27. data/include/prism/util/pm_newline_list.h +70 -27
  28. data/include/prism/util/pm_state_stack.h +25 -7
  29. data/include/prism/util/pm_string.h +115 -27
  30. data/include/prism/util/pm_string_list.h +25 -6
  31. data/include/prism/util/pm_strncasecmp.h +32 -0
  32. data/include/prism/util/pm_strpbrk.h +31 -17
  33. data/include/prism/version.h +27 -2
  34. data/include/prism.h +224 -31
  35. data/lib/prism/compiler.rb +6 -3
  36. data/lib/prism/debug.rb +23 -7
  37. data/lib/prism/dispatcher.rb +33 -18
  38. data/lib/prism/dsl.rb +10 -5
  39. data/lib/prism/ffi.rb +132 -80
  40. data/lib/prism/lex_compat.rb +25 -15
  41. data/lib/prism/mutation_compiler.rb +10 -5
  42. data/lib/prism/node.rb +370 -135
  43. data/lib/prism/node_ext.rb +1 -1
  44. data/lib/prism/node_inspector.rb +1 -1
  45. data/lib/prism/pack.rb +79 -40
  46. data/lib/prism/parse_result/comments.rb +7 -2
  47. data/lib/prism/parse_result/newlines.rb +4 -0
  48. data/lib/prism/parse_result.rb +150 -30
  49. data/lib/prism/pattern.rb +11 -0
  50. data/lib/prism/ripper_compat.rb +28 -10
  51. data/lib/prism/serialize.rb +86 -54
  52. data/lib/prism/visitor.rb +10 -3
  53. data/lib/prism.rb +20 -2
  54. data/prism.gemspec +4 -2
  55. data/rbi/prism.rbi +104 -60
  56. data/rbi/prism_static.rbi +16 -2
  57. data/sig/prism.rbs +72 -43
  58. data/sig/prism_static.rbs +14 -1
  59. data/src/diagnostic.c +56 -53
  60. data/src/enc/pm_big5.c +1 -0
  61. data/src/enc/pm_euc_jp.c +1 -0
  62. data/src/enc/pm_gbk.c +1 -0
  63. data/src/enc/pm_shift_jis.c +1 -0
  64. data/src/enc/pm_tables.c +316 -80
  65. data/src/enc/pm_unicode.c +53 -8
  66. data/src/enc/pm_windows_31j.c +1 -0
  67. data/src/node.c +334 -321
  68. data/src/options.c +170 -0
  69. data/src/prettyprint.c +74 -47
  70. data/src/prism.c +1642 -856
  71. data/src/regexp.c +151 -95
  72. data/src/serialize.c +44 -20
  73. data/src/token_type.c +3 -1
  74. data/src/util/pm_buffer.c +45 -15
  75. data/src/util/pm_char.c +103 -57
  76. data/src/util/pm_constant_pool.c +51 -21
  77. data/src/util/pm_list.c +12 -4
  78. data/src/util/pm_memchr.c +5 -3
  79. data/src/util/pm_newline_list.c +20 -12
  80. data/src/util/pm_state_stack.c +9 -3
  81. data/src/util/pm_string.c +95 -85
  82. data/src/util/pm_string_list.c +14 -15
  83. data/src/util/pm_strncasecmp.c +10 -3
  84. data/src/util/pm_strpbrk.c +25 -19
  85. metadata +5 -3
  86. data/docs/prism.png +0 -0
data/include/prism/pack.h CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @file pack.h
3
+ *
4
+ * A pack template string parser.
5
+ */
1
6
  #ifndef PRISM_PACK_H
2
7
  #define PRISM_PACK_H
3
8
 
@@ -6,15 +11,18 @@
6
11
  #include <stdint.h>
7
12
  #include <stdlib.h>
8
13
 
14
+ /** The version of the pack template language that we are parsing. */
9
15
  typedef enum pm_pack_version {
10
16
  PM_PACK_VERSION_3_2_0
11
17
  } pm_pack_version;
12
18
 
19
+ /** The type of pack template we are parsing. */
13
20
  typedef enum pm_pack_variant {
14
21
  PM_PACK_VARIANT_PACK,
15
22
  PM_PACK_VARIANT_UNPACK
16
23
  } pm_pack_variant;
17
24
 
25
+ /** A directive within the pack template. */
18
26
  typedef enum pm_pack_type {
19
27
  PM_PACK_SPACE,
20
28
  PM_PACK_COMMENT,
@@ -40,12 +48,14 @@ typedef enum pm_pack_type {
40
48
  PM_PACK_END
41
49
  } pm_pack_type;
42
50
 
51
+ /** The signness of a pack directive. */
43
52
  typedef enum pm_pack_signed {
44
53
  PM_PACK_UNSIGNED,
45
54
  PM_PACK_SIGNED,
46
55
  PM_PACK_SIGNED_NA
47
56
  } pm_pack_signed;
48
57
 
58
+ /** The endianness of a pack directive. */
49
59
  typedef enum pm_pack_endian {
50
60
  PM_PACK_AGNOSTIC_ENDIAN,
51
61
  PM_PACK_LITTLE_ENDIAN, // aka 'VAX', or 'V'
@@ -54,6 +64,7 @@ typedef enum pm_pack_endian {
54
64
  PM_PACK_ENDIAN_NA
55
65
  } pm_pack_endian;
56
66
 
67
+ /** The size of an integer pack directive. */
57
68
  typedef enum pm_pack_size {
58
69
  PM_PACK_SIZE_SHORT,
59
70
  PM_PACK_SIZE_INT,
@@ -67,6 +78,7 @@ typedef enum pm_pack_size {
67
78
  PM_PACK_SIZE_NA
68
79
  } pm_pack_size;
69
80
 
81
+ /** The type of length of a pack directive. */
70
82
  typedef enum pm_pack_length_type {
71
83
  PM_PACK_LENGTH_FIXED,
72
84
  PM_PACK_LENGTH_MAX,
@@ -74,6 +86,7 @@ typedef enum pm_pack_length_type {
74
86
  PM_PACK_LENGTH_NA
75
87
  } pm_pack_length_type;
76
88
 
89
+ /** The type of encoding for a pack template string. */
77
90
  typedef enum pm_pack_encoding {
78
91
  PM_PACK_ENCODING_START,
79
92
  PM_PACK_ENCODING_ASCII_8BIT,
@@ -81,6 +94,7 @@ typedef enum pm_pack_encoding {
81
94
  PM_PACK_ENCODING_UTF_8
82
95
  } pm_pack_encoding;
83
96
 
97
+ /** The result of parsing a pack template. */
84
98
  typedef enum pm_pack_result {
85
99
  PM_PACK_OK,
86
100
  PM_PACK_ERROR_UNSUPPORTED_DIRECTIVE,
@@ -90,39 +104,31 @@ typedef enum pm_pack_result {
90
104
  PM_PACK_ERROR_DOUBLE_ENDIAN
91
105
  } pm_pack_result;
92
106
 
93
- // Parse a single directive from a pack or unpack format string.
94
- //
95
- // Parameters:
96
- // - [in] pm_pack_version version the version of Ruby
97
- // - [in] pm_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] pm_pack_type *type the type of the directive
103
- // - [out] pm_pack_signed *signed_type
104
- // whether the value is signed
105
- // - [out] pm_pack_endian *endian the endianness of the value
106
- // - [out] pm_pack_size *size the size of the value
107
- // - [out] pm_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] pm_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
- // PM_PACK_ENCODING_START when pm_pack_parse is called for the first
115
- // directive in a format string
116
- //
117
- // Return:
118
- // - PM_PACK_OK on success
119
- // - PM_PACK_ERROR_* on error
120
- //
121
- // Notes:
122
- // Consult Ruby documentation for the meaning of directives.
107
+ /**
108
+ * Parse a single directive from a pack or unpack format string.
109
+ *
110
+ * @param variant (in) pack or unpack
111
+ * @param format (in, out) the start of the next directive to parse on calling,
112
+ * and advanced beyond the parsed directive on return, or as much of it as
113
+ * was consumed until an error was encountered
114
+ * @param format_end (in) the end of the format string
115
+ * @param type (out) the type of the directive
116
+ * @param signed_type (out) whether the value is signed
117
+ * @param endian (out) the endianness of the value
118
+ * @param size (out) the size of the value
119
+ * @param length_type (out) what kind of length is specified
120
+ * @param length (out) the length of the directive
121
+ * @param encoding (in, out) takes the current encoding of the string which
122
+ * would result from parsing the whole format string, and returns a possibly
123
+ * changed directive - the encoding should be `PM_PACK_ENCODING_START` when
124
+ * pm_pack_parse is called for the first directive in a format string
125
+ *
126
+ * @return `PM_PACK_OK` on success or `PM_PACK_ERROR_*` on error
127
+ * @note Consult Ruby documentation for the meaning of directives.
128
+ */
123
129
  PRISM_EXPORTED_FUNCTION pm_pack_result
124
130
  pm_pack_parse(
125
- pm_pack_variant variant_arg,
131
+ pm_pack_variant variant,
126
132
  const char **format,
127
133
  const char *format_end,
128
134
  pm_pack_type *type,
@@ -134,8 +140,13 @@ pm_pack_parse(
134
140
  pm_pack_encoding *encoding
135
141
  );
136
142
 
137
- // prism abstracts sizes away from the native system - this converts an abstract
138
- // size to a native size.
143
+ /**
144
+ * Prism abstracts sizes away from the native system - this converts an abstract
145
+ * size to a native size.
146
+ *
147
+ * @param size The abstract size to convert.
148
+ * @return The native size.
149
+ */
139
150
  PRISM_EXPORTED_FUNCTION size_t pm_size_to_native(pm_pack_size size);
140
151
 
141
152
  #endif