KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > SchemeMode


1 /*
2  * SchemeMode.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: SchemeMode.java,v 1.1.1.1 2002/09/24 16:09:19 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 JavaDoc;
25
26 public final class SchemeMode extends AbstractMode implements Constants, Mode
27 {
28     private static final SchemeMode mode = new SchemeMode();
29
30     private SchemeMode()
31     {
32         super(SCHEME_MODE, SCHEME_MODE_NAME);
33         keywords = new Keywords(this);
34     }
35
36     public static final SchemeMode getMode()
37     {
38         return mode;
39     }
40
41     public final String JavaDoc getCommentStart()
42     {
43         return "; ";
44     }
45
46     public final Formatter getFormatter(Buffer buffer)
47     {
48         return new SchemeFormatter(buffer);
49     }
50
51     protected void setKeyMapDefaults(KeyMap km)
52     {
53         km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
54         km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag");
55         km.mapKey(KeyEvent.VK_PERIOD, ALT_MASK, "findTagAtDot");
56         km.mapKey(KeyEvent.VK_L, CTRL_MASK | SHIFT_MASK, "listTags");
57         km.mapKey(')', "closeParen");
58     }
59
60     public boolean isTaggable()
61     {
62         return true;
63     }
64
65     public Tagger getTagger(SystemBuffer buffer)
66     {
67         return new SchemeTagger(buffer);
68     }
69
70     private static final String JavaDoc validChars =
71         "!$%&*+-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{}~";
72
73     public final boolean isIdentifierStart(char c)
74     {
75         return validChars.indexOf(c) >= 0;
76     }
77
78     public final boolean isIdentifierPart(char c)
79     {
80         return validChars.indexOf(c) >= 0;
81     }
82
83     public boolean isInQuote(Buffer buffer, Position pos)
84     {
85         // This implementation only considers the current line.
86
Line line = pos.getLine();
87         int offset = pos.getOffset();
88         boolean inQuote = false;
89         for (int i = 0; i < offset; i++) {
90             char c = line.charAt(i);
91             if (c == '\\') {
92                 // Escape.
93
++i;
94             } else if (inQuote) {
95                 if (c == '"')
96                     inQuote = false;
97             } else {
98                 if (c == '"')
99                     inQuote = true;
100             }
101         }
102         return inQuote;
103     }
104 }
105
Popular Tags