01: /*
02: * SchemeMode.java
03: *
04: * Copyright (C) 1998-2002 Peter Graves
05: * $Id: SchemeMode.java,v 1.1.1.1 2002/09/24 16:09:19 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: import java.awt.event.KeyEvent;
25:
26: public final class SchemeMode extends AbstractMode implements
27: Constants, Mode {
28: private static final SchemeMode mode = new SchemeMode();
29:
30: private SchemeMode() {
31: super (SCHEME_MODE, SCHEME_MODE_NAME);
32: keywords = new Keywords(this );
33: }
34:
35: public static final SchemeMode getMode() {
36: return mode;
37: }
38:
39: public final String getCommentStart() {
40: return "; ";
41: }
42:
43: public final Formatter getFormatter(Buffer buffer) {
44: return new SchemeFormatter(buffer);
45: }
46:
47: protected void setKeyMapDefaults(KeyMap km) {
48: km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
49: km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag");
50: km.mapKey(KeyEvent.VK_PERIOD, ALT_MASK, "findTagAtDot");
51: km.mapKey(KeyEvent.VK_L, CTRL_MASK | SHIFT_MASK, "listTags");
52: km.mapKey(')', "closeParen");
53: }
54:
55: public boolean isTaggable() {
56: return true;
57: }
58:
59: public Tagger getTagger(SystemBuffer buffer) {
60: return new SchemeTagger(buffer);
61: }
62:
63: private static final String validChars = "!$%&*+-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~";
64:
65: public final boolean isIdentifierStart(char c) {
66: return validChars.indexOf(c) >= 0;
67: }
68:
69: public final boolean isIdentifierPart(char c) {
70: return validChars.indexOf(c) >= 0;
71: }
72:
73: public boolean isInQuote(Buffer buffer, Position pos) {
74: // This implementation only considers the current line.
75: Line line = pos.getLine();
76: int offset = pos.getOffset();
77: boolean inQuote = false;
78: for (int i = 0; i < offset; i++) {
79: char c = line.charAt(i);
80: if (c == '\\') {
81: // Escape.
82: ++i;
83: } else if (inQuote) {
84: if (c == '"')
85: inQuote = false;
86: } else {
87: if (c == '"')
88: inQuote = true;
89: }
90: }
91: return inQuote;
92: }
93: }
|