01: /*
02: * VHDLSyntaxIterator.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: VHDLSyntaxIterator.java,v 1.1.1.1 2002/09/24 16:09:28 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: // Supports movement through the syntactically important text of a buffer, i.e.
25: // skipping whitespace and comments.
26: public final class VHDLSyntaxIterator extends DefaultSyntaxIterator {
27: private static final int STATE_NEUTRAL = 0;
28: private static final int STATE_DOUBLEQUOTE = 1;
29:
30: public VHDLSyntaxIterator(Position pos) {
31: super (pos);
32: }
33:
34: public char[] hideSyntacticWhitespace(Line line) {
35: return hideSyntacticWhitespace(line.getText());
36: }
37:
38: // Returns char array with syntactic whitespace (quotes and comments)
39: // replaced with actual space characters.
40: public char[] hideSyntacticWhitespace(String s) {
41: final char[] chars = s.toCharArray();
42: int state = STATE_NEUTRAL;
43: final int length = chars.length;
44: for (int i = 0; i < length; i++) {
45: char c = chars[i];
46: if (c == '\\' && i < length - 1) {
47: // Escape character.
48: chars[i++] = ' ';
49: chars[i] = ' ';
50: continue;
51: }
52: if (state == STATE_DOUBLEQUOTE) {
53: chars[i] = ' ';
54: if (c == '"')
55: state = STATE_NEUTRAL;
56: continue;
57: }
58: // Reaching here, STATE_NEUTRAL...
59: if (c == '"') {
60: chars[i] = ' ';
61: state = STATE_DOUBLEQUOTE;
62: continue;
63: }
64: if (c == '-') {
65: if (i < length - 1) {
66: if (chars[i + 1] == '-') {
67: // "//" comment starting
68: for (int j = i; j < length; j++)
69: chars[j] = ' ';
70: return chars;
71: }
72: }
73: }
74: }
75: return chars;
76: }
77: }
|