1 package org.antlr.works.ate.syntax.language; 2 3 import org.antlr.works.ate.syntax.generic.ATESyntaxEngine; 4 import org.antlr.works.ate.syntax.generic.ATESyntaxLexer; 5 import org.antlr.works.ate.syntax.generic.ATESyntaxParser; 6 import org.antlr.works.ate.syntax.misc.ATEToken; 7 8 import javax.swing.text.AttributeSet ; 9 import javax.swing.text.SimpleAttributeSet ; 10 import javax.swing.text.StyleConstants ; 11 import java.awt.*; 12 import java.util.Set ; 13 43 44 public class ATELanguageSyntaxEngine extends ATESyntaxEngine { 45 46 protected SimpleAttributeSet commentAttr; 47 protected SimpleAttributeSet stringAttr; 48 protected SimpleAttributeSet keywordAttr; 49 50 public ATELanguageSyntaxEngine() { 51 commentAttr = new SimpleAttributeSet (); 52 stringAttr = new SimpleAttributeSet (); 53 keywordAttr = new SimpleAttributeSet (); 54 } 55 56 public void applyCommentAttribute(SimpleAttributeSet commentAttr) { 57 StyleConstants.setForeground(commentAttr, Color.lightGray); 58 StyleConstants.setItalic(commentAttr, true); 59 } 60 61 public void applyStringAttribute(SimpleAttributeSet stringAttr) { 62 StyleConstants.setForeground(stringAttr, new Color(0, 0.5f, 0)); 63 StyleConstants.setBold(stringAttr, true); 64 } 65 66 public void applyKeywordAttribute(SimpleAttributeSet keywordAttr) { 67 StyleConstants.setForeground(keywordAttr, new Color(0, 0, 0.5f)); 68 StyleConstants.setBold(keywordAttr, true); 69 } 70 71 public void refreshColoring() { 72 applyCommentAttribute(commentAttr); 73 applyStringAttribute(stringAttr); 74 applyKeywordAttribute(keywordAttr); 75 } 76 77 public ATESyntaxLexer createLexer() { 78 return new ATELanguageSyntaxLexer(); 79 } 80 81 public ATESyntaxParser createParser() { 82 return null; 84 } 85 86 91 public Set <String > getKeywords() { 92 return null; 93 } 94 95 public AttributeSet getAttributeForToken(ATEToken token) { 96 AttributeSet attr = null; 97 switch(token.type) { 98 case ATESyntaxLexer.TOKEN_COMPLEX_COMMENT: 99 case ATESyntaxLexer.TOKEN_SINGLE_COMMENT: 100 attr = commentAttr; 101 break; 102 case ATESyntaxLexer.TOKEN_DOUBLE_QUOTE_STRING: 103 case ATESyntaxLexer.TOKEN_SINGLE_QUOTE_STRING: 104 attr = stringAttr; 105 break; 106 default: 107 Set <String > s = getKeywords(); 108 if(s != null && s.contains(token.getAttribute())) 109 attr = keywordAttr; 110 break; 111 } 112 return attr; 113 } 114 115 } 116 | Popular Tags |