1 20 21 package org.armedbear.j; 22 23 import java.util.Vector ; 24 25 public final class SchemeTagger extends Tagger 26 { 27 private static final int NEUTRAL = 0; 29 private static final int DEFUN = 1; 30 31 protected Position pos; 32 protected String token; 33 protected Position tokenStart; 34 35 private static final Mode schemeMode = SchemeMode.getMode(); 36 37 public SchemeTagger(SystemBuffer buffer) 38 { 39 super(buffer); 40 } 41 42 public void run() 43 { 44 Vector tags = new Vector (); 45 pos = new Position(buffer.getFirstLine(), 0); 46 token = null; 47 tokenStart = null; 48 int state = NEUTRAL; 49 while (!pos.atEnd()) { 50 char c = pos.getChar(); 51 if (Character.isWhitespace(c)) { 52 pos.skipWhitespace(); 53 continue; 54 } 55 if (c == '\\') { 56 if (pos.getOffset() < pos.getLineLength() - 1) { 58 pos.skip(2); 59 continue; 60 } 61 Line nextLine = pos.getNextLine(); 62 if (nextLine == null) 63 break; 64 pos.moveTo(nextLine, 0); 65 continue; 66 } 67 if (c == '\"') { 68 pos.skipQuote(); 69 continue; 70 } 71 if (c == ';') { 72 Line nextLine = pos.getNextLine(); 74 if (nextLine == null) 75 break; 76 pos.moveTo(nextLine, 0); 77 continue; 78 } 79 if (schemeMode.isIdentifierStart(c)) { 80 gatherToken(); 81 if (state == DEFUN) { 82 LocalTag tag = new LispTag(token, tokenStart); 83 tags.add(tag); 84 state = NEUTRAL; 85 } else if (token.equals("define")) 86 state = DEFUN; 87 continue; 88 } 89 pos.next(); 90 } 91 buffer.setTags(tags); 92 } 93 94 private void gatherToken() 95 { 96 tokenStart = new Position(pos); 97 FastStringBuffer sb = new FastStringBuffer(); 98 char c; 99 while (schemeMode.isIdentifierPart(c = pos.getChar())) { 100 sb.append(c); 101 if (!pos.next()) 102 break; 103 } 104 token = sb.toString(); 105 } 106 } 107 | Popular Tags |