Skip to content

Commit 80c46e6

Browse files
committed
Wire up parse_comments
1 parent b460f0b commit 80c46e6

5 files changed

Lines changed: 22 additions & 9 deletions

File tree

java/wasm-full/src/main/java/org/ruby_lang/prism/wasm/full/Prism.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public boolean parseSuccess(Source source, Options options) {
8888
return exports.pmSerializeParseSuccessP(source.pointer, source.length, options.pointer) != 0;
8989
}
9090

91+
public void parseComments(Buffer buffer, Source source, Options options) {
92+
exports.pmSerializeParseComments(buffer.pointer, source.pointer, source.length, options.pointer);
93+
}
94+
9195
public class Buffer implements AutoCloseable {
9296
final int pointer;
9397

lib/prism/ffi.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ def parse_comments(code, **options)
105105
# to use mmap when it is available.
106106
def parse_file_comments(filepath, **options)
107107
options[:filepath] = filepath
108-
FFICommon.with_file(filepath) { |string| FFICommon.parse_comments(string, string.read, options) }
108+
FFICommon.with_file(filepath) do |file|
109+
code = file.read
110+
FFICommon.with_string(code) do |string|
111+
FFICommon.parse_comments(string, code, options)
112+
end
113+
end
109114
end
110115

111116
# Mirror the Prism.parse_lex API by using the serialization API.

lib/prism/ffi/common.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def parse_lex(string, code, options) # :nodoc:
3535
end
3636
end
3737

38+
def parse_comments(string, code, options) # :nodoc:
39+
with_buffer do |buffer|
40+
parse_comments_only(buffer, string, options)
41+
Serialize.load_parse_comments(code, buffer.read, options.fetch(:freeze, false))
42+
end
43+
end
44+
3845
# Return the value that should be dumped for the command_line option.
3946
def dump_options_command_line(options)
4047
command_line = options.fetch(:command_line, "")
@@ -217,7 +224,7 @@ def parse_stream(buffer, callback, eof_callback, options, source) # :nodoc:
217224
raise NotImplementedError
218225
end
219226

220-
def parse_comments(string, code, options) # :nodoc:
227+
def parse_comments_only(string, code, options) # :nodoc:
221228
raise NotImplementedError
222229
end
223230

lib/prism/ffi/native_ffi.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,8 @@ def parse_stream(buffer, callback, eof_callback, options, source) # :nodoc:
287287
end
288288
end
289289

290-
def parse_comments(string, code, options) # :nodoc:
291-
with_buffer do |buffer|
292-
LibRubyParser.pm_serialize_parse_comments(buffer.pointer, string.pointer, string.length, dump_options(options))
293-
Serialize.load_parse_comments(code, buffer.read, options.fetch(:freeze, false))
294-
end
290+
def parse_comments_only(buffer, string, options) # :nodoc:
291+
LibRubyParser.pm_serialize_parse_comments(buffer.pointer, string.pointer, string.length, dump_options(options))
295292
end
296293

297294
def parse_lex_only(buffer, string, options) # :nodoc:

lib/prism/ffi/wasm_ffi.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def parse_stream(buffer, callback, eof_callback, options, source) # :nodoc:
7575
raise NotImplementedError
7676
end
7777

78-
def parse_comments(string, code, options) # :nodoc:
79-
raise NotImplementedError
78+
def parse_comments_only(buffer, string, options) # :nodoc:
79+
PRISM.parse_comments(buffer, string, PRISM.new_options(dump_options(options).to_java_bytes))
8080
end
8181

8282
def parse_lex_only(buffer, string, options) # :nodoc:

0 commit comments

Comments
 (0)