KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * PHPMode.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: PHPMode.java,v 1.3 2003/06/12 16:37:37 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 public final class PHPMode extends JavaMode implements Constants, Mode
25 {
26     private static final String JavaDoc[] phpConditionals = {
27         "if",
28         "else",
29         "elseif",
30         "do",
31         "while",
32         "for",
33         "foreach",
34         "switch"
35     };
36
37     // Since this class is final, we may as well construct the singleton class
38
// instance right away.
39
private static Mode mode = new PHPMode();
40
41     private PHPMode()
42     {
43         super(PHP_MODE, PHP_MODE_NAME);
44         keywords = new Keywords(this);
45         conditionals = phpConditionals;
46         setProperty(Property.TAB_WIDTH, 4);
47     }
48
49     public static final Mode getMode()
50     {
51         return mode;
52     }
53
54     public void populateModeMenu(Editor editor, Menu menu)
55     {
56         // No mode menu yet.
57
}
58
59     public SyntaxIterator getSyntaxIterator(Position pos)
60     {
61         return new PHPSyntaxIterator(pos);
62     }
63
64     public Formatter getFormatter(Buffer buffer)
65     {
66         return new PHPFormatter(buffer);
67     }
68
69     public Tagger getTagger(SystemBuffer buffer)
70     {
71         return new PHPTagger(buffer);
72     }
73
74     public final boolean isIdentifierStart(char c)
75     {
76         if (c > 255)
77             return false;
78         return values[c] == 1;
79     }
80
81     public final boolean isIdentifierPart(char c)
82     {
83         if (c > 255)
84             return false;
85         return values[c] != 0;
86     }
87
88     public boolean isInQuote(Buffer buffer, Position pos)
89     {
90         if (buffer.getMode() != this)
91             Debug.bug();
92         if (buffer.needsParsing())
93             buffer.getFormatter().parseBuffer();
94         Line line = pos.getLine();
95         int offset = pos.getOffset();
96         boolean inQuote = false;
97         char quoteChar = '\0';
98         int state = PHPFormatter.getState(line.flags());
99         if (state == STATE_QUOTE) {
100             inQuote = true;
101             quoteChar = '"';
102         } else if (state == STATE_SINGLEQUOTE) {
103             inQuote = true;
104             quoteChar = '\'';
105         }
106         for (int i = 0; i < offset; i++) {
107             char c = line.charAt(i);
108             if (c == '\\') {
109                 // Escape.
110
++i;
111             } else if (inQuote && c == quoteChar) {
112                 inQuote = false;
113             } else if (c == '"' || c == '\'') {
114                 inQuote = true;
115                 quoteChar = c;
116             }
117         }
118         return inQuote;
119     }
120
121     public static void phpHelp(String JavaDoc s)
122     {
123         WebMode.query("http://www.php.net/", s);
124     }
125
126     private static final byte values[] = {
127         0, 0, 0, 0, 0, 0, 0, 0, // 0x00-0x07
128
0, 0, 0, 0, 0, 0, 0, 0, // 0x09-0xff
129
0, 0, 0, 0, 0, 0, 0, 0, // 0x10-0x17
130
0, 0, 0, 0, 0, 0, 0, 0, // 0x18-0x1f
131
0, 0, 0, 0, 1, 0, 0, 0, // 0x20-0x27 !"#$%&'
132
0, 0, 0, 0, 0, 0, 0, 0, // 0x28-0x2f ()*+,-./
133
2, 2, 2, 2, 2, 2, 2, 2, // 0x30-0x37 01234567
134
2, 2, 0, 0, 0, 0, 0, 0, // 0x38-0x40 89:;<=>?
135
0, 1, 1, 1, 1, 1, 1, 1, // 0x41-0x47 @ABCDEFG
136
1, 1, 1, 1, 1, 1, 1, 1, // 0x48-0x4f HIJKLMNO
137
1, 1, 1, 1, 1, 1, 1, 1, // 0x50-0x57 PQRSTUVW
138
1, 1, 1, 0, 0, 0, 0, 1, // 0x58-0x5f XYZ[\]^_
139
0, 1, 1, 1, 1, 1, 1, 1, // 0x60-0x67 `abcdefg
140
1, 1, 1, 1, 1, 1, 1, 1, // 0x68-0x6f hijklmno
141
1, 1, 1, 1, 1, 1, 1, 1, // 0x70-0x77 pqrstuvw
142
1, 1, 1, 0, 0, 0, 0, 1, // 0x78-0x7f xyz{|}~
143
1, 1, 1, 1, 1, 1, 1, 1,
144         1, 1, 1, 1, 1, 1, 1, 1,
145         1, 1, 1, 1, 1, 1, 1, 1,
146         1, 1, 1, 1, 1, 1, 1, 1,
147         1, 1, 1, 1, 1, 1, 1, 1,
148         1, 1, 1, 1, 1, 1, 1, 1,
149         1, 1, 1, 1, 1, 1, 1, 1,
150         1, 1, 1, 1, 1, 1, 1, 1,
151         1, 1, 1, 1, 1, 1, 1, 1,
152         1, 1, 1, 1, 1, 1, 1, 1,
153         1, 1, 1, 1, 1, 1, 1, 1,
154         1, 1, 1, 1, 1, 1, 1, 1,
155         1, 1, 1, 1, 1, 1, 1, 1,
156         1, 1, 1, 1, 1, 1, 1, 1,
157         1, 1, 1, 1, 1, 1, 1, 1,
158         1, 1, 1, 1, 1, 1, 1, 1
159     };
160 }
161
Popular Tags