001: /*
002: * PHPMode.java
003: *
004: * Copyright (C) 2002-2003 Peter Graves
005: * $Id: PHPMode.java,v 1.3 2003/06/12 16:37:37 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: public final class PHPMode extends JavaMode implements Constants, Mode {
025: private static final String[] phpConditionals = { "if", "else",
026: "elseif", "do", "while", "for", "foreach", "switch" };
027:
028: // Since this class is final, we may as well construct the singleton class
029: // instance right away.
030: private static Mode mode = new PHPMode();
031:
032: private PHPMode() {
033: super (PHP_MODE, PHP_MODE_NAME);
034: keywords = new Keywords(this );
035: conditionals = phpConditionals;
036: setProperty(Property.TAB_WIDTH, 4);
037: }
038:
039: public static final Mode getMode() {
040: return mode;
041: }
042:
043: public void populateModeMenu(Editor editor, Menu menu) {
044: // No mode menu yet.
045: }
046:
047: public SyntaxIterator getSyntaxIterator(Position pos) {
048: return new PHPSyntaxIterator(pos);
049: }
050:
051: public Formatter getFormatter(Buffer buffer) {
052: return new PHPFormatter(buffer);
053: }
054:
055: public Tagger getTagger(SystemBuffer buffer) {
056: return new PHPTagger(buffer);
057: }
058:
059: public final boolean isIdentifierStart(char c) {
060: if (c > 255)
061: return false;
062: return values[c] == 1;
063: }
064:
065: public final boolean isIdentifierPart(char c) {
066: if (c > 255)
067: return false;
068: return values[c] != 0;
069: }
070:
071: public boolean isInQuote(Buffer buffer, Position pos) {
072: if (buffer.getMode() != this )
073: Debug.bug();
074: if (buffer.needsParsing())
075: buffer.getFormatter().parseBuffer();
076: Line line = pos.getLine();
077: int offset = pos.getOffset();
078: boolean inQuote = false;
079: char quoteChar = '\0';
080: int state = PHPFormatter.getState(line.flags());
081: if (state == STATE_QUOTE) {
082: inQuote = true;
083: quoteChar = '"';
084: } else if (state == STATE_SINGLEQUOTE) {
085: inQuote = true;
086: quoteChar = '\'';
087: }
088: for (int i = 0; i < offset; i++) {
089: char c = line.charAt(i);
090: if (c == '\\') {
091: // Escape.
092: ++i;
093: } else if (inQuote && c == quoteChar) {
094: inQuote = false;
095: } else if (c == '"' || c == '\'') {
096: inQuote = true;
097: quoteChar = c;
098: }
099: }
100: return inQuote;
101: }
102:
103: public static void phpHelp(String s) {
104: WebMode.query("http://www.php.net/", s);
105: }
106:
107: private static final byte values[] = { 0, 0,
108: 0,
109: 0,
110: 0,
111: 0,
112: 0,
113: 0, // 0x00-0x07
114: 0, 0,
115: 0,
116: 0,
117: 0,
118: 0,
119: 0,
120: 0, // 0x09-0xff
121: 0, 0,
122: 0,
123: 0,
124: 0,
125: 0,
126: 0,
127: 0, // 0x10-0x17
128: 0, 0,
129: 0,
130: 0,
131: 0,
132: 0,
133: 0,
134: 0, // 0x18-0x1f
135: 0, 0,
136: 0,
137: 0,
138: 1,
139: 0,
140: 0,
141: 0, // 0x20-0x27 !"#$%&'
142: 0, 0,
143: 0,
144: 0,
145: 0,
146: 0,
147: 0,
148: 0, // 0x28-0x2f ()*+,-./
149: 2, 2,
150: 2,
151: 2,
152: 2,
153: 2,
154: 2,
155: 2, // 0x30-0x37 01234567
156: 2, 2,
157: 0,
158: 0,
159: 0,
160: 0,
161: 0,
162: 0, // 0x38-0x40 89:;<=>?
163: 0, 1,
164: 1,
165: 1,
166: 1,
167: 1,
168: 1,
169: 1, // 0x41-0x47 @ABCDEFG
170: 1, 1,
171: 1,
172: 1,
173: 1,
174: 1,
175: 1,
176: 1, // 0x48-0x4f HIJKLMNO
177: 1, 1,
178: 1,
179: 1,
180: 1,
181: 1,
182: 1,
183: 1, // 0x50-0x57 PQRSTUVW
184: 1, 1,
185: 1,
186: 0,
187: 0,
188: 0,
189: 0,
190: 1, // 0x58-0x5f XYZ[\]^_
191: 0, 1,
192: 1,
193: 1,
194: 1,
195: 1,
196: 1,
197: 1, // 0x60-0x67 `abcdefg
198: 1, 1,
199: 1,
200: 1,
201: 1,
202: 1,
203: 1,
204: 1, // 0x68-0x6f hijklmno
205: 1, 1,
206: 1,
207: 1,
208: 1,
209: 1,
210: 1,
211: 1, // 0x70-0x77 pqrstuvw
212: 1, 1,
213: 1,
214: 0,
215: 0,
216: 0,
217: 0,
218: 1, // 0x78-0x7f xyz{|}~
219: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
220: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
221: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
222: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
223: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
224: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
225: 1, 1, 1, 1, 1, 1, 1, 1 };
226: }
|