root/org.axdt.as3/src/org/axdt/as3/imp/tokenColorer/AS3TokenColorer.java @ 1d13b6581b070fa76b318152f73560dc3a4aa2a6

Revision 1d13b6581b070fa76b318152f73560dc3a4aa2a6, 2.6 KB (checked in by mb0 <mb0@…>, 17 months ago)

#155 now compatible to IMP Runtime 0.1.97

  • Property mode set to 100644
Line 
1package org.axdt.as3.imp.tokenColorer;
2
3import org.eclipse.imp.parser.IParseController;
4import org.eclipse.imp.services.ITokenColorer;
5import org.eclipse.imp.services.base.TokenColorerBase;
6import org.eclipse.jface.text.IRegion;
7import org.eclipse.jface.text.TextAttribute;
8import org.eclipse.swt.SWT;
9import org.eclipse.swt.graphics.Color;
10import org.eclipse.swt.widgets.Display;
11
12import org.axdt.as3.imp.parser.AS3ParseController;
13import org.axdt.as3.imp.parser.AS3Parsersym;
14
15import lpg.runtime.Adjunct;
16import lpg.runtime.IToken;
17
18public class AS3TokenColorer extends TokenColorerBase implements AS3Parsersym, ITokenColorer {
19
20        TextAttribute commentAttribute, docAttribute, keywordAttribute, stringAttribute,
21                        numberAttribute, doubleAttribute, identifierAttribute;
22        Color commentColor, docColor, stringColor, identifierColor, numberColor, keywordColor;
23
24        public TextAttribute getColoring(IParseController controller, Object o) {
25                IToken token = (IToken) o;
26                if (token.getKind() == TK_EOF_TOKEN) return null;
27
28                switch (token.getKind()) {
29                case TK_IDENTIFIER:
30                        return identifierAttribute;
31                case TK_Number:
32                        return numberAttribute;
33                case TK_String:
34                        return stringAttribute;
35                case TK_MlComment:
36                        int i = token.getAdjunctIndex();
37                        Adjunct adj = (Adjunct) token.getIPrsStream().getAdjuncts().get(i);
38                        if (adj.toString().startsWith("/**")) return docAttribute;
39                case TK_SlComment:
40                        return commentAttribute;
41                default:
42                        if (token == null) {
43                                return null;
44                        }
45                        if (((AS3ParseController) controller).isKeyword(token.getKind()))
46                                return keywordAttribute;
47                        return super.getColoring(controller, token);
48                }
49        }
50
51        public AS3TokenColorer() {
52                super();
53                // TODO: add color and text preference
54                Display display = Display.getDefault();
55                docColor = new Color(display, 0x3F, 0x5F, 0xBF);
56                docAttribute = new TextAttribute(docColor, null, SWT.NORMAL);
57                commentColor = new Color(display, 0x3F, 0x7F, 0x5F);
58                commentAttribute = new TextAttribute(commentColor, null, SWT.NORMAL);
59                stringColor = new Color(display, 0x2A, 0x00, 0xFF);
60                stringAttribute = new TextAttribute(stringColor, null, SWT.BOLD);
61                identifierColor = new Color(display, 0x00, 0x00, 0x00);
62                identifierAttribute = new TextAttribute(identifierColor, null, SWT.NORMAL);
63                numberColor = new Color(display, 0x64, 0x64, 0x64);
64                numberAttribute = new TextAttribute(numberColor, null, SWT.BOLD);
65                keywordColor = new Color(display, 0x7F, 0x00, 0x55);
66                keywordAttribute = new TextAttribute(keywordColor, null, SWT.BOLD);
67        }
68
69        public IRegion calculateDamageExtent(IRegion seed) {
70                return seed;
71        }
72
73        public IRegion calculateDamageExtent(IRegion seed, IParseController arg1) {
74                return seed;
75        }
76
77}
Note: See TracBrowser for help on using the browser.