prism 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -1
- data/Makefile +2 -1
- data/README.md +1 -0
- data/config.yml +264 -37
- data/docs/parser_translation.md +8 -23
- data/docs/ripper_translation.md +1 -1
- data/ext/prism/api_node.c +2 -0
- data/ext/prism/extension.c +14 -1
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +275 -49
- data/include/prism/diagnostic.h +4 -0
- data/include/prism/options.h +43 -3
- data/include/prism/regexp.h +2 -2
- data/include/prism/util/pm_buffer.h +8 -0
- data/include/prism/util/pm_integer.h +4 -0
- data/include/prism/util/pm_list.h +6 -0
- data/include/prism/util/pm_string.h +12 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +39 -14
- data/lib/prism/compiler.rb +456 -151
- data/lib/prism/desugar_compiler.rb +1 -0
- data/lib/prism/dispatcher.rb +16 -0
- data/lib/prism/dot_visitor.rb +5 -1
- data/lib/prism/dsl.rb +3 -0
- data/lib/prism/ffi.rb +17 -7
- data/lib/prism/inspect_visitor.rb +3 -0
- data/lib/prism/lex_compat.rb +1 -0
- data/lib/prism/mutation_compiler.rb +3 -0
- data/lib/prism/node.rb +506 -335
- data/lib/prism/node_ext.rb +4 -1
- data/lib/prism/pack.rb +2 -0
- data/lib/prism/parse_result/comments.rb +1 -0
- data/lib/prism/parse_result/errors.rb +1 -0
- data/lib/prism/parse_result/newlines.rb +1 -0
- data/lib/prism/parse_result.rb +1 -0
- data/lib/prism/pattern.rb +1 -0
- data/lib/prism/polyfill/scan_byte.rb +14 -0
- data/lib/prism/polyfill/warn.rb +42 -0
- data/lib/prism/reflection.rb +3 -0
- data/lib/prism/relocation.rb +1 -0
- data/lib/prism/serialize.rb +24 -19
- data/lib/prism/string_query.rb +1 -0
- data/lib/prism/translation/parser/builder.rb +1 -0
- data/lib/prism/translation/parser/compiler.rb +47 -25
- data/lib/prism/translation/parser/lexer.rb +29 -21
- data/lib/prism/translation/parser.rb +13 -1
- data/lib/prism/translation/parser33.rb +1 -0
- data/lib/prism/translation/parser34.rb +1 -0
- data/lib/prism/translation/parser35.rb +1 -0
- data/lib/prism/translation/parser_current.rb +24 -0
- data/lib/prism/translation/ripper/sexp.rb +1 -0
- data/lib/prism/translation/ripper.rb +17 -1
- data/lib/prism/translation/ruby_parser.rb +286 -3
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +457 -152
- data/lib/prism.rb +2 -0
- data/prism.gemspec +5 -1
- data/rbi/prism/dsl.rbi +3 -3
- data/rbi/prism/node.rbi +21 -9
- data/sig/prism/dispatcher.rbs +3 -0
- data/sig/prism/dsl.rbs +3 -3
- data/sig/prism/node.rbs +444 -30
- data/sig/prism/node_ext.rbs +84 -17
- data/sig/prism/parse_result/comments.rbs +38 -0
- data/sig/prism/parse_result.rbs +4 -0
- data/sig/prism/reflection.rbs +1 -1
- data/src/diagnostic.c +7 -1
- data/src/node.c +2 -0
- data/src/options.c +2 -2
- data/src/prettyprint.c +2 -0
- data/src/prism.c +252 -130
- data/src/serialize.c +2 -0
- data/src/token_type.c +36 -34
- metadata +6 -2
data/sig/prism/node_ext.rbs
CHANGED
@@ -1,46 +1,40 @@
|
|
1
1
|
module Prism
|
2
|
+
class Node
|
3
|
+
def deprecated: (*String replacements) -> void
|
4
|
+
end
|
5
|
+
|
2
6
|
class InterpolatedMatchLastLineNode < Node
|
3
|
-
# Returns a numeric value that represents the flags that were used to create
|
4
|
-
# the regular expression.
|
5
7
|
def options: () -> Integer
|
6
8
|
end
|
7
9
|
|
8
10
|
class InterpolatedRegularExpressionNode < Node
|
9
|
-
# Returns a numeric value that represents the flags that were used to create
|
10
|
-
# the regular expression.
|
11
11
|
def options: () -> Integer
|
12
12
|
end
|
13
13
|
|
14
14
|
class MatchLastLineNode < Node
|
15
|
-
# Returns a numeric value that represents the flags that were used to create
|
16
|
-
# the regular expression.
|
17
15
|
def options: () -> Integer
|
18
16
|
end
|
19
17
|
|
20
18
|
class RegularExpressionNode < Node
|
21
|
-
# Returns a numeric value that represents the flags that were used to create
|
22
|
-
# the regular expression.
|
23
19
|
def options: () -> Integer
|
24
20
|
end
|
25
21
|
|
26
22
|
class InterpolatedStringNode < Node
|
27
|
-
|
28
|
-
def heredoc?: () -> bool?
|
23
|
+
def heredoc?: () -> bool
|
29
24
|
end
|
30
25
|
|
31
26
|
class InterpolatedXStringNode < Node
|
32
|
-
|
33
|
-
def heredoc?: () -> bool?
|
27
|
+
def heredoc?: () -> bool
|
34
28
|
end
|
35
29
|
|
36
30
|
class StringNode < Node
|
37
|
-
|
38
|
-
def
|
31
|
+
def heredoc?: () -> bool
|
32
|
+
def to_interpolated: () -> InterpolatedStringNode
|
39
33
|
end
|
40
34
|
|
41
35
|
class XStringNode < Node
|
42
|
-
|
43
|
-
def
|
36
|
+
def heredoc?: () -> bool
|
37
|
+
def to_interpolated: () -> InterpolatedXStringNode
|
44
38
|
end
|
45
39
|
|
46
40
|
class ImaginaryNode < Node
|
@@ -49,10 +43,16 @@ module Prism
|
|
49
43
|
|
50
44
|
class RationalNode < Node
|
51
45
|
def value: () -> Rational
|
46
|
+
def numeric: () -> (IntegerNode | FloatNode)
|
52
47
|
end
|
53
48
|
|
54
49
|
class ConstantReadNode < Node
|
55
|
-
def full_name_parts: () -> [Symbol]
|
50
|
+
def full_name_parts: () -> Array[Symbol]
|
51
|
+
def full_name: () -> String
|
52
|
+
end
|
53
|
+
|
54
|
+
class ConstantWriteNode < Node
|
55
|
+
def full_name_parts: () -> Array[Symbol]
|
56
56
|
def full_name: () -> String
|
57
57
|
end
|
58
58
|
|
@@ -65,11 +65,18 @@ module Prism
|
|
65
65
|
|
66
66
|
def full_name_parts: () -> Array[Symbol]
|
67
67
|
def full_name: () -> String
|
68
|
+
def child: () -> (ConstantReadNode | MissingNode)
|
68
69
|
end
|
69
70
|
|
70
71
|
class ConstantPathTargetNode < Node
|
71
72
|
def full_name_parts: () -> Array[Symbol]
|
72
73
|
def full_name: () -> String
|
74
|
+
def child: () -> (ConstantReadNode | MissingNode)
|
75
|
+
end
|
76
|
+
|
77
|
+
class ConstantTargetNode < Node
|
78
|
+
def full_name_parts: () -> Array[Symbol]
|
79
|
+
def full_name: () -> String
|
73
80
|
end
|
74
81
|
|
75
82
|
class ParametersNode < Node
|
@@ -79,4 +86,64 @@ module Prism
|
|
79
86
|
class CallNode < Node
|
80
87
|
def full_message_loc: () -> Location?
|
81
88
|
end
|
89
|
+
|
90
|
+
class CallOperatorWriteNode < Node
|
91
|
+
def operator: () -> Symbol
|
92
|
+
def operator_loc: () -> Location
|
93
|
+
end
|
94
|
+
|
95
|
+
class ClassVariableOperatorWriteNode < Node
|
96
|
+
def operator: () -> Symbol
|
97
|
+
def operator_loc: () -> Location
|
98
|
+
end
|
99
|
+
|
100
|
+
class ConstantOperatorWriteNode < Node
|
101
|
+
def operator: () -> Symbol
|
102
|
+
def operator_loc: () -> Location
|
103
|
+
end
|
104
|
+
|
105
|
+
class ConstantPathOperatorWriteNode < Node
|
106
|
+
def operator: () -> Symbol
|
107
|
+
def operator_loc: () -> Location
|
108
|
+
end
|
109
|
+
|
110
|
+
class GlobalVariableOperatorWriteNode < Node
|
111
|
+
def operator: () -> Symbol
|
112
|
+
def operator_loc: () -> Location
|
113
|
+
end
|
114
|
+
|
115
|
+
class IndexOperatorWriteNode < Node
|
116
|
+
def operator: () -> Symbol
|
117
|
+
def operator_loc: () -> Location
|
118
|
+
end
|
119
|
+
|
120
|
+
class InstanceVariableOperatorWriteNode < Node
|
121
|
+
def operator: () -> Symbol
|
122
|
+
def operator_loc: () -> Location
|
123
|
+
end
|
124
|
+
|
125
|
+
class LocalVariableOperatorWriteNode < Node
|
126
|
+
def operator: () -> Symbol
|
127
|
+
def operator_loc: () -> Location
|
128
|
+
end
|
129
|
+
|
130
|
+
class CaseMatchNode < Node
|
131
|
+
def consequent: () -> ElseNode?
|
132
|
+
end
|
133
|
+
|
134
|
+
class CaseNode < Node
|
135
|
+
def consequent: () -> ElseNode?
|
136
|
+
end
|
137
|
+
|
138
|
+
class IfNode < Node
|
139
|
+
def consequent: () -> (ElseNode | IfNode | nil)
|
140
|
+
end
|
141
|
+
|
142
|
+
class RescueNode < Node
|
143
|
+
def consequent: () -> RescueNode?
|
144
|
+
end
|
145
|
+
|
146
|
+
class UnlessNode < Node
|
147
|
+
def consequent: () -> ElseNode?
|
148
|
+
end
|
82
149
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Prism
|
2
|
+
class ParseResult < Result
|
3
|
+
class Comments
|
4
|
+
interface _Target
|
5
|
+
def start_offset: () -> Integer
|
6
|
+
def end_offset: () -> Integer
|
7
|
+
def encloses?: (comment) -> bool
|
8
|
+
def leading_comment: (comment) -> void
|
9
|
+
def trailing_comment: (comment) -> void
|
10
|
+
end
|
11
|
+
|
12
|
+
class NodeTarget
|
13
|
+
include _Target
|
14
|
+
|
15
|
+
attr_reader node: node
|
16
|
+
|
17
|
+
def initialize: (node) -> void
|
18
|
+
end
|
19
|
+
|
20
|
+
class LocationTarget
|
21
|
+
include _Target
|
22
|
+
|
23
|
+
attr_reader location: Location
|
24
|
+
|
25
|
+
def initialize: (Location location) -> void
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader parse_result: ParseResult
|
29
|
+
|
30
|
+
def initialize: (ParseResult parse_result) -> void
|
31
|
+
def attach!: () -> void
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def nearest_targets: (node, comment) -> [_Target?, _Target, _Target?]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/sig/prism/parse_result.rbs
CHANGED
@@ -24,6 +24,7 @@ module Prism
|
|
24
24
|
def code_units_offset: (Integer byte_offset, Encoding encoding) -> Integer
|
25
25
|
def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
|
26
26
|
def code_units_column: (Integer byte_offset, Encoding encoding) -> Integer
|
27
|
+
def deep_freeze: () -> void
|
27
28
|
|
28
29
|
def self.for: (String source) -> Source
|
29
30
|
end
|
@@ -145,6 +146,7 @@ module Prism
|
|
145
146
|
|
146
147
|
def initialize: (Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
|
147
148
|
def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
|
149
|
+
def encoding: () -> Encoding
|
148
150
|
def success?: () -> bool
|
149
151
|
def failure?: () -> bool
|
150
152
|
def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
|
@@ -155,6 +157,7 @@ module Prism
|
|
155
157
|
|
156
158
|
def initialize: (ProgramNode value, Array[comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, Source source) -> void
|
157
159
|
def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
|
160
|
+
def errors_format: () -> String
|
158
161
|
end
|
159
162
|
|
160
163
|
class LexResult < Result
|
@@ -181,6 +184,7 @@ module Prism
|
|
181
184
|
def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped]
|
182
185
|
def pretty_print: (untyped q) -> untyped
|
183
186
|
def ==: (untyped other) -> bool
|
187
|
+
def deep_freeze: () -> void
|
184
188
|
end
|
185
189
|
|
186
190
|
class Scope
|
data/sig/prism/reflection.rbs
CHANGED
data/src/diagnostic.c
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/* :markup: markdown */
|
2
|
+
|
1
3
|
/*----------------------------------------------------------------------------*/
|
2
4
|
/* This file is generated by the templates/template.rb script and should not */
|
3
5
|
/* be modified manually. See */
|
@@ -8,7 +10,7 @@
|
|
8
10
|
|
9
11
|
#include "prism/diagnostic.h"
|
10
12
|
|
11
|
-
#define PM_DIAGNOSTIC_ID_MAX
|
13
|
+
#define PM_DIAGNOSTIC_ID_MAX 321
|
12
14
|
|
13
15
|
/** This struct holds the data for each diagnostic. */
|
14
16
|
typedef struct {
|
@@ -192,6 +194,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
192
194
|
[PM_ERR_EXPECT_FOR_DELIMITER] = { "unexpected %s; expected a 'do', newline, or ';' after the 'for' loop collection", PM_ERROR_LEVEL_SYNTAX },
|
193
195
|
[PM_ERR_EXPECT_IDENT_REQ_PARAMETER] = { "expected an identifier for the required parameter", PM_ERROR_LEVEL_SYNTAX },
|
194
196
|
[PM_ERR_EXPECT_IN_DELIMITER] = { "expected a delimiter after the patterns of an `in` clause", PM_ERROR_LEVEL_SYNTAX },
|
197
|
+
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN] = { "expected a `(` immediately after `not`", PM_ERROR_LEVEL_SYNTAX },
|
198
|
+
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER] = { "expected a `(` after `not`", PM_ERROR_LEVEL_SYNTAX },
|
195
199
|
[PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX },
|
196
200
|
[PM_ERR_EXPECT_MESSAGE] = { "unexpected %s; expecting a message to send to the receiver", PM_ERROR_LEVEL_SYNTAX },
|
197
201
|
[PM_ERR_EXPECT_RBRACKET] = { "expected a matching `]`", PM_ERROR_LEVEL_SYNTAX },
|
@@ -519,6 +523,8 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
519
523
|
case PM_ERR_EXPECT_FOR_DELIMITER: return "expect_for_delimiter";
|
520
524
|
case PM_ERR_EXPECT_IDENT_REQ_PARAMETER: return "expect_ident_req_parameter";
|
521
525
|
case PM_ERR_EXPECT_IN_DELIMITER: return "expect_in_delimiter";
|
526
|
+
case PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN: return "expect_lparen_after_not_lparen";
|
527
|
+
case PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER: return "expect_lparen_after_not_other";
|
522
528
|
case PM_ERR_EXPECT_LPAREN_REQ_PARAMETER: return "expect_lparen_req_parameter";
|
523
529
|
case PM_ERR_EXPECT_MESSAGE: return "expect_message";
|
524
530
|
case PM_ERR_EXPECT_RBRACKET: return "expect_rbracket";
|
data/src/node.c
CHANGED
data/src/options.c
CHANGED
@@ -89,7 +89,7 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
89
89
|
}
|
90
90
|
|
91
91
|
if (strncmp(version, "3.5", 3) == 0) {
|
92
|
-
options->version =
|
92
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
|
93
93
|
return true;
|
94
94
|
}
|
95
95
|
|
@@ -108,7 +108,7 @@ pm_options_version_set(pm_options_t *options, const char *version, size_t length
|
|
108
108
|
}
|
109
109
|
|
110
110
|
if (strncmp(version, "3.5.", 4) == 0 && is_number(version + 4, length - 4)) {
|
111
|
-
options->version =
|
111
|
+
options->version = PM_OPTIONS_VERSION_CRUBY_3_5;
|
112
112
|
return true;
|
113
113
|
}
|
114
114
|
}
|