Commit d97a59c9 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Added scanner to detect integers and floats; added number highlighting prefs


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 74c9dd5e
/******************************************************************************
* Copyright (c) 2000-2022 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.editors;
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;
/**
* Scanner rule to detect integers and floats
*
* @author Miklos Magyari
*
*/
public class NumberDetectionPatternRule implements IRule {
private final IToken integerToken;
private final IToken floatToken;
public NumberDetectionPatternRule(final IToken integerToken, final IToken floatToken) {
this.integerToken = integerToken;
this.floatToken = floatToken;
}
@Override
public IToken evaluate(ICharacterScanner scanner) {
boolean isDot = false;
int c = scanner.read();
if (isNumber((char)c)) {
do {
c = scanner.read();
if ((char)c == '.') {
isDot = true;
}
} while (isNumber((char)c) || (char)c == '.');
scanner.unread();
return isDot ? floatToken : integerToken;
}
scanner.unread();
return Token.UNDEFINED;
}
private boolean isNumber(char c) {
return c >= '0' && c <= '9';
}
}
......@@ -24,6 +24,7 @@ import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.titan.designer.editors.ColorManager;
import org.eclipse.titan.designer.editors.IDocumentGetter;
import org.eclipse.titan.designer.editors.NumberDetectionPatternRule;
import org.eclipse.titan.designer.editors.StringDetectionPatternRule;
import org.eclipse.titan.designer.editors.WhiteSpaceDetector;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
......@@ -128,9 +129,9 @@ public final class CodeScanner extends RuleBasedScanner implements IDocumentGett
final IToken otherConst = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_OTHER_CONST);
final IToken macro = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_PREPROCESSOR);
final IToken visibility = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_VISIBILITY_OP);
final IToken ninteger = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_INTEGER);
final IToken nfloat = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_FLOAT);
final IToken string = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_STRINGS);
final IToken other = colorManager.createTokenFromPreference(PreferenceConstants.COLOR_NORMAL_TEXT);
final List<IRule> rules = new ArrayList<IRule>();
......@@ -138,7 +139,8 @@ public final class CodeScanner extends RuleBasedScanner implements IDocumentGett
rules.add(new WhitespaceRule(new WhiteSpaceDetector()));
rules.add(new TTCN3StringDetectionPatternRule(string));
rules.add(new StringDetectionPatternRule("'", new char[][] { { '\'', 'B' }, { '\'', 'H' }, { '\'', 'O' } }, string));
rules.add(new NumberDetectionPatternRule(ninteger, nfloat));
final WordRule wordRule = new AstWordRule(new WordDetector(), other);
for (final String element : CodeScanner.KEYWORDS) {
wordRule.addWord(element, keyword);
......
......@@ -56,6 +56,13 @@ public final class PreferenceConstantValues {
put(PreferenceConstants.COLOR_STRINGS + PreferenceConstants.FOREGROUND, DARKGREEN);
put(PreferenceConstants.COLOR_STRINGS + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_STRINGS + PreferenceConstants.BACKGROUND, WHITE);
put(PreferenceConstants.COLOR_INTEGER + PreferenceConstants.FOREGROUND, DARKGREEN);
put(PreferenceConstants.COLOR_INTEGER + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_INTEGER + PreferenceConstants.BACKGROUND, WHITE);
put(PreferenceConstants.COLOR_FLOAT + PreferenceConstants.FOREGROUND, DARKGREEN);
put(PreferenceConstants.COLOR_FLOAT + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_FLOAT + PreferenceConstants.BACKGROUND, WHITE);
put(PreferenceConstants.COLOR_COMMENTS + PreferenceConstants.FOREGROUND, GREY20);
put(PreferenceConstants.COLOR_COMMENTS + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_COMMENTS + PreferenceConstants.BACKGROUND, WHITE);
......@@ -194,6 +201,12 @@ public final class PreferenceConstantValues {
put(PreferenceConstants.COLOR_STRINGS + PreferenceConstants.FOREGROUND, LIGHTGREEN);
put(PreferenceConstants.COLOR_STRINGS + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_STRINGS + PreferenceConstants.BACKGROUND, WHITE);
put(PreferenceConstants.COLOR_INTEGER + PreferenceConstants.FOREGROUND, LIGHTGREEN);
put(PreferenceConstants.COLOR_INTEGER + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_INTEGER + PreferenceConstants.BACKGROUND, WHITE);
put(PreferenceConstants.COLOR_FLOAT + PreferenceConstants.FOREGROUND, LIGHTGREEN);
put(PreferenceConstants.COLOR_FLOAT + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_FLOAT + PreferenceConstants.BACKGROUND, WHITE);
put(PreferenceConstants.COLOR_COMMENTS + PreferenceConstants.FOREGROUND, LIGHTGREY);
put(PreferenceConstants.COLOR_COMMENTS + PreferenceConstants.USEBACKGROUNDCOLOR, false);
put(PreferenceConstants.COLOR_COMMENTS + PreferenceConstants.BACKGROUND, WHITE);
......
......@@ -217,6 +217,8 @@ public final class PreferenceConstants {
public static final String COLOR_NORMAL_TEXT = COLOR_PREFIX + ".normalText";
public static final String COLOR_COMMENTS = COLOR_PREFIX + ".comments";
public static final String COLOR_STRINGS = COLOR_PREFIX + ".strings";
public static final String COLOR_INTEGER = COLOR_PREFIX + ".integers";
public static final String COLOR_FLOAT = COLOR_PREFIX + ".floats";
// asn1 specific
public static final String COLOR_ASN1_KEYWORDS = COLOR_PREFIX + ".asn1keywords";
......
......@@ -480,17 +480,17 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
addTemplateText(PreferenceConstants.COLOR_COMMENT_TAG, "@desc", " ");
addTemplateText(PreferenceConstants.COLOR_COMMENTS, "Syntax highlighting preview");
addTemplateText(PreferenceConstants.COLOR_HTML_TAG, "<br>", "\n");
addTemplateText(PreferenceConstants.COLOR_COMMENTS, "*/", "\n ");
addTemplateText(PreferenceConstants.COLOR_COMMENTS, "*/", "\n");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "module", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "MyExample", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "{", "\n\t");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "{", "\n");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "type", " ");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "port", " ");
addTemplateText(PreferenceConstants.COLOR_AST_DEFTYPE, "PCOType", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "message", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "{", "\n\t\t");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "{", "\n\t");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "inout", " ");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "charstring");
addTemplateText(PreferenceConstants.COLOR_TYPE, "charstring");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ";", "\n");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "}", "\n");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "type", " ");
......@@ -506,12 +506,33 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "record", " ");
addTemplateText(PreferenceConstants.COLOR_AST_DEFTYPE, "MyRecord", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "{", "\n\t");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "integer", " ");
addTemplateText(PreferenceConstants.COLOR_TYPE, "integer", " ");
addTemplateText(PreferenceConstants.COLOR_AST_VARIABLE, "x1");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ",", "\n\t");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "charstring", " ");
addTemplateText(PreferenceConstants.COLOR_TYPE, "charstring", " ");
addTemplateText(PreferenceConstants.COLOR_AST_VARIABLE, "c2", "\n");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "}", "\n");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "type", " ");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "enumerated", " ");
addTemplateText(PreferenceConstants.COLOR_AST_DEFTYPE, "WorkDays", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "{", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "Monday");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ",", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "Tuesday");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ",", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "Wednesday");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ",", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "Thursday");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ",", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "Friday", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "}", "\n");
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "const", " ");
addTemplateText(PreferenceConstants.COLOR_TYPE, "integer", " ");
addTemplateText(PreferenceConstants.COLOR_AST_CONSTANT, "c_integer", " ");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ":=", " ");
addTemplateText(PreferenceConstants.COLOR_INTEGER, "33");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, ";", "\n");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "}");
final IPreferenceStore defaultStore = Activator.getDefault().getPreferenceStore();
for (Map.Entry<String,List<StyleRange>> entry : rangeMap.entrySet()) {
......@@ -590,9 +611,9 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
final SyntaxHighlightColoringGroup generalGroup = new SyntaxHighlightColoringGroup("General");
generalGroup.add(new SyntaxHighlightColoringElement("Plain text", PreferenceConstants.COLOR_NORMAL_TEXT));
generalGroup.add(new SyntaxHighlightColoringElement("Documentation comment tags", PreferenceConstants.COLOR_COMMENT_TAG));
generalGroup.add(new SyntaxHighlightColoringElement("HTML tags in document comments", PreferenceConstants.COLOR_HTML_TAG));
generalGroup.add(new SyntaxHighlightColoringElement("Strings", PreferenceConstants.COLOR_STRINGS));
generalGroup.add(new SyntaxHighlightColoringElement("Integers", PreferenceConstants.COLOR_INTEGER));
generalGroup.add(new SyntaxHighlightColoringElement("Floats", PreferenceConstants.COLOR_FLOAT));
root.add(generalGroup);
final SyntaxHighlightColoringGroup asn1Group = new SyntaxHighlightColoringGroup("ASN.1 specific");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment