KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * PythonMode.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: PythonMode.java,v 1.3 2003/10/30 19:22:57 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 PythonMode extends AbstractMode implements Constants, Mode
27 {
28     private static final PythonMode mode = new PythonMode();
29
30     private PythonMode()
31     {
32         super(PYTHON_MODE, PYTHON_MODE_NAME);
33         keywords = new Keywords(this);
34     }
35
36     public static final PythonMode getMode()
37     {
38         return mode;
39     }
40
41     public boolean canIndent()
42     {
43         return true;
44     }
45
46     public boolean canIndentPaste()
47     {
48         return false;
49     }
50
51     public final SyntaxIterator getSyntaxIterator(Position pos)
52     {
53         return new PythonSyntaxIterator(pos);
54     }
55
56     public final String JavaDoc getCommentStart()
57     {
58         return "#";
59     }
60
61     public final Formatter getFormatter(Buffer buffer)
62     {
63         return new PythonFormatter(buffer);
64     }
65
66     protected void setKeyMapDefaults(KeyMap km)
67     {
68         km.mapKey(KeyEvent.VK_TAB, 0, "tab");
69         km.mapKey(KeyEvent.VK_TAB, SHIFT_MASK, "slideOut");
70         km.mapKey(KeyEvent.VK_TAB, CTRL_MASK, "insertTab");
71         km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
72         km.mapKey(KeyEvent.VK_I, ALT_MASK, "cycleIndentSize");
73     }
74
75     public final boolean isTaggable()
76     {
77         return true;
78     }
79
80     public final Tagger getTagger(SystemBuffer buffer)
81     {
82         return new PythonTagger(buffer);
83     }
84
85     public int getCorrectIndentation(Line line, Buffer buffer)
86     {
87         return new PythonIndenter(line, buffer).getCorrectIndentation();
88     }
89
90     public final boolean isIdentifierStart(char c)
91     {
92         if (c > 127)
93             return false;
94         return values[c] == 1;
95     }
96
97     public final boolean isIdentifierPart(char c)
98     {
99         if (c > 127)
100             return false;
101         return values[c] != 0;
102     }
103
104     private static final byte values[] =
105     {
106         0, 0, 0, 0, 0, 0, 0, 0, // 0x00-0x07
107
0, 0, 0, 0, 0, 0, 0, 0, // 0x09-0xff
108
0, 0, 0, 0, 0, 0, 0, 0, // 0x10-0x17
109
0, 0, 0, 0, 0, 0, 0, 0, // 0x18-0x1f
110
0, 0, 0, 0, 0, 0, 0, 0, // 0x20-0x27 !"#$%&'
111
0, 0, 0, 0, 0, 0, 0, 0, // 0x28-0x2f ()*+,-./
112
2, 2, 2, 2, 2, 2, 2, 2, // 0x30-0x37 01234567
113
2, 2, 0, 0, 0, 0, 0, 0, // 0x38-0x40 89:;<=>?
114
0, 1, 1, 1, 1, 1, 1, 1, // 0x41-0x47 @ABCDEFG
115
1, 1, 1, 1, 1, 1, 1, 1, // 0x48-0x4f HIJKLMNO
116
1, 1, 1, 1, 1, 1, 1, 1, // 0x50-0x57 PQRSTUVW
117
1, 1, 1, 0, 0, 0, 0, 1, // 0x58-0x5f XYZ[\]^_
118
0, 1, 1, 1, 1, 1, 1, 1, // 0x60-0x67 `abcdefg
119
1, 1, 1, 1, 1, 1, 1, 1, // 0x68-0x6f hijklmno
120
1, 1, 1, 1, 1, 1, 1, 1, // 0x70-0x77 pqrstuvw
121
1, 1, 1, 0, 0, 0, 0, 0 // 0x78-0x7f xyz{|}~
122
};
123 }
124
Popular Tags