Skip to content

Commit

Permalink
Showing 3 changed files with 38 additions and 5 deletions.
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

This comment has been minimized.

Copy link
@b1tfury

b1tfury Jan 3, 2016

Contributor

@chrisseaton is this change from 2015 to 2016 has to throughout codebase ?
If thats true, then I can do that.

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Jan 3, 2016

Author Contributor

It's on files we've modified in 2016. We have a script to do it anyway.

This comment has been minimized.

Copy link
@b1tfury

b1tfury Jan 3, 2016

Contributor

ohk , thanks :)

* 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());

0 comments on commit 1150491

Please sign in to comment.