-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphp.vim
3625 lines (3070 loc) · 272 KB
/
php.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Vim syntax file
" Language: PHP 4/5
" Maintainer: Peter Hodge <[email protected]>
" Last Change: May 7, 2008
"
" URL: http://www.vim.org/scripts/script.php?script_id=1571
" Version: 0.9.7
"
" ================================================================
"
" Note: If you are having speed issues loading or editting PHP files, try
" disabling some of the options. In your .vimrc, try adding:
" :let php_folding = 0
" :let php_strict_blocks = 0
"
" Also, there is a 'large file' mode which can disable certain options
" if a PHP file is too big (see php_large_file below).
"
" ================================================================
"
" Note: If you are using a colour terminal with a dark background, you will
" probably find the 'elflord' colorscheme will give you the most
" distinctive colors.
"
" ================================================================
"
" OPTIONS:
"
" Many of these default to 1 (On), so you would need to set
" them to 0 to turn them off. E.g., in your .vimrc file:
" let php_special_vars = 0
" let php_special_functions = 0
" let php_alt_comparisons = 0
" etc.
" If the variables do not exist, the default value will be used.
"
"
" All options can be set globally or on a per-file basis by using
" global or buffer-local variables. For example, you could turn on
" automatic folding for all PHP scripts in your .vimrc:
" let g:php_folding = 3
"
" Then you could turn it off in only one file using this command:
"
" :let b:php_folding = 0 | setfiletype php
"
"
" -- PHP FEATURES --
"
" let php_sql_query = 1/0 [default 0]
" ... for SQL syntax highlighting inside strings
"
" let php_htmlInStrings = 1/0 [default 0]
" ... for HTML syntax highlighting inside strings
"
" let php_baselib = 1/0 [default 0]
" ... for highlighting baselib functions
"
" let php_special_vars = 1/0 [default 1]
" ... to highlight superglobals like $_GET, $_SERVER, etc.
" * always on if using php_oldStyle
"
" let php_special_functions = 1/0 [default 1]
" ... to highlight functions with special behaviour
" e.g., unset(), extract()
"
" let php_alt_comparisons = 1/0 [default 1]
" ... to highlight comparison operators in an alternate colour
" * always on if using php_oldStyle
"
" let php_alt_assignByReference = 1/0 [default 1]
" ... to highlight '=&' in '$foo =& $bar' in an alternate colour.
" This also applies to a function which returns by-reference,
" as well as a function argument which is by-reference.
"
" let php_smart_members = 1/0 [default 0]
" ... syntax works out whether -> indicates a property or method.
" Otherwise method colours may be used on properties, for
" example:
" $object->__get[] = true;
" '__get' would be highlighted as a special method, even
" thought it is clearly a property in this context.
" Note: turning this OFF can improve the highlighting speed on
" object-oriented code
"
" let php_alt_properties = 1/0 [default 0]
" ... use a different color for '->' based on whether it is used
" for property access, method access, or dynamic access (using
" '->{...}')
" * requires php_smart_members
"
" let php_highlight_quotes = 1/0 [default 0]
" ... makes quote characters the same colour as the string
" contents, like in C syntax.
"
" let php_show_semicolon = 1/0 [default 1]
" ... to make the semicolon (;) more visible
"
" let php_smart_semicolon = 1/0 [default 1]
" ... semicolon adopts the color of a 'return' or 'break' keyword
" * requires php_show_semicolon
" Note: this also includes the ':' or ';' which follows a
" 'case' or 'default' inside a switch
"
" let php_alt_blocks = 1/0 [default 1]
" ... colorize { and } around class/function/try/catch bodies
" according to the type of code block.
" * requires php_strict_blocks
"
" let php_alt_arrays = 0/1/2 [default 1]
" ... to colorize ( and ) around an array body, as well as '=>'
" * requires php_strict_blocks
" Setting this to '2' will highlighting the commas as well.
" Commas are not highlighted by default because it's too much
" color.
"
" let php_alt_construct_parents = 0/1 [default 0]
" ... to colorize the ( and ) around an if, while, foreach, or switch
" body.
" * requires ... what?
" TODO: work out dependencies, code them correctly
"
" let php_show_spl = 1/0 [default 1]
" .. to colorize methods which are defined by PHP default interfaces
" TODO: work out what these interfaces are part of: SPL or just
" PHP
"
" let php_show_pcre = 1/0 [default 1]
" (was: 'php_show_preg')
" ... to highlight regular expression patterns inside calls
" to preg_match(), preg_replace(), etc.
"
"
" -- FINDING ERRORS --
"
" let php_parent_error_close = 1/0 [default 1]
" ... for highlighting parent error ] or ) or }
" * requires php_strict_blocks
"
" let php_parent_error_open = ?
" ... for skipping a php end tag, if there exists an
" open ( or [ without a closing one
" Note: this option is now enabled permanently (unless
" php_strict_blocks is disabled).
" * requires php_strict_blocks
"
" let php_empty_construct_error = 0/1 [default 1]
" ... highlights ';' as an error if it comes immediately after
" an if/else/while/for/foreach/switch statement (the
" logical constructs should have a body).
" * requires php_strict_blocks
" let php_show_semicolon_error = 1/0 [default 1]
" ... highlights certain cases when ';' is followed by an
" operator such as '+'.
" * requires php_show_semicolon
"
" let php_nested_functions = 0/1 [default 0]
" ... Whether or not to allow contiaining one function inside
" another. This option is mostly for speeding up syntax
" highlighting - { } blocks can by inserted much faster while
" editting a large class.
" Note: this is the only option which might break valid PHP
" code, although only if you define one function inside
" another, which is usually discouraged.
" * only relevant when using php_strict_blocks
"
" -- OTHER OPTIONS --
"
" let php_large_file = 0/? [ default 3000 ]
" ... If a PHP script has more lines than this limit (e.g., more
" than 3000 lines), some options are automatically turned off
" to help it load faster. These options are:
" php_strict_blocks = 0
" php_smart_members = 0
" php_smart_semicolon = 0
" php_show_pcre = 0
" php_folding = 0
" Note: If you set this option to '0', then this feature will
" be disabled; thus you can use:
" :let b:php_large_file = 0 | setfiletype php
" to reload the current file with the disabled syntax options
" re-activated.
"
" let php_strict_blocks = 1/0 [default 1]
" ... to match together all {} () and [] blocks correctly. This is
" required by some of the other options for finding errors and
" applying correct colors to { } blocks, etc. However, it may
" cause Vim to slow down on large files.
"
" let php_asp_tags = 1/0 [default 0]
" ... for highlighting ASP-style short tags: <% %>
"
" let php_noShortTags = 1/0 [default 0]
" ... don't sync <? ?> as php
" * This has been deprecated in favour of php_short_tags (which
" has the opposite meaning)
"
" let php_short_tags = 1/0 [default 1]
" ... highlight <?...?> blocks as php. If this is OFF, you need to
" use the longer <?php...?>
"
" let php_oldStyle = 1
" ... for using old colorstyle
"
" let php_folding = 1/2/3 [default 0]
" ... 1: for folding classes and functions
" 2: for folding all { } regions
" 3: for folding only functions
" TODO: documentation for php_folding_manual
"
" let php_fold_arrays = 0/1 [default 0]
" ... To fold arrays as well.
" * requires php_folding, php_strict_blocks, php_alt_arrays
"
" let php_fold_heredoc = 0/1 [default 0]
" ... Fold heredoc blocks ($string = <<<ENDOFSTRING)
" * requires php_folding
"
" let php_sync_method = x
" ... x = -1 to sync by search (default)
" x > 0 to sync at least x lines backwards
" x = 0 to sync from start
"
"
" ================================================================
"
" TODO LIST:
"
" PRIORITY:
" - document the phpControlParent feature, make sure it works fully, or not
" at all
" - what to do about 'iskeyword' containing '$'?
" - test syntax against older Vims (6.4, 6.0, 5.7)
" - concat rid of lines beginning with '\'
" - allow turning off all semicolon errors
" - fix bug in highlighting of pattern: /[\\\]/ and /[\\]]/
" - fix bug in highlighting of pattern: "/\$/" should make the '$' match the
" end-of-pattern
" - case/default syntax items don't work inside a switch/endswitch
" although it's still OK using {...}
"
" PHP Syntax:
" - review support for PHP built-in superglobals:
" - ensure all PHP 5.2 superglobals are recognized
" - review support for PHP built-in constants, make sure I've got them all
" - make support for PHP built-in class methods optional.
" - review highlight links to ensure maximum readability on GUI
" and color terminal using colorschemes 'elflord' and 'default'
" - new group phpReservedFunction, because some parts of
" phpSpecialFunction can be used as a method name.
" - what is php_oldStyle? is it still needed?
" - use 'nextgroup' to highlight errors when a ']' or ')' is followed by
" a constant/variable or function call. This will also help find when
" a closing ')' is missing.
" - Review syncing searches, see if there is anything we can add to help the
" syncing process.
" - make ';' on the end of a while() NOT a problem unless it is followed by
" a '{'
"
" PCRE Syntax:
" - fix problem: in regex "/(...)\1/", '\1' does NOT refer to a backreference!
" this is caused by incorrect matching of escape sequences in
" double-quoted strings where the double-quote escape sequences should
" take precedence
" - fix problem: this line breaks folding
" preg_match("#^require MODULES_PATH \. (['\"])main\.inc\.php\\1;$#m", '', $m))
"
" - decide on terminology: 'PCRE' or 'PREG'
" - Review effects of paired delimiters when combined with other
" PCRE complex atoms using those symbols
" - decide on better colors for the
" (?(?=lookahead/lookbehind)conditional|sub-pattern)
"
"
" Future Plans:
" - option to choose PHP4 or PHP5 compatibility
" - differentiate between an interface block and a class block
" - add ability to highlight user-defined functions and keywords
" using any of the following means:
" 1) a comma-separated string of user functions
" 2) a file containing user functions
" 3) using names from the tags file(s)
" (this may be better as a separate plugin)
" - add support for phpDocumentor comment blocks and tags
" - add support for POSIX Regex patterns
" - allow easy embedding of the PHP syntax using 'contains=@phpClTop' or
" 'syn region phpRegion ...'
" - automatically select best colors by examining the colorscheme
" - check to see if 'baselib' needs to be highlighted still
" - Add support 2nd parameter to preg_replace and highlight
" "\1" and other confusing sequences as errors ("\1" is "\x01")
" - Add support for class constants (foo::bar)
"
" Difficult To Implement:
" - Highlight expressions without operators or commas, such as:
" echo $a $b;
" These expressions are *really* difficult to find efficiently.
" - Folding around 'case' blocks.
"
"
"
" ================================================================
"
" Note:
" - syntax case is 'ignore' unless explicitly set to 'match'
" for a single item.
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syn clear
elseif exists("b:current_syntax")
finish
endif
if !exists("main_syntax")
let main_syntax = 'php'
endif
" TODO: what's all this about?
if version < 600
unlet! php_folding
if exists("php_sync_method") && !php_sync_method
let php_sync_method=-1
endif
so <sfile>:p:h/html.vim
else
runtime! syntax/html.vim
unlet b:current_syntax
endif
" accept old options
if !exists("php_sync_method")
if exists("php_minlines")
let php_sync_method=php_minlines
else
let php_sync_method=-1
endif
endif
function! s:ChooseValue(name, default)
if exists('b:' . a:name)
return b:{a:name}
elseif exists('g:' . a:name)
return g:{a:name}
else
return a:default
endif
endfunction
" set up variables based on global or buffer variables {{{1
" Is it a large file? (s:large_file) {{{2
let s:large_file_limit = s:ChooseValue('php_large_file', 3000)
let s:large_file = (s:large_file_limit == 0) ? 0 : (line('$') >= s:large_file_limit)
if s:large_file
echohl WarningMsg
echomsg printf('WARNING: Large PHP File (%d lines); some syntax options have been disabled.', line('$'))
echohl None
endif
" Strict Blocks (s:strict_blocks) {{{2
let s:strict_blocks = s:large_file ? 0 : s:ChooseValue('php_strict_blocks', 1)
" Fold Level (s:folding) {{{2
let s:folding = s:large_file ? 0 : s:ChooseValue('php_folding', 0)
" Fold manually (s:fold_manual) {{{2
let s:fold_manual = s:large_file ? 0 : s:ChooseValue('php_fold_manual', s:folding ? 1 : 0)
" Fold arrays (s:fold_arrays) {{{2
let s:fold_arrays = (s:folding && s:ChooseValue('php_fold_arrays', 0))
" Fold heredoc strings (s:fold_heredoc) {{{2
let s:fold_heredoc = (s:folding && s:ChooseValue('php_fold_heredoc', 0))
" Allow nested functions (s:nested_functions) {{{2
let s:nested_functions = s:ChooseValue('php_nested_functions', 1)
" Allow ASP-style <% %> tags (s:asp_tags) {{{2
let s:asp_tags = s:ChooseValue('php_asp_tags', 0)
" Only allow long tags '<?php' (s:long_tags) {{{2
let s:long_tags = !s:ChooseValue('php_short_tags', !s:ChooseValue('php_noShortTags', 0))
" SQL in strings (s:show_sql) {{{2
let s:show_sql = s:ChooseValue('php_sql_query', 0)
" HTML in strings (s:show_html_in_strings) {{{2
let s:show_html_in_strings = s:ChooseValue('php_htmlInStrings', 0)
" Highlight the PHP baselib (s:show_baselib) {{{2
let s:show_baselib = s:ChooseValue('php_baselib', 0)
" Highlight superglobals (s:special_vars) {{{2
let s:special_vars = s:ChooseValue('php_special_vars', s:ChooseValue('php_special_variables', s:ChooseValue('php_oldStyle', 1)))
" Highlight special functions (s:special_functions) {{{2
let s:special_functions = s:ChooseValue('php_special_functions', 1)
" Highlight quotes around strings (s:show_quotes) {{{2
let s:show_quotes = s:ChooseValue('php_highlight_quotes', 0)
" Highlight PCRE patterns (s:show_pcre) {{{2
let s:show_pcre = s:large_file ? 0 : s:ChooseValue('php_show_pcre', s:ChooseValue('php_show_preg', 1))
" Highlight ';' (s:show_semicolon) {{{2
let s:show_semicolon = s:ChooseValue('php_show_semicolon', 1)
" Highlight ';' errors (s:show_semicolon_error) {{{2
let s:show_semicolon_error = (s:show_semicolon && s:ChooseValue('php_show_semicolon_error', 1))
" Highlight parent error ) ] or } (s:parent_error_close) {{{2
let s:parent_error_close = (s:strict_blocks && s:ChooseValue('php_parent_error_close', 1))
" Highlight invalid ';' after if/while/foreach (s:no_empty_construct) {{{2
let s:no_empty_construct = (s:strict_blocks && s:ChooseValue('php_empty_construct_error', 1))
" Alt colors for {} around class/func/try/catch blocks (s:alt_blocks) {{{2
let s:alt_blocks = (s:strict_blocks && s:ChooseValue('php_alt_blocks', 1))
" Alt color for by-reference operators (s:alt_refs) {{{2
let s:alt_refs = s:ChooseValue('php_alt_assignByReference', 1)
" Alt color for control structure parents (s:alt_control_parents) {{{2
let s:alt_control_parents = s:ChooseValue('php_alt_construct_parents', 0)
" Alt color for array syntax (s:alt_arrays) {{{2
" * requires strict_blocks
let s:alt_arrays = (s:strict_blocks ? s:ChooseValue('php_alt_arrays', 1) : 0)
" Alt color for comparisons (s:alt_comparisons) {{{2
let s:alt_comparisons = s:ChooseValue('php_alt_comparisons', s:ChooseValue('php_oldStyle', 1))
" Alt colors for ';' after return/break (s:smart_semicolon) {{{2
let s:smart_semicolon = s:large_file ? 0 : (s:show_semicolon && s:ChooseValue('php_smart_semicolon', 1))
" Alt colors for '->' (s:smart_members / s:alt_properties) {{{2
let s:smart_members = s:large_file ? 0 : s:ChooseValue('php_smart_members', 0)
let s:alt_properties = (s:smart_members && s:ChooseValue('php_alt_properties', 0))
" Syncing method (s:sync) {{{2
let s:sync = s:ChooseValue('php_sync_method', -1)
" }}}1
delfunction s:ChooseValue
syn cluster htmlPreproc add=phpRegion,phpRegionAsp,phpRegionSc
" need to source the SQL syntax file in case we encounter
" heredoc containing SQL
if version < 600
syn include @sqlTop <sfile>:p:h/sql.vim
else
syn include @sqlTop syntax/sql.vim
endif
syn sync clear
unlet b:current_syntax
syn cluster sqlTop remove=sqlString,sqlComment
if s:show_sql
syn cluster phpClShowInStrings contains=@sqlTop
endif
if s:show_html_in_strings
syn cluster phpClShowInStrings add=@htmlTop
endif
" NOTE: syntax case should be 'ignore' for all items (in keeping
" with PHP's case insensitive behaviour). If an item MUST be case
" sensitive, 'syntax case match' should precede that item and
" 'syntax case ignore' must follow IMMEDIATELY after so that there
" can be no confusion over the value of 'syntax case' for most items
" syntax matches and regions may use '\C' to utilize case sensitivity
syn case ignore
" PHP syntax: clusters {{{1
" these represent a single value in PHP
syn cluster phpClValues add=@phpClConstants
syn cluster phpClValues add=phpIdentifier,phpIdentifierComplex,phpMethodsVar
" TODO: add class constants (foo::BAR)
" these can go anywhere an expression is valid inside PHP code
syn cluster phpClExpressions add=@phpClValues
syn cluster phpClExpressions add=phpRelation,phpList
syn cluster phpClExpressions add=phpParent,phpParentError
syn cluster phpClExpressions add=phpObjectOperator
" these are the control statements - they shouldn't contain each other
syn cluster phpClCode add=@phpClExpressions
syn cluster phpClCode add=phpLabel
syn cluster phpClCode add=phpFoldTry,phpFoldCatch
" TODO: what is phpStorageClass class exactly? it needs a more descriptive
" name so I know where to include it. Maybe it should be broken up
syn cluster phpClCode add=phpStorageClass
" code which is inside a function/method/class or global scope
syn cluster phpClInFunction add=@phpClCode
syn cluster phpClInMethod add=@phpClCode
syn cluster phpClInClass add=@phpClValues,phpAssign,phpSemicolon
syn cluster phpClTop add=@phpClCode
" This cluster contains matches to find where an expression follows another
" expression without a comma or operator inbetween
" TODO: is this even possible to do?
syn cluster phpClExprNotSeparated add=NONE
" Note: there is one cluster here each for:
" - constants
" - functions
" - classes
" - interfaces
" - structures (classes and interfaces combined)
" - methods
" - properties
" - members (things which are a method and a property)
syn cluster phpClConstants add=NONE
syn cluster phpClFunctions add=NONE
syn cluster phpClClasses add=NONE
syn cluster phpClInterfaces add=NONE
syn cluster phpClStructures add=@phpClClasses,@phpClInterfaces
syn cluster phpClMethods add=@phpClMembers
syn cluster phpClProperties add=@phpClMembers
syn cluster phpClMembers add=NONE
" these are the things which can be matched inside an identifier
syn cluster phpClIdentifier add=NONE
" Note: the next clusters contains all the regions or matches that can
" contain a class or interface name
syn cluster phpClClassHere add=phpStructureHere
syn cluster phpClInterfaceHere add=phpStructureHere
syn cluster phpClStructureHere add=@phpClClassHere,@phpClStructureHere
syn cluster phpClMethodHere add=phpMemberHere,phpMethodHere
syn cluster phpClPropertyHere add=phpMemberHere,phpPropertyHere
syn cluster phpClMemberHere add=@phpClMethodHere,@phpClPropertyHere
" also, some very basic matches for these place-holders
syn match phpStructureHere /\h\w*/ contained display
syn match phpMemberHere /\h\w*/ contained display
syn match phpMethodHere /\h\w*/ contained display
syn match phpPropertyHere /\h\w*/ contained display
" what to include at the top level?
if ! s:strict_blocks
" if not strict blocks, we must also allow matching of things from inside
" functions/methods/classes
syn cluster phpClTop add=@phpClInFunction,@phpClInMethod,@phpClInClass
endif
" Note: these are the old clusters ... they are deprecated now, but still
" here just in case someone is using them elsewhere
syn cluster phpClInside add=@phpClExpressions
syn cluster phpClConst add=@phpClExpressions
syn cluster phpClFunction add=@phpClCode
" PHP syntax: comments {{{1
syn cluster phpClValues add=phpComment
syn cluster phpClInClass add=phpComment
syn region phpComment start="/\*" end="\*/" contained extend contains=@Spell
if version >= 600
syn match phpComment "#.\{-}\(?>\|$\)\@=" contained extend contains=@Spell
syn match phpComment "//.\{-}\(?>\|$\)\@=" contained extend contains=@Spell
else
syn match phpComment "#.\{-}$" contained
syn match phpComment "#.\{-}?>"me=e-2 contained
syn match phpComment "//.\{-}$" contained
syn match phpComment "//.\{-}?>"me=e-2 contained
endif
" PHP syntax: Operators: + - * / && || (etc) {{{1
" NOTE: these need to come before the numbers (so that floats work)
syn cluster phpClExpressions add=phpAssign
syn match phpAssign /==\@!/ contained display
hi link phpAssign phpOperator
syn cluster phpClExpressions add=phpOperator
syn match phpOperator contained display /[%^|*!.~]/
" & can't be preceded by a '=' or ',' or '('
syn match phpOperator contained display /\%([=,(]\_s*\)\@<!&/
" + can't be followed by a number or '.'
" - can't be followed by a number or '.' or '>'
syn match phpOperator contained display /+[.0-9]\@!/
syn match phpOperator contained display /-[.>0-9]\@!/
syn match phpOperator contained display /[-+*/%^&|.]=/
syn match phpOperator contained display /\/[*/]\@!/
syn match phpOperator contained display /&&/
syn match phpOperator contained display /||/
syn match phpOperator contained display />>/
" Note: how the shift-left operator can't be followed by another '<' (that
" would make it a Heredoc syntax)
syn match phpOperator contained display /<<<\@!/
syn keyword phpOperator contained and or xor
" allow a ':' on its own - this may be after an 'else:' or something like that
syn match phpOperator contained display /::\@!/
syn cluster phpClExpressions add=phpTernaryRegion
syn region phpTernaryRegion matchgroup=phpOperator start=/?/ end=/::\@!/
\ transparent keepend extend display
\ contained matchgroup=Error end=/[;)\]}]/
" PHP syntax: null/true/false/numbers {{{1
syn cluster phpClValues add=phpNull
syn keyword phpNull contained null
syn cluster phpClValues add=phpBoolean
syn keyword phpBoolean contained true false
syn cluster phpClValues add=phpNumber
syn match phpNumber contained display /\<[1-9]\d*\>/
syn match phpNumber contained display /-[1-9]\d*\>/
syn match phpNumber contained display /+[1-9]\d*\>/
syn match phpNumber contained display /\<0x\x\{1,8}\>/
syn match phpNumber contained display /\<0\d*\>/ contains=phpOctalError
syn match phpOctalError contained display /[89]/
" Note: I've split float into 3 matches which each have a fixed starting
" character
syn cluster phpClValues add=phpFloat
syn match phpFloat contained display /\.\d\+\>/
syn match phpFloat contained display /\<\d\+\.\d\+\>/
syn match phpFloat contained display /-\d*\.\d\+\>/
syn match phpFloat contained display /+\d*\.\d\+\>/
" PHP syntax: dynamic strings {{{1
" single-quoted strings are always the same
" TODO: work out a good name for an option which will add 'display' option
" to these strings
syn cluster phpClValues add=phpStringSingle
syn region phpStringSingle matchgroup=phpQuoteSingle start=/'/ skip=/\\./ end=/'/
\ contained keepend extend contains=@phpClShowInStrings
" Note: this next version of the php double-quoted string can't contain
" variables, because a few parts of PHP code require strings without
" variables. There is another string match later which takes precedence
" over this one in most circumstances where a string containing variables IS
" allowed
syn cluster phpClValues add=phpStringDoubleConstant
syn region phpStringDoubleConstant contained keepend extend
\ matchgroup=phpQuoteSingle start=/"/ end=/"/ skip=/\\./
\ contains=@phpClShowInStrings,phpSpecialChar
" Note: this version of the double-quoted string also contains
" @phpClStringIdentifiers, which means variables can go inside the string
syn cluster phpClExpressions add=phpStringDouble
syn region phpStringDouble matchgroup=phpQuoteDouble start=/"/ skip=/\\./ end=/"/
\ contained keepend extend
\ contains=@phpClShowInStrings,phpSpecialChar,@phpClStringIdentifiers
" backticks
syn cluster phpClExpressions add=phpBacktick
syn region phpBacktick matchgroup=phpQuoteBacktick start=/`/ skip=/\\./ end=/`/
\ contained keepend extend
\ contains=phpSpecialChar,@phpClStringIdentifiers
" this cluster contains only strings which accept things like \n or \x32
" inside them
syn cluster phpClStringsWithSpecials add=phpStringDoubleConstant,@phpClStringsWithIdentifiers
" this cluster contains strings which accept things like {$foo} inside them
syn cluster phpClStringsWithIdentifiers add=phpStringDouble,phpBacktick,phpHereDoc
" HereDoc {{{
if version >= 600
syn cluster phpClExpressions add=phpHereDoc
syn case match
" syn keyword phpHereDoc contained foobar
if s:folding && s:fold_heredoc
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/<<<\s*\z(\h\w*\)$/
\ contains=phpSpecialChar
\ fold
" always match special Heredocs which state what type of content they have
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/\c<<<\s*\z(\%(\h\w*\)\=html\)$/
\ contains=@htmlTop,phpSpecialChar
\ fold
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/\c<<<\s*\z(\%(\h\w*\)\=sql\)$/
\ contains=@sqlTop,phpSpecialChar
\ fold
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/\c<<<\s*\z(\%(\h\w*\)\=javascript\)$/
\ contains=@htmlJavascript,phpSpecialChar
\fold
else
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/<<<\s*\z(\h\w*\)$/
\ contains=phpSpecialChar
" always match special Heredocs which state what type of content they have
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/\c<<<\s*\z(\%(\h\w*\)\=html\)$/
\ contains=@htmlTop,phpSpecialChar
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/\c<<<\s*\z(\%(\h\w*\)\=sql\)$/
\ contains=@sqlTop,phpSpecialChar
syn region phpHereDoc keepend extend contained
\ matchgroup=phpHereDocDelimiter end=/^\z1\%(;\=$\)\@=/
\ start=/\c<<<\s*\z(\%(\h\w*\)\=javascript\)$/
\ contains=@htmlJavascript,phpSpecialChar
endif
syn case ignore
endif " }}}
" PHP syntax: strings: special sequences {{{1
" match an escaped backslash inside any type of string
syn match phpStringLiteral /\\\\/ contained display
\ containedin=phpStringSingle,@phpClStringsWithSpecials
" match an escaped quote in each type of string
syn match phpStringLiteral /\\`/ contained display containedin=phpBacktick
syn match phpStringLiteral /\\'/ contained display containedin=phpStringSingle
syn match phpStringLiteral /\\"/ contained display
\ containedin=phpStringDouble,phpStringDoubleConstant
" highlighting for an escaped '\$' inside a double-quoted string
syn match phpStringLiteral /\\\$/ contained display containedin=@phpClStringsWithSpecials
" match \{ as regular string content so that it stops \{$var} from
" highlighting the { } region
syn match phpStringRegular /\\{/ contained display containedin=@phpClStringsWithSpecials
hi link phpStringRegular phpStringDouble
" match an \r\n\t or hex or octal sequence
" TODO: these should also be available in PCRE pattern strings
" TODO: what were all these extra escape sequences???
syn match phpSpecialChar contained display /\\[nrt]/
syn match phpSpecialChar contained display /\\\o\{1,3}/
syn match phpSpecialChar contained display /\\x\x\x\=/
" create an identifier match for inside strings:
syn match phpIdentifierInString /\$\h\w*/ contained display
\ nextgroup=phpPropertyInString,phpPropertyInStringError,@phpClIdentifierIndexInString
\ contains=phpIdentifier
\ containedin=@phpClStringsWithIdentifiers
" match an index [bar] [0] [$key] after a variable inside a string {{{2
" First: match the [ and ] which would appear in the index (they're
" contained int the following items)
syn match phpBracketInString /[[\]]/ contained display
hi link phpBracketInString phpSpecialChar
" Second: match a single '[' as an error
syn cluster phpClIdentifierIndexInString add=phpBracketInStringFalseStart
syn match phpBracketInStringFalseStart /\[\]\=/ contained display
hi link phpBracketInStringFalseStart Error
" Third: match any other [] region which is completed, but doesn't have a
" valid key
syn cluster phpClIdentifierIndexInString add=phpIdentifierIndexInString
syn match phpIdentifierIndexInString /\[[^"]\{-1,}\]/
\ contains=phpBracketInString,phpIdentifierIndexInStringError
\ contained display
" error on a bracket which is inside another bracket
syn match phpIdentifierIndexInStringError /\[[$_a-z0-9]*\[/ contained display
hi link phpIdentifierIndexInStringError Error
" any character which isn't a valid index character
syn match phpIdentifierIndexInStringError /[^$a-z0-9_[\]]\+/ contained display
" a number *must not* be preceded by the '[' and followed by a \w
syn match phpIdentifierIndexInStringError /\[\@<=\d\+\w\@=/ contained display
" a dollar sign *must* be preceded by the '['
syn match phpIdentifierIndexInStringError /\[\@<!\$/ contained display
\ containedin=phpIdentifierIndexInStringError
" Fourth: match a complete '[]' region properly
" 1) an index containing a number
syn match phpIdentifierIndexInString /\[\d\+\]/ contained display
\ contains=phpBracketInString
" 2) a word or variable
syn match phpIdentifierIndexInString /\[\$\=\h\w*\]/ contained display
\ contains=phpBracketInString,phpVarSelector
hi link phpIdentifierIndexInString Identifier
" }}}2
" match an property after a variable inside a string
syn cluster phpClPropertyHere add=phpPropertyInString
syn match phpPropertyInString /->\h\w*/ contained display extend
\ contains=phpPropertySelector,@phpClProperties
" it's sometimes easy to get it wrong
syn match phpPropertyInStringError contained display /->\%([^a-z0-9_"\\]\|\\.\)/
\ contains=phpPropertySelector
syn match phpPropertyInStringError contained display /->"\@=/
hi! link phpPropertyInStringError Error
syn region phpIdentifierInStringComplex matchgroup=phpSpecialChar
\ start=/{\$\@=/ start=/\${\w\@!/ end=/}/
\ contained extend keepend contains=@phpClExpressions
\ containedin=@phpClStringsWithIdentifiers
syn region phpIdentifierInStringErratic contained extend
\ matchgroup=phpSpecialChar start=/\${\w\@=/ end=/}/
\ containedin=@phpClStringsWithIdentifiers
\ contains=phpIdentifierErratic
syn match phpIdentifierErratic /{\@<=\h\w*/ contained
\ nextgroup=phpErraticBracketRegion
\ nextgroup=phpIdentifierInStringErraticError skipwhite skipempty
syn region phpErraticBracketRegion contained keepend extend contains=@phpClExpressions
\ matchgroup=phpParent start=/\[/ end=/\]/ display
\ matchgroup=Error end=/;/
\ nextgroup=phpIdentifierInStringErraticError skipwhite skipempty
syn match phpIdentifierInStringErraticError contained /[^ \t\r\n}]\+/
\ nextgroup=phpIdentifierInStringErraticError skipwhite skipempty
hi link phpIdentifierInStringErraticError Error
" PHP syntax: variables/identifiers ($foo) {{{1
" one $
syn match phpVarSelector contained display /\$/
" two $$
syn match phpVarSelectorDeref contained display /\$\$/
syn match phpVarSelectorError contained display /\$\$\$\+/
" match a regular variable
syn cluster phpClExpressions add=phpIdentifier
syn match phpIdentifier /\$\h\w*/ contained display
\ contains=phpVarSelector,@phpClIdentifier
" match a dereference-variable ($$variable)
syn match phpIdentifier /\$\$\+\h\w*/ contained display
\ contains=@phpClIdentifier,phpVarSelectorDeref,phpVarSelectorError,phpDerefInvalid
" you can't dereference these variables:
syn match phpDerefInvalid contained display
\ /\C\$\$\ze\%(this\|arg[cv]\|GLOBALS\)\>/
syn match phpDerefInvalid contained display
\ /\C\$\$\ze_\%(GET\|POST\|REQUEST\|COOKIE\|SESSION\|SERVER\|ENV\)\>/
hi link phpDerefInvalid Error
if s:special_vars
syn case match
" Superglobals: {{{2
syn cluster phpClIdentifier add=phpSuperglobal
syn match phpSuperglobal contained display /\$\@<=GLOBALS\>/
syn match phpSuperglobal contained display /\$\@<=_GET\>/
syn match phpSuperglobal contained display /\$\@<=_POST\>/
syn match phpSuperglobal contained display /\$\@<=_COOKIE\>/
syn match phpSuperglobal contained display /\$\@<=_REQUEST\>/
syn match phpSuperglobal contained display /\$\@<=_FILES\>/
syn match phpSuperglobal contained display /\$\@<=_SESSION\>/
syn match phpSuperglobal contained display /\$\@<=_SERVER\>/
syn match phpSuperglobal contained display /\$\@<=_ENV\>/
syn match phpSuperglobal contained display /\$\@<=this\>/
" Built In Variables: {{{2
syn cluster phpClIdentifier add=phpBuiltinVar
syn match phpBuiltinVar contained display /\$\@<=argc\>/
syn match phpBuiltinVar contained display /\$\@<=argv\>/
syn match phpBuiltinVar contained display /\$\@<=php_errormsg\>/
" Long Arrays: {{{2
syn cluster phpClIdentifier add=phpLongVar
syn match phpLongVar contained display /\$\@<=HTTP_GET_VARS\>/
syn match phpLongVar contained display /\$\@<=HTTP_POST_VARS\>/
syn match phpLongVar contained display /\$\@<=HTTP_POST_FILES\>/
syn match phpLongVar contained display /\$\@<=HTTP_COOKIE_VARS\>/
syn match phpLongVar contained display /\$\@<=HTTP_SESSION_VARS\>/
syn match phpLongVar contained display /\$\@<=HTTP_SERVER_VARS\>/
syn match phpLongVar contained display /\$\@<=HTTP_ENV_VARS\>/
" Server Variables: {{{2
" TODO: check these against the latest PHP manual
syn cluster phpClIdentifier add=phpEnvVar
syn match phpEnvVar contained display /\C\$\@<=GATEWAY_INTERFACE\>/
syn match phpEnvVar contained display /\C\$\@<=SERVER_NAME\>/
syn match phpEnvVar contained display /\C\$\@<=SERVER_SOFTWARE\>/
syn match phpEnvVar contained display /\C\$\@<=SERVER_PROTOCOL\>/
syn match phpEnvVar contained display /\C\$\@<=REQUEST_METHOD\>/
syn match phpEnvVar contained display /\C\$\@<=QUERY_STRING\>/
syn match phpEnvVar contained display /\C\$\@<=DOCUMENT_ROOT\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_ACCEPT\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_ACCEPT_CHARSET\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_ENCODING\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_ACCEPT_LANGUAGE\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_CONNECTION\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_HOST\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_REFERER\>/
syn match phpEnvVar contained display /\C\$\@<=HTTP_USER_AGENT\>/
syn match phpEnvVar contained display /\C\$\@<=REMOTE_ADDR\>/
syn match phpEnvVar contained display /\C\$\@<=REMOTE_PORT\>/
syn match phpEnvVar contained display /\C\$\@<=SCRIPT_FILENAME\>/
syn match phpEnvVar contained display /\C\$\@<=SERVER_ADMIN\>/
syn match phpEnvVar contained display /\C\$\@<=SERVER_PORT\>/
syn match phpEnvVar contained display /\C\$\@<=SERVER_SIGNATURE\>/
syn match phpEnvVar contained display /\C\$\@<=PATH_TRANSLATED\>/
syn match phpEnvVar contained display /\C\$\@<=SCRIPT_NAME\>/
syn match phpEnvVar contained display /\C\$\@<=REQUEST_URI\>/
endif
" }}}2
" PHP Syntax: type-casting: (string)$foo {{{1
syn cluster phpClValues add=phpType
syn keyword phpType contained null bool boolean int integer real double float string object
" only match 'array' as a type when it *isn't* followed by '('
syn match phpType contained /\<array\>\%(\_s*(\)\@!/
" PHP Syntax: function/static calls: {{{1
" Note: I could have forced function calls to be matched only when a '('
" follows, but I think users would want PHP functions highlighted in more
" places, rather than less, so I have just added the :\@! to make sure it is
" not part of a static method call
" Note: this didn't work properly ... if the match didn't include the
" '(...)', then functions in @phpClFunctions can't have a nextgroup on them
syn cluster phpClExpressions add=@phpClFunctions
" syn cluster phpClExpressions add=phpFunctionCall
" syn match phpFunctionCall contained /\<\%(\h\w*\)(\_.*)/
" \ contains=@phpClFunctions
" Also, a match when a word is part of a :: reference:
syn cluster phpClValues add=phpStaticUsage
syn cluster phpClExpressions add=phpStaticUsage
syn cluster phpClStructureHere add=phpStaticUsage
syn match phpStaticUsage contained display /\<\%(\h\w*\)\@>\%(\_s*::\)\@=/
\ transparent contains=@phpClClasses
" a match for a static function call
syn cluster phpClValues add=phpStaticAccess
syn cluster phpClExpressions add=phpStaticVariable,phpStaticCall
syn cluster phpClPropertyHere add=phpStaticAccess
syn cluster phpClMethodHere add=phpStaticCall
" also allowed in function prototypes
syn cluster phpClDefineFuncProtoArgs add=phpStaticAccess
syn match phpStaticAccess contained extend display /::\_s*\%(\h\w*\|\%#\)/ contains=phpDoubleColon
syn match phpStaticCall contained extend display /::\_s*\h\w*\ze\_s*(/
\ contains=phpDoubleColon,@phpClMethods
" a match for a static variable usage
syn match phpStaticVariable contained display /::\_s*\$\h\w*/ extend
\ contains=phpDoubleColon,phpIdentifier
" a match for a static constant usage
syn match phpDoubleColon contained display /::/
hi link phpDoubleColon phpDefine
" PHP Syntax: magic classes (self/parent): {{{1
syn cluster phpClClasses add=phpMagicClass
syn keyword phpMagicClass contained self parent
" Note: 'self' and 'parent' are also matched in other places because they
" could be confusing otherwise ...
syn cluster phpClValues add=phpMagicClass
" PHP Syntax: control structures: {{{1
syn cluster phpClCode add=phpConditional
syn keyword phpConditional contained declare enddeclare if else elseif endif
syn cluster phpClCode add=phpRepeat
syn keyword phpRepeat contained foreach endforeach
\ do while endwhile for endfor