Changeset 184
- Timestamp:
- 10/30/02 17:46:35 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/LispTagger.java
r170 r184 21 21 package org.armedbear.j; 22 22 23 import java.util. Vector;23 import java.util.ArrayList; 24 24 25 25 public final class LispTagger extends Tagger 26 26 { 27 27 // States. 28 private static final int NEUTRAL = 0; 29 private static final int DEFUN = 1; 28 private static final int NEUTRAL = 0; 29 private static final int OPEN_PAREN = 1; 30 private static final int DEFUN = 2; 30 31 31 protected Position pos; 32 protected String token; 33 protected Position tokenStart; 34 35 private static final Mode lispMode = LispMode.getMode(); 32 private static final Mode mode = LispMode.getMode(); 36 33 37 34 public LispTagger(SystemBuffer buffer) … … 42 39 public void run() 43 40 { 44 Vector tags = new Vector(); 45 pos = new Position(buffer.getFirstLine(), 0); 46 token = null; 47 tokenStart = null; 41 ArrayList tags = new ArrayList(); 42 Position pos = new Position(buffer.getFirstLine(), 0); 48 43 int state = NEUTRAL; 49 44 while (!pos.atEnd()) { … … 77 72 continue; 78 73 } 79 if (lispMode.isIdentifierStart(c)) { 80 gatherToken(); 74 if (c == '(') { 75 state = OPEN_PAREN; 76 pos.next(); 77 continue; 78 } 79 if (mode.isIdentifierStart(c)) { 81 80 if (state == DEFUN) { 81 Position tokenStart = pos.copy(); 82 String token = gatherToken(pos); 82 83 LocalTag tag = new LispTag(token, tokenStart); 83 84 tags.add(tag); 84 85 state = NEUTRAL; 85 } else if (token.startsWith("def")) { 86 if (token.equals("defun") || 87 token.equals("defvar") || 88 token.equals("defmacro") || 89 token.equals("defcustom") || 90 token.equals("defgroup") || 91 token.equals("defsubst")) 86 continue; 87 } 88 if (state == OPEN_PAREN) { 89 String preceding = 90 pos.getLine().substring(0, pos.getOffset()).trim(); 91 if (!preceding.equals("(")) { 92 state = NEUTRAL; 93 continue; 94 } 95 String token = gatherToken(pos); 96 if (isDefinitionStart(token, pos)) 92 97 state = DEFUN; 98 else 99 state = NEUTRAL; 100 continue; 93 101 } 102 skipToken(pos); 94 103 continue; 95 104 } 105 state = NEUTRAL; 96 106 pos.next(); 97 107 } 98 108 buffer.setTags(tags); 99 109 } 110 111 private static final String[] tokens = new String[] { 112 "defun", "defvar", "defmacro", "defcustom", "defgroup", "defsubst" 113 }; 114 115 // pos points to first char after token. 116 private boolean isDefinitionStart(String token, Position pos) 117 { 118 if (token.startsWith("def")) 119 if (Utilities.isOneOf(token, tokens)) 120 return true; 121 122 return false; 123 } 100 124 101 private void gatherToken() 125 // Advances pos past token. 126 private String gatherToken(Position pos) 102 127 { 103 tokenStart = new Position(pos);104 128 FastStringBuffer sb = new FastStringBuffer(); 105 129 char c; 106 while ( lispMode.isIdentifierPart(c = pos.getChar())) {130 while (mode.isIdentifierPart(c = pos.getChar())) { 107 131 sb.append(c); 108 132 if (!pos.next()) 109 133 break; 110 134 } 111 token = sb.toString(); 135 return sb.toString(); 136 } 137 138 // Advances pos past token. 139 private void skipToken(Position pos) 140 { 141 while (mode.isIdentifierPart(pos.getChar())) { 142 if (!pos.next()) 143 return; 144 } 112 145 } 113 146 }
Note: See TracChangeset
for help on using the changeset viewer.