I have made another fix so that the followings pass.
/\Aabc\z/m
abc
0: abc
*** Failers
No match
abc\n
No match
qqq\nabc
No match
abc\nzzz
No match
qqq\nabc\nzzz
No match
/b\z/
a\nb
0: b
*** Failers
No match
/$(?<=^(a))/
a
0:
1: a
/\Gabc/
abc
0: abc
*** Failers
No match
xyzabc
No match
ChangeLog:
2006-03-23 Ito Kazumitsu <[EMAIL PROTECTED]>
* gnu/regexp/CharIndexed.java(setLastMatch, getLastMatch): New methods.
* gnu/regexp/CharIndexedCharArray.java(setLastMatch, getLastMatch):
New methods.
* gnu/regexp/CharIndexedInputStream.java(setLastMatch, getLastMatch):
New methods.
* gnu/regexp/CharIndexedString.java(setLastMatch, getLastMatch):
New methods.
* gnu/regexp/CharIndexedStringBuffer.java(setLastMatch, getLastMatch):
New methods.
* gnu/regexp/RE.java(initialize): Added support for \z and \G.
(getMatchImpl): Set the found REMatch to the input.
* gnu/regexp/RETokenEndOfPreviousMatch.java: New file.
* gnu/regexp/RETokenLookBehind.java(matchThis): Added the settings of
offset.
Index: classpath/gnu/regexp/CharIndexed.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/CharIndexed.java,v
retrieving revision 1.3
diff -u -r1.3 CharIndexed.java
--- classpath/gnu/regexp/CharIndexed.java 6 Feb 2006 14:03:59 -0000
1.3
+++ classpath/gnu/regexp/CharIndexed.java 23 Mar 2006 16:02:03 -0000
@@ -93,4 +93,14 @@
* Returns the effective length of this CharIndexed
*/
int length();
+
+ /**
+ * Sets the REMatch last found on this input.
+ */
+ void setLastMatch(REMatch match);
+
+ /**
+ * Returns the REMatch last found on this input.
+ */
+ REMatch getLastMatch();
}
Index: classpath/gnu/regexp/CharIndexedCharArray.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/CharIndexedCharArray.java,v
retrieving revision 1.3
diff -u -r1.3 CharIndexedCharArray.java
--- classpath/gnu/regexp/CharIndexedCharArray.java 6 Feb 2006 14:03:59
-0000 1.3
+++ classpath/gnu/regexp/CharIndexedCharArray.java 23 Mar 2006 16:02:03
-0000
@@ -68,4 +68,9 @@
public int length() {
return s.length - anchor;
}
+
+ private REMatch lastMatch;
+ public void setLastMatch(REMatch match) { lastMatch = match; }
+ public REMatch getLastMatch() { return lastMatch; }
+
}
Index: classpath/gnu/regexp/CharIndexedInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/CharIndexedInputStream.java,v
retrieving revision 1.4
diff -u -r1.4 CharIndexedInputStream.java
--- classpath/gnu/regexp/CharIndexedInputStream.java 6 Feb 2006 14:03:59
-0000 1.4
+++ classpath/gnu/regexp/CharIndexedInputStream.java 23 Mar 2006 16:02:03
-0000
@@ -155,5 +155,10 @@
throw new UnsupportedOperationException(
"difficult to tell the length for an input stream");
}
+
+ private REMatch lastMatch;
+ public void setLastMatch(REMatch match) { lastMatch = match; }
+ public REMatch getLastMatch() { return lastMatch; }
+
}
Index: classpath/gnu/regexp/CharIndexedString.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/CharIndexedString.java,v
retrieving revision 1.3
diff -u -r1.3 CharIndexedString.java
--- classpath/gnu/regexp/CharIndexedString.java 6 Feb 2006 14:03:59 -0000
1.3
+++ classpath/gnu/regexp/CharIndexedString.java 23 Mar 2006 16:02:03 -0000
@@ -70,4 +70,8 @@
public int length() {
return len - anchor;
}
+
+ private REMatch lastMatch;
+ public void setLastMatch(REMatch match) { lastMatch = match; }
+ public REMatch getLastMatch() { return lastMatch; }
}
Index: classpath/gnu/regexp/CharIndexedStringBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/CharIndexedStringBuffer.java,v
retrieving revision 1.3
diff -u -r1.3 CharIndexedStringBuffer.java
--- classpath/gnu/regexp/CharIndexedStringBuffer.java 6 Feb 2006 14:03:59
-0000 1.3
+++ classpath/gnu/regexp/CharIndexedStringBuffer.java 23 Mar 2006 16:02:03
-0000
@@ -68,4 +68,8 @@
public int length() {
return s.length() - anchor;
}
+
+ private REMatch lastMatch;
+ public void setLastMatch(REMatch match) { lastMatch = match; }
+ public REMatch getLastMatch() { return lastMatch; }
}
Index: classpath/gnu/regexp/RE.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/RE.java,v
retrieving revision 1.20
diff -u -r1.20 RE.java
--- classpath/gnu/regexp/RE.java 22 Mar 2006 22:25:00 -0000 1.20
+++ classpath/gnu/regexp/RE.java 23 Mar 2006 16:02:04 -0000
@@ -966,9 +966,15 @@
}
// END OF STRING OPERATOR
- // \Z
+ // \Z, \z
- else if (unit.bk && (unit.ch == 'Z') &&
syntax.get(RESyntax.RE_STRING_ANCHORS)) {
+ // FIXME: \Z and \z are different in that if the input string
+ // ends with a line terminator, \Z matches the position before
+ // the final terminator. This special behavior of \Z is yet
+ // to be implemented.
+
+ else if (unit.bk && (unit.ch == 'Z' || unit.ch == 'z') &&
+ syntax.get(RESyntax.RE_STRING_ANCHORS)) {
addToken(currentToken);
currentToken = new RETokenEnd(subIndex,null);
}
@@ -999,6 +1005,15 @@
currentToken = getRETokenNamedProperty(subIndex,np,insens,index);
}
+ // END OF PREVIOUS MATCH
+ // \G
+
+ else if (unit.bk && (unit.ch == 'G') &&
+ syntax.get(RESyntax.RE_STRING_ANCHORS)) {
+ addToken(currentToken);
+ currentToken = new RETokenEndOfPreviousMatch(subIndex);
+ }
+
// NON-SPECIAL CHARACTER (or escape to make literal)
// c | \* for example
@@ -1562,8 +1577,6 @@
mymatch.backtrackStack = new BacktrackStack();
boolean b = match(input, mymatch);
if (b) {
- // mymatch.backtrackStack.push(new REMatch.Backtrack(
- // this, input, mymatch, null));
return mymatch;
}
return null;
@@ -1652,6 +1665,7 @@
*/
best.end[0] = best.index;
best.finish(input);
+ input.setLastMatch(best);
return best;
}
}
Index: classpath/gnu/regexp/RETokenEndOfPreviousMatch.java
===================================================================
RCS file: classpath/gnu/regexp/RETokenEndOfPreviousMatch.java
diff -N classpath/gnu/regexp/RETokenEndOfPreviousMatch.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ classpath/gnu/regexp/RETokenEndOfPreviousMatch.java 23 Mar 2006 16:02:04
-0000
@@ -0,0 +1,71 @@
+/* gnu/regexp/RETokenEndOfPreviousMatch.java
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.regexp;
+
+class RETokenEndOfPreviousMatch extends RETokenStart {
+
+ RETokenEndOfPreviousMatch(int subIndex) {
+ super(subIndex, null);
+ }
+
+ int getMaximumLength() {
+ return 0;
+ }
+
+ REMatch matchThis(CharIndexed input, REMatch mymatch) {
+ REMatch lastMatch = input.getLastMatch();
+ if (lastMatch == null) return super.matchThis(input, mymatch);
+ if (mymatch.offset+mymatch.index == lastMatch.offset+lastMatch.index) {
+ return mymatch;
+ }
+ else {
+ return null;
+ }
+ }
+
+ boolean returnsFixedLengthmatches() { return true; }
+
+ int findFixedLengthMatches(CharIndexed input, REMatch mymatch, int max) {
+ if (matchThis(input, mymatch) != null) return max;
+ else return 0;
+ }
+
+ void dump(StringBuffer os) {
+ os.append("\\G");
+ }
+}
Index: classpath/gnu/regexp/RETokenLookBehind.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/regexp/RETokenLookBehind.java,v
retrieving revision 1.3
diff -u -r1.3 RETokenLookBehind.java
--- classpath/gnu/regexp/RETokenLookBehind.java 18 Mar 2006 00:43:11 -0000
1.3
+++ classpath/gnu/regexp/RETokenLookBehind.java 23 Mar 2006 16:02:04 -0000
@@ -65,6 +65,7 @@
int diff = behind.length() - input.length();
int curIndex = trymatch.index + diff;
trymatch.index = 0;
+ trymatch.offset = 0;
RETokenMatchHereOnly stopper = new RETokenMatchHereOnly(curIndex);
REToken re1 = (REToken) re.clone();
re1.chain(stopper);
@@ -79,6 +80,7 @@
}
}
trymatch.index = mymatch.index;
+ trymatch.offset = mymatch.offset;
return trymatch;
}
else {