[kaffe] CVS kaffe (robilad): Resynced with gnu classpath: regexp fix

Kaffe CVS cvs-commits at kaffe.org
Sat Jul 2 19:12:18 PDT 2005


PatchSet 6681 
Date: 2005/07/03 02:07:36
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with gnu classpath: regexp fix

2005-07-03  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-06-12  Ziga Mahkovec  <ziga.mahkovec at klika.si>

        PR libgcj/20435:
        * gnu/regexp/RESyntax.java (RE_POSSESSIVE_OPS): New field.
        (static): Add possessive matching to JAVA_1_4 syntax.
        * gnu/regexp/RETokenRepeated.java (possessive): New field.
        (makePossessive, isPossessive): New methods.
        (match): Don't back off during possessive matching.
        * gnu/regexp/RE.java (initalize): Accept possessive quantifier.
        * java/util/regex/Pattern.java (constructor): Switch syntax from PERL5
        to JAVA_1_4.

Members: 
	ChangeLog:1.4206->1.4207 
	libraries/javalib/gnu/regexp/RE.java:1.6->1.7 
	libraries/javalib/gnu/regexp/RESyntax.java:1.2->1.3 
	libraries/javalib/gnu/regexp/RETokenRepeated.java:1.2->1.3 
	libraries/javalib/java/util/regex/Pattern.java:1.11->1.12 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4206 kaffe/ChangeLog:1.4207
--- kaffe/ChangeLog:1.4206	Sun Jul  3 01:32:14 2005
+++ kaffe/ChangeLog	Sun Jul  3 02:07:36 2005
@@ -2,6 +2,22 @@
 
 	Resynced with GNU Classpath.
 
+	2005-06-12  Ziga Mahkovec  <ziga.mahkovec at klika.si>
+
+        PR libgcj/20435:
+        * gnu/regexp/RESyntax.java (RE_POSSESSIVE_OPS): New field.
+        (static): Add possessive matching to JAVA_1_4 syntax.
+        * gnu/regexp/RETokenRepeated.java (possessive): New field.
+        (makePossessive, isPossessive): New methods.
+        (match): Don't back off during possessive matching.
+        * gnu/regexp/RE.java (initalize): Accept possessive quantifier.
+        * java/util/regex/Pattern.java (constructor): Switch syntax from PERL5
+        to JAVA_1_4.
+
+2005-07-03  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+
 	2005-06-28  Audrius Meskauskas  <AudriusA at Bioinformatics.org>
 
         * org/omg/CosNaming/BindingIterator.java: Inherit from
Index: kaffe/libraries/javalib/gnu/regexp/RE.java
diff -u kaffe/libraries/javalib/gnu/regexp/RE.java:1.6 kaffe/libraries/javalib/gnu/regexp/RE.java:1.7
--- kaffe/libraries/javalib/gnu/regexp/RE.java:1.6	Thu May 26 10:24:32 2005
+++ kaffe/libraries/javalib/gnu/regexp/RE.java	Sun Jul  3 02:07:39 2005
@@ -629,20 +629,29 @@
 	currentToken = setRepeated(currentToken,0,Integer.MAX_VALUE,index);
       }
 
-      // ONE-OR-MORE REPEAT OPERATOR
+      // ONE-OR-MORE REPEAT OPERATOR / POSSESSIVE MATCHING OPERATOR
       //  + | \+ depending on RE_BK_PLUS_QM
       //  not available if RE_LIMITED_OPS is set
 
       else if ((unit.ch == '+') && !syntax.get(RESyntax.RE_LIMITED_OPS) && (!syntax.get(RESyntax.RE_BK_PLUS_QM) ^ (unit.bk || quot))) {
 	if (currentToken == null)
           throw new REException(getLocalizedMessage("repeat.no.token"),REException.REG_BADRPT,index);
-	if (currentToken instanceof RETokenRepeated)
-          throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index);
-	if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary)
+	
+	// Check for possessive matching on RETokenRepeated
+	if (currentToken instanceof RETokenRepeated) {
+	  RETokenRepeated tokenRep = (RETokenRepeated)currentToken;
+	  if (syntax.get(RESyntax.RE_POSSESSIVE_OPS) && !tokenRep.isPossessive() && !tokenRep.isStingy())
+	    tokenRep.makePossessive();
+	  else
+	    throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index);
+
+	}
+	else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary)
 	  throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index);
-	if (currentToken.getMinimumLength() == 0)
+	else if (currentToken.getMinimumLength() == 0)
 	  throw new REException(getLocalizedMessage("repeat.empty.token"),REException.REG_BADRPT,index);
-	currentToken = setRepeated(currentToken,1,Integer.MAX_VALUE,index);
+	else
+	  currentToken = setRepeated(currentToken,1,Integer.MAX_VALUE,index);
       }
 
       // ZERO-OR-ONE REPEAT OPERATOR / STINGY MATCHING OPERATOR
