1 21 22 package org.armedbear.j; 23 24 public final class LispSyntaxIterator extends DefaultSyntaxIterator 27 implements Constants 28 { 29 public LispSyntaxIterator(Position pos) 30 { 31 super(pos); 32 } 33 34 public char[] hideSyntacticWhitespace(Line line) 37 { 38 if (line.flags() == STATE_QUOTE) 39 return hideSyntacticWhitespace(line.getText(), STATE_QUOTE); 40 else 41 return hideSyntacticWhitespace(line.getText(), STATE_NEUTRAL); 42 } 43 44 public char[] hideSyntacticWhitespace(String s) 45 { 46 return hideSyntacticWhitespace(s, STATE_NEUTRAL); 47 } 48 49 public char[] hideSyntacticWhitespace(String s, int initialState) 52 { 53 char[] chars = s.toCharArray(); 54 int state = initialState; 55 int length = chars.length; 56 for (int i = 0; i < length; i++) { 57 char c = chars[i]; 58 if (c == '\\' && i < length-1) { 59 chars[i++] = ' '; 61 chars[i] = ' '; 62 continue; 63 } 64 if (state == STATE_QUOTE) { 65 chars[i] = ' '; 66 if (c == '"') 67 state = STATE_NEUTRAL; 68 } else if (c == '"') { 69 state = STATE_QUOTE; 70 chars[i] = ' '; 71 } 72 } 73 int index = -1; 75 for (int i = 0; i < length-1; i++) { 76 if (chars[i] == '\\') 77 ++i; else if (chars[i] == ';') { 79 index = i; 80 break; 81 } 82 } 83 if (index >= 0) { 84 for (int i = index; i < length; i++) 85 chars[i] = ' '; 86 } 87 return chars; 88 } 89 } 90 | Popular Tags |