prism 2.0.0.rc1-x86_64-linux-gnu → 2.0.0.rc2-x86_64-linux-gnu

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.
@@ -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
- #: (String source, Integer start_line, Array[Integer] offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> Source
38
- def self.for(source, start_line, offsets, comments = [], comment_attachments = [], comment_ranges = [])
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
@@ -44,9 +44,11 @@ module Prism
44
44
  loader.load_header
45
45
  encoding = loader.load_encoding
46
46
  start_line = loader.load_varsint
47
+ checksum = loader.load_uint64
47
48
  offsets = loader.load_line_offsets(freeze)
48
49
 
49
50
  source.replace_start_line(start_line)
51
+ source.replace_checksum(checksum)
50
52
  source.replace_offsets(offsets)
51
53
 
52
54
  loader.load_comments(source.comments, freeze)
@@ -100,9 +102,11 @@ module Prism
100
102
  tokens = loader.load_tokens
101
103
  encoding = loader.load_encoding
102
104
  start_line = loader.load_varsint
105
+ checksum = loader.load_uint64
103
106
  offsets = loader.load_line_offsets(freeze)
104
107
 
105
108
  source.replace_start_line(start_line)
109
+ source.replace_checksum(checksum)
106
110
  source.replace_offsets(offsets)
107
111
 
108
112
  loader.load_comments(source.comments, freeze)
@@ -145,16 +149,18 @@ module Prism
145
149
  source = Source.for(input, 1, [])
146
150
  loader = Loader.new(source, serialized)
147
151
 
148
- loader.load_header
149
- loader.load_encoding
150
- start_line = loader.load_varsint
151
- offsets = loader.load_line_offsets(freeze)
152
+ loader.load_header
153
+ loader.load_encoding
154
+ start_line = loader.load_varsint
155
+ checksum = loader.load_uint64
156
+ offsets = loader.load_line_offsets(freeze)
152
157
 
153
158
  source.replace_start_line(start_line)
159
+ source.replace_checksum(checksum)
154
160
  source.replace_offsets(offsets)
155
161
 
156
- result = loader.load_comments(source.comments, freeze)
157
- raise unless loader.eof?
162
+ result = loader.load_comments(source.comments, freeze)
163
+ raise unless loader.eof?
158
164
 
159
165
  source.deep_freeze if freeze
160
166
  result
@@ -175,9 +181,11 @@ module Prism
175
181
  loader.load_header
176
182
  encoding = loader.load_encoding
177
183
  start_line = loader.load_varsint
184
+ checksum = loader.load_uint64
178
185
  offsets = loader.load_line_offsets(freeze)
179
186
 
180
187
  source.replace_start_line(start_line)
188
+ source.replace_checksum(checksum)
181
189
  source.replace_offsets(offsets)
182
190
 
183
191
  loader.load_comments(source.comments, freeze)
@@ -863,6 +871,11 @@ module Prism
863
871
  (io.read(4) or raise).unpack1("L") #: Integer
864
872
  end
865
873
 
874
+ #: () -> Integer
875
+ def load_uint64
876
+ (io.read(8) or raise).unpack1("Q") #: Integer
877
+ end
878
+
866
879
  #: (ConstantPool constant_pool, Encoding encoding, bool freeze) -> node?
867
880
  def load_optional_node(constant_pool, encoding, freeze)
868
881
  if io.getbyte != 0
@@ -11,6 +11,7 @@ module Prism
11
11
  # def self.local?: (String string) -> bool
12
12
  # def self.constant?: (String string) -> bool
13
13
  # def self.method_name?: (String string) -> bool
14
+ # def self.keyword?: (String string) -> bool
14
15
 
15
16
  # The string that this query is wrapping.
16
17
  attr_reader :string #: String
@@ -42,5 +43,12 @@ module Prism
42
43
  def method_name?
43
44
  StringQuery.method_name?(string)
44
45
  end
46
+
47
+ # Whether or not this string is a valid keyword.
48
+ #
49
+ #: () -> bool
50
+ def keyword?
51
+ StringQuery.keyword?(string)
52
+ end
45
53
  end
46
54
  end
data/prism.gemspec CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prism"
5
- spec.version = "2.0.0.rc1"
6
- spec.authors = ["Shopify"]
7
- spec.email = ["ruby@shopify.com"]
5
+ spec.version = "2.0.0.rc2"
6
+ spec.authors = ["Ruby developers"]
7
+ spec.email = ["ruby-core@ruby-lang.org"]
8
8
 
9
9
  spec.summary = "Prism Ruby parser"
10
10
  spec.homepage = "https://github.com/ruby/prism"
@@ -49,6 +49,8 @@ Gem::Specification.new do |spec|
49
49
  "include/prism/compiler/accel.h",
50
50
  "include/prism/compiler/align.h",
51
51
  "include/prism/compiler/assume.h",
52
+ "include/prism/compiler/bswap.h",
53
+ "include/prism/compiler/endianness.h",
52
54
  "include/prism/compiler/exported.h",
53
55
  "include/prism/compiler/fallthrough.h",
54
56
  "include/prism/compiler/filesystem.h",
@@ -86,6 +88,7 @@ Gem::Specification.new do |spec|
86
88
  "include/prism/internal/stringy.h",
87
89
  "include/prism/internal/strpbrk.h",
88
90
  "include/prism/internal/tokens.h",
91
+ "include/prism/internal/xxh3.h",
89
92
  "include/prism/arena.h",
90
93
  "include/prism/ast.h",
91
94
  "include/prism/buffer.h",
@@ -224,7 +227,8 @@ Gem::Specification.new do |spec|
224
227
  "src/stringy.c",
225
228
  "src/strncasecmp.c",
226
229
  "src/strpbrk.c",
227
- "src/tokens.c"
230
+ "src/tokens.c",
231
+ "src/xxh3.c"
228
232
  ]
229
233
 
230
234
  spec.extensions = ["ext/prism/extconf.rb"]