Skip to content

Commit

Permalink
Showing 3 changed files with 11 additions and 14 deletions.
15 changes: 7 additions & 8 deletions core/src/main/java/org/jruby/lexer/LexingCommon.java
Original file line number Diff line number Diff line change
@@ -99,24 +99,23 @@ public ByteList createTokenByteList() {
}

public String createTokenString(int start) {
byte[] bytes = lexb.getUnsafeBytes();
int begin = lexb.begin();
Charset charset;
return createAsEncodedString(lexb.getUnsafeBytes(), lexb.begin() + start, lex_p - start, getEncoding());
}

public String createAsEncodedString(byte[] bytes, int start, int length, Encoding encoding) {
// FIXME: We should be able to move some faster non-exception cache using Encoding.isDefined
try {
charset = getEncoding().getCharset();
Charset charset = getEncoding().getCharset();
if (charset != null) {
if (charset == RubyEncoding.UTF8) {
return RubyEncoding.decodeUTF8(bytes, begin + start, lex_p - start);
return RubyEncoding.decodeUTF8(bytes, start, length);
} else {
return new String(bytes, begin + start, lex_p - start, charset);
return new String(bytes, start, length, charset);
}
}
} catch (UnsupportedCharsetException e) {}


return new String(bytes, begin + start, lex_p - start);
return new String(bytes, start, length);
}

public String createTokenString() {
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java
Original file line number Diff line number Diff line change
@@ -318,7 +318,8 @@ public void compile_error(String message) {

// FIXME: How does lexb.toString() vs getCurrentLine() differ.
public void compile_error(PID pid, String message) {
throw new SyntaxException(pid, getFile(), ruby_sourceline, getCurrentLine(), message);
String src = createAsEncodedString(lex_lastline.unsafeBytes(), lex_lastline.begin(), lex_lastline.length(), getEncoding());
throw new SyntaxException(pid, getFile(), ruby_sourceline, src, message);
}

public void heredoc_restore(HeredocTerm here) {
7 changes: 2 additions & 5 deletions test/mri/excludes/TestSyntax.rb
Original file line number Diff line number Diff line change
@@ -2,12 +2,9 @@
exclude :test_constant_reassignment_nested, "needs investigation"
exclude :test_constant_reassignment_toplevel, "needs investigation"
exclude :test_defined_empty_argument, "needs investigation"
exclude :test_do_block_in_lambda, "needs investigation"
exclude :test_duplicated_when, "needs investigation"
exclude :test_error_message_encoding, "#2127"
exclude :test_integer_suffix, "needs investigation"
exclude :test_keyword_duplicated_splat, "fix when dealing w/ mixed sym/str keys"
exclude :test_keyword_self_reference, "#2124"
exclude :test_optional_self_reference, "#2124"
exclude :test_do_block_in_lambda, "needs investigation"
exclude :test_invalid_next, "needs investigation"
exclude :test_keyword_duplicated_splat, "fix when dealing w/ mixed sym/str keys"
exclude :test_null_range_cmdarg, "needs investigation"

0 comments on commit 2d88cd8

Please sign in to comment.