bug fixing
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java
index e886872..8616a36 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java
@@ -28,7 +28,7 @@
 	
 	private int fStart;
 	private int fEnd;
-	private int	fDocumentLength;
+	private int fDocumentLength;
 	
 	
 	/**
@@ -107,7 +107,7 @@
 				
 		if (fOffset == fEnd)
 			shiftBuffer(fEnd);
-		else if (fOffset > fEnd)
+		else if (fOffset < fStart || fEnd < fOffset)
 			shiftBuffer(fOffset);
 			
 		return fBuffer[fOffset++ - fStart];			
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java
index 6d8f55a..f067197 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java
@@ -34,6 +34,6 @@
 	 * @param escapeCharacter the escape character
 	 */
 	public EndOfLineRule(String startSequence, IToken token, char escapeCharacter) {
-		super(startSequence, null, token, escapeCharacter);
+		super(startSequence, null, token, escapeCharacter, true);
 	}
 }
\ No newline at end of file
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java
index f247574..21494bd 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java
@@ -21,7 +21,7 @@
 	 * @param token the token to be returned on success
 	 */
 	public MultiLineRule(String startSequence, String endSequence, IToken token) {
-		this(startSequence, endSequence, token, (char)0);
+		this(startSequence, endSequence, token, (char) 0);
 	}
 
 	/**
@@ -35,6 +35,21 @@
 	 * @param escapeCharacter the escape character
 	 */
 	public MultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) {
-		super(startSequence, endSequence, token, escapeCharacter, false);
+		this(startSequence, endSequence, token, escapeCharacter, false);
+	}
+	
+	/**
+	 * Creates a rule for the given starting and ending sequence
+	 * which, if detected, will return the specific token.
+	 * Any character which follows the given escape character will be ignored.
+	 *
+	 * @param startSequence the pattern's start sequence
+	 * @param endSequence the pattern's end sequence
+	 * @param token the token to be returned on success
+	 * @param escapeCharacter the escape character
+	 * @param breaksOnEOF indicates whether the end of the file terminates this rule successfully
+	 */
+	public MultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF) {
+		super(startSequence, endSequence, token, escapeCharacter, false, breaksOnEOF);
 	}
 }
\ No newline at end of file
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java
index 80ca1ea..57bf9ba 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java
@@ -39,8 +39,10 @@
 	protected int fColumn= UNDEFINED;
 	/** The pattern's escape character */
 	protected char fEscapeCharacter;
-	/** Indicates whether end of line termines the pattern */
+	/** Indicates whether end of line terminates the pattern */
 	protected boolean fBreaksOnEOL;
+	/** Indicates whether end of file terminates the pattern */
+	protected boolean fBreaksOnEOF;
 
 	/**
 	 * Creates a rule for the given starting and ending sequence.
@@ -52,7 +54,7 @@
 	 * @param endSequence the pattern's end sequence, <code>null</code> is a legal value
 	 * @param token the token which will be returned on success
 	 * @param escapeCharacter any character following this one will be ignored
-	 * @param indicates whether the end of the line also termines the pattern
+	 * @param breaksOnEOL indicates whether the end of the line also terminates the pattern
 	 */
 	public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL) {
 		Assert.isTrue(startSequence != null && startSequence.length() > 0);
@@ -67,6 +69,24 @@
 	}
 	
 	/**
+	 * Creates a rule for the given starting and ending sequence.
+	 * When these sequences are detected the rule will return the specified token.
+	 * Alternatively, the sequence can also be ended by the end of the line.
+	 * Any character which follows the given escapeCharacter will be ignored.
+	 *
+	 * @param startSequence the pattern's start sequence
+	 * @param endSequence the pattern's end sequence, <code>null</code> is a legal value
+	 * @param token the token which will be returned on success
+	 * @param escapeCharacter any character following this one will be ignored
+	 * @param breaksOnEOL indicates whether the end of the line also terminates the pattern
+	 * @param breaksOnEOF indicates whether the end of the file also terminates the pattern
+	 */
+	public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF) {
+		this(startSequence, endSequence, token, escapeCharacter, breaksOnEOL);
+		fBreaksOnEOF= breaksOnEOF;
+	}
+	
+	/**
 	 * Sets a column constraint for this rule. If set, the rule's token
 	 * will only be returned if the pattern is detected starting at the 
 	 * specified column. If the column is smaller then 0, the column
@@ -152,11 +172,12 @@
 			} else if (fBreaksOnEOL) {
 				// Check for end of line since it can be used to terminate the pattern.
 				for (int i= 0; i < delimiters.length; i++) {
-					if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false))
+					if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], true))
 						return true;
 				}
 			}
 		}
+		if (fBreaksOnEOF) return true;
 		scanner.unread();
 		return false;
 	}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java
index 9ffdfbc..65caf8e 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java
@@ -36,6 +36,22 @@
 	 * @param escapeCharacter the escape character
 	 */
 	public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) {
-		super(startSequence, endSequence, token, escapeCharacter, true);
+		this(startSequence, endSequence, token, escapeCharacter, false);
+	}
+	
+	/**
+	 * Creates a rule for the given starting and ending sequence
+	 * which, if detected, will return the specified token.
+	 * Any character which follows the given escape character
+	 * will be ignored.
+	 *
+	 * @param startSequence the pattern's start sequence
+	 * @param endSequence the pattern's end sequence
+	 * @param token the token to be returned on success
+	 * @param escapeCharacter the escape character
+	 * @param breaksOnEOF indicates whether the end of the file successfully terminates this rule
+	 */
+	public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF) {
+		super(startSequence, endSequence, token, escapeCharacter, true, breaksOnEOF);
 	}
 }
\ No newline at end of file
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
index 1a7bcef..c46da34 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
@@ -88,8 +88,8 @@
 		rules.add(new WordPredicateRule(comment));

 

 		// Add rules for multi-line comments and javadoc.

-		rules.add(new MultiLineRule("/**", "*/", javaDoc)); //$NON-NLS-1$ //$NON-NLS-2$

-		rules.add(new MultiLineRule("/*", "*/", comment)); //$NON-NLS-1$ //$NON-NLS-2$

+		rules.add(new MultiLineRule("/**", "*/", javaDoc, (char) 0, true)); //$NON-NLS-1$ //$NON-NLS-2$

+		rules.add(new MultiLineRule("/*", "*/", comment, (char) 0, true)); //$NON-NLS-1$ //$NON-NLS-2$

 

 		IPredicateRule[] result= new IPredicateRule[rules.size()];

 		rules.toArray(result);