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