Skip to content

Commit

Permalink
For Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Apr 21, 2015
1 parent 214dea5 commit 15584ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -39,6 +39,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.ast.ArrayNode;
import org.jruby.ast.BlockNode;
import org.jruby.ast.CallNode;
Expand Down Expand Up @@ -2750,7 +2751,7 @@ private void setupSourceEncoding(ParserConfiguration parserConfig) {
}
parserConfig.setDefaultEncoding(getEncodingService().getEncodingFromString(config.getSourceEncoding()));
} else {
parserConfig.setDefaultEncoding(getEncodingService().getLocaleEncoding());
parserConfig.setDefaultEncoding(UTF8Encoding.INSTANCE);
}
}

Expand Down
20 changes: 14 additions & 6 deletions core/src/main/java/org/jruby/lexer/GetsLexerSource.java
Expand Up @@ -18,17 +18,25 @@ public class GetsLexerSource extends LexerSource {
private IRubyObject io;
private Encoding encoding;
private int offset;
public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines) {
// FIXME: Does this source needs SCRIPT_LINES support?

// Main-line Parsing constructor
public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines, Encoding encoding) {
super(sourceName, line, scriptLines);

this.io = io;
encoding = frobnicateEncoding();
this.encoding = encoding;
}

// FIXME: ripper probably has same problem as main-line parser so this constructor may need to be a mix
// of frobbing the encoding of an incoming object plus defaultEncoding if not. but main-line parser
// should not be asking IO for encoding.
// Ripper constructor
public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines) {
this(sourceName, line, io, scriptLines, frobnicateEncoding(io));
}

// FIXME: Should be a hard failure likely if no encoding is possible
public final Encoding frobnicateEncoding() {
public static final Encoding frobnicateEncoding(IRubyObject io) {
// Non-ripper IO will not have encoding so we will just use default external
if (!io.respondsTo("encoding")) return io.getRuntime().getDefaultExternalEncoding();

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/parser/Parser.java
Expand Up @@ -83,7 +83,7 @@ public Node parse(String file, ByteList content, DynamicScope blockScope,
public Node parse(String file, byte[] content, DynamicScope blockScope,
ParserConfiguration configuration) {
RubyArray list = getLines(configuration, runtime, file);
ByteList in = new ByteList(content, runtime.getDefaultExternalEncoding());
ByteList in = new ByteList(content, configuration.getDefaultEncoding());
LexerSource lexerSource = new ByteListLexerSource(file, configuration.getLineNumber(), in, list);
return parse(file, lexerSource, blockScope, configuration);
}
Expand All @@ -96,7 +96,7 @@ public Node parse(String file, InputStream content, DynamicScope blockScope,
} else {
RubyArray list = getLines(configuration, runtime, file);
RubyIO io = RubyIO.newIO(runtime, Channels.newChannel(content));
LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list);
LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list, configuration.getDefaultEncoding());
return parse(file, lexerSource, blockScope, configuration);
}
}
Expand Down

0 comments on commit 15584ba

Please sign in to comment.