prism 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/Makefile +6 -0
- data/README.md +1 -1
- data/config.yml +50 -35
- data/docs/fuzzing.md +1 -1
- data/docs/serialization.md +28 -29
- data/ext/prism/api_node.c +802 -770
- data/ext/prism/api_pack.c +20 -9
- data/ext/prism/extension.c +464 -162
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +3173 -763
- data/include/prism/defines.h +32 -9
- data/include/prism/diagnostic.h +36 -3
- data/include/prism/enc/pm_encoding.h +118 -28
- data/include/prism/node.h +38 -13
- data/include/prism/options.h +204 -0
- data/include/prism/pack.h +44 -33
- data/include/prism/parser.h +445 -200
- data/include/prism/prettyprint.h +12 -1
- data/include/prism/regexp.h +16 -2
- data/include/prism/util/pm_buffer.h +94 -16
- data/include/prism/util/pm_char.h +162 -48
- data/include/prism/util/pm_constant_pool.h +126 -32
- data/include/prism/util/pm_list.h +68 -38
- data/include/prism/util/pm_memchr.h +18 -3
- data/include/prism/util/pm_newline_list.h +70 -27
- data/include/prism/util/pm_state_stack.h +25 -7
- data/include/prism/util/pm_string.h +115 -27
- data/include/prism/util/pm_string_list.h +25 -6
- data/include/prism/util/pm_strncasecmp.h +32 -0
- data/include/prism/util/pm_strpbrk.h +31 -17
- data/include/prism/version.h +27 -2
- data/include/prism.h +224 -31
- data/lib/prism/compiler.rb +6 -3
- data/lib/prism/debug.rb +23 -7
- data/lib/prism/dispatcher.rb +33 -18
- data/lib/prism/dsl.rb +10 -5
- data/lib/prism/ffi.rb +132 -80
- data/lib/prism/lex_compat.rb +25 -15
- data/lib/prism/mutation_compiler.rb +10 -5
- data/lib/prism/node.rb +370 -135
- data/lib/prism/node_ext.rb +1 -1
- data/lib/prism/node_inspector.rb +1 -1
- data/lib/prism/pack.rb +79 -40
- data/lib/prism/parse_result/comments.rb +7 -2
- data/lib/prism/parse_result/newlines.rb +4 -0
- data/lib/prism/parse_result.rb +150 -30
- data/lib/prism/pattern.rb +11 -0
- data/lib/prism/ripper_compat.rb +28 -10
- data/lib/prism/serialize.rb +86 -54
- data/lib/prism/visitor.rb +10 -3
- data/lib/prism.rb +20 -2
- data/prism.gemspec +4 -2
- data/rbi/prism.rbi +104 -60
- data/rbi/prism_static.rbi +16 -2
- data/sig/prism.rbs +72 -43
- data/sig/prism_static.rbs +14 -1
- data/src/diagnostic.c +56 -53
- data/src/enc/pm_big5.c +1 -0
- data/src/enc/pm_euc_jp.c +1 -0
- data/src/enc/pm_gbk.c +1 -0
- data/src/enc/pm_shift_jis.c +1 -0
- data/src/enc/pm_tables.c +316 -80
- data/src/enc/pm_unicode.c +53 -8
- data/src/enc/pm_windows_31j.c +1 -0
- data/src/node.c +334 -321
- data/src/options.c +170 -0
- data/src/prettyprint.c +74 -47
- data/src/prism.c +1642 -856
- data/src/regexp.c +151 -95
- data/src/serialize.c +44 -20
- data/src/token_type.c +3 -1
- data/src/util/pm_buffer.c +45 -15
- data/src/util/pm_char.c +103 -57
- data/src/util/pm_constant_pool.c +51 -21
- data/src/util/pm_list.c +12 -4
- data/src/util/pm_memchr.c +5 -3
- data/src/util/pm_newline_list.c +20 -12
- data/src/util/pm_state_stack.c +9 -3
- data/src/util/pm_string.c +95 -85
- data/src/util/pm_string_list.c +14 -15
- data/src/util/pm_strncasecmp.c +10 -3
- data/src/util/pm_strpbrk.c +25 -19
- metadata +5 -3
- 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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
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
|
-
|
138
|
-
|
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
|