Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2504b6bcf9d0
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 41e4b3466751
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 9, 2016

  1. Copy the full SHA
    6f6c1bb View commit details
  2. Copy the full SHA
    41e4b34 View commit details
Showing with 17 additions and 2 deletions.
  1. +9 −0 core/src/main/java/org/jruby/RubyRegexp.java
  2. +8 −2 core/src/main/java/org/jruby/parser/ParserSupport.java
9 changes: 9 additions & 0 deletions core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
@@ -329,6 +329,15 @@ public static RubyRegexp newRegexp(Ruby runtime, ByteList pattern, RegexpOptions
}
}

/**
* throws RaiseException on error so parser can pick this up and give proper line and line number
* error as opposed to any non-literal regexp creation which may raise a syntax error but will not
* have this extra source info in the error message
*/
public static RubyRegexp newRegexpParser(Ruby runtime, ByteList pattern, RegexpOptions options) {
return new RubyRegexp(runtime, pattern, (RegexpOptions)options.clone());
}

// used only by the compiler/interpreter (will set the literal flag)
public static RubyRegexp newDRegexp(Ruby runtime, RubyString pattern, RegexpOptions options) {
try {
10 changes: 8 additions & 2 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -1337,7 +1337,7 @@ private char optionsEncodingChar(Encoding optionEncoding) {
public void compile_error(String message) { // mri: rb_compile_error_with_enc
String line = lexer.getCurrentLine();
ISourcePosition position = lexer.getPosition();
String errorMessage = lexer.getFile() + ":" + position.getLine() + ": ";
String errorMessage = lexer.getFile() + ":" + (position.getLine() + 1) + ": ";

if (line != null && line.length() > 5) {
boolean addNewline = message != null && ! message.endsWith("\n");
@@ -1384,7 +1384,13 @@ protected void checkRegexpSyntax(ByteList value, RegexpOptions options) {
// Joni doesn't support these modifiers - but we can fix up in some cases - let the error delay until we try that
if (stringValue.startsWith("(?u)") || stringValue.startsWith("(?a)") || stringValue.startsWith("(?d)"))
return;
RubyRegexp.newRegexp(getConfiguration().getRuntime(), value, options);

try {
// This is only for syntax checking but this will as a side-effect create an entry in the regexp cache.
RubyRegexp.newRegexpParser(getConfiguration().getRuntime(), value, (RegexpOptions)options.clone());
} catch (RaiseException re) {
compile_error(re.getMessage());
}
}

public Node newRegexpNode(ISourcePosition position, Node contents, RegexpNode end) {