prism 1.1.0 → 1.3.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 +39 -1
- data/Makefile +1 -1
- data/config.yml +422 -3
- data/docs/build_system.md +8 -11
- data/docs/relocation.md +34 -0
- data/ext/prism/api_node.c +18 -10
- data/ext/prism/extconf.rb +13 -36
- data/ext/prism/extension.c +68 -0
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +427 -3
- data/include/prism/defines.h +22 -7
- data/include/prism/diagnostic.h +1 -0
- data/include/prism/parser.h +25 -12
- data/include/prism/version.h +2 -2
- data/include/prism.h +47 -0
- data/lib/prism/dot_visitor.rb +10 -0
- data/lib/prism/dsl.rb +4 -4
- data/lib/prism/ffi.rb +49 -2
- data/lib/prism/inspect_visitor.rb +2 -0
- data/lib/prism/node.rb +1839 -96
- data/lib/prism/parse_result/errors.rb +1 -1
- data/lib/prism/parse_result.rb +140 -3
- data/lib/prism/reflection.rb +2 -2
- data/lib/prism/relocation.rb +504 -0
- data/lib/prism/serialize.rb +17 -5
- data/lib/prism/string_query.rb +30 -0
- data/lib/prism/translation/parser/compiler.rb +36 -26
- data/lib/prism/translation/parser.rb +3 -3
- data/lib/prism/translation/ripper.rb +1 -5
- data/lib/prism/translation/ruby_parser.rb +14 -5
- data/lib/prism.rb +6 -4
- data/prism.gemspec +7 -1
- data/rbi/prism/dsl.rbi +4 -4
- data/rbi/prism/node.rbi +5118 -1030
- data/rbi/prism/parse_result.rbi +29 -0
- data/rbi/prism/string_query.rbi +12 -0
- data/rbi/prism.rbi +34 -34
- data/sig/prism/dsl.rbs +2 -2
- data/sig/prism/node.rbs +13 -98
- data/sig/prism/parse_result.rbs +20 -0
- data/sig/prism/relocation.rbs +185 -0
- data/sig/prism/string_query.rbs +11 -0
- data/src/diagnostic.c +3 -1
- data/src/node.c +18 -0
- data/src/prettyprint.c +32 -0
- data/src/prism.c +586 -195
- data/src/regexp.c +7 -3
- data/src/serialize.c +12 -0
- data/src/static_literals.c +1 -1
- data/src/util/pm_char.c +1 -1
- data/src/util/pm_string.c +1 -0
- metadata +9 -3
@@ -0,0 +1,185 @@
|
|
1
|
+
module Prism
|
2
|
+
module Relocation
|
3
|
+
interface _Value
|
4
|
+
def start_line: () -> Integer
|
5
|
+
def end_line: () -> Integer
|
6
|
+
def start_offset: () -> Integer
|
7
|
+
def end_offset: () -> Integer
|
8
|
+
def start_character_offset: () -> Integer
|
9
|
+
def end_character_offset: () -> Integer
|
10
|
+
def cached_start_code_units_offset: (_CodeUnitsCache cache) -> Integer
|
11
|
+
def cached_end_code_units_offset: (_CodeUnitsCache cache) -> Integer
|
12
|
+
def start_column: () -> Integer
|
13
|
+
def end_column: () -> Integer
|
14
|
+
def start_character_column: () -> Integer
|
15
|
+
def end_character_column: () -> Integer
|
16
|
+
def cached_start_code_units_column: (_CodeUnitsCache cache) -> Integer
|
17
|
+
def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer
|
18
|
+
def leading_comments: () -> Array[Comment]
|
19
|
+
def trailing_comments: () -> Array[Comment]
|
20
|
+
end
|
21
|
+
|
22
|
+
interface _Field
|
23
|
+
def fields: (_Value value) -> entry_values
|
24
|
+
end
|
25
|
+
|
26
|
+
type entry_value = untyped
|
27
|
+
type entry_values = Hash[Symbol, entry_value]
|
28
|
+
|
29
|
+
class Entry
|
30
|
+
class MissingValueError < StandardError
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize: (Repository repository) -> void
|
34
|
+
|
35
|
+
def filepath: () -> String
|
36
|
+
|
37
|
+
def start_line: () -> Integer
|
38
|
+
def end_line: () -> Integer
|
39
|
+
|
40
|
+
def start_offset: () -> Integer
|
41
|
+
def end_offset: () -> Integer
|
42
|
+
def start_character_offset: () -> Integer
|
43
|
+
def end_character_offset: () -> Integer
|
44
|
+
def start_code_units_offset: () -> Integer
|
45
|
+
def end_code_units_offset: () -> Integer
|
46
|
+
|
47
|
+
def start_column: () -> Integer
|
48
|
+
def end_column: () -> Integer
|
49
|
+
def start_character_column: () -> Integer
|
50
|
+
def end_character_column: () -> Integer
|
51
|
+
def start_code_units_column: () -> Integer
|
52
|
+
def end_code_units_column: () -> Integer
|
53
|
+
|
54
|
+
def leading_comments: () -> Array[CommentsField::Comment]
|
55
|
+
def trailing_comments: () -> Array[CommentsField::Comment]
|
56
|
+
def comments: () -> Array[CommentsField::Comment]
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def fetch_value: (Symbol name) -> entry_value
|
61
|
+
def values: () -> entry_values
|
62
|
+
end
|
63
|
+
|
64
|
+
class Source
|
65
|
+
attr_reader value: untyped
|
66
|
+
|
67
|
+
def initialize: (untyped value) -> void
|
68
|
+
|
69
|
+
def result: () -> ParseResult
|
70
|
+
def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
|
71
|
+
end
|
72
|
+
|
73
|
+
class SourceFilepath < Source
|
74
|
+
def result: () -> ParseResult
|
75
|
+
end
|
76
|
+
|
77
|
+
class SourceString < Source
|
78
|
+
def result: () -> ParseResult
|
79
|
+
end
|
80
|
+
|
81
|
+
class FilepathField
|
82
|
+
attr_reader value: String
|
83
|
+
|
84
|
+
def initialize: (String value) -> void
|
85
|
+
|
86
|
+
def fields: (_Value value) -> entry_values
|
87
|
+
end
|
88
|
+
|
89
|
+
class LinesField
|
90
|
+
def fields: (_Value value) -> entry_values
|
91
|
+
end
|
92
|
+
|
93
|
+
class OffsetsField
|
94
|
+
def fields: (_Value value) -> entry_values
|
95
|
+
end
|
96
|
+
|
97
|
+
class CharacterOffsetsField
|
98
|
+
def fields: (_Value value) -> entry_values
|
99
|
+
end
|
100
|
+
|
101
|
+
class CodeUnitOffsetsField
|
102
|
+
attr_reader repository: Repository
|
103
|
+
attr_reader encoding: Encoding
|
104
|
+
|
105
|
+
def initialize: (Repository repository, Encoding encoding) -> void
|
106
|
+
def fields: (_Value value) -> entry_values
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def cache: () -> _CodeUnitsCache
|
111
|
+
end
|
112
|
+
|
113
|
+
class ColumnsField
|
114
|
+
def fields: (_Value value) -> entry_values
|
115
|
+
end
|
116
|
+
|
117
|
+
class CharacterColumnsField
|
118
|
+
def fields: (_Value value) -> entry_values
|
119
|
+
end
|
120
|
+
|
121
|
+
class CodeUnitColumnsField
|
122
|
+
attr_reader repository: Repository
|
123
|
+
attr_reader encoding: Encoding
|
124
|
+
|
125
|
+
def initialize: (Repository repository, Encoding encoding) -> void
|
126
|
+
def fields: (_Value value) -> entry_values
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def cache: () -> _CodeUnitsCache
|
131
|
+
end
|
132
|
+
|
133
|
+
class CommentsField
|
134
|
+
class Comment
|
135
|
+
attr_reader slice: String
|
136
|
+
|
137
|
+
def initialize: (String slice) -> void
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def comments: (entry_value value) -> Array[Comment]
|
143
|
+
end
|
144
|
+
|
145
|
+
class LeadingCommentsField < CommentsField
|
146
|
+
def fields: (_Value value) -> entry_values
|
147
|
+
end
|
148
|
+
|
149
|
+
class TrailingCommentsField < CommentsField
|
150
|
+
def fields: (_Value value) -> entry_values
|
151
|
+
end
|
152
|
+
|
153
|
+
class Repository
|
154
|
+
class ConfigurationError < StandardError
|
155
|
+
end
|
156
|
+
|
157
|
+
attr_reader source: Source
|
158
|
+
attr_reader fields: Hash[Symbol, _Field]
|
159
|
+
attr_reader entries: Hash[Integer, Hash[Symbol, Entry]]
|
160
|
+
|
161
|
+
def initialize: (Source source) -> void
|
162
|
+
|
163
|
+
def code_units_cache: (Encoding encoding) -> _CodeUnitsCache
|
164
|
+
|
165
|
+
def filepath: () -> self
|
166
|
+
def lines: () -> self
|
167
|
+
def offsets: () -> self
|
168
|
+
def character_offsets: () -> self
|
169
|
+
def code_unit_offsets: (Encoding encoding) -> self
|
170
|
+
def columns: () -> self
|
171
|
+
def character_columns: () -> self
|
172
|
+
def code_unit_columns: (Encoding encoding) -> self
|
173
|
+
def leading_comments: () -> self
|
174
|
+
def trailing_comments: () -> self
|
175
|
+
def comments: () -> self
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def field: (Symbol name, _Field) -> self
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.filepath: (String value) -> Repository
|
183
|
+
def self.string: (String value) -> Repository
|
184
|
+
end
|
185
|
+
end
|
data/src/diagnostic.c
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
#include "prism/diagnostic.h"
|
10
10
|
|
11
|
-
#define PM_DIAGNOSTIC_ID_MAX
|
11
|
+
#define PM_DIAGNOSTIC_ID_MAX 319
|
12
12
|
|
13
13
|
/** This struct holds the data for each diagnostic. */
|
14
14
|
typedef struct {
|
@@ -231,6 +231,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|
231
231
|
[PM_ERR_INCOMPLETE_VARIABLE_INSTANCE] = { "'%.*s' is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
232
232
|
[PM_ERR_INSTANCE_VARIABLE_BARE] = { "'@' without identifiers is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
233
233
|
[PM_ERR_INVALID_BLOCK_EXIT] = { "Invalid %s", PM_ERROR_LEVEL_SYNTAX },
|
234
|
+
[PM_ERR_INVALID_COMMA] = { "invalid comma", PM_ERROR_LEVEL_SYNTAX },
|
234
235
|
[PM_ERR_INVALID_ESCAPE_CHARACTER] = { "Invalid escape character syntax", PM_ERROR_LEVEL_SYNTAX },
|
235
236
|
[PM_ERR_INVALID_FLOAT_EXPONENT] = { "invalid exponent", PM_ERROR_LEVEL_SYNTAX },
|
236
237
|
[PM_ERR_INVALID_LOCAL_VARIABLE_READ] = { "identifier %.*s is not valid to get", PM_ERROR_LEVEL_SYNTAX },
|
@@ -558,6 +559,7 @@ pm_diagnostic_id_human(pm_diagnostic_id_t diag_id) {
|
|
558
559
|
case PM_ERR_INSTANCE_VARIABLE_BARE: return "instance_variable_bare";
|
559
560
|
case PM_ERR_INVALID_BLOCK_EXIT: return "invalid_block_exit";
|
560
561
|
case PM_ERR_INVALID_CHARACTER: return "invalid_character";
|
562
|
+
case PM_ERR_INVALID_COMMA: return "invalid_comma";
|
561
563
|
case PM_ERR_INVALID_ENCODING_MAGIC_COMMENT: return "invalid_encoding_magic_comment";
|
562
564
|
case PM_ERR_INVALID_ESCAPE_CHARACTER: return "invalid_escape_character";
|
563
565
|
case PM_ERR_INVALID_FLOAT_EXPONENT: return "invalid_float_exponent";
|
data/src/node.c
CHANGED
@@ -8418,6 +8418,15 @@ pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *no
|
|
8418
8418
|
pm_buffer_append_string(buffer, "\"keyword_loc\":", 14);
|
8419
8419
|
pm_dump_json_location(buffer, parser, &cast->keyword_loc);
|
8420
8420
|
|
8421
|
+
// Dump the do_keyword_loc field
|
8422
|
+
pm_buffer_append_byte(buffer, ',');
|
8423
|
+
pm_buffer_append_string(buffer, "\"do_keyword_loc\":", 17);
|
8424
|
+
if (cast->do_keyword_loc.start != NULL) {
|
8425
|
+
pm_dump_json_location(buffer, parser, &cast->do_keyword_loc);
|
8426
|
+
} else {
|
8427
|
+
pm_buffer_append_string(buffer, "null", 4);
|
8428
|
+
}
|
8429
|
+
|
8421
8430
|
// Dump the closing_loc field
|
8422
8431
|
pm_buffer_append_byte(buffer, ',');
|
8423
8432
|
pm_buffer_append_string(buffer, "\"closing_loc\":", 14);
|
@@ -8511,6 +8520,15 @@ pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *no
|
|
8511
8520
|
pm_buffer_append_string(buffer, "\"keyword_loc\":", 14);
|
8512
8521
|
pm_dump_json_location(buffer, parser, &cast->keyword_loc);
|
8513
8522
|
|
8523
|
+
// Dump the do_keyword_loc field
|
8524
|
+
pm_buffer_append_byte(buffer, ',');
|
8525
|
+
pm_buffer_append_string(buffer, "\"do_keyword_loc\":", 17);
|
8526
|
+
if (cast->do_keyword_loc.start != NULL) {
|
8527
|
+
pm_dump_json_location(buffer, parser, &cast->do_keyword_loc);
|
8528
|
+
} else {
|
8529
|
+
pm_buffer_append_string(buffer, "null", 4);
|
8530
|
+
}
|
8531
|
+
|
8514
8532
|
// Dump the closing_loc field
|
8515
8533
|
pm_buffer_append_byte(buffer, ',');
|
8516
8534
|
pm_buffer_append_string(buffer, "\"closing_loc\":", 14);
|
data/src/prettyprint.c
CHANGED
@@ -8521,6 +8521,22 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
|
|
8521
8521
|
pm_buffer_append_string(output_buffer, "\"\n", 2);
|
8522
8522
|
}
|
8523
8523
|
|
8524
|
+
// do_keyword_loc
|
8525
|
+
{
|
8526
|
+
pm_buffer_concat(output_buffer, prefix_buffer);
|
8527
|
+
pm_buffer_append_string(output_buffer, "+-- do_keyword_loc:", 19);
|
8528
|
+
pm_location_t *location = &cast->do_keyword_loc;
|
8529
|
+
if (location->start == NULL) {
|
8530
|
+
pm_buffer_append_string(output_buffer, " nil\n", 5);
|
8531
|
+
} else {
|
8532
|
+
pm_buffer_append_byte(output_buffer, ' ');
|
8533
|
+
prettyprint_location(output_buffer, parser, location);
|
8534
|
+
pm_buffer_append_string(output_buffer, " = \"", 4);
|
8535
|
+
pm_buffer_append_source(output_buffer, location->start, (size_t) (location->end - location->start), PM_BUFFER_ESCAPING_RUBY);
|
8536
|
+
pm_buffer_append_string(output_buffer, "\"\n", 2);
|
8537
|
+
}
|
8538
|
+
}
|
8539
|
+
|
8524
8540
|
// closing_loc
|
8525
8541
|
{
|
8526
8542
|
pm_buffer_concat(output_buffer, prefix_buffer);
|
@@ -8672,6 +8688,22 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm
|
|
8672
8688
|
pm_buffer_append_string(output_buffer, "\"\n", 2);
|
8673
8689
|
}
|
8674
8690
|
|
8691
|
+
// do_keyword_loc
|
8692
|
+
{
|
8693
|
+
pm_buffer_concat(output_buffer, prefix_buffer);
|
8694
|
+
pm_buffer_append_string(output_buffer, "+-- do_keyword_loc:", 19);
|
8695
|
+
pm_location_t *location = &cast->do_keyword_loc;
|
8696
|
+
if (location->start == NULL) {
|
8697
|
+
pm_buffer_append_string(output_buffer, " nil\n", 5);
|
8698
|
+
} else {
|
8699
|
+
pm_buffer_append_byte(output_buffer, ' ');
|
8700
|
+
prettyprint_location(output_buffer, parser, location);
|
8701
|
+
pm_buffer_append_string(output_buffer, " = \"", 4);
|
8702
|
+
pm_buffer_append_source(output_buffer, location->start, (size_t) (location->end - location->start), PM_BUFFER_ESCAPING_RUBY);
|
8703
|
+
pm_buffer_append_string(output_buffer, "\"\n", 2);
|
8704
|
+
}
|
8705
|
+
}
|
8706
|
+
|
8675
8707
|
// closing_loc
|
8676
8708
|
{
|
8677
8709
|
pm_buffer_concat(output_buffer, prefix_buffer);
|