Changeset 161
- Timestamp:
- 10/18/02 21:35:47 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/LispSyntaxIterator.java
r2 r161 3 3 * 4 4 * Copyright (C) 1998-2002 Peter Graves 5 * $Id: LispSyntaxIterator.java,v 1. 1.1.1 2002-09-24 16:09:30piso Exp $5 * $Id: LispSyntaxIterator.java,v 1.2 2002-10-18 21:35:47 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 25 25 // i.e. skipping whitespace and comments. 26 26 public final class LispSyntaxIterator extends DefaultSyntaxIterator 27 implements Constants 27 28 { 28 29 public LispSyntaxIterator(Position pos) … … 31 32 } 32 33 34 // Caller must make sure parseBuffer() has been called so flags will be 35 // correct. 36 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 33 49 // Returns char array with syntactic whitespace (quotes and comments) 34 50 // replaced with actual space characters. 35 public char[] hideSyntacticWhitespace(String s )51 public char[] hideSyntacticWhitespace(String s, int initialState) 36 52 { 37 53 char[] chars = s.toCharArray(); 38 boolean inQuote = false;54 int state = initialState; 39 55 int length = chars.length; 40 56 for (int i = 0; i < length; i++) { 41 57 char c = chars[i]; 42 if (inQuote) { 58 if (c == '\\' && i < length-1) { 59 // Escape character. 60 chars[i++] = ' '; 43 61 chars[i] = ' '; 44 if (c == '\\' && i < length-1) { 45 // Handle escape char. 46 chars[++i] = ' '; 47 } else if (c == '"') 48 inQuote = false; 62 continue; 63 } 64 if (state == STATE_QUOTE) { 65 chars[i] = ' '; 66 if (c == '"') 67 state = STATE_NEUTRAL; 49 68 } else if (c == '"') { 50 inQuote = true;69 state = STATE_QUOTE; 51 70 chars[i] = ' '; 52 71 } … … 55 74 int index = -1; 56 75 for (int i = 0; i < length-1; i++) { 57 if (chars[i] == ';') { 76 if (chars[i] == '\\') 77 ++i; // Escape character. 78 else if (chars[i] == ';') { 58 79 index = i; 59 80 break;
Note: See TracChangeset
for help on using the changeset viewer.