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: 01e8d940ccc8
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 11504914b302
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 3, 2016

  1. Joni doesn't support modifiers, but in some cases Truffle can shim, s…

    …o let errors delay until they are compiled.
    chrisseaton committed Jan 3, 2016
    Copy the full SHA
    81c658a View commit details
  2. 3
    Copy the full SHA
    1150491 View commit details
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -1277,6 +1277,10 @@ public void setRegexpEncoding(RegexpNode end, ByteList value) {
}

protected void checkRegexpSyntax(ByteList value, RegexpOptions options) {
final String stringValue = value.toString();
// 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);
}

1 change: 0 additions & 1 deletion spec/truffle/tags/language/regexp/modifiers_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
@@ -198,8 +198,42 @@ private static void setLocalVariable(Frame frame, String name, Object value) {
}
}

public static ByteList shimModifiers(ByteList bytes) {
// Joni doesn't support (?u) etc but we can shim some common cases

String bytesString = bytes.toString();

if (bytesString.startsWith("(?u)") || bytesString.startsWith("(?d)") || bytesString.startsWith("(?a)")) {
final char modifier = (char) bytes.get(2);
bytesString = bytesString.substring(4);

switch (modifier) {
case 'u': {
bytesString = bytesString.replace("\\w", "[[:alpha:]]");
} break;

case 'd': {

} break;

case 'a': {
bytesString = bytesString.replace("[[:alpha:]]", "[a-zA-Z]");
} break;

default:
throw new UnsupportedOperationException();
}

bytes = ByteList.create(bytesString);
}

return bytes;
}

@TruffleBoundary
public static Regex compile(Node currentNode, RubyContext context, ByteList bytes, RegexpOptions options) {
bytes = shimModifiers(bytes);

try {
/*
// This isn't quite right - we shouldn't be looking up by name, we need a real reference to this constants
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
@@ -138,8 +138,8 @@ public Object searchRegion(DynamicObject regexp, DynamicObject string, int start
final ByteList stringBl = StringOperations.getByteList(string);
final ByteList bl = Layouts.REGEXP.getSource(regexp);
final Encoding enc = RegexpNodes.checkEncoding(regexp, StringOperations.getCodeRangeable(string), true);
final ByteList preprocessed = RegexpSupport.preprocess(getContext().getRuntime(), bl, enc, new Encoding[]{null}, RegexpSupport.ErrorMode.RAISE);

ByteList preprocessed = RegexpSupport.preprocess(getContext().getRuntime(), bl, enc, new Encoding[]{null}, RegexpSupport.ErrorMode.RAISE);
preprocessed = RegexpNodes.shimModifiers(preprocessed);
final Regex r = new Regex(preprocessed.getUnsafeBytes(), preprocessed.getBegin(), preprocessed.getBegin() + preprocessed.getRealSize(), Layouts.REGEXP.getRegex(regexp).getOptions(), RegexpNodes.checkEncoding(regexp, StringOperations.getCodeRangeable(string), true));
final Matcher matcher = r.matcher(stringBl.getUnsafeBytes(), stringBl.begin(), stringBl.begin() + stringBl.realSize());