aboutsummaryrefslogtreecommitdiffstats
path: root/org.openembedded.bc.ui/src/org/openembedded/bc/ui/editors/bitbake/VariableRule.java
blob: c615a9fd099a98262b288c2e9fbfc3813ec6fed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*****************************************************************************
 * Copyright (c) 2009 Ken Gilmer
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ken Gilmer - initial API and implementation
 *******************************************************************************/
package org.openembedded.bc.ui.editors.bitbake;

import org.eclipse.jface.text.rules.ICharacterScanner;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;

final class VariableRule implements IRule {

	/** Token to return for this rule */
	private final IToken fToken;

	/**
	 * Creates a new operator rule.
	 * 
	 * @param token
	 *            Token to use for this rule
	 */
	public VariableRule(IToken token) {
		fToken = token;
	}

	public IToken evaluate(ICharacterScanner scanner) {
		if (scanner.getColumn() > 0) {
			return Token.UNDEFINED;
		}

		int i = scanner.read();
		int c = 1;
		
		if (!Character.isLetter(i) && i != 10) {
			scanner.unread();
			return Token.UNDEFINED;
		}

		int p = i;

		while (i != ICharacterScanner.EOF && i != 10) {
			p = i;
			i = scanner.read();
			c++;
			
			if (i == '=') {
				scanner.unread();

				if (p == '?' || p == '+') {
					scanner.unread();
				}
				return fToken;
			}
		}

		for (int t = 0; t < c; t++) {
			scanner.unread();
		}
		
		return Token.UNDEFINED;
	}
}