Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 53b28e51537ba61faba5d570922269ae280246ac (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2010 Mat Booth and others.
 * 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
 *******************************************************************************/
package org.eclipse.dltk.sh.ui.text;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.dltk.sh.ui.IShellColorConstants;
import org.eclipse.dltk.ui.text.AbstractScriptScanner;
import org.eclipse.dltk.ui.text.IColorManager;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.WhitespaceRule;

/**
 * Scans command substitution document partitions. I.e., the sections between
 * back-ticks or enclosed in $()s.
 */
public class EvalScanner extends AbstractScriptScanner {

	/**
	 * Array of preference keys used to define the style of token types used by
	 * this scanner.
	 */
	private static String fgTokenProperties[] = new String[] { IShellColorConstants.SHELL_EVAL,
		IShellColorConstants.SHELL_VARIABLE };

	public EvalScanner(IColorManager manager, IPreferenceStore store) {
		super(manager, store);
		initialize();
	}

	@Override
	protected List<IRule> createRules() {
		List<IRule> rules = new ArrayList<>();

		// Token types used in the rules
		IToken defaultToken = this.getToken(IShellColorConstants.SHELL_EVAL);
		IToken varToken = this.getToken(IShellColorConstants.SHELL_VARIABLE);

		// Add generic whitespace rule. This is here for efficiency reasons,
		// there is a LOT of whitespace and when a token is detected the other
		// rules are not evaluated.
		rules.add(new WhitespaceRule(new WhitespaceDetector()));
		rules.add(new DollarBraceCountingRule('{', '}', varToken, '\\'));
		rules.add(new DollarRule(new DollarDetector(), defaultToken, varToken));
		setDefaultReturnToken(defaultToken);
		return rules;
	}

	@Override
	protected String[] getTokenProperties() {
		return fgTokenProperties;
	}

}

Back to the top