@@ -655,13 +664,14 @@
 
 	// Check for stingy matching on RETokenRepeated
 	if (currentToken instanceof RETokenRepeated) {
-          if (syntax.get(RESyntax.RE_STINGY_OPS) && !((RETokenRepeated)currentToken).isStingy())
-            ((RETokenRepeated)currentToken).makeStingy();
-          else
-            throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index);
-        }
-        else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary)
-          throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index);
+	  RETokenRepeated tokenRep = (RETokenRepeated)currentToken;
+	  if (syntax.get(RESyntax.RE_STINGY_OPS) && !tokenRep.isStingy() && !tokenRep.isPossessive())
+	    tokenRep.makeStingy();
+	  else
+	    throw new REException(getLocalizedMessage("repeat.chained"),REException.REG_BADRPT,index);
+	}
+	else if (currentToken instanceof RETokenWordBoundary || currentToken instanceof RETokenWordBoundary)
+	  throw new REException(getLocalizedMessage("repeat.assertion"),REException.REG_BADRPT,index);
 	else
 	  currentToken = setRepeated(currentToken,0,1,index);
       }
Index: kaffe/libraries/javalib/gnu/regexp/RESyntax.java
diff -u kaffe/libraries/javalib/gnu/regexp/RESyntax.java:1.2 kaffe/libraries/javalib/gnu/regexp/RESyntax.java:1.3
--- kaffe/libraries/javalib/gnu/regexp/RESyntax.java:1.2	Wed Mar 17 19:28:05 2004
+++ kaffe/libraries/javalib/gnu/regexp/RESyntax.java	Sun Jul  3 02:07:39 2005
@@ -197,7 +197,12 @@
    */
   public static final int RE_CHAR_CLASS_ESC_IN_LISTS   = 24;
 
-  private static final int BIT_TOTAL                   = 25;
+  /**
+   * Syntax bit.  Possessive matching is allowed (++, *+, ?+, {x,y}+).
+   */
+  public static final int RE_POSSESSIVE_OPS            = 25;
+
+  private static final int BIT_TOTAL                   = 26;
 
   /**
    * Predefined syntax.
@@ -425,6 +430,7 @@
 
       RE_SYNTAX_JAVA_1_4 = new RESyntax(RE_SYNTAX_PERL5)
 	  // XXX
+	  .set(RE_POSSESSIVE_OPS)         // *+,?+,++,{}+
 	  .makeFinal();
   }
 
Index: kaffe/libraries/javalib/gnu/regexp/RETokenRepeated.java
diff -u kaffe/libraries/javalib/gnu/regexp/RETokenRepeated.java:1.2 kaffe/libraries/javalib/gnu/regexp/RETokenRepeated.java:1.3
--- kaffe/libraries/javalib/gnu/regexp/RETokenRepeated.java:1.2	Wed Mar 17 19:28:06 2004
+++ kaffe/libraries/javalib/gnu/regexp/RETokenRepeated.java	Sun Jul  3 02:07:39 2005
@@ -44,6 +44,7 @@
     private REToken token;
     private int min,max;
     private boolean stingy;
+    private boolean possessive;
     
     RETokenRepeated(int subIndex, REToken token, int min, int max) {
 	super(subIndex);
@@ -61,6 +62,16 @@
     boolean isStingy() {
 	return stingy;
     }
+
+    /** Sets possessive matching mode to true. */
+    void makePossessive() {
+        possessive = true;
+    }
+
+    /** Queries if this token has possessive matching enabled. */
+    boolean isPossessive() {
+        return possessive;
+    }
     
     /**
      * The minimum length of a repeated token is the minimum length
@@ -172,6 +183,8 @@
 		}
 	    }
 	    // else did not match rest of the tokens, try again on smaller sample
+	    // or break out when performing possessive matching
+	    if (possessive) break;
 	}
 	if (allResults != null) {
 	    mymatch.assignFrom(allResults); // does this get all?
Index: kaffe/libraries/javalib/java/util/regex/Pattern.java
diff -u kaffe/libraries/javalib/java/util/regex/Pattern.java:1.11 kaffe/libraries/javalib/java/util/regex/Pattern.java:1.12
--- kaffe/libraries/javalib/java/util/regex/Pattern.java:1.11	Thu May 26 10:24:32 2005
+++ kaffe/libraries/javalib/java/util/regex/Pattern.java	Sun Jul  3 02:07:40 2005
@@ -84,8 +84,7 @@
     // if ((flags & UNICODE_CASE) != 0) gnuFlags =
     // if ((flags & CANON_EQ) != 0) gnuFlags =
 
-    // Eventually there will be such a thing as JDK 1_4 syntax
-    RESyntax syntax = RESyntax.RE_SYNTAX_PERL5;
+    RESyntax syntax = RESyntax.RE_SYNTAX_JAVA_1_4;
     if ((flags & UNIX_LINES) != 0)
       {
 	// Use a syntax set with \n for linefeeds?



More information about the kaffe mailing list