GithubHelp home page GithubHelp logo

gerardroche / sublime-php-grammar Goto Github PK

View Code? Open in Web Editor NEW
31.0 4.0 4.0 679 KB

PHP macros for Sublime Text.

Home Page: https://blog.gerardroche.com

License: BSD 3-Clause "New" or "Revised" License

Python 8.74% PHP 91.26%
sublime-text php php-completions auto-complete formatting

sublime-php-grammar's Introduction

WHAT PHPGRAMMAR IS

An improved PHP syntax, good indentation rules, smart macros, and more.

Travis CI Build Status AppVeyor Build status Coveralls Coverage Status Codecov Coverage Status Minimum Sublime Version Latest Version GitHub stars Downloads

Completions and snippets are provided separately by PHP Completions Kit and PHP Snippets.

INSTALLATION

Package Control installation

The preferred method of installation is Package Control.

Manual installation

Close Sublime Text, then download or clone this repository to a directory named PHPGrammar in the Sublime Text Packages directory for your platform:

OS Command
Linux git clone https://github.com/gerardroche/sublime-php-grammar.git ~/.config/sublime-text-3/Packages/PHPGrammar
OSX git clone https://github.com/gerardroche/sublime-php-grammar.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/PHPGrammar
Windows git clone https://github.com/gerardroche/sublime-php-grammar.git %APPDATA%\Sublime/ Text/ 3/Packages/PHPGrammar

USAGE

Smart macros

To insert any literal character add Shift e.g. in a case where Enter runs a macro, to insert a newline on Enter (instead of running the macro) press Shift+Enter.

On Ctrl+Enter

<?php

array(                      //    array(
    'str|'                  //        'str',
)                           //        |
                            //    )
<?php

'str|ing'                   //    'string';
                            //    |
<?php

function_call(|)            //    function_call();
                            //    |
<?php

if ($condition|)            //    if ($condition) {
                            //        |
                            //    }
<?php

foreach ($x => $y|)         //    foreach ($x => $y) {
                            //        |
                            //    }
<?php

while ($condition|)         //    while ($condition) {
                            //        |
                            //    }
<?php

for ($i = 0; $i < ; $i++|)  //    for ($i = 0; $i < ; $i++) {
                            //        |
                            //    }
<?php

switch ($condition|)        //    switch ($condition) {
                            //        |
                            //    }
<?php

function x(|)               //    function x()
                            //    {
                            //        |
                            //    }
<?php

class x                     //    class x
{                           //    {
    public function y(|)    //        public function y()
}                           //        {
                            //            |
                            //        }
                            //    }

On Ctrl+;

'str|ing'                   //    'string';|
<?php

function_call(|)            //    function_call();|

On Enter

array(|)                    //    array(
                            //        |
                            //    )
<?php

function_call(|)            //    function_call(
                            //        |
                            //    )
<?php

new class_name(|)           //    new class_name(
                            //        |
                            //    )

On Tab

$arr = array(               //    $arr = array(
    'str|'                  //        'str' => |
)                           //    )
<?php

$arr = array(               //    $arr = array(
    'str'|                  //        'str' => |
)                           //    )

On [

$arr = |                    //    $arr = [|];

On ]

