1 21 22 package org.armedbear.j; 23 24 public final class PHPMode extends JavaMode implements Constants, Mode 25 { 26 private static final String [] phpConditionals = { 27 "if", 28 "else", 29 "elseif", 30 "do", 31 "while", 32 "for", 33 "foreach", 34 "switch" 35 }; 36 37 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 } 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 ++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 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 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 |