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: e263fe4701dc
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 74028ea629bc
Choose a head ref
  • 7 commits
  • 34 files changed
  • 2 contributors

Commits on Mar 1, 2015

  1. Copy the full SHA
    f63f105 View commit details
  2. Copy the full SHA
    a1ef2b7 View commit details

Commits on Mar 2, 2015

  1. Copy the full SHA
    0c32736 View commit details
  2. Copy the full SHA
    1bf005c View commit details
  3. Copy the full SHA
    ea0765d View commit details
  4. Copy the full SHA
    e57479f View commit details
  5. Merge pull request #2638 from bjfish/truffle_strscan

    [Truffle] Implemented Regexp#match_start for strscan.
    chrisseaton committed Mar 2, 2015
    Copy the full SHA
    74028ea View commit details
Showing with 73 additions and 80 deletions.
  1. +21 −0 spec/truffle/spec/rubysl/rubysl-strscan/spec/match_start_spec.rb
  2. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/beginning_of_line_tags.txt
  3. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/bol_tags.txt
  4. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/check_tags.txt
  5. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/check_until_tags.txt
  6. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/dup_tags.txt
  7. +0 −4 spec/truffle/tags/rubysl/rubysl-strscan/spec/element_reference_tags.txt
  8. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/exist_tags.txt
  9. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/get_byte_tags.txt
  10. +0 −5 spec/truffle/tags/rubysl/rubysl-strscan/spec/getbyte_tags.txt
  11. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/getch_tags.txt
  12. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/inspect_tags.txt
  13. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/match_tags.txt
  14. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/matched_size_tags.txt
  15. +0 −5 spec/truffle/tags/rubysl/rubysl-strscan/spec/matched_tags.txt
  16. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/pointer_tags.txt
  17. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/pos_tags.txt
  18. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/post_match_tags.txt
  19. +0 −5 spec/truffle/tags/rubysl/rubysl-strscan/spec/pre_match_tags.txt
  20. +0 −1 spec/truffle/tags/rubysl/rubysl-strscan/spec/reset_tags.txt
  21. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/rest_size_tags.txt
  22. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/rest_tags.txt
  23. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/restsize_tags.txt
  24. +0 −4 spec/truffle/tags/rubysl/rubysl-strscan/spec/scan_full_tags.txt
  25. +0 −7 spec/truffle/tags/rubysl/rubysl-strscan/spec/scan_tags.txt
  26. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/scan_until_tags.txt
  27. +0 −4 spec/truffle/tags/rubysl/rubysl-strscan/spec/search_full_tags.txt
  28. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/skip_tags.txt
  29. +0 −2 spec/truffle/tags/rubysl/rubysl-strscan/spec/skip_until_tags.txt
  30. +0 −3 spec/truffle/tags/rubysl/rubysl-strscan/spec/unscan_tags.txt
  31. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/MatchDataNodes.java
  32. +41 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
  33. +4 −0 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyMatchData.java
  34. +6 −1 truffle/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
21 changes: 21 additions & 0 deletions spec/truffle/spec/rubysl/rubysl-strscan/spec/match_start_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require File.expand_path('../../../../../../ruby/spec_helper', __FILE__)

describe "Regexp#match_start" do
it "matches a string N bytes from the beginning" do
m = /b/.match_start("ab", 1)
m[0].should == "b"
end

it "preserves zero length captures" do
r = /(a)?/
str = "ab"

m = r.match_start(str, 0)
m[0].should == "a"
m[1].should == "a"

