1 21 22 package org.armedbear.j; 23 24 import gnu.regexp.RE; 25 import gnu.regexp.UncheckedRE; 26 import java.awt.event.KeyEvent ; 27 28 public final class VHDLMode extends AbstractMode implements Constants, Mode 29 { 30 private static final VHDLMode mode = new VHDLMode(); 31 32 private VHDLMode() 33 { 34 super(VHDL_MODE, VHDL_MODE_NAME); 35 keywords = new Keywords(this); 36 } 37 38 public static VHDLMode getMode() 39 { 40 return mode; 41 } 42 43 public String getCommentStart() 44 { 45 return "-- "; 46 } 47 48 public Formatter getFormatter(Buffer buffer) 49 { 50 return new VHDLFormatter(buffer); 51 } 52 53 public boolean isKeyword(String s) 54 { 55 return keywords.isKeyword(s.toLowerCase()); 56 } 57 58 protected void setKeyMapDefaults(KeyMap km) 59 { 60 km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent"); 61 km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag"); 62 km.mapKey(KeyEvent.VK_PERIOD, ALT_MASK, "findTagAtDot"); 63 km.mapKey(KeyEvent.VK_F12, 0, "wrapComment"); 64 km.mapKey(0xffc9, 0, "wrapComment"); } 67 68 public boolean isTaggable() 69 { 70 return true; 71 } 72 73 public Tagger getTagger(SystemBuffer buffer) 74 { 75 return new VHDLTagger(buffer); 76 } 77 78 public boolean canIndent() 79 { 80 return true; 81 } 82 83 public boolean canIndentPaste() 84 { 85 return false; 86 } 87 88 private static final RE beginRE = new UncheckedRE("^begin\\s"); 89 private static final RE thenRE = new UncheckedRE("\\s+then$"); 90 private static final RE loopRE = new UncheckedRE("\\s+loop$"); 91 92 public int getCorrectIndentation(Line line, Buffer buffer) 93 { 94 final int indentSize = buffer.getIndentSize(); 95 final Line model = findModel(line); 96 if (model == null) 97 return 0; 98 final int modelIndent = buffer.getIndentation(model); 99 final String modelTrim = trimSyntacticWhitespace(model); 100 101 if (modelTrim.equals("begin") || beginRE.getMatch(modelTrim) != null) { 102 return modelIndent + indentSize; 104 } 105 if (modelTrim.equals("then") || thenRE.getMatch(modelTrim) != null) { 106 return modelIndent + indentSize; 108 } 109 if (modelTrim.equals("loop") || loopRE.getMatch(modelTrim) != null) { 110 return modelIndent + indentSize; 112 } 113 114 return modelIndent; 115 } 116 117 private Line findModel(Line line) 118 { 119 Line model = line.previous(); 120 while (model != null && model.isBlank()) 121 model = model.previous(); 122 return model; 123 } 124 125 private static String trimSyntacticWhitespace(Line line) 128 { 129 VHDLSyntaxIterator it = new VHDLSyntaxIterator(null); 130 return new String (it.hideSyntacticWhitespace(line.getText())).trim(); 131 } 132 133 public boolean isIdentifierStart(char c) 134 { 135 return startChars.indexOf(c) >= 0; 136 } 137 138 public boolean isIdentifierPart(char c) 139 { 140 return partChars.indexOf(c) >= 0; 141 } 142 143 private static final String startChars = 144 "`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 145 146 private static final String partChars = 147 "`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; 148 } 149 | Popular Tags |