|
From: <mir...@us...> - 2006-08-28 22:38:03
|
Revision: 1592 Author: mirkostocker Date: 2006-08-28 15:37:44 -0700 (Mon, 28 Aug 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1592&view=rev Log Message: ----------- fixed bug #104 (syntax highlighting of heredocs with indented identifier) and also fixed the classpath of the astviewer Modified Paths: -------------- trunk/org.rubypeople.rdt.astviewer/.classpath trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java Modified: trunk/org.rubypeople.rdt.astviewer/.classpath =================================================================== --- trunk/org.rubypeople.rdt.astviewer/.classpath 2006-08-26 18:01:41 UTC (rev 1591) +++ trunk/org.rubypeople.rdt.astviewer/.classpath 2006-08-28 22:37:44 UTC (rev 1592) @@ -3,6 +3,6 @@ <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="lib" path="/Users/cwilliams/Documents/merge/trunk/org.jruby/lib/jruby.jar"/> + <classpathentry kind="lib" path="/org.jruby/lib/jruby.jar"/> <classpathentry kind="output" path="bin"/> </classpath> Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java =================================================================== --- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java 2006-08-26 18:01:41 UTC (rev 1591) +++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/HereDocPatternRule.java 2006-08-28 22:37:44 UTC (rev 1592) @@ -20,12 +20,13 @@ } protected boolean endSequenceDetected(ICharacterScanner scanner) { - char firstChar = (char) scanner.read(); if (Character.isWhitespace(firstChar)) { return false; } - + + boolean indentedKeyword = false; if (firstChar == '-') { + indentedKeyword = true; firstChar = (char) scanner.read(); } boolean isQuoted = false; @@ -35,26 +36,61 @@ quote = firstChar; firstChar = (char) scanner.read(); } - String keyword = ""; - char c = firstChar; - do { - if ((byte) c == ICharacterScanner.EOF || Character.isWhitespace(c)) { - break; - } - keyword += c; - c = (char) scanner.read(); - } while (true); + String keyword = readKeyword(scanner, firstChar); if (keyword.length() == 0) { return false; } if (isQuoted && !(keyword.charAt(keyword.length() - 1) == quote)) { return false; } if (isQuoted) { - fEndSequence = keyword.substring(0, keyword.length() - 1).toCharArray(); + fEndSequence = removeEndQuote(keyword).toCharArray(); } else { fEndSequence = keyword.toCharArray(); } boolean result = super.endSequenceDetected(scanner); if (!result) { return false; } - // the keyword must be at the beginning of the line - return scanner.getColumn() == fEndSequence.length; + + if(indentedKeyword) { + rewindToBeginOfLine(scanner); + char lastChar; + do { + lastChar = (char) scanner.read(); + } + while(Character.isWhitespace(lastChar)); + + String newKeyword = readKeyword(scanner, lastChar); + + if(isQuoted) + return removeEndQuote(keyword).equals(newKeyword); + else + return keyword.equals(newKeyword); + + } else { + return scanner.getColumn() == fEndSequence.length; + } } + private String removeEndQuote(String keyword) { + return keyword.substring(0, keyword.length() - 1); + } + + private void rewindToBeginOfLine(ICharacterScanner scanner) { + char readChar = 0; + while (readChar != '\n') { + scanner.unread(); + scanner.unread(); + readChar = (char) scanner.read(); + } + } + + private String readKeyword(ICharacterScanner scanner, char firstChar) { + String keyword = ""; + char c = firstChar; + do { + if ((byte) c == ICharacterScanner.EOF || Character.isWhitespace(c)) { + break; + } + keyword += c; + c = (char) scanner.read(); + } while (true); + return keyword; + } + } Modified: trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java =================================================================== --- trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java 2006-08-26 18:01:41 UTC (rev 1591) +++ trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/text/TC_RubyPartitionScanner.java 2006-08-28 22:37:44 UTC (rev 1592) @@ -55,6 +55,16 @@ assertEquals(IDocument.DEFAULT_CONTENT_TYPE, this.getContentType(source, 10)); } + public void testHereDocWithSpacesOK() { + String source = "puts <<-TEST\nMyName\n\tTEST\nputs 'ab'"; + assertEquals(RubyPartitionScanner.RUBY_STRING, this.getContentType(source, 5)); + + source = "puts <<-TEST\nMyName\n TEST\nputs 'ab'"; + assertEquals(RubyPartitionScanner.RUBY_STRING, this.getContentType(source, 5)); + + source = "puts <<-'ax%&'\nMyName\n ax%&"; + assertEquals(RubyPartitionScanner.RUBY_STRING, this.getContentType(source, 5)); + } public void testHereDocOK() { String source = "puts <<TEST\nMyName\nTEST"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |