Skip to content
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

[PHP] closure scope does not cover body #2625

Closed
kapitanluffy opened this issue Nov 16, 2020 · 0 comments · Fixed by #3331
Closed

[PHP] closure scope does not cover body #2625

kapitanluffy opened this issue Nov 16, 2020 · 0 comments · Fixed by #3331

Comments

@kapitanluffy
Copy link

I was reviewing the syntax highlighting for PHP and noticed that the meta_scope meta.function.closure.php ends before use as shown below. Shouldn't it scope all the closure's body similar to meta.function.php?

  • Sublime Version: 3211
  • OS Version: Windows 10
<?php

class Test
{
    public function __construct($foo)
// ^-----> meta.function.php starts here
    {
        $this->query(function ($bar) use ($foo, $baz) {
                  // ^-------------^-----> meta.function.closure.php only covers these
            return $foo;
        }, $zzz);
    // ^-----> I expected meta.function.closure.php to end here
    
        return $bar;
    }
// ^-----> meta.function.php ends here, scoping the whole function
}
@kapitanluffy kapitanluffy changed the title [PHP] closure syntax does not cover body [PHP] closure scope does not cover body Nov 16, 2020
deathaxe added a commit that referenced this issue May 21, 2022
[PHP] Refactor Syntax

Fixes #625
Fixes #643
Fixes #1168
Fixes #1665
Fixes #2459
Fixes #2625
Fixes #3214
Fixes #3375

Close #2789

This commit refactors PHP to...

1. solve known issues, such as huge syntax cache and compile times
2. improve maintainability and readability
3. apply some design patterns with regards to scope naming or syntax architecture

Major Changes
=============

- converts most contexts to named contexts
  - for readability reasons
  - to improve re-usability of contexts
  - to improve inheritance support

- organizes all rules into
  - declarations (classes, functions, ...)
  - statements (if, else, while, ...)
  - expressions (arithmetic, function-calls, ...)

- replaces (nearly) all `push ... with_prototype` constructs
  - to significantly reduce syntax cache size
  - gain more control over string interpolation scenarios `meta.string meta.interpolation`
  - significantly reduce risk of exceeding context sanity limit (see: #1665)

- applies scope changes to more closely follow recently discussed scope naming
- upgrades all parts to sublime-syntax version 2
- improves highlighting of incomplete statements and expressions
- improve support for syntax based folding 
  (as good as possible with regards to mixing HTML/CSS/JS with PHP)

Benchmarks
==========

Attribute                                         | ST4131   | this PR | Diff
--------------------------------------------------+----------+---------+--------------------
Syntax Cache Size                                 | 38.050kB | 7.481kB | -30.569kB (-80%)
Syntax Compile Time                               |     2,8s |    0,6s |    -2,2ms (-78,6%)
Syntax Test -- Performance [syntax_test_php.php]  |   11,2ms |   7,9ms |    -3.3ms (-29%)
Syntax Test -- Performance [PHPUnit/composer.php] |    557ms |   376ms |    -181ms (-32%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant