[5] | 1 | package de.ugoe.cs.swe.bnftools.ui.syntaxcoloring;
|
---|
| 2 |
|
---|
| 3 | import org.eclipse.xtext.ui.editor.syntaxcoloring.antlr.DefaultAntlrTokenToAttributeIdMapper;
|
---|
| 4 |
|
---|
| 5 | public class EtsiBnfAntlrTokenToAttributeMapper extends
|
---|
| 6 | DefaultAntlrTokenToAttributeIdMapper {
|
---|
| 7 | String[] punctuation = new String[]{"::=", ";"};
|
---|
| 8 | String[] operators = new String[]{"|", "+"};
|
---|
| 9 | String[] parentheses = new String[]{"}", "{", "(", ")", "[", "]"};
|
---|
| 10 |
|
---|
| 11 | @Override
|
---|
| 12 | protected String calculateId(String tokenName, int tokenType) {
|
---|
| 13 | if (tokenName.contains("STRING")) {
|
---|
| 14 | return EtsiBnfHighlightingConfiguration.STRING_ID;
|
---|
| 15 | }
|
---|
| 16 | if (tokenName.contains("COLON")) {
|
---|
| 17 | return EtsiBnfHighlightingConfiguration.STRING_ID;
|
---|
| 18 | }
|
---|
| 19 | if (tokenName.contains("RULE_ID")) {
|
---|
| 20 | return EtsiBnfHighlightingConfiguration.ID_ID;
|
---|
| 21 | }
|
---|
| 22 | if (tokenName.contains("SECTIONHEADER")) {
|
---|
| 23 | return EtsiBnfHighlightingConfiguration.SECTIONHEADER_ID;
|
---|
| 24 | }
|
---|
| 25 | for (int i=0; i < punctuation.length; i++) {
|
---|
| 26 | if (tokenName.contains(punctuation[i]))
|
---|
| 27 | return EtsiBnfHighlightingConfiguration.PUNCTUATION_ID;
|
---|
| 28 | }
|
---|
| 29 | for (int i=0; i < operators.length; i++) {
|
---|
| 30 | if (tokenName.contains(operators[i]))
|
---|
| 31 | return EtsiBnfHighlightingConfiguration.OPERATOR_ID;
|
---|
| 32 | }
|
---|
| 33 | for (int i=0; i < parentheses.length; i++) {
|
---|
| 34 | if (tokenName.contains(parentheses[i]))
|
---|
| 35 | return EtsiBnfHighlightingConfiguration.PARENTHESES_ID;
|
---|
| 36 | }
|
---|
| 37 | if("RULE_ML_COMMENT".equals(tokenName) | "RULE_SL_COMMENT".equals(tokenName)) {
|
---|
| 38 | return EtsiBnfHighlightingConfiguration.COMMENT_ID;
|
---|
| 39 | }
|
---|
| 40 | return EtsiBnfHighlightingConfiguration.DEFAULT_ID;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | }
|
---|