m = r.match_start(str, 1)
m[0].should == ""
m[1].should be_nil
end
end

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/rubysl/rubysl-strscan/spec/bol_tags.txt

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/rubysl/rubysl-strscan/spec/dup_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
fails:StringScanner#[] returns the n-th subgroup in the most recent match
fails:StringScanner#[] returns nil if index is outside of self
fails:StringScanner#[] calls to_int on the given index
fails:StringScanner#[] raises a TypeError if the given index is nil
fails:StringScanner#[] raises a TypeError when a String is as argument
fails:StringScanner#[] raises a TypeError when a Range is as argument
3 changes: 0 additions & 3 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/exist_tags.txt

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/getbyte_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
fails:StringScanner#getbyte scans one byte and returns it
fails:StringScanner#getbyte is not multi-byte character sensitive
fails:StringScanner#getbyte returns nil at the end of the string
fails:StringScanner#getbyte warns in verbose mode that the method is obsolete
fails:StringScanner#getbyte returns an instance of String when passed a String subclass
fails:StringScanner#getbyte taints the returned String if the input was tainted
3 changes: 0 additions & 3 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/getch_tags.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
fails:StringScanner#getch scans one character and returns it
fails:StringScanner#getch is multi-byte character sensitive
fails:StringScanner#getch returns nil at the end of the string
fails:StringScanner#getch returns an instance of String when passed a String subclass
fails:StringScanner#getch taints the returned String if the input was tainted

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/match_tags.txt

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/matched_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
fails:StringScanner#matched returns the last matched string
fails:StringScanner#matched returns nil if there's no match
fails:StringScanner#matched returns an instance of String when passed a String subclass
fails:StringScanner#matched taints the returned String if the input was tainted
fails:StringScanner#matched? returns true if the last match was successful
fails:StringScanner#matched? returns false if there's no match
2 changes: 0 additions & 2 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/pointer_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/pos_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:StringScanner#post_match returns the post-match (in the regular expression sense) of the last scan
fails:StringScanner#post_match returns nil if there's no match
fails:StringScanner#post_match returns an instance of String when passed a String subclass
fails:StringScanner#post_match taints the returned String if the input was tainted
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
fails:StringScanner#pre_match returns the pre-match (in the regular expression sense) of the last scan
fails:StringScanner#pre_match returns nil if there's no match
fails:StringScanner#pre_match is more than just the data from the last match
fails:StringScanner#pre_match is not changed when the scanner's position changes
fails:StringScanner#pre_match returns an instance of String when passed a String subclass
fails:StringScanner#pre_match taints the returned String if the input was tainted

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/rest_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:StringScanner#rest returns the rest of the string
fails:StringScanner#rest returns an instance of String when passed a String subclass
fails:StringScanner#rest taints the returned String if the input was tainted
fails:StringScanner#rest? returns true if there is more data in the string

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/scan_tags.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
fails:StringScanner#scan returns the matched string
fails:StringScanner#scan returns the first character for a multi byte string with no KCODE
fails:StringScanner#scan returns the matched string for a multi byte string with KCODE
fails:StringScanner#scan returns the matched string for a multi byte string with unicode regexp
fails:StringScanner#scan returns the matched string for a multi byte string
fails:StringScanner#scan treats ^ as matching from the beginning of the current position
fails:StringScanner#scan returns nil if there's no match
fails:StringScanner#scan returns nil when there is no more to scan
fails:StringScanner#scan returns an empty string when the pattern matches empty
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:StringScanner#scan_until returns the substring up to and including the end of the match
fails:StringScanner#scan_until returns nil if there's no match
fails:StringScanner#scan_until can match anchors properly

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/skip_tags.txt

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/rubysl/rubysl-strscan/spec/unscan_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public GetIndexNode(GetIndexNode prev) {
public Object getIndex(RubyMatchData matchData, int index) {
notDesignedForCompilation();

if (index >= matchData.getValues().length) {
if (index >= matchData.getValues().length || index < 0) {
return getContext().getCoreLibrary().getNilObject();
} else {
return matchData.getValues()[index];
Original file line number Diff line number Diff line change
@@ -11,10 +11,12 @@

import static org.jruby.util.StringSupport.CR_7BIT;

import org.joni.Region;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyMatchData;
import org.jruby.truffle.runtime.core.RubyRegexp;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
@@ -232,6 +234,28 @@ public Object match(RubyRegexp regexp, RubyString string) {

}

@CoreMethod(names = "match_start", required = 2)
public abstract static class MatchStartNode extends CoreMethodNode {

public MatchStartNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public MatchStartNode(MatchStartNode prev) {
super(prev);
}

@Specialization
public Object matchStart(RubyRegexp regexp, RubyString string, int startPos) {
final Object matchResult = regexp.matchCommon(string, false, false, startPos);
if (matchResult instanceof RubyMatchData && ((RubyMatchData) matchResult).getNumberOfRegions() > 0
&& ((RubyMatchData) matchResult).getRegion().beg[0] == startPos) {
return matchResult;
}
return getContext().getCoreLibrary().getNilObject();
}
}

@CoreMethod(names = "options")
public abstract static class OptionsNode extends CoreMethodNode {

@@ -292,6 +316,23 @@ public RubyString quote(RubySymbol raw) {

}

@CoreMethod(names = "search_from", required = 2)
public abstract static class SearchFromNode extends CoreMethodNode {

public SearchFromNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public SearchFromNode(SearchFromNode prev) {
super(prev);
}

@Specialization
public Object searchFrom(RubyRegexp regexp, RubyString string, int startPos) {
return regexp.matchCommon(string, false, false, startPos);
}
}

@CoreMethod(names = "source")
public abstract static class SourceNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -121,6 +121,10 @@ public RubyString getGlobal() {
return global;
}

public Region getRegion() {
return region;
}

public RubyString getSource() {
return source;
}
Original file line number Diff line number Diff line change
@@ -98,11 +98,16 @@ public RegexpOptions getOptions() {

@CompilerDirectives.TruffleBoundary
public Object matchCommon(RubyString source, boolean operator, boolean setNamedCaptures) {
return matchCommon(source, operator, setNamedCaptures, 0);
}

@CompilerDirectives.TruffleBoundary
public Object matchCommon(RubyString source, boolean operator, boolean setNamedCaptures, int startPos) {
final byte[] stringBytes = source.getByteList().bytes();
final Matcher matcher = regex.matcher(stringBytes);
int range = stringBytes.length;

return matchCommon(source, operator, setNamedCaptures, matcher, 0, range);
return matchCommon(source, operator, setNamedCaptures, matcher, startPos, range);
}

@CompilerDirectives.TruffleBoundary