Skip to content

Separating function from phpKeyword to phpKeywordFunction #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 170 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
00a9a65
Add spell-checking to strings and comments.
StanAngeloff Nov 17, 2011
993e312
Update PHP functions list.
StanAngeloff Nov 17, 2011
2580adf
Add spelling support in heredocs.
StanAngeloff Nov 17, 2011
845c961
Add compatibility with recent html5.vim changes.
StanAngeloff Mar 6, 2012
02a3410
Silent call to unlet! + spellcheck updates.
StanAngeloff Apr 16, 2012
14823f4
Get rid of some extensions and rebuild with latest PHP 5.3.x on Ubuntu.
StanAngeloff Apr 16, 2012
aaf3338
Update template and get rid of whitespace at EOL.
StanAngeloff Apr 16, 2012
c74b98e
Update template script to be smarter about missing extensions.
StanAngeloff Apr 16, 2012
eae0503
Basic PHP 5.4 support.
StanAngeloff Apr 16, 2012
c9ff5be
Update README (switch to Markdown too).
StanAngeloff Jun 1, 2012
fcfbb12
Auto-generate Vim syntax with PHP 5.4.6-1ubuntu1.1.
StanAngeloff Nov 29, 2012
e6c311f
Use Mysql for SQL Syntax
jaywilliams Feb 22, 2013
54cce05
Use Mysql for SQL Syntax
jaywilliams Feb 22, 2013
e231676
Clean up syntax file, no functional changes.
StanAngeloff Feb 25, 2013
48d2f7b
Merge remote-tracking branch 'jaywilliams/mysql'
StanAngeloff Feb 25, 2013
6e695b0
Use MySQL as the default buffer SQL syntax.
StanAngeloff Feb 25, 2013
f398d9a
Auto-generate Vim syntax with PHP 5.5.0alpha5 (cli) (built: Feb 25 20…
StanAngeloff Feb 25, 2013
36ccde5
Auto-generate Vim syntax with PHP 5.5.0RC1.
StanAngeloff May 14, 2013
4cd4f22
Merge @aantonello commits.
StanAngeloff Jan 2, 2014
8adb70b
Merge @pixelastic commit.
StanAngeloff Jan 2, 2014
200921f
Merge @joshtronic commit.
StanAngeloff Jan 2, 2014
c85155b
Update template file and re-generate using PHP 5.5.7
StanAngeloff Jan 2, 2014
dface50
Add 'yield' to the list of keywords (as of PHP 5.5).
StanAngeloff Jan 2, 2014
fc99f30
Highlight booleans as 'Boolean'.
StanAngeloff Jan 2, 2014
bbe3272
Merge @paulyg commits.
StanAngeloff Jan 3, 2014
356f296
Extend PHP to use Java-like syntaxing highlighting (via @tetsuo13).
StanAngeloff Jan 3, 2014
65e2b0a
Stop phpDocParam highlight leakage
boxofrox Jan 9, 2014
b6c2b29
Merge remote-tracking branch 'boxofrox/fix/php-tag-recognition'
StanAngeloff Jan 9, 2014
22c7308
Restore spell-checking in docblock comments.
StanAngeloff Jan 13, 2014
2ee305d
Don't be too clever with how comments are highlighted.
StanAngeloff Jan 16, 2014
92376a1
Link children to parent group, highlight '$' as part of the identifier.
StanAngeloff Jan 16, 2014
02b910c
TODOs and NOTEs must be spelt uppercase.
StanAngeloff Jan 16, 2014
86ac875
Add missing PHPDoc tags.
StanAngeloff Jan 16, 2014
b6b6ba7
Drop the README file until we come up with something better.
StanAngeloff Jan 16, 2014
93dc1d0
Basic splat operator support for PHP 5.6.
StanAngeloff Jan 25, 2014
8d0deae
Update template file and re-generate using PHP 5.5.8
StanAngeloff Jan 25, 2014
b82fd30
Don't highlight '$' as an identifier by default.
StanAngeloff Feb 3, 2014
c66cc18
Update {phpCommentTitle,phpDocTags} leakage.
StanAngeloff Feb 6, 2014
20fcf17
Highlight static class references as 'phpClasses'.
StanAngeloff Feb 24, 2014
cca3e42
Add a Dockerfile which can be used to rebuild the syntax.
StanAngeloff Feb 24, 2014
260d33a
Rebuild the syntax file from Docker, #nfc.
StanAngeloff Feb 24, 2014
108d9ed
Docker: Update README instructions and tag the image correctly.
StanAngeloff May 29, 2014
9119f44
Docker: Build using Ubuntu 14.04 LTS.
StanAngeloff May 29, 2014
d1b125c
Project: Move PHP files to scripts/, update Dockerfile reference.
StanAngeloff May 29, 2014
76896c9
Scripts: Drop php.template file.
StanAngeloff May 29, 2014
e36abef
Scripts: Update syntax script.
StanAngeloff May 29, 2014
c343741
Scripts: Add block for last modified date and PHP version.
StanAngeloff May 29, 2014
a5228c0
Syntax: Re-generate using PHP 5.5.12 and new script.
StanAngeloff May 29, 2014
81e68be
Syntax: Add ability to enable / disable built-ins for extensions.
StanAngeloff May 29, 2014
3672361
Scripts: DOS => Unix line endings, no functional changes.
StanAngeloff May 29, 2014
d80e36e
Syntax: Update against PHP 5.6.0beta3.
StanAngeloff May 29, 2014
4635893
Syntax: Sort constants, functions and classes alphabetically, #nfc.
StanAngeloff May 29, 2014
5c385de
README: Call for help.
StanAngeloff May 29, 2014
8f519e8
Syntax: Check variable values, not only if they exist.
StanAngeloff May 29, 2014
6d59d00
add simple method, class and extend class match with the purpose of h…
rodrigore May 25, 2014
7fc37c6
add link(highlighting) to definitions of the classes, extend class an…
rodrigore May 25, 2014
2da25fd
change links in order to display others colors
rodrigore May 25, 2014
f55a8dc
Improved regex phpDefineExtendsName
rodrigore May 26, 2014
dee046a
add implements classes highlighting
rodrigore May 26, 2014
01ce354
change colour of use, namespace keyword
rodrigore May 26, 2014
c5c2125
Syntax: Tweak groups for function names and class properties.
StanAngeloff May 30, 2014
e39e28e
Merge branch 'rodrigore/master'.
StanAngeloff May 30, 2014
6ea462e
Syntax: Turn off fancy options by defaut.
StanAngeloff Jun 2, 2014
67730b8
check for *pre* set date.timezone before defaulting to UTC if unset, …
Jun 2, 2014
3ac9ded
Merge branch 'gehidore/master'
StanAngeloff Jun 3, 2014
1c9bc9b
Scripts: Always use UTC timezone.
StanAngeloff Jun 3, 2014
5b9a52b
Distinguish PHPDoc annotation arguments clearly
commonquail Jun 12, 2014
ff5968b
Merge pull request #19 from commonquail/lazy-annotations
StanAngeloff Jun 13, 2014
e56735c
Fixed some indentation.
swekaj Jun 30, 2014
8522985
Added option for not highlighting SQL in heredocs.
swekaj Jun 30, 2014
b29fbbf
Added options related to HTML syntax highlighting.
swekaj Jul 1, 2014
5f63535
Explained some unexplained options. Cleaned up explanation of folding…
swekaj Jul 1, 2014
80522a0
Moved the JavaScript heredoc up with the HTML one.
swekaj Jul 1, 2014
9f70735
Merge pull request #21 from swekaj/option-refactoring
StanAngeloff Jul 2, 2014
b622a10
Add parens and brackets to folded delimiters.
swekaj Jun 30, 2014
e17ef95
Conditionally define keywords for if, else, elseif, etc. so they can …
swekaj Jul 8, 2014
4d4f6ea
Folding for if..elseif..else
swekaj Jul 5, 2014
800af13
Folding while and do/while loops.
swekaj Jul 5, 2014
86bfdc7
Added for loop folding.
swekaj Jul 5, 2014
16f2ca0
Added folding for foreach loops
swekaj Jul 7, 2014
a3e2554
Improved folding for try/catch/finally
swekaj Jul 7, 2014
1783fc7
Added folding for switch/case/default.
swekaj Jul 7, 2014
84e8b2c
Updated folding option description and cleaned up option checking.
swekaj Jul 8, 2014
c4f3182
Folding for heredocs and nowdocs.
swekaj Jul 8, 2014
1d20655
All folding regions contain the necessary clusters/regions so that th…
swekaj Jul 10, 2014
a325717
Fold HEREDOCs without repeating code.
swekaj Jul 10, 2014
f1cff2f
Merge branch 'swekaj/fold-enhancements'
StanAngeloff Jul 10, 2014
4550a75
Folding: {Doc => Syn}Fold, after syntax/yacc.vim.
StanAngeloff Jul 10, 2014
973e6b1
Docker: Don't add the syntax file in the container.
StanAngeloff Jul 10, 2014
e86c0ce
PHP 5.6.0RC2
StanAngeloff Jul 10, 2014
0c6519c
Fixed bug with highlighting things in closures.
swekaj Jul 12, 2014
04f1c95
Merge pull request #23 from swekaj/fold-enhancements
StanAngeloff Jul 14, 2014
d228468
Explain what the php_ignore_phpdoc does and allow the variable to exi…
swekaj Jul 17, 2014
37d8ff6
Only match first, optional, identifier in doc tag
commonquail Jun 13, 2014
4011785
Merge pull request #25 from swekaj/option-refactoring
StanAngeloff Jul 21, 2014
d867857
Merge branch 'commonquail/match-first-tag-identifier'
StanAngeloff Jul 21, 2014
fccd639
Comments: Don't highlight whitespace as part of a match.
StanAngeloff Jul 22, 2014
1c23964
Save the 'iskeyword' setting before including the HTML syntax.
StanAngeloff Aug 4, 2014
62ff6ab
Add tags from StanAngeloff/php.vim/issues/28
baldrs Aug 12, 2014
dfd8cc8
Sort PHPDoc tags alphabetically, no functional changes.
StanAngeloff Aug 14, 2014
3a8c2fd
Update PHPDoc with PSR proposed tags, closes #26.
StanAngeloff Aug 14, 2014
48fc731
Don't highlight {TRUE,FALSE,NULL} as constants.
StanAngeloff Aug 14, 2014
15c5360
Add syntax overriding documentation.
StanAngeloff Aug 14, 2014
a0c9a9b
Add support for folding phpDoc comments
sudar Sep 17, 2014
90cc67b
Merge remote-tracking branch 'sudar/master'
StanAngeloff Sep 17, 2014
5bdc6f0
Syntax: Re-generate using PHP 5.6, no major changes.
StanAngeloff Sep 18, 2014
43e4931
added highlight for __TRAIT__
ruchee Dec 11, 2014
70cc9a4
Update against PHP 5.6.3-1.
StanAngeloff Dec 11, 2014
d9be2fa
Merge remote-tracking branch 'ruchee/master'
StanAngeloff Dec 11, 2014
9773b02
Highlight '::' as phpMemberSelector.
StanAngeloff Jan 5, 2015
ff788d7
Add pathogen.vim installation instructions.
gabesullice Feb 19, 2015
3ef881b
Tweak README.md, no functional changes.
StanAngeloff Feb 20, 2015
d9f6df1
Updated repo URL
Incognito Jun 15, 2015
f1df680
Merge pull request #39 from Incognito/patch-1
StanAngeloff Jun 15, 2015
734af7d
Fix highlighting of periods in phpDocComment
synthetiv Jul 23, 2015
f48f074
Merge pull request #40 from synthetiv/master
StanAngeloff Jul 23, 2015
502c96d
Update against PHP 5.6.13-1.
StanAngeloff Sep 14, 2015
cc1d95a
Support "use function" properly. Fixes #42.
msjyoo Oct 23, 2015
85a6cac
Merge branch 'sekjun9878/patch-1' into use-function
StanAngeloff Nov 11, 2015
b880101
Add two new matches, phpUseFunction and phpUseClass.
StanAngeloff Nov 11, 2015
aca1925
Add new matche, phpUseAlias.
StanAngeloff Nov 11, 2015
ca56841
Merge branch 'use-function'
StanAngeloff Nov 12, 2015
8ebb0e1
Fix "Undefined variable: main_syntax".
StanAngeloff Mar 7, 2016
424a51e
README: Drop PHP 5.6 notice.
StanAngeloff Mar 7, 2016
a55b6eb
Closes #51, PHP closing tag in DocBlock.
StanAngeloff Mar 23, 2016
85388c0
Closes #47, Differentiate between class properties and functions.
StanAngeloff Mar 23, 2016
a3d3bf5
Add php 7.1 types as a valid types
Taluu Jan 2, 2017
f1e6729
Update against PHP 7.1.0-3+deb.sury.org~trusty+1
StanAngeloff Jan 5, 2017
ae939a7
Update README with developing instructions.
StanAngeloff Jan 5, 2017
0447f77
Update via stanangeloff/php:7.1-cli
StanAngeloff Jan 5, 2017
91a9935
Fix some unintended matches outside of '<?php'
Jan 28, 2017
4f68225
Merge branch 'adriaanzon/master'
StanAngeloff Jan 30, 2017
50adbbc
syntax match for php numbers
Jul 20, 2017
a07ac6f
missing contained and display keyword
Jul 20, 2017
763119d
Fix screenshot rendering
mikaelz Aug 8, 2017
48fdbfd
Add support for SQL coloration in nowdoc blocks
Taluu Sep 19, 2017
61292de
Add support for HTML/JS coloration in nowdoc blocks
Taluu Sep 19, 2017
4ee2f5c
Highlight FQCN in phpDocParam.
StanAngeloff Oct 26, 2017
41c36f7
Allow use of '|' in phpDocParam.
StanAngeloff Oct 30, 2017
f24a2bc
Add maximum size to lookbehind for phpHereDoc and phpNowDoc.
StanAngeloff Dec 4, 2017
97aaeb3
Add php{Doc,Class,Use}NamespaceSeparator.
StanAngeloff Dec 4, 2017
7147336
Update README, add additional options of interest and related projects.
StanAngeloff Dec 4, 2017
1081084
Update README with syntax overriding snippets.
StanAngeloff Dec 4, 2017
1ed6465
Use PHP 7.2 in Dockerfile.
StanAngeloff Feb 6, 2018
d1aef69
Add more syntax groups inside interpolated expressions.
StanAngeloff Feb 6, 2018
bf25868
Update syntax against PHP 7.2.2-1.
StanAngeloff Feb 6, 2018
afa6961
Add phpNull as keyword
mylgeorge Apr 8, 2018
66222bc
Add new phpNullValue keyword.
StanAngeloff Apr 9, 2018
93d46db
Wrap Vim 7.4+ features in a conditional block.
StanAngeloff Apr 9, 2018
c6f9187
Add post-processors for syntax file.
StanAngeloff Apr 9, 2018
9f2d8fb
Post-process syntax for Vim 7.3.
StanAngeloff Apr 9, 2018
5934eb0
Add support for XML heredoc and nowdoc
akrabat Oct 26, 2018
9cbc002
Update syntax/php.vim
StanAngeloff Oct 26, 2018
eafacf5
Update syntax/php.vim
StanAngeloff Oct 26, 2018
068702b
Update syntax/php.vim
StanAngeloff Oct 26, 2018
ea8d6a5
Update syntax/php.vim
StanAngeloff Oct 26, 2018
7671a5a
Merge pull request #86 from akrabat/xml-heredoc
StanAngeloff Oct 26, 2018
ca9a285
PHP 7 Generator & delegation via yield from
StanAngeloff Mar 25, 2019
bbad8f6
Update built-ins against multiple PHP versions, incl. PHP 7.3.
StanAngeloff Mar 25, 2019
6b6dfcd
Allow Whitespace Before Heredoc / Nowdoc Blocks
eknowlton Oct 25, 2019
d57c94a
removed check for version, which i thought was a check for php version
eknowlton Oct 28, 2019
b30d1fc
updated end for both versions of vim
eknowlton Oct 28, 2019
f261a48
Fix per PR recommendation
eknowlton Jan 23, 2020
873d6da
Fixed vim variable, tested with 70300, and 70200
eknowlton Jan 23, 2020
1d677af
Update README.md
StanAngeloff Feb 4, 2020
042e60a
Merge pull request #95 from eknowlton/fix/herdoc-nowdoc-php-73
StanAngeloff Feb 4, 2020
a984bc0
Update README.md
StanAngeloff Feb 4, 2020
2ec2ab9
Update README.md
StanAngeloff Feb 4, 2020
5a77189
Allow whitespaces after '<<<' operator in Heredoc
iusmac May 27, 2020
930aec5
Merge pull request #97 from iusmac/master
StanAngeloff May 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README

This file was deleted.

143 changes: 143 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
php.vim
=======

An up-to-date Vim syntax for PHP.

_This project is a fork of [php.vim--Garvin][php.vim-garvin] which in turn is an update of the [php.vim][php.vim-original] script which in turn is an updated version of the php.vim syntax file distributed with Vim. **Whew!**_

Installation
------------

If you don't have a preferred installation method, [vim-plug] is quick and simple. With [vim-plug installed], add the following to your `vimrc` (if you are a NeoVim user, see the [FAQ page][neovim-faq] for help):

```vim
Plug 'StanAngeloff/php.vim'
```

If you are using Git, please be aware [the original repository this project was forked from][php.vim-garvin] contains bad timezone in some of the commits. You'll need to fetch with `fsckObjects` disabled:

```sh
git clone -c fetch.fsckObjects=false [email protected]:StanAngeloff/php.vim.git
```

Unless you specify `-c fetch.fsckObjects=false` as an option to `git clone`, you may see `badTimezone: invalid author/committer line - bad time zone` in the output and the cloning will [fail](https://github.com/StanAngeloff/php.vim/issues/96).

Configuration
-------------

`php.vim` comes with sensible defaults for most use cases. Below is a list of some interesting configuration options you may tweak. Refer to the [source code][php.vim-source] for additional options.

- `g:php_version_id`,
`b:php_version_id`

Default: `g:php_version_id = 70300`

The PHP version the Vim syntax should adhere to. This currently determines how strict [Heredoc/Nowdoc syntax](https://www.php.net/manual/en/migration73.new-features.php#migration73.new-features.core.heredoc) should be. The format of the Vim variable follows the [PHP predefined constant `PHP_VERSION_ID`](https://www.php.net/manual/en/reserved.constants.php#constant.php-version-id).

- `g:php_syntax_extensions_enabled`, `g:php_syntax_extensions_disabled`
`b:php_syntax_extensions_enabled`, `b:php_syntax_extensions_disabled`

Default: `g:php_syntax_extensions_enabled = ["bcmath", "bz2", "core", "curl", "date", "dom", "ereg", "gd", "gettext", "hash", "iconv", "json", "libxml", "mbstring", "mcrypt", "mhash", "mysql", "mysqli", "openssl", "pcre", "pdo", "pgsql", "phar", "reflection", "session", "simplexml", "soap", "sockets", "spl", "sqlite3", "standard", "tokenizer", "wddx", "xml", "xmlreader", "xmlwriter", "zip", "zlib"]`

A list of PHP extension names (lowercase) for which highlighting of built-in functions, constants, classes and interfaces is enabled / disabled.

If you are **not** interested in highlighting **any** built-in functions/constants/etc., set `g:php_syntax_extensions_enabled` to an empty list `[]`.

If you are **not** interested in highlighting built-in functions/constants/etc. for a subset of PHP extensions, set `g:php_syntax_extensions_enabled` to a list of extensions you wish to disable, e.g., `["mcrypt"]`.

- `php_var_selector_is_identifier`

Default: `0`

Set this to a truthy value (e.g., `1`) to include the dollar sign `$` as part of the highlighting group for a PHP variable.

- `php_html_load`, `php_html_in_heredoc`, `php_html_in_nowdoc`

Default: `1` (NOTE: setting `php_html_load` to a truthy value takes precedence and overrides both `php_html_in_heredoc` & `php_html_in_nowdoc`)

Set to a falsy value (e.g., `0`) to disable embedding HTML in PHP. Doing so may yield significant speed-ups of syntax highlighting.

This should not affect HTML highlighting in templating languages, such as [Blade].

- `php_sql_query`, `php_sql_heredoc`, `php_sql_nowdoc`

Default: `1`

Set to a falsy value (e.g., `0`) to disable SQL syntax in PHP. Doing so may yield moderate speed-ups of syntax highlighting.

### Projects of interest

`php.vim` pairs nicely with:

- [`phpfolding.vim`](https://github.com/rayburgemeestre/phpfolding.vim): _Automatic folding of PHP functions, classes, … (also folds related PhpDoc)_
- [`PHP-Indenting-for-VIm`](https://github.com/2072/PHP-Indenting-for-VIm): _The official VIm indent script for PHP_

### Overriding highlighting

Syntax highlighting can be controlled at a fine-grained level. For example, all text in PHP comments is highlighted as `phpComment` by default, however there are smaller syntax groups you can tweak, e.g., how PHPDoc `@tags` appear. There are [several syntax groups you can choose from](syntax-groups).

Example: Overriding PHP `@tags` and `$parameters` in comments to appear as a different highlighting group, giving them distinct colouring:

```vim
" Put this function at the very end of your vimrc file.

function! PhpSyntaxOverride()
" Put snippet overrides in this function.
hi! link phpDocTags phpDefine
hi! link phpDocParam phpType
endfunction

augroup phpSyntaxOverride
autocmd!
autocmd FileType php call PhpSyntaxOverride()
augroup END
```

#### Snippets

You may add the code snippets below to your `PhpSyntaxOverride` function (see above for instructions on how to create this function).

##### Colourising namespace separator in `use`, `extends` and `implements`

If you wish to highlight the namespace separator `\` differently ([original request](https://github.com/StanAngeloff/php.vim/issues/63)):

```vim
hi phpUseNamespaceSeparator guifg=#808080 guibg=NONE gui=NONE
hi phpClassNamespaceSeparator guifg=#808080 guibg=NONE gui=NONE
```

##### Colourising parentheses

If you wish to highlight `(` and `)` differently ([original request](https://github.com/StanAngeloff/php.vim/issues/31#issuecomment-52879108)):

```vim
syn match phpParentOnly "[()]" contained containedin=phpParent
hi phpParentOnly guifg=#f08080 guibg=NONE gui=NONE
```

Developing
----------

When you install `php.vim` using your preferred installation method, all the needed files are already in place.

If you wish to rebuild the syntax file with a more recent version of PHP available on the [Docker Hub], you should use the provided `Dockerfile` to do so:

```bash
docker build --no-cache --force-rm -f attic/Dockerfile -t php.vim .
cat syntax/php.vim | docker run --rm -i php.vim > syntax/php.vim.new
docker rmi php.vim
mv syntax/php.vim.new syntax/php.vim
```

NOTE: If the updated syntax file fails to load and is corrupted, try loading `syntax/php.vim` in your favourite editor and ensure line endings are set to Unix `\n`.


[php.vim-garvin]: https://github.com/vim-scripts/php.vim--Garvin
[php.vim-original]: http://www.vim.org/scripts/script.php?script_id=2874
[vim-plug]: https://github.com/junegunn/vim-plug
[vim-plug installed]: https://github.com/junegunn/vim-plug#installation
[neovim-faq]: https://github.com/neovim/neovim/wiki/FAQ#where-should-i-put-my-config-vimrc
[php.vim-source]: https://github.com/StanAngeloff/php.vim/blob/master/syntax/php.vim#L35
[Blade]: https://github.com/jwalton512/vim-blade
[syntax-groups]: https://github.com/StanAngeloff/php.vim/blob/41c36f7f/syntax/php.vim#L804
[Docker Hub]: https://docs.docker.com/samples/library/php/
6 changes: 6 additions & 0 deletions attic/0-bootstrap.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

error_reporting(E_ALL | E_DEPRECATED | E_STRICT);
ini_set('display_errors', 'On');

date_default_timezone_set('UTC');
52 changes: 52 additions & 0 deletions attic/10-collect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Script to update Vim's PHP syntax file.
*
* @author Stan Angeloff <[email protected]>
*
* @author Paul Garvin <[email protected]>
* @copyright Copyright 2009 Paul Garvin
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*
* Loosely based on Paul Garvin <[email protected]> original script.
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/

require __DIR__ . '/0-bootstrap.inc.php';

# Parse the configuration file associated with this script.
$configuration = parse_ini_file(__DIR__ . '/syntax.ini', /* $process_sections = */ true);

# Process extensions and serialize built-in functions, constants, classes and interfaces.
$extensions = array();

foreach ($configuration['extensions'] as $extensionName => $isEnabled) {
if (! $isEnabled) {
continue;
}

try {
$reflect = new \ReflectionExtension($extensionName);

$collected = array(
'name' => $reflect->getName(),
'versions' => array(sprintf('%d.%d.%d', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION)),
'classes' => array(),
'functions' => array_keys($reflect->getFunctions()),
'constants' => array_diff(array_keys($reflect->getConstants()), array('TRUE', 'FALSE', 'NULL')),
);

foreach ($reflect->getClasses() as $extensionClass) {
$collected['classes'][] = $extensionClass->getName();
$collected['constants'] = array_unique(array_merge($collected['constants'], array_keys($extensionClass->getConstants())));
}

$extensions[$extensionName] = $collected;
} catch (ReflectionException $e) {
file_put_contents('php://stderr', sprintf('[ERROR] [PHP %d.%d] %\'.12s: %s.' . PHP_EOL, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, $extensionName, rtrim($e->getMessage(), ' ?!.')));
}
}

echo serialize($extensions) . PHP_EOL;
103 changes: 103 additions & 0 deletions attic/20-generate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

require __DIR__ . '/0-bootstrap.inc.php';

$extensions = [];
$versions = [];

while (false !== $line = fgets(STDIN)) {
$unserialized = unserialize($line, ['allowed_classes' => false]);
foreach ($unserialized as $extension => &$collected) {
if (! isset($extensions[$extension])) {
$extensions[$extension] = $collected;
continue;
}

$extensions[$extension] = array(
'name' => $extensions[$extension]['name'],
'versions' => array_merge($extensions[$extension]['versions'], $collected['versions']),
'classes' => array_merge($extensions[$extension]['classes'], $collected['classes']),
'functions' => array_merge($extensions[$extension]['functions'], $collected['functions']),
'constants' => array_merge($extensions[$extension]['constants'], $collected['constants']),
);
}
}

foreach ($extensions as &$collected) {
$collected['classes'] = array_unique($collected['classes']);
$collected['functions'] = array_unique($collected['functions']);
$collected['constants'] = array_unique($collected['constants']);

sort($collected['classes'], SORT_NATURAL);
sort($collected['functions'], SORT_NATURAL);
sort($collected['constants'], SORT_NATURAL);

$versions = array_merge($versions, $collected['versions']);
}

$versions = array_unique($versions);
sort($versions, SORT_NATURAL);

$blocks = array(
'extensions' => array(),
'last-modified' => sprintf(
'%s, PHP %s',
date('r' /* RFC 2822 */),
implode(/* $glue = */ ', ', $versions)
),
);

$blocks['extensions'][] = 'if ! exists("g:php_syntax_extensions_enabled")';
$blocks['extensions'][] = sprintf(' let g:php_syntax_extensions_enabled = ["%s"]', implode(/* $glue = */ '", "', array_map('strtolower', array_keys($extensions))));
$blocks['extensions'][] = 'endif';

$blocks['extensions'][] = 'if ! exists("g:php_syntax_extensions_disabled")';
$blocks['extensions'][] = ' let g:php_syntax_extensions_disabled = []';
$blocks['extensions'][] = 'endif';

$ifExtensionEnabled = function ($extensionName) {
return sprintf(
'if ' .
'index(g:php_syntax_extensions_enabled, "%1$s") >= 0 && ' .
'index(g:php_syntax_extensions_disabled, "%1$s") < 0 && ' .
'( ! exists("b:php_syntax_extensions_enabled") || index(b:php_syntax_extensions_enabled, "%1$s") >= 0) && ' .
'( ! exists("b:php_syntax_extensions_disabled") || index(b:php_syntax_extensions_disabled, "%1$s") < 0)',
strtolower($extensionName)
);
};

$blocks['extensions'][] = 'syn case match';

foreach ($extensions as $extension) {
if (! count($extension['constants'])) {
continue;
}

$blocks['extensions'][] = $ifExtensionEnabled($extension['name']);
$blocks['extensions'][] = sprintf('" %s constants', $extension['name']);
$blocks['extensions'][] = sprintf('syn keyword phpConstants %s contained', implode(/* $glue = */ ' ', $extension['constants']));
$blocks['extensions'][] = 'endif';
}

$blocks['extensions'][] = 'syn case ignore';

foreach ($extensions as $extension) {
if (! count($extension['functions']) && ! count($extension['classes'])) {
continue;
}

$blocks['extensions'][] = $ifExtensionEnabled($extension['name']);

if (count($extension['functions'])) {
$blocks['extensions'][] = sprintf('" %s functions', $extension['name']);
$blocks['extensions'][] = sprintf('syn keyword phpFunctions %s contained', implode(/* $glue = */ ' ', $extension['functions']));
}
if (count($extension['classes'])) {
$blocks['extensions'][] = sprintf('" %s classes and interfaces', $extension['name']);
$blocks['extensions'][] = sprintf('syn keyword phpClasses %s contained', implode(/* $glue = */ ' ', $extension['classes']));
}

$blocks['extensions'][] = 'endif';
}

echo serialize($blocks);
71 changes: 71 additions & 0 deletions attic/30-update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

require __DIR__ . '/0-bootstrap.inc.php';

$blocks = unserialize(file_get_contents('php://stdin'), ['allowed_classes' => false]);

# Read the existing syntax file with block markers in it.
#
$template = file_get_contents($argv[1]);

# Clean up any previously defined blocks.
$template = preg_replace(
sprintf(
'/(@block\([\'"](%s)[\'"]\)["\r\n\t ]*).*?(["\r\n\t ]*@endblock)\b/ism',
implode(/* $glue = */ '|', array_keys($blocks))
),
"\\1___\\2___\\3",
$template
);

# Update block contents in the template.
foreach ($blocks as $blockName => $lines) {
$template = str_ireplace(
sprintf('___%s___', $blockName),
rtrim(is_array($lines) ? implode(/* $glue = */ "\n", $lines) : $lines),
$template
);
}

$template = preg_replace_callback(
'/
(?<begin>"\s*@copy\s+(?<copy>[a-zA-Z0-9_]+)(?<processors>(\s+(strip_maximum_size))+)?)
(?<script>.*?)
(?<end>"\s*@end\s+([a-zA-Z0-9_]+))
/sx',
function (array $groups) use ($template) {
$copy = preg_quote($groups['copy'], /* $delimiter = */ '/');

$processors = array_filter(array_map('trim', preg_split('{[;, ]+}', $groups['processors'])));

preg_match("/
\"\\s*@begin\\s+{$copy}\b
(?<script>.*?)
\"\\s*@end\\s+{$copy}\b
/sx", $template, $captures);

if (! isset($captures['script'])) {
file_put_contents('php://stderr', "[ERROR] The block referenced by '{$groups['begin']}' was not found." . PHP_EOL);

return $groups['begin'] . $groups['script'] . $groups['end'];
}

$script = $captures['script'];

foreach ($processors as $processor) {
switch ($processor) {
case 'strip_maximum_size':
$script = preg_replace('{\\\\@\d+}', '\@', $script);
break;

default:
file_put_contents('php://stderr', "[ERROR] The processor \"{$processor}\" is not supported, found in '{$groups['begin']}'." . PHP_EOL);
}
}

return $groups['begin'] . $script . $groups['end'];
},
$template
);

echo $template;
Loading