|
From: Christopher W. <caw...@us...> - 2005-04-01 01:59:32
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16048/src/org/rubypeople/rdt/internal/ui/text Modified Files: RubySourceViewerConfiguration.java IRubyColorConstants.java RubyPartitionScanner.java RubyTextTools.java Log Message: highlight and partition regular expressions separately from code. Handle more ways of defining strings and regexps (like %r, %q, %Q, etc) for syntax highlighting Index: RubyPartitionScanner.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RubyPartitionScanner.java 2 Mar 2005 00:56:49 -0000 1.6 --- RubyPartitionScanner.java 1 Apr 2005 01:59:20 -0000 1.7 *************** *** 15,25 **** - public final static String SKIP = "partition_scanner_ruby_skip"; public final static String STRING = "partition_scanner_ruby_string"; public final static String MULTI_LINE_COMMENT = "partition_scanner_ruby_multiline_comment"; public static final String SINGLE_LINE_COMMENT = "partition_scanner_ruby_singleline_comment"; ! public static final String[] LEGAL_CONTENT_TYPES = {STRING, MULTI_LINE_COMMENT, SINGLE_LINE_COMMENT}; ! ! public RubyPartitionScanner() { super(); --- 15,25 ---- public final static String STRING = "partition_scanner_ruby_string"; public final static String MULTI_LINE_COMMENT = "partition_scanner_ruby_multiline_comment"; public static final String SINGLE_LINE_COMMENT = "partition_scanner_ruby_singleline_comment"; ! public static final String REGULAR_EXPRESSION = "partition_scanner_ruby_regular_expression"; ! ! public static final String[] LEGAL_CONTENT_TYPES = {STRING, MULTI_LINE_COMMENT, SINGLE_LINE_COMMENT, REGULAR_EXPRESSION}; ! public RubyPartitionScanner() { super(); *************** *** 28,35 **** protected void initialize() { - IToken skip = new Token(SKIP); IToken string = new Token(STRING); IToken multiLineComment = new Token(MULTI_LINE_COMMENT); IToken singleLineComment = new Token(SINGLE_LINE_COMMENT); List rules = new ArrayList(); --- 28,35 ---- protected void initialize() { IToken string = new Token(STRING); IToken multiLineComment = new Token(MULTI_LINE_COMMENT); IToken singleLineComment = new Token(SINGLE_LINE_COMMENT); + IToken regexp = new Token(REGULAR_EXPRESSION); List rules = new ArrayList(); *************** *** 38,52 **** // strings (and therefore have quotes inside them which don't end the // partition) rules.add(new SingleLineRule("\"", "\"", string, '\\')); ! // Add rule for single line comments. rules.add(new EndOfLineRule("#", singleLineComment)); ! ! rules.add(new SingleLineRule("'", "'", skip, '\\')); rules.add(new MultiLineRule("=begin", "=end", multiLineComment)); IPredicateRule[] result = new IPredicateRule[rules.size()]; rules.toArray(result); setPredicateRules(result); } } \ No newline at end of file --- 38,76 ---- // strings (and therefore have quotes inside them which don't end the // partition) + + // Strings rules.add(new SingleLineRule("\"", "\"", string, '\\')); + rules.add(new SingleLineRule("'", "'", string, '\\')); + createGeneralDelimitedRules(rules, "%q", string, '\\'); + createGeneralDelimitedRules(rules, "%Q", string, '\\'); + createGeneralDelimitedRules(rules, "%", string, '\\'); + // Regular expressions + createRuleWithOptionalEndChars(rules, "/", "/", new char[] {'s', 'u', 'e', 'n', 'x', 'm', 'o', 'i'}, regexp, '\\'); + rules.add(new SingleLineRule("/", "/", regexp, '\\')); + createGeneralDelimitedRules(rules, "%r", regexp, '\\'); ! // Single line comments rules.add(new EndOfLineRule("#", singleLineComment)); ! // Multiline comments rules.add(new MultiLineRule("=begin", "=end", multiLineComment)); + // TODO Handle Heredocs! + IPredicateRule[] result = new IPredicateRule[rules.size()]; rules.toArray(result); setPredicateRules(result); } + + private void createRuleWithOptionalEndChars(List rules, String prefix, String endString, char[] options, IToken token, char escapeChar) { + for (int i = 0; i < options.length; i++) { + rules.add(new SingleLineRule(prefix, endString + options[i], token, escapeChar)); + } + } + + private void createGeneralDelimitedRules(List rules, String prefix, IToken token, char escapeChar) { + rules.add(new MultiLineRule(prefix + "[", "]", token, escapeChar)); + rules.add(new MultiLineRule(prefix + "{", "}", token, escapeChar)); + rules.add(new MultiLineRule(prefix + "(", ")", token, escapeChar)); + rules.add(new MultiLineRule(prefix + "<", ">", token, escapeChar)); + } } \ No newline at end of file Index: RubyTextTools.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyTextTools.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** RubyTextTools.java 2 Mar 2005 00:56:49 -0000 1.8 --- RubyTextTools.java 1 Apr 2005 01:59:20 -0000 1.9 *************** *** 46,49 **** --- 46,50 ---- /** The preference change listener */ private PreferenceListener fPreferenceListener = new PreferenceListener(); + private SingleTokenRubyCodeScanner fRegexpScanner; /** *************** *** 103,107 **** fSinglelineCommentScanner = new RubyCommentScanner(fColorManager, store, coreStore, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT); stringScanner = new SingleTokenRubyCodeScanner(fColorManager, store, IRubyColorConstants.RUBY_STRING); ! fPreferenceStore = store; fPreferenceStore.addPropertyChangeListener(fPreferenceListener); --- 104,109 ---- fSinglelineCommentScanner = new RubyCommentScanner(fColorManager, store, coreStore, IRubyColorConstants.RUBY_SINGLE_LINE_COMMENT); stringScanner = new SingleTokenRubyCodeScanner(fColorManager, store, IRubyColorConstants.RUBY_STRING); ! fRegexpScanner = new SingleTokenRubyCodeScanner(fColorManager, store, IRubyColorConstants.RUBY_REGEXP); ! fPreferenceStore = store; fPreferenceStore.addPropertyChangeListener(fPreferenceListener); *************** *** 128,131 **** --- 130,134 ---- if (fSinglelineCommentScanner.affectsBehavior(event)) fSinglelineCommentScanner.adaptToPreferenceChange(event); if (stringScanner.affectsBehavior(event)) stringScanner.adaptToPreferenceChange(event); + if (fRegexpScanner.affectsBehavior(event)) fRegexpScanner.adaptToPreferenceChange(event); // if (fJavaDocScanner.affectsBehavior(event)) // fJavaDocScanner.adaptToPreferenceChange(event); *************** *** 180,184 **** || fMultilineCommentScanner.affectsBehavior(event) || fSinglelineCommentScanner.affectsBehavior(event) ! || stringScanner.affectsBehavior(event); } --- 183,188 ---- || fMultilineCommentScanner.affectsBehavior(event) || fSinglelineCommentScanner.affectsBehavior(event) ! || stringScanner.affectsBehavior(event) ! || fRegexpScanner.affectsBehavior(event); } *************** *** 213,216 **** --- 217,221 ---- fSinglelineCommentScanner = null; stringScanner = null; + fRegexpScanner = null; // fJavaDocScanner= null; partitionScanner = null; *************** *** 234,236 **** --- 239,245 ---- } + public ITokenScanner getRegexpScanner() { + return fRegexpScanner; + } + } Index: RubySourceViewerConfiguration.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubySourceViewerConfiguration.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** RubySourceViewerConfiguration.java 5 Mar 2005 19:38:08 -0000 1.18 --- RubySourceViewerConfiguration.java 1 Apr 2005 01:59:20 -0000 1.19 *************** *** 56,59 **** --- 56,63 ---- reconciler.setRepairer(dr, RubyPartitionScanner.STRING); + dr = new DefaultDamagerRepairer(getRegexpScanner()); + reconciler.setDamager(dr, RubyPartitionScanner.REGULAR_EXPRESSION); + reconciler.setRepairer(dr, RubyPartitionScanner.REGULAR_EXPRESSION); + return reconciler; } *************** *** 74,77 **** --- 78,85 ---- return textTools.getStringScanner(); } + + protected ITokenScanner getRegexpScanner() { + return textTools.getRegexpScanner(); + } public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { Index: IRubyColorConstants.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/IRubyColorConstants.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IRubyColorConstants.java 2 Mar 2005 00:56:49 -0000 1.2 --- IRubyColorConstants.java 1 Apr 2005 01:59:20 -0000 1.3 *************** *** 6,9 **** --- 6,10 ---- public static final String RUBY_KEYWORD = RUBY_COLOR_PREFIX + "keyword"; public static final String RUBY_STRING = RUBY_COLOR_PREFIX + "string"; + public static final String RUBY_REGEXP = RUBY_COLOR_PREFIX + "regexp"; public static final String RUBY_MULTI_LINE_COMMENT = RUBY_COLOR_PREFIX + "multiline_comment"; |