Skip to content

Commit 8653221

Browse files
committed
Wire up parse_success for WASM
1 parent bc85717 commit 8653221

5 files changed

Lines changed: 15 additions & 6 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
@@ -84,6 +84,10 @@ public byte[] parseLex(Buffer buffer, Source source, Options options) {
8484
return buffer.readBytes();
8585
}
8686

87+
public boolean parseSuccess(Source source, Options options) {
88+
return exports.pmSerializeParseSuccessP(source.pointer, source.length, options.pointer) != 0;
89+
}
90+
8791
public class Buffer implements AutoCloseable {
8892
final int pointer;
8993

lib/prism/ffi.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def parse_lex_file(filepath, **options)
126126

127127
# Mirror the Prism.parse_success? API by using the serialization API.
128128
def parse_success?(code, **options)
129-
FFICommon.with_string(code) { |string| FFICommon.parse_file_success(string, options) }
129+
FFICommon.with_string(code) { |string| FFICommon.parse_success(string, options) }
130130
end
131131

132132
# Mirror the Prism.parse_failure? API by using the serialization API.
@@ -137,7 +137,12 @@ def parse_failure?(code, **options)
137137
# Mirror the Prism.parse_file_success? API by using the serialization API.
138138
def parse_file_success?(filepath, **options)
139139
options[:filepath] = filepath
140-
FFICommon.with_file(filepath) { |string| FFICommon.parse_file_success(string, options) }
140+
FFICommon.with_file(filepath) do |file|
141+
code = file.read
142+
FFICommon.with_string(code) do |string|
143+
FFICommon.parse_success(string, options)
144+
end
145+
end
141146
end
142147

143148
# Mirror the Prism.parse_file_failure? API by using the serialization API.

lib/prism/ffi/common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def parse_comments(string, code, options) # :nodoc:
221221
raise NotImplementedError
222222
end
223223

224-
def parse_file_success(string, options) # :nodoc:
224+
def parse_success(string, options) # :nodoc:
225225
raise NotImplementedError
226226
end
227227

lib/prism/ffi/native_ffi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def parse_lex_only(buffer, string, options) # :nodoc:
298298
LibRubyParser.pm_serialize_parse_lex(buffer.pointer, string.pointer, string.length, dump_options(options))
299299
end
300300

301-
def parse_file_success(string, options) # :nodoc:
301+
def parse_success(string, options) # :nodoc:
302302
LibRubyParser.pm_serialize_parse_success_p(string.pointer, string.length, dump_options(options))
303303
end
304304

lib/prism/ffi/wasm_ffi.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def parse_lex_only(buffer, string, options) # :nodoc:
8383
String.from_java_bytes(PRISM.parse_lex(buffer, string, PRISM.new_options(dump_options(options).to_java_bytes)))
8484
end
8585

86-
def parse_file_success(string, options) # :nodoc:
87-
raise NotImplementedError
86+
def parse_success(string, options) # :nodoc:
87+
PRISM.parse_success(string, PRISM.new_options(dump_options(options).to_java_bytes))
8888
end
8989

9090
def string_query_method_name(string) # :nodoc:

0 commit comments

Comments
 (0)