1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.phpeditor.php;
14 import java.util.ArrayList;
15 import java.util.List;
17 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
18 import net.sourceforge.phpeclipse.phpeditor.util.PHPWhitespaceDetector;
19 import net.sourceforge.phpeclipse.phpeditor.util.PHPWordDetector;
20 import org.eclipse.jface.text.TextAttribute;
21 import org.eclipse.jface.text.rules.EndOfLineRule;
22 import org.eclipse.jface.text.rules.IRule;
23 import org.eclipse.jface.text.rules.IToken;
24 import org.eclipse.jface.text.rules.MultiLineRule;
25 import org.eclipse.jface.text.rules.RuleBasedScanner;
26 import org.eclipse.jface.text.rules.SingleLineRule;
27 import org.eclipse.jface.text.rules.Token;
28 import org.eclipse.jface.text.rules.WhitespaceRule;
29 import org.eclipse.jface.text.rules.WordRule;
32 * A Java code scanner.
34 public class PHPCodeScanner extends RuleBasedScanner {
36 private static String[] fgKeywords =
74 private static String[] fgTypes =
94 "apache_child_terminate",
107 "array_merge_recursive",
164 "call_user_func_array",
166 "call_user_method_array",
207 "confirm_cybermut_compiled",
208 "confirm_extname_compiled",
210 "connection_aborted",
213 "convert_cyr_string",
218 "cpdf_add_annotation",
226 "cpdf_closepath_fill_stroke",
227 "cpdf_closepath_stroke",
228 "cpdf_continue_text",
234 "cpdf_finalize_page",
235 "cpdf_global_set_document_limits",
241 "cpdf_output_buffer",
243 "cpdf_place_inline_image",
253 "cpdf_set_action_url",
254 "cpdf_set_char_spacing",
256 "cpdf_set_current_page",
258 "cpdf_set_font_directories",
259 "cpdf_set_font_map_file",
260 "cpdf_set_horiz_scaling",
263 "cpdf_set_page_animation",
265 "cpdf_set_text_matrix",
267 "cpdf_set_text_rendering",
268 "cpdf_set_text_rise",
270 "cpdf_set_viewer_preferences",
271 "cpdf_set_word_spacing",
276 "cpdf_setgray_stroke",
280 "cpdf_setmiterlimit",
282 "cpdf_setrgbcolor_fill",
283 "cpdf_setrgbcolor_stroke",
292 "crack_getlastmessage",
336 "cybercash_base64_decode",
337 "cybercash_base64_encode",
340 "cybermut_creerformulairecm",
341 "cybermut_creerreponsecm",
359 "dbase_delete_record",
361 "dbase_get_record_with_names",
366 "dbase_replace_record",
389 "define_syslog_variables",
397 "display_disabled_function",
403 "domxml_elem_get_attribute",
404 "domxml_elem_set_attribute",
405 "domxml_get_attribute",
410 "domxml_node_attributes",
411 "domxml_node_children",
412 "domxml_node_new_child",
413 "domxml_node_set_content",
414 "domxml_node_unlink_node",
416 "domxml_set_attribute",
418 "domxml_unlink_node",
451 "fbsql_affected_rows",
459 "fbsql_database_password",
467 "fbsql_fetch_lengths",
468 "fbsql_fetch_object",
508 "fdf_next_field_name",
514 "fdf_set_javascript_action",
517 "fdf_set_submit_form_action",
536 "filepro_fieldcount",
539 "filepro_fieldwidth",
596 "get_declared_classes",
597 "get_defined_functions",
599 "get_extension_funcs",
600 "get_html_translation_table",
601 "get_included_files",
602 "get_loaded_extensions",
603 "get_magic_quotes_gpc",
604 "get_magic_quotes_runtime",
608 "get_required_files",
678 "gmp_perfect_square",
730 "hw_connection_info",
735 "hw_document_attributes",
736 "hw_document_bodytag",
737 "hw_document_content",
738 "hw_document_setcontent",
750 "hw_getchildcollobj",
751 "hw_getchilddoccoll",
752 "hw_getchilddoccollobj",
754 "hw_getobjectbyftquery",
755 "hw_getobjectbyftquerycoll",
756 "hw_getobjectbyftquerycollobj",
757 "hw_getobjectbyftqueryobj",
758 "hw_getobjectbyquery",
759 "hw_getobjectbyquerycoll",
760 "hw_getobjectbyquerycollobj",
761 "hw_getobjectbyqueryobj",
766 "hw_getremotechildren",
767 "hw_getsrcbydestobj",
782 "hw_new_document_from_file",
784 "hw_output_document",
807 "ibase_fetch_object",
819 "icap_create_calendar",
820 "icap_delete_calendar",
827 "icap_rename_calendar",
832 "iconv_get_encoding",
833 "iconv_set_encoding",
835 "ifx_blobinfile_mode",
846 "ifx_fieldproperties",
854 "ifx_htmltbl_result",
874 "iis_getdirsecurity",
876 "iis_getserverbycomment",
877 "iis_getserverbypath",
878 "iis_getserverright",
879 "iis_getservicestate",
881 "iis_setappsettings",
882 "iis_setdirsecurity",
884 "iis_setserverright",
890 "imagealphablending",
894 "imagecolorallocate",
897 "imagecolorclosestalpha",
898 "imagecolorclosesthwb",
899 "imagecolordeallocate",
901 "imagecolorexactalpha",
903 "imagecolorresolvealpha",
905 "imagecolorsforindex",
907 "imagecolortransparent",
910 "imagecopymergegray",
911 "imagecopyresampled",
914 "imagecreatefromgif",
915 "imagecreatefromjpeg",
916 "imagecreatefrompng",
917 "imagecreatefromstring",
918 "imagecreatefromwbmp",
919 "imagecreatefromxbm",
920 "imagecreatefromxpm",
921 "imagecreatetruecolor",
927 "imagefilledellipse",
928 "imagefilledpolygon",
929 "imagefilledrectangle",
960 "imagetruecolortopalette",
973 "imap_clearflag_full",
976 "imap_createmailbox",
978 "imap_deletemailbox",
981 "imap_fetch_overview",
984 "imap_fetchstructure",
988 "imap_getsubscribed",
995 "imap_listsubscribed",
1002 "imap_mailboxmsginfo",
1003 "imap_mime_header_decode",
1012 "imap_renamemailbox",
1014 "imap_rfc822_parse_adrlist",
1015 "imap_rfc822_parse_headers",
1016 "imap_rfc822_write_address",
1021 "imap_setflag_full",
1033 "ingres_autocommit",
1037 "ingres_fetch_array",
1038 "ingres_fetch_object",
1040 "ingres_field_length",
1041 "ingres_field_name",
1042 "ingres_field_nullable",
1043 "ingres_field_precision",
1044 "ingres_field_scale",
1045 "ingres_field_type",
1046 "ingres_num_fields",
1059 "ircg_channel_mode",
1064 "ircg_is_conn_alive",
1067 "ircg_lookup_format_messages",
1070 "ircg_nickname_escape",
1071 "ircg_nickname_unescape",
1075 "ircg_register_format_messages",
1102 "java_last_exception_clear",
1103 "java_last_exception_get",
1127 "ldap_count_entries",
1134 "ldap_first_attribute",
1136 "ldap_first_reference",
1138 "ldap_get_attributes",
1143 "ldap_get_values_len",
1149 "ldap_next_attribute",
1151 "ldap_next_reference",
1152 "ldap_parse_reference",
1153 "ldap_parse_result",
1174 "magic_quotes_runtime",
1178 "mcal_append_event",
1180 "mcal_create_calendar",
1181 "mcal_date_compare",
1185 "mcal_days_in_month",
1186 "mcal_delete_calendar",
1187 "mcal_delete_event",
1188 "mcal_event_add_attribute",
1190 "mcal_event_set_alarm",
1191 "mcal_event_set_category",
1192 "mcal_event_set_class",
1193 "mcal_event_set_description",
1194 "mcal_event_set_end",
1195 "mcal_event_set_recur_daily",
1196 "mcal_event_set_recur_monthly_mday",
1197 "mcal_event_set_recur_monthly_wday",
1198 "mcal_event_set_recur_none",
1199 "mcal_event_set_recur_weekly",
1200 "mcal_event_set_recur_yearly",
1201 "mcal_event_set_start",
1202 "mcal_event_set_title",
1203 "mcal_fetch_current_stream_event",
1205 "mcal_is_leap_year",
1208 "mcal_next_recurrence",
1211 "mcal_rename_calendar",
1216 "mcal_week_of_year",
1222 "mcrypt_enc_get_algorithms_name",
1223 "mcrypt_enc_get_block_size",
1224 "mcrypt_enc_get_iv_size",
1225 "mcrypt_enc_get_key_size",
1226 "mcrypt_enc_get_modes_name",
1227 "mcrypt_enc_get_supported_key_sizes",
1228 "mcrypt_enc_is_block_algorithm",
1229 "mcrypt_enc_is_block_algorithm_mode",
1230 "mcrypt_enc_is_block_mode",
1231 "mcrypt_enc_self_test",
1234 "mcrypt_generic_end",
1235 "mcrypt_generic_init",
1236 "mcrypt_get_block_size",
1237 "mcrypt_get_cipher_name",
1238 "mcrypt_get_iv_size",
1239 "mcrypt_get_key_size",
1240 "mcrypt_list_algorithms",
1241 "mcrypt_list_modes",
1242 "mcrypt_module_close",
1243 "mcrypt_module_get_algo_block_size",
1244 "mcrypt_module_get_algo_key_size",
1245 "mcrypt_module_get_supported_key_sizes",
1246 "mcrypt_module_is_block_algorithm",
1247 "mcrypt_module_is_block_algorithm_mode",
1248 "mcrypt_module_is_block_mode",
1249 "mcrypt_module_open",
1250 "mcrypt_module_self_test",
1258 "mhash_get_block_size",
1259 "mhash_get_hash_name",
1263 "ming_setcubicthreshold",
1268 "move_uploaded_file",
1275 "msql_affected_rows",
1288 "msql_fetch_object",
1320 "mssql_affected_rows",
1321 "mssql_affected_rows",
1331 "mssql_fetch_array",
1332 "mssql_fetch_array",
1333 "mssql_fetch_array",
1334 "mssql_fetch_batch",
1335 "mssql_fetch_field",
1336 "mssql_fetch_field",
1337 "mssql_fetch_field",
1338 "mssql_fetch_object",
1339 "mssql_fetch_object",
1340 "mssql_fetch_object",
1344 "mssql_field_length",
1350 "mssql_free_result",
1351 "mssql_free_result",
1352 "mssql_free_result",
1353 "mssql_get_last_message",
1354 "mssql_get_last_message",
1355 "mssql_get_last_message",
1356 "mssql_min_client_severity",
1357 "mssql_min_error_severity",
1358 "mssql_min_error_severity",
1359 "mssql_min_message_severity",
1360 "mssql_min_message_severity",
1361 "mssql_min_server_severity",
1362 "mssql_next_result",
1378 "mssql_rows_affected",
1392 "mysql_affected_rows",
1405 "mysql_escape_string",
1406 "mysql_fetch_array",
1407 "mysql_fetch_assoc",
1408 "mysql_fetch_field",
1409 "mysql_fetch_lengths",
1410 "mysql_fetch_object",
1412 "mysql_field_flags",
1416 "mysql_field_table",
1423 "mysql_free_result",
1425 "mysql_get_client_info",
1426 "mysql_get_host_info",
1427 "mysql_get_proto_info",
1428 "mysql_get_server_info",
1431 "mysql_list_fields",
1432 "mysql_list_tables",
1446 "mysql_unbuffered_query",
1457 "notes_create_note",
1460 "notes_header_info",
1463 "notes_mark_unread",
1475 "ob_implicit_flush",
1481 "ocicollassignelem",
1482 "ocicolldateappendelem",
1483 "ocicolldateassignelem",
1484 "ocicolldategetelem",
1491 "ocicolumnprecision",
1502 "ocifetchstatement",
1526 "ociwritelobtofile",
1532 "odbc_columnprivileges",
1544 "odbc_fetch_object",
1549 "odbc_field_precision",
1562 "odbc_procedurecolumns",
1568 "odbc_specialcolumns",
1570 "odbc_tableprivileges",
1575 "openssl_error_string",
1577 "openssl_get_privatekey",
1578 "openssl_get_publickey",
1580 "openssl_pkcs7_decrypt",
1581 "openssl_pkcs7_encrypt",
1582 "openssl_pkcs7_sign",
1583 "openssl_pkcs7_verify",
1587 "openssl_x509_checkpurpose",
1588 "openssl_x509_free",
1589 "openssl_x509_parse",
1590 "openssl_x509_read",
1614 "orbit_caught_exception",
1615 "orbit_exception_id",
1616 "orbit_exception_value",
1617 "orbit_get_repository_id",
1622 "ovrimos_close_all",
1628 "ovrimos_fetch_into",
1629 "ovrimos_fetch_row",
1630 "ovrimos_field_len",
1631 "ovrimos_field_name",
1632 "ovrimos_field_num",
1633 "ovrimos_field_type",
1634 "ovrimos_free_result",
1635 "ovrimos_longreadlen",
1636 "ovrimos_num_fields",
1640 "ovrimos_result_all",
1649 "pdf_add_annotation",
1651 "pdf_add_launchlink",
1652 "pdf_add_locallink",
1656 "pdf_add_thumbnail",
1662 "pdf_begin_pattern",
1663 "pdf_begin_template",
1669 "pdf_close_pdi_page",
1671 "pdf_closepath_fill_stroke",
1672 "pdf_closepath_stroke",
1674 "pdf_continue_text",
1688 "pdf_get_image_height",
1689 "pdf_get_image_width",
1690 "pdf_get_parameter",
1691 "pdf_get_pdi_parameter",
1692 "pdf_get_pdi_value",
1696 "pdf_makespotcolor",
1704 "pdf_open_image_file",
1706 "pdf_open_memory_image",
1708 "pdf_open_pdi_page",
1712 "pdf_place_pdi_page",
1718 "pdf_set_border_color",
1719 "pdf_set_border_dash",
1720 "pdf_set_border_style",
1721 "pdf_set_char_spacing",
1724 "pdf_set_horiz_scaling",
1726 "pdf_set_info_author",
1727 "pdf_set_info_creator",
1728 "pdf_set_info_keywords",
1729 "pdf_set_info_subject",
1730 "pdf_set_info_title",
1732 "pdf_set_parameter",
1734 "pdf_set_text_rendering",
1735 "pdf_set_text_rise",
1736 "pdf_set_transition",
1738 "pdf_set_word_spacing",
1745 "pdf_setgray_stroke",
1750 "pdf_setmiterlimit",
1753 "pdf_setrgbcolor_fill",
1754 "pdf_setrgbcolor_stroke",
1765 "pfpro_process_raw",
1768 "pg_client_encoding",
1769 "pg_clientencoding",
1805 "pg_set_client_encoding",
1806 "pg_setclientencoding",
1856 "preg_replace_callback",
1862 "printer_create_brush",
1863 "printer_create_dc",
1864 "printer_create_font",
1865 "printer_create_pen",
1866 "printer_delete_brush",
1867 "printer_delete_dc",
1868 "printer_delete_font",
1869 "printer_delete_pen",
1871 "printer_draw_chord",
1872 "printer_draw_elipse",
1873 "printer_draw_line",
1875 "printer_draw_rectangle",
1876 "printer_draw_roundrect",
1877 "printer_draw_text",
1880 "printer_get_option",
1882 "printer_logical_fontheight",
1884 "printer_select_brush",
1885 "printer_select_font",
1886 "printer_select_pen",
1887 "printer_set_option",
1888 "printer_start_doc",
1889 "printer_start_page",
1892 "pspell_add_to_personal",
1893 "pspell_add_to_session",
1895 "pspell_clear_session",
1896 "pspell_config_create",
1897 "pspell_config_ignore",
1898 "pspell_config_mode",
1899 "pspell_config_personal",
1900 "pspell_config_repl",
1901 "pspell_config_runtogether",
1902 "pspell_config_save_repl",
1904 "pspell_new_config",
1905 "pspell_new_personal",
1906 "pspell_save_wordlist",
1907 "pspell_store_replacement",
1913 "quoted_printable_decode",
1926 "readline_add_history",
1927 "readline_clear_history",
1928 "readline_completion_function",
1930 "readline_list_history",
1931 "readline_list_history",
1932 "readline_read_history",
1933 "readline_write_history",
1945 "register_shutdown_function",
1946 "register_tick_function",
1951 "restore_error_handler",
1961 "satellite_caught_exception",
1962 "satellite_exception_id",
1963 "satellite_exception_value",
1964 "satellite_get_repository_id",
1965 "satellite_load_idl",
1979 "session_cache_limiter",
1983 "session_get_cookie_params",
1985 "session_is_registered",
1986 "session_module_name",
1989 "session_save_path",
1990 "session_set_cookie_params",
1991 "session_set_save_handler",
1993 "session_unregister",
1995 "session_write_close",
1997 "set_error_handler",
2000 "set_magic_quotes_runtime",
2002 "set_socket_blocking",
2066 "snmp_get_quick_print",
2067 "snmp_set_quick_print",
2076 "socket_get_status",
2077 "socket_set_blocking",
2078 "socket_set_timeout",
2079 "socket_set_timeout",
2129 "swf_actiongotoframe",
2130 "swf_actiongotolabel",
2131 "swf_actionnextframe",
2133 "swf_actionprevframe",
2134 "swf_actionsettarget",
2136 "swf_actiontogglequality",
2137 "swf_actionwaitforframe",
2138 "swf_addbuttonrecord",
2154 "swf_getbitmapinfo",
2179 "swf_shapecurveto3",
2180 "swf_shapefillbitmapclip",
2181 "swf_shapefillbitmaptile",
2183 "swf_shapefillsolid",
2184 "swf_shapelinesolid",
2189 "swf_startdoaction",
2198 "swfbutton_keypress",
2208 "sybase_affected_rows",
2209 "sybase_affected_rows",
2216 "sybase_fetch_array",
2217 "sybase_fetch_array",
2218 "sybase_fetch_field",
2219 "sybase_fetch_field",
2220 "sybase_fetch_object",
2221 "sybase_fetch_object",
2224 "sybase_field_seek",
2225 "sybase_field_seek",
2226 "sybase_free_result",
2227 "sybase_free_result",
2228 "sybase_get_last_message",
2229 "sybase_get_last_message",
2230 "sybase_min_client_severity",
2231 "sybase_min_error_severity",
2232 "sybase_min_message_severity",
2233 "sybase_min_server_severity",
2234 "sybase_num_fields",
2235 "sybase_num_fields",
2261 "udm_add_search_limit",
2264 "udm_clear_search_limits",
2269 "udm_free_ispell_data",
2271 "udm_get_doc_count",
2272 "udm_get_res_field",
2273 "udm_get_res_param",
2274 "udm_load_ispell_data",
2275 "udm_set_agent_param",
2283 "unregister_tick_function",
2293 "velocis_autocommit",
2299 "velocis_fieldname",
2301 "velocis_freeresult",
2302 "velocis_off_autocommit",
2306 "vpopmail_add_alias_domain",
2307 "vpopmail_add_alias_domain_ex",
2308 "vpopmail_add_domain",
2309 "vpopmail_add_domain_ex",
2310 "vpopmail_add_user",
2311 "vpopmail_auth_user",
2312 "vpopmail_del_domain",
2313 "vpopmail_del_domain_ex",
2314 "vpopmail_del_user",
2317 "vpopmail_set_user_quota",
2321 "wddx_packet_start",
2322 "wddx_serialize_value",
2323 "wddx_serialize_vars",
2328 "xml_get_current_byte_index",
2329 "xml_get_current_column_number",
2330 "xml_get_current_line_number",
2331 "xml_get_error_code",
2333 "xml_parse_into_struct",
2334 "xml_parser_create",
2335 "xml_parser_create_ns",
2337 "xml_parser_get_option",
2338 "xml_parser_set_option",
2339 "xml_set_character_data_handler",
2340 "xml_set_default_handler",
2341 "xml_set_element_handler",
2342 "xml_set_end_namespace_decl_handler",
2343 "xml_set_external_entity_ref_handler",
2344 "xml_set_notation_decl_handler",
2346 "xml_set_processing_instruction_handler",
2347 "xml_set_start_namespace_decl_handler",
2348 "xml_set_unparsed_entity_decl_handler",
2353 "xpath_eval_expression",
2359 "xslt_fetch_result",
2362 "xslt_output_begintransform",
2363 "xslt_output_endtransform",
2367 "xslt_set_encoding",
2368 "xslt_set_error_handler",
2369 "xslt_set_sax_handler",
2370 "xslt_set_scheme_handler",
2396 "yp_get_default_domain",
2406 "zzip_entry_compressedsize",
2407 "zzip_entry_compressionmethod",
2408 "zzip_entry_filesize",
2415 private static String[] fgConstants = { "__LINE__", "__FILE__", "true", "false" };
2416 private TextAttribute fComment;
2417 private TextAttribute fKeyword;
2418 private TextAttribute fType;
2419 private TextAttribute fString;
2420 private PHPColorProvider fColorProvider;
2423 * Creates a Java code scanner
2425 public PHPCodeScanner(PHPColorProvider provider) {
2427 IToken keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
2428 IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.TYPE)));
2429 IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
2430 IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
2431 IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
2432 IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
2434 List rules = new ArrayList();
2436 // Add rule for single line comments.
2437 rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
2438 EndOfLineRule endOfLine = new EndOfLineRule("#", comment);
2439 endOfLine.setColumnConstraint(0);
2440 rules.add(endOfLine);
2442 // Add rule for strings and character constants.
2443 rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
2444 rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
2446 // rules.add(new SingleLineRule("//", "//", php_comment));
2447 rules.add(new MultiLineRule("/*", "*/", multi_comment));
2449 // Add generic whitespace rule.
2450 rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
2452 // Add word rule for keywords, types, and constants.
2453 WordRule wordRule = new WordRule(new PHPWordDetector(), other);
2454 for (int i = 0; i < fgKeywords.length; i++)
2455 wordRule.addWord(fgKeywords[i], keyword);
2456 for (int i = 0; i < fgTypes.length; i++)
2457 wordRule.addWord(fgTypes[i], type);
2458 for (int i = 0; i < fgConstants.length; i++)
2459 wordRule.addWord(fgConstants[i], type);
2460 rules.add(wordRule);
2462 IRule[] result = new IRule[rules.size()];
2463 rules.toArray(result);