KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * RubyMode.java
3  *
4  * Copyright (C) 2002 Jens Luedicke <jens@irs-net.com>
5  * based on PythonMode.java
6  * $Id: RubyMode.java,v 1.1.1.1 2002/09/24 16:08:22 piso Exp $
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

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