01: /*******************************************************************************
02: * Copyright (c) 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
11:
12: import org.eclipse.jface.text.rules.ICharacterScanner;
13: import org.eclipse.jface.text.rules.IToken;
14: import org.eclipse.jface.text.rules.IWordDetector;
15: import org.eclipse.jface.text.rules.WordPatternRule;
16:
17: public class ArgumentRule extends WordPatternRule {
18:
19: private static class ArgumentDetector implements IWordDetector {
20:
21: /*
22: * @see IWordDetector#isWordStart
23: */
24: public boolean isWordStart(char c) {
25: return '{' == c;
26: }
27:
28: /*
29: * @see IWordDetector#isWordPart
30: */
31: public boolean isWordPart(char c) {
32: return c == '}' || Character.isDigit(c);
33: }
34: }
35:
36: private int fCount = 0;
37:
38: /**
39: * Creates an argument rule for the given <code>token</code>.
40: *
41: * @param token the token to be returned on success
42: */
43: public ArgumentRule(IToken token) {
44: super (new ArgumentDetector(), "{", "}", token); //$NON-NLS-1$//$NON-NLS-2$
45: }
46:
47: /*
48: * @see org.eclipse.jface.text.rules.WordPatternRule#endSequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner)
49: */
50: protected boolean endSequenceDetected(ICharacterScanner scanner) {
51: fCount++;
52:
53: if (scanner.read() == '}')
54: return fCount > 2;
55:
56: scanner.unread();
57: return super .endSequenceDetected(scanner);
58: }
59:
60: /*
61: * @see org.eclipse.jface.text.rules.PatternRule#sequenceDetected(org.eclipse.jface.text.rules.ICharacterScanner, char[], boolean)
62: */
63: protected boolean sequenceDetected(ICharacterScanner scanner,
64: char[] sequence, boolean eofAllowed) {
65: fCount = 0;
66: return super.sequenceDetected(scanner, sequence, eofAllowed);
67: }
68: }
|