3131
3232package org .jruby .ext .jruby ;
3333
34+ import org .jcodings .Encoding ;
3435import org .jcodings .specific .ASCIIEncoding ;
36+ import org .jcodings .specific .UTF8Encoding ;
3537import org .jruby .*;
3638import org .jruby .anno .JRubyMethod ;
3739import org .jruby .anno .JRubyModule ;
5254
5355import java .io .ByteArrayInputStream ;
5456
57+ import static org .jruby .parser .ParserManager .INLINE ;
58+
5559/**
5660 * Native part of require 'jruby', e.g. provides methods for swapping between the normal Ruby reference to an
5761 * object and the Java-integration-wrapped reference.
@@ -207,7 +211,7 @@ private static Node parseImpl(ThreadContext context, IRubyObject[] args, Block b
207211
208212 final RubyString content = args [0 ].convertToString ();
209213 final String filename ;
210- boolean extra_position_info = false ; int lineno = 0 ;
214+ boolean inlineSource = false ; int lineno = 0 ;
211215
212216 switch (args .length ) {
213217 case 1 :
@@ -218,31 +222,22 @@ private static Node parseImpl(ThreadContext context, IRubyObject[] args, Block b
218222 break ;
219223 case 3 :
220224 filename = args [1 ].convertToString ().toString ();
221- extra_position_info = args [2 ].isTrue ();
225+ inlineSource = args [2 ].isTrue ();
222226 break ;
223227 case 4 :
224228 filename = args [1 ].convertToString ().toString ();
225- extra_position_info = args [2 ].isTrue ();
229+ inlineSource = args [2 ].isTrue ();
226230 lineno = args [3 ].convertToInteger ().getIntValue ();
227231 break ;
228232 default :
229233 throw new AssertionError ("unexpected arguments: " + java .util .Arrays .toString (args ));
230234 }
231235
232236 final ByteList bytes = content .getByteList ();
233- final DynamicScope scope = null ;
234-
235- final Node parseResult ;
236- if (content .getEncoding () == ASCIIEncoding .INSTANCE ) {
237- // binary content, parse as though from a stream
238- ByteArrayInputStream stream = new ByteArrayInputStream (bytes .getUnsafeBytes (), bytes .getBegin (), bytes .getRealSize ());
239- parseResult = context .runtime .parseFile (stream , filename , scope , lineno );
240- }
241- else {
242- parseResult = context .runtime .parse (bytes , filename , scope , lineno , extra_position_info );
243- }
237+ ByteArrayInputStream stream = new ByteArrayInputStream (bytes .getUnsafeBytes (), bytes .getBegin (), bytes .getRealSize ());
238+ Encoding encoding = content .getEncoding () == ASCIIEncoding .INSTANCE ? context .runtime .setupSourceEncoding (UTF8Encoding .INSTANCE ) : bytes .getEncoding ();
244239
245- return parseResult ;
240+ return ( Node ) context . runtime . getParserManager (). parseFile ( filename , lineno , stream , encoding , null , inlineSource ? INLINE : 0 ). getAST () ;
246241 }
247242
248243 @ JRubyMethod (module = true , name = "compile_ir" , required = 1 , optional = 3 , checkArity = false )
0 commit comments