Skip to content

Commit

Permalink
PHP 8.4 Support: Asymmetric Visibility v2 (Part 1)
Browse files Browse the repository at this point in the history
- apache#8035
- https://wiki.php.net/rfc#php_84
- https://wiki.php.net/rfc/asymmetric-visibility-v2
- https://www.php.net/manual/en/language.oop5.final.php

- Fix the lexers and the parser(grammar file)
- Support for the `final` field(property)
- Don't handle modifier errors for methods, constants, and fields in the parser. Instead, handle them in the hint error.
  Writing all valid cases for each member is very hard and complicated because the current PHP has many modifiers.
- Fix the `PHP84UnhandledError`
- Add/Fix unit tests for the navigator, lexer, and parser

Example:
```php
class AsymmetricVisibilityClass {
    // Constructor Property Promotion
    public function __construct(
        public(set) string $field1, // implicit public
        public private(set) int $field2,
        public protected(set) readonly int $field3,
    ) {}

    // valid fields
    public(set) string $example1; // implicit public
    pulbic private(set) int $example2 = 1;
    public protected(set) readonly int $example3;
    final private private(set) readonly string|int $example4; // final is available as of PHP 8.4

    // invalid cases but the parser doesn't handle them as errors
    // e.g.
    public public string $invalid1 = "invalid"; // multiple same modifiers
    final private private(set) string|int $invalid2; // cannot use both final and private
    public public(set) $invalid3; // need type
    private public(set) string $invalid4; // visibility(private) must not be weaker than set visibility
}
```
  • Loading branch information
junichi11 committed Jan 21, 2025
1 parent 5df292f commit 94e2cf5
Show file tree
Hide file tree
Showing 101 changed files with 91,837 additions and 62,535 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public enum PHPTokenId implements TokenId {
PHP_FUNCTION(null, "keyword"), //NOI18N
PHP_PROTECTED(null, "keyword"), //NOI18N
PHP_PRIVATE(null, "keyword"), //NOI18N
PHP_PUBLIC_SET(null, "keyword"), //NOI18N PHP 8.4
PHP_PROTECTED_SET(null, "keyword"), //NOI18N PHP 8.4
PHP_PRIVATE_SET(null, "keyword"), //NOI18N PHP 8.4
PHP_ENDDECLARE(null, "keyword"), //NOI18N
PHP_CURLY_CLOSE(null, "php"), //NOI18N
PHP_ELSE("else", "keyword"), //NOI18N
Expand Down
6,215 changes: 3,055 additions & 3,160 deletions php/php.editor/src/org/netbeans/modules/php/editor/parser/ASTPHP5Parser.java

Large diffs are not rendered by default.

1,046 changes: 535 additions & 511 deletions php/php.editor/src/org/netbeans/modules/php/editor/parser/ASTPHP5Scanner.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Mon Jan 06 13:39:03 JST 2025
// Sun Jan 12 13:42:53 JST 2025
//----------------------------------------------------

package org.netbeans.modules.php.editor.parser;
Expand Down Expand Up @@ -97,6 +97,7 @@ public interface ASTPHP5Symbols {
public static final int T_AS = 25;
public static final int T_CURLY_CLOSE = 72;
public static final int T_ENDDECLARE = 22;
public static final int T_PROTECTED_SET = 173;
public static final int T_CATCH = 41;
public static final int T_CASE = 29;
public static final int T_VARIABLE = 8;
Expand All @@ -118,6 +119,7 @@ public interface ASTPHP5Symbols {
public static final int T_CURLY_OPEN_WITH_DOLAR = 70;
public static final int T_FINAL = 146;
public static final int T_REQUIRE = 83;
public static final int T_PRIVATE_SET = 174;
public static final int T_FILE = 66;
public static final int T_DEC = 129;
public static final int T_CLOSE_PARENTHESE = 151;
Expand Down Expand Up @@ -188,6 +190,7 @@ public interface ASTPHP5Symbols {
public static final int T_SL = 118;
public static final int T_END_HEREDOC = 68;
public static final int T_DOUBLE_ARROW = 57;
public static final int T_PUBLIC_SET = 172;
public static final int T_STRING_CAST = 132;
public static final int T_STRING = 6;
public static final int T_PLUS_EQUAL = 91;
Expand Down
5,280 changes: 2,640 additions & 2,640 deletions php/php.editor/src/org/netbeans/modules/php/editor/parser/EncodedActionTable1.java

Large diffs are not rendered by default.

Loading

0 comments on commit 94e2cf5

Please sign in to comment.