001: /*
002: * RubyMode.java
003: *
004: * Copyright (C) 2002 Jens Luedicke <jens@irs-net.com>
005: * based on PythonMode.java
006: * $Id: RubyMode.java,v 1.1.1.1 2002/09/24 16:08:22 piso Exp $
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.armedbear.j;
024:
025: import java.awt.event.KeyEvent;
026:
027: public final class RubyMode extends AbstractMode implements Constants,
028: Mode {
029: private static final RubyMode mode = new RubyMode();
030:
031: private RubyMode() {
032: super (RUBY_MODE, RUBY_MODE_NAME);
033: keywords = new Keywords(this );
034: }
035:
036: public static final RubyMode getMode() {
037: return mode;
038: }
039:
040: public boolean canIndent() {
041: return true;
042: }
043:
044: public final SyntaxIterator getSyntaxIterator(Position pos) {
045: return new RubySyntaxIterator(pos);
046: }
047:
048: public final Formatter getFormatter(Buffer buffer) {
049: return new RubyFormatter(buffer);
050: }
051:
052: protected void setKeyMapDefaults(KeyMap km) {
053: km.mapKey(KeyEvent.VK_TAB, 0, "tab");
054: km.mapKey(KeyEvent.VK_TAB, SHIFT_MASK, "slideOut");
055: km.mapKey(KeyEvent.VK_TAB, CTRL_MASK, "insertTab");
056: km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
057: km.mapKey(KeyEvent.VK_I, ALT_MASK, "cycleIndentSize");
058: }
059:
060: public final boolean isTaggable() {
061: return true;
062: }
063:
064: public final Tagger getTagger(SystemBuffer buffer) {
065: return new RubyTagger(buffer);
066: }
067:
068: public int getCorrectIndentation(Line line, Buffer buffer) {
069: return new RubyIndenter(line, buffer).getCorrectIndentation();
070: }
071:
072: public final boolean isIdentifierStart(char c) {
073: if (c > 127)
074: return false;
075: return values[c] == 1;
076: }
077:
078: public final boolean isIdentifierPart(char c) {
079: if (c > 127)
080: return false;
081: return values[c] != 0;
082: }
083:
084: private static final byte values[] = { 0, 0, 0, 0, 0, 0, 0, 0, // 0x00-0x07
085: 0, 0, 0, 0, 0, 0, 0, 0, // 0x09-0xff
086: 0, 0, 0, 0, 0, 0, 0, 0, // 0x10-0x17
087: 0, 0, 0, 0, 0, 0, 0, 0, // 0x18-0x1f
088: 0, 0, 0, 0, 0, 0, 0, 0, // 0x20-0x27 !"#$%&'
089: 0, 0, 0, 0, 0, 0, 0, 0, // 0x28-0x2f ()*+,-./
090: 2, 2, 2, 2, 2, 2, 2, 2, // 0x30-0x37 01234567
091: 2, 2, 0, 0, 0, 0, 0, 0, // 0x38-0x40 89:;<=>?
092: 0, 1, 1, 1, 1, 1, 1, 1, // 0x41-0x47 @ABCDEFG
093: 1, 1, 1, 1, 1, 1, 1, 1, // 0x48-0x4f HIJKLMNO
094: 1, 1, 1, 1, 1, 1, 1, 1, // 0x50-0x57 PQRSTUVW
095: 1, 1, 1, 0, 0, 0, 0, 1, // 0x58-0x5f XYZ[\]^_
096: 0, 1, 1, 1, 1, 1, 1, 1, // 0x60-0x67 `abcdefg
097: 1, 1, 1, 1, 1, 1, 1, 1, // 0x68-0x6f hijklmno
098: 1, 1, 1, 1, 1, 1, 1, 1, // 0x70-0x77 pqrstuvw
099: 1, 1, 1, 0, 0, 0, 0, 0 // 0x78-0x7f xyz{|}~
100: };
101: }
|