|
From: <mir...@us...> - 2006-09-17 00:01:31
|
Revision: 1613
http://svn.sourceforge.net/rubyeclipse/?rev=1613&view=rev
Author: mirkostocker
Date: 2006-09-16 17:01:21 -0700 (Sat, 16 Sep 2006)
Log Message:
-----------
new rule for documentation comments that checks if the =end is on the beginning of a line. fixes ticket#205.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/DocumentationCommentRule.java
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/DocumentationCommentRule.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/DocumentationCommentRule.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/DocumentationCommentRule.java 2006-09-17 00:01:21 UTC (rev 1613)
@@ -0,0 +1,51 @@
+package org.rubypeople.rdt.internal.ui.text;
+
+import java.io.EOFException;
+
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.MultiLineRule;
+
+public class DocumentationCommentRule extends MultiLineRule {
+
+ private final static String endSequence = "=end";
+
+ public DocumentationCommentRule(IToken token) {
+ super("=begin", "", token);
+ setColumnConstraint(0);
+ }
+
+ @Override
+ protected boolean endSequenceDetected(ICharacterScanner scanner) {
+ if(scanner.getColumn() != 0)
+ return false;
+
+ String line = "";
+ do {
+ try {
+ line = readLine(scanner);
+ } catch (EOFException e) {
+ return true;
+ }
+ }
+ while(! endSequence.equals(line));
+
+ return true;
+ }
+
+ private String readLine(ICharacterScanner scanner) throws EOFException {
+ StringBuffer line = new StringBuffer();
+
+ while(true) {
+ int c = scanner.read();
+ if((char) c == '\n' || (char) c == '\r')
+ break;
+ else if (c == ICharacterScanner.EOF)
+ throw new EOFException();
+ else
+ line.append((char) c);
+ }
+
+ return line.toString();
+ }
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2006-09-11 20:02:13 UTC (rev 1612)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java 2006-09-17 00:01:21 UTC (rev 1613)
@@ -115,12 +115,7 @@
}, "?", "/", Token.UNDEFINED));
rules.add(new EndOfLineRule("#", singleLineComment));
- // Multiline comments
- MultiLineRule multiLineCommentRule = new MultiLineRule("=begin",
- "=end", multiLineComment);
- multiLineCommentRule.setColumnConstraint(0);
- rules.add(multiLineCommentRule);
-
+ rules.add(new DocumentationCommentRule(multiLineComment));
rules.add(new HereDocPatternRule(hereDoc));
// FIXME Create Hyrbid of RuleBasedPartitionScanner which allows IRule
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|