prism 2.0.0.rc1 → 2.0.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 +13 -2
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.md +1 -1
- data/docs/serialization.md +20 -6
- data/ext/prism/api_node.c +81 -81
- data/ext/prism/extension.c +54 -69
- data/ext/prism/extension.h +1 -1
- data/include/prism/arena.h +8 -0
- data/include/prism/arena.hpp +42 -0
- data/include/prism/ast.h +11 -1
- data/include/prism/ast.hpp +641 -0
- data/include/prism/buffer.h +8 -0
- data/include/prism/buffer.hpp +55 -0
- data/include/prism/comments.h +17 -0
- data/include/prism/compiler/accel.h +3 -1
- data/include/prism/compiler/branch.h +26 -0
- data/include/prism/compiler/bswap.h +46 -0
- data/include/prism/compiler/cplusplus.hpp +16 -0
- data/include/prism/compiler/endianness.h +34 -0
- data/include/prism/compiler/exceptions.hpp +17 -0
- data/include/prism/compiler/format.h +2 -0
- data/include/prism/compiler/lifetimebound.hpp +25 -0
- data/include/prism/constant_pool.h +25 -0
- data/include/prism/diagnostic.h +18 -0
- data/include/prism/errors_format.h +8 -0
- data/include/prism/internal/buffer.h +3 -0
- data/include/prism/internal/node.h +8 -4
- data/include/prism/internal/parser.h +20 -0
- data/include/prism/internal/stringy.h +1 -6
- data/include/prism/internal/xxh3.h +16 -0
- data/include/prism/json.h +8 -0
- data/include/prism/line_offset_list.h +8 -0
- data/include/prism/magic_comments.h +18 -0
- data/include/prism/node.h +55 -10
- data/include/prism/node.hpp +272 -0
- data/include/prism/node_type.hpp +38 -0
- data/include/prism/options.h +10 -1
- data/include/prism/options.hpp +43 -0
- data/include/prism/parser.h +93 -64
- data/include/prism/parser.hpp +274 -0
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/serialize.h +8 -0
- data/include/prism/source.h +8 -0
- data/include/prism/stream.h +8 -0
- data/include/prism/string_query.h +19 -0
- data/include/prism/stringy.h +16 -27
- data/include/prism/stringy.hpp +31 -0
- data/include/prism/version.h +9 -1
- data/include/prism.h +0 -8
- data/include/prism.hpp +24 -0
- data/lib/prism/ffi.rb +6 -0
- data/lib/prism/node.rb +736 -0
- data/lib/prism/parse_result.rb +23 -8
- data/lib/prism/serialize.rb +2567 -3286
- data/lib/prism/string_query.rb +8 -0
- data/prism.gemspec +21 -4
- data/rbi/generated/prism/node.rbi +2430 -968
- data/rbi/generated/prism/parse_result.rbi +16 -4
- data/rbi/generated/prism/serialize.rbi +8 -4
- data/rbi/generated/prism/string_query.rbi +7 -0
- data/sig/generated/prism/node.rbs +2439 -967
- data/sig/generated/prism/parse_result.rbs +16 -4
- data/sig/generated/prism/serialize.rbs +9 -4
- data/sig/generated/prism/string_query.rbs +7 -0
- data/src/buffer.c +9 -0
- data/src/comments.c +2 -2
- data/src/diagnostic.c +8 -0
- data/src/node.c +216 -368
- data/src/options.c +7 -13
- data/src/parser.c +70 -48
- data/src/prism.c +581 -419
- data/src/regexp.c +0 -1
- data/src/serialize.c +2301 -1950
- data/src/source.c +8 -2
- data/src/string_query.c +14 -0
- data/src/stringy.c +3 -33
- data/src/xxh3.c +292 -0
- metadata +20 -3
data/lib/prism/parse_result.rb
CHANGED
|
@@ -34,15 +34,18 @@ module Prism
|
|
|
34
34
|
# empty when the source is created by the parser and filled in afterward,
|
|
35
35
|
# because the comments themselves refer to the source.
|
|
36
36
|
#
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
# The checksum parameter is the value described by the attribute of the same
|
|
38
|
+
# name. It is nil when the source is not created by the parser.
|
|
39
|
+
#
|
|
40
|
+
#: (String source, Integer start_line, Array[Integer] offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges, ?Integer? checksum) -> Source
|
|
41
|
+
def self.for(source, start_line, offsets, comments = [], comment_attachments = [], comment_ranges = [], checksum = nil)
|
|
39
42
|
if source.ascii_only?
|
|
40
|
-
ASCIISource.new(source, start_line, offsets, comments, comment_attachments, comment_ranges)
|
|
43
|
+
ASCIISource.new(source, start_line, offsets, comments, comment_attachments, comment_ranges, checksum)
|
|
41
44
|
elsif source.encoding == Encoding::BINARY
|
|
42
45
|
source.force_encoding(Encoding::UTF_8)
|
|
43
46
|
|
|
44
47
|
if source.valid_encoding?
|
|
45
|
-
new(source, start_line, offsets, comments, comment_attachments, comment_ranges)
|
|
48
|
+
new(source, start_line, offsets, comments, comment_attachments, comment_ranges, checksum)
|
|
46
49
|
else
|
|
47
50
|
# This is an extremely niche use case where the file is marked as
|
|
48
51
|
# binary, contains multi-byte characters, and those characters are not
|
|
@@ -51,10 +54,10 @@ module Prism
|
|
|
51
54
|
# problems when asking for code units, but it appears to be the
|
|
52
55
|
# cleanest solution at the moment.
|
|
53
56
|
source.force_encoding(Encoding::BINARY)
|
|
54
|
-
ASCIISource.new(source, start_line, offsets, comments, comment_attachments, comment_ranges)
|
|
57
|
+
ASCIISource.new(source, start_line, offsets, comments, comment_attachments, comment_ranges, checksum)
|
|
55
58
|
end
|
|
56
59
|
else
|
|
57
|
-
new(source, start_line, offsets, comments, comment_attachments, comment_ranges)
|
|
60
|
+
new(source, start_line, offsets, comments, comment_attachments, comment_ranges, checksum)
|
|
58
61
|
end
|
|
59
62
|
end
|
|
60
63
|
|
|
@@ -64,6 +67,10 @@ module Prism
|
|
|
64
67
|
# The line number where this source starts.
|
|
65
68
|
attr_reader :start_line #: Integer
|
|
66
69
|
|
|
70
|
+
# The checksum of the source code which can be used to quickly determine if
|
|
71
|
+
# the source has changed.
|
|
72
|
+
attr_reader :checksum #: Integer?
|
|
73
|
+
|
|
67
74
|
# The list of comments that were encountered during parsing. When the source
|
|
68
75
|
# is parsed with the attach_comments option, these are sorted by start
|
|
69
76
|
# offset.
|
|
@@ -95,10 +102,11 @@ module Prism
|
|
|
95
102
|
# parameter can be either an Array of Integer byte offsets or a packed
|
|
96
103
|
# binary string of uint32_t values (from the C extension).
|
|
97
104
|
#
|
|
98
|
-
#: (String source, Integer start_line, Array[Integer] | String offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> void
|
|
99
|
-
def initialize(source, start_line, offsets, comments = [], comment_attachments = [], comment_ranges = [])
|
|
105
|
+
#: (String source, Integer start_line, Array[Integer] | String offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges, ?Integer? checksum) -> void
|
|
106
|
+
def initialize(source, start_line, offsets, comments = [], comment_attachments = [], comment_ranges = [], checksum = nil)
|
|
100
107
|
@source = source
|
|
101
108
|
@start_line = start_line
|
|
109
|
+
@checksum = checksum
|
|
102
110
|
@offsets = offsets
|
|
103
111
|
@comments = comments
|
|
104
112
|
@comment_attachments = comment_attachments
|
|
@@ -112,6 +120,13 @@ module Prism
|
|
|
112
120
|
@start_line = start_line
|
|
113
121
|
end
|
|
114
122
|
|
|
123
|
+
# Replace the value of checksum with the given value.
|
|
124
|
+
#
|
|
125
|
+
#: (Integer checksum) -> void
|
|
126
|
+
def replace_checksum(checksum)
|
|
127
|
+
@checksum = checksum
|
|
128
|
+
end
|
|
129
|
+
|
|
115
130
|
# Replace the value of offsets with the given value.
|
|
116
131
|
#
|
|
117
132
|
#: (Array[Integer] offsets) -> void
|