$arr = [|                   //    $arr = [|];

CONTRIBUTING

See CONTRIBUTING.md.

LICENSE

Released under the BSD 3-Clause License.

sublime-php-grammar's People

Contributors

anlutro avatar borela avatar ezzatron avatar gerardroche avatar mathroc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sublime-php-grammar's Issues

Error loading syntax files PHP.sublime-syntax

I'm using ST3 build 3092.

After cloning sublime-php-grammar into ~/Library/Application Support/Sublime Text 3/Packages, I get this error:

Error loading syntax file "Packages/PHP/PHP.sublime-syntax": Unable to read Packages/PHP/PHP.sublime-syntax

Third-party syntaxes, "source.php" scope not working

A package I'm using for laravel blade template syntax highlighting uses - include: 'scope:source.php' to achieve PHP syntax highlighting where appropriate. This works fine with the default PHP syntax definition, not so much with this package.

I see that the default PHP syntax is split into two files - one for the "embedding.php" scope, and one for the "source.php" scope. The embedding one is the one actually used for files, and it includes the "source.php" one, but also allows other syntax definitions to include the "source.php" scope without importing the full embedded HTML syntax.

Is this approach something this package could adopt? It would fix compatibility with the blade package and possibly others that build on top of the "source.php" scope.

https://github.com/sublimehq/Packages/blob/master/PHP/PHP.sublime-syntax
https://github.com/sublimehq/Packages/blob/master/PHP/PHP%20Source.sublime-syntax

PHP "double-slash" comments are not indented. And breaks further indentation.

Hi!

I have search in issues, but did not find anything similar, please correct me if I'm wrong:

At first, guys, Great plugin! Works great and does 'almost' all I have needed.
Except.

If I have one comment line in PHP, starting with "//", it will not be indented, but will start from first column:

<?php
class Product extends Controller {
    private $error = array();
    public function indentationTest() {
// This is comment line, 
    // both lines must start at column 3 after indentation!
        echo "test";
    }
}

And also - if the "//" comment line starts at the end of PHP line, then indentation from the next line start at column 1:

<?php
class Product extends Controller {
    private $error = array();
public function indentationTest() { // This is comment and breaks THIS line and everything further
// now this and all other lines must still start
// at column 3 ! But they don't.
    echo "test";
}
}

Is this a bug or is this a Feature?

PHP Syntax disappeared after uninstall

After I uninstalled the php grammar plugin, my PHP syntax completely disappeared. I tried to close all files. Reopened sublime. Nothing seems to help. When I take a look in the list of syntaxes, the PHP syntax is missing.

I'm using Mac OS X, ST3 build 3083.

Short array syntax indentation not working

$v = array(
array(
array(
array()
)
)
);

$v = [
[
[
[]
]
]
]

Expect

$v = array(
    array(
        array(
            array()
        )
    )
);

$v = [
    [
        [
            []
        ]
    ]
]

Actual

$v = array(
    array(
        array(
            array()
        )
    )
);

$v = [
[
[
[]
]
]
]

PSR 2 switch case

See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#52-switch-case

Expected

switch ($expr) {
    case 0:
        echo 'First case, with a break';
        break;
    case 1:
        echo 'Second case, which falls through';
        // no break
    case 2:
    case 3:
    case 4:
        echo 'Third case, return instead of break';
        return;
    default:
        echo 'Default case';
        break;
}

Actual

switch ($expr) {
    case 0:
    echo 'First case, with a break';
    break;
    case 1:
    echo 'Second case, which falls through';
        // no break
    case 2:
    case 3:
    case 4:
    echo 'Third case, return instead of break';
    return;
    default:
    echo 'Default case';
    break;
}

Error loading syntax file dialog

When installing php-grammar sometimes an error dialog pops up with "Error loading syntax file".

Error loading syntax file "Packages/HTML/HTML.tmLanguage": Unable to open Packages/PHP/PHP.tmLanguage
Error loading syntax file "Packages/php-grammar/PHP.sublime-syntax": Unable to read Packages/php-grammar/PHP.sublime-syntax

To resolve this, close any opened php files. Once closed reopening them will have the new installed syntax applied and there will be no more error dialogs.

The reason this happens is because ST caches the syntax definition applied to the opened views. When the new syntax is installed it is not automatically applied to opened views by ST.

When opening other workspaces that had the old syntax applied, if the workspace starts with opened files there may be the error dialog again. Closing the open files will resolve it.

This only needs to be done once on install if there open php files when php-grammar is installed and once for workspaces created before installing php-grammar and that start with opened files.

re: #9 (comment)

final class should not be storage.modifier.abstract

Actual

abstract class Name {}
// ^ meta.class storage.modifier.abstract

final class Name {}
// ^ meta.class storage.modifier.abstract

Expected

abstract class Name {}
// ^ meta.class storage.modifier.abstract

final class Name {}
// ^ meta.class storage.modifier.final

Add "array" to storage type in function arguments

function x(array $a) {}

The array type hint scope is:

meta.function meta.function.arguments meta.function.argument.array storage.type

it could be:

meta.function meta.function.arguments meta.function.argument.array storage.type.array

Function call and class instantiation parens should increase indentation

Indentation between parens for fucntion calls and instantiation should at least not decrease indentation.

Ideally the indentation is increased. And better still, a macro to put the closing parent on a newline.

Example 1 - Instantiation

function test() {
    throw new InvalidArgumentException(|)
}
Expected at least
function test() {
    throw new InvalidArgumentException(
    |)
}
Actual
function test() {
    throw new InvalidArgumentException(
|)
}
Ideal
function test() {
    throw new InvalidArgumentException(
        |
    )
}

Example 2 - Function calls

function test2() {
    test(|)
}
Expected at least
function test2() {
    test(
    |)
}
Actual
function test2() {
    test(
|)
}
Ideal
function test2() {
    test(
        |
    )
}

autocomplete conflict

Enter

```php
$val = array(               | $val = array(
    'str|'                  |     'str',
)                           |     |
                            | )
```

this should use Ctrl + Enter instead because when typing 'string' if has an autocomplete popup visible, press Enter should select autocomplete value instead of run the macro.

Long array definition with empty spaces in values assignment breaks indentation

I have strange problem - with this kind of "long" array definition,

<?php
class Test {
public function testFunction($product_id, $exclude = '') {
if ($product_id) {
$result = array(
'product_id'       => $query->row['product_id'],
'name'            => $query->row['name'],
'subtitle'         => $query->row['subtitle'],
'description'      => $query->row['description'],
'meta_description' => $query->row['meta_description'],
'meta_keyword'     => $query->row['meta_keyword'],
'tag'              => $query->row['tag'],
'model'            => $query->row['model'],
'sku'             => $query->row['sku'],
'upc'                => $query->row['upc'],
'ean'              => $query->row['ean'],
'jan'        => $query->row['jan'],
'a' => $query->row['a'],
'b' => $query->row['b'],
'c' => $query->row['c'],
'd' => $query->row['d'],
'f' => $query->row['f'],
'image'            => $query->row['image']);
echo "test";
}
}
}

Indentation works only till array definition closure.

Untill you delete "at least one" empty space character in any array element assigmen

'product_id'---delete-one-space-here-e.g.-=> $query->row['product_id'],

Then, indentation works!!! This is slosest I've got with debug.

Consistent function argument scopes

Argument parsing could be consistent with "default" and "no-default" scopes.

Either add them to all function arguments or remove them.

Example of adding them:

Actual

function x($a) {}
//          ^ meta.function meta.function.arguments meta.function.argument.no-default
function x($a = null) {}
//          ^ meta.function meta.function.arguments meta.function.argument.default
function x(array $a) {}
//          ^ meta.function meta.function.arguments meta.function.argument.array
function x(array $a = null) {}
//          ^ meta.function meta.function.arguments meta.function.argument.array
function x(array $a = []) {}
//          ^ meta.function meta.function.arguments meta.function.argument.array
function x(array $a = array()) {}
//          ^ meta.function meta.function.arguments meta.function.argument.array
function x(Name $a) {}
//          ^ meta.function meta.function.arguments meta.function.argument.typehinted
function x(Name $a = null) {}
//          ^ meta.function meta.function.arguments meta.function.argument.typehinted

Expected

function x($a) {}
//          ^ meta.function meta.function.arguments meta.function.argument.no-default
function x($a = null) {}
//          ^ meta.function meta.function.arguments meta.function.argument.default
function x(array $a) {}
//          ^ meta.function meta.function.arguments meta.function.argument.no-default.array
function x(array $a = null) {}
//          ^ meta.function meta.function.arguments meta.function.argument.default.array
function x(array $a = []) {}
//          ^ meta.function meta.function.arguments meta.function.argument.default.array
function x(array $a = array()) {}
//          ^ meta.function meta.function.arguments meta.function.argument.default.array
function x(Name $a) {}
//          ^ meta.function meta.function.arguments meta.function.argument.no-default.typehinted
function x(Name $a = null) {}
//          ^ meta.function meta.function.arguments meta.function.argument.default.typehinted

ctrl + enter macro

if ($some_var == 'some value'|) 

ctrl+enter then should be:

| if ($some_var == 'some value') 
|    |

or

| if ($some_var == 'some value') {
|    |
| }

instead of:

| if ($some_var == 'some value');
|

No HTML syntax highlighting

Any HTML that is outside PHP tags is not getting highlighted. Tags, attributes etc just come up black. The default PHP syntax highlighting has this (plus CSS/JS where appropriate).

Using ST build 3083 (latest stable). Using the "Lazy" colour scheme but changing it doesn't make a difference - the HTML is all one colour.

One line control statements should not cause indentation

Actual

if (true) { }
    if (true) { }
        if (true) { }
            foreach (array() as $item) { }
                foreach (array() as $item) { }
                    foreach (array() as $item) { }

Expect

if (true) { }
if (true) { }
if (true) { }
foreach (array() as $item) { }
foreach (array() as $item) { }
foreach (array() as $item) { }

Incorrect phtml declare() statement indentation in ST3

ST3 dependency issue with the HTML and PHP packages.

The following is due to the HTML package doing PHP indentation and the PHP is not able to override it and fix it.

Some existing indentation are failing because of this.

Expect

    <?php declare(ticks = 0) : ?>
        <?php echo "Statement 1\n"; ?>
        <?= "Statement 2\n"; ?>
    <?php enddeclare; ?>

Actual

    <?php declare(ticks = 0) : ?>
    <?php echo "Statement 1\n"; ?>
    <?= "Statement 2\n"; ?>
    <?php enddeclare; ?>

A possible wrong indentation?

Let's take the preg_replace for an example.
Sometimes it's long to write a preg_replace(...) statement in a single line so I write it in the form of the following.

$str = preg_replace(
    my_pattern_string,
    my_replacement_string,
    $str
);

But it causes a weird indentation which is shown as the following screenshot.
(This is tested under a clean Sublime Text 3092 dev.)
gif

<?php
if (1) {
    $a = preg_replace(|)
}

After pressing Enter:

<?php
if (1) {
    $a = preg_replace(
|)
}

Is this a bug?

PSR 2 closures

See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#6-closures

$longArgs_noVars = function (
    $longArgument,
    $longerArgument,
    $muchLongerArgument
) {
   echo 'body';
};

$noArgs_longVars = function () use (
    $longVar1,
    $longerVar2,
    $muchLongerVar3
) {
   echo 'body';
};

$longArgs_longVars = function (
    $longArgument,
    $longerArgument,
    $muchLongerArgument
) use (
    $longVar1,
    $longerVar2,
    $muchLongerVar3
) {
   echo 'body';
};

$longArgs_shortVars = function (
    $longArgument,
    $longerArgument,
    $muchLongerArgument
) use ($var1) {
   echo 'body';
};

$shortArgs_longVars = function ($arg) use (
    $longVar1,
    $longerVar2,
    $muchLongerVar3
) {
   echo 'body';
};

Actual

$longArgs_noVars = function (
    $longArgument,
    $longerArgument,
    $muchLongerArgument
    ) {
 echo 'body';
};

$noArgs_longVars = function () use (
    $longVar1,
    $longerVar2,
    $muchLongerVar3
    ) {
 echo 'body';
};

$longArgs_longVars = function (
    $longArgument,
    $longerArgument,
    $muchLongerArgument
    ) use (
    $longVar1,
    $longerVar2,
    $muchLongerVar3
    ) {
     echo 'body';
 };

 $longArgs_shortVars = function (
    $longArgument,
    $longerArgument,
    $muchLongerArgument
    ) use ($var1) {
     echo 'body';
 };

 $shortArgs_longVars = function ($arg) use (
    $longVar1,
    $longerVar2,
    $muchLongerVar3
    ) {
     echo 'body';
 };

namespace scope should be consistent with other scopes like classes and functions

Example

Actual

namespace Xyz;
//  ^ meta.namespace keyword.other.namespace
//        ^ meta.namespace entity.name.type.namespace

class Name
// ^ meta.class storage.type.class
//      ^ meta.class entity.name.type.class

Expected

namespace Xyz;
// ^ meta.namespace storage.type.namespace
//        ^ meta.class entity.name.type.namespace

class Name
// ^ meta.class storage.type.class
//      ^ meta.class entity.name.type.class

Tab no working

Hi, when I put the following does not work

$g = array(
                'sdfdofokosdf',
                'hola',
                "hola(PRESS TAB)"

            )
             ?>

The result should be

$g = array(
                'sdfdofokosdf',
                'hola',
                "hola" => 

            )
             ?>

but it does not work, it can be happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.