| 1 | package org.axdt.as3.imp.tokenColorer; |
|---|
| 2 | |
|---|
| 3 | import org.eclipse.imp.parser.IParseController; |
|---|
| 4 | import org.eclipse.imp.services.ITokenColorer; |
|---|
| 5 | import org.eclipse.imp.services.base.TokenColorerBase; |
|---|
| 6 | import org.eclipse.jface.text.IRegion; |
|---|
| 7 | import org.eclipse.jface.text.TextAttribute; |
|---|
| 8 | import org.eclipse.swt.SWT; |
|---|
| 9 | import org.eclipse.swt.graphics.Color; |
|---|
| 10 | import org.eclipse.swt.widgets.Display; |
|---|
| 11 | |
|---|
| 12 | import org.axdt.as3.imp.parser.AS3ParseController; |
|---|
| 13 | import org.axdt.as3.imp.parser.AS3Parsersym; |
|---|
| 14 | |
|---|
| 15 | import lpg.runtime.Adjunct; |
|---|
| 16 | import lpg.runtime.IToken; |
|---|
| 17 | |
|---|
| 18 | public 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 | } |
|---|