1 21 22 package org.armedbear.j; 23 24 import gnu.regexp.RE; 25 import gnu.regexp.REMatch; 26 import gnu.regexp.UncheckedRE; 27 28 public final class AsmFormatter extends Formatter 29 { 30 private static final UncheckedRE labelRE = new UncheckedRE("^[_a-zA-z0-9]+:"); 31 32 private static final int ASM_FORMAT_TEXT = 0; 33 private static final int ASM_FORMAT_COMMENT = 1; 34 private static final int ASM_FORMAT_LABEL = 2; 35 36 public AsmFormatter(Buffer buffer) 37 { 38 this.buffer = buffer; 39 } 40 41 public LineSegmentList formatLine(Line line) 42 { 43 clearSegmentList(); 44 final String text = getDetabbedText(line); 45 if (text.length() > 0) { 46 int start = 0; 47 int index = text.indexOf(':'); 48 if (index > 0) { 49 REMatch match = labelRE.getMatch(text); 50 if (match != null) { 51 index = match.getEndIndex(); 52 addSegment(text, 0, index, ASM_FORMAT_LABEL); 53 start = index; 54 } 55 } 56 index = text.indexOf(';', start); 57 if (index >= 0) { 58 addSegment(text, start, index, ASM_FORMAT_TEXT); 59 addSegment(text, index, ASM_FORMAT_COMMENT); 60 } else 61 addSegment(text, start, ASM_FORMAT_TEXT); 62 } else 63 addSegment(text, ASM_FORMAT_TEXT); 64 return segmentList; 65 } 66 67 public FormatTable getFormatTable() 68 { 69 if (formatTable == null) { 70 formatTable = new FormatTable(null); 71 formatTable.addEntryFromPrefs(ASM_FORMAT_TEXT, "text"); 72 formatTable.addEntryFromPrefs(ASM_FORMAT_COMMENT, "comment"); 73 formatTable.addEntryFromPrefs(ASM_FORMAT_LABEL, "function"); 74 } 75 return formatTable; 76 } 77 } 78 | Popular Tags |