Skip to content

Commit

Permalink
PHP 8.3 Support: Typed class constants (Part 3)
Browse files Browse the repository at this point in the history
- apache#6701
- https://wiki.php.net/rfc/typed_class_constants
- Fix the context sensitive lexer (Reserved keywords can be used as constant names)
- Get the constant names as the `PHP_STRING` token
- Add unit tests

Example:
```php
class Example {
    public const string|array array = [1, 2, 3], string = "example";
}
```
  • Loading branch information
junichi11 committed Dec 8, 2023
1 parent 0da18db commit 04b0434
Show file tree
Hide file tree
Showing 11 changed files with 7,367 additions and 1,344 deletions.
2,692 changes: 1,360 additions & 1,332 deletions php/php.editor/src/org/netbeans/modules/php/editor/lexer/PHP5ColoringLexer.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
class ClassExample {

public const (A&B)|string abstract = "test";
public const ?string and = "test";
public const array array = array("test", array("foo" => 1)), as = ["test", ["foo" => 1]];
public const A&B break = "test";
public const bool = "test";
public const string bool = "test";
public const string callable = self::{"and"} . self::{self::{"abstract"}};
public const string|\NS\B case = "test";
public const string catch = "test";
public const string clone = "test";
public const string const = "test";
public const string continue = "test";
public const string declare = "test";
public const string default = "test";
public const string define = "test";
public const string die = "test";
public const string do = "test";
public const string echo = "test";
public const string else = "test";
public const string elseif = "test";
public const string enddeclare = "test";
public const string endfor = "test";
public const string endforeach = "test";
public const string endif = "test";
public const string endswitch = "test";
public const string endwhile = "test";
public const string exit = "test";
public const string extends = "test";
public const false = "test";
public const string false = "test";
public const string final = "test";
public const string finally = "test";
public const float = "test";
public const string float = "test";
public const fn = "test";
public const string fn = "test";
public const string for = "test";
public const string foreach = "test";
public const string function = "test";
public const string global = "test";
public const string goto = "test";
public const string if = "test";
public const string implements = "test";
public const string include = "test";
public const string include_once = "test";
public const string instanceof = "test";
public const string insteadof = "test";
public const int = "test";
public const string int = "test";
public const string interface = "test";
public const iterable = "test";
public const string iterable = "test";
public const string list = "test";
public const match = "test";
public const string match = "test";
public const mixed = "test";
public const string mixed = "test";
public const string namespace = "test";
public const string new = "test";
public const never = "test";
public const string never = "test";
public const null = "test";
public const string null = "test";
public const object = "test";
public const string object = "test";
public const string or = "test";
public const string parent = "test";
public const string print = "test";
public const string private = "test";
public const string protected = "test";
public const string public = "test";
public const readonly = "test";
public const string readonly = "test";
public const string require = "test";
public const string require_once = "test";
public const string return = "test";
public const string self = "test";
public const string static = "test";
public const string = "test";
public const string string = "test";
public const string switch = "test";
public const string throw = "test";
public const string trait = "test";
public const true = "test";
public const string true = "test";
public const string try = "test";
public const string use = "test";
public const string var = "test";
public const void = "test";
public const string void = "test";
public const string while = "test";
public const string xor = "test";
public const string yield = "test";
public const string __CLASS__ = "test";
public const string __DIR__ = "test";
public const string __FILE__ = "test";
public const string __FUNCTION__ = "test";
public const string __LINE__ = "test";
public const string __METHOD__ = "test";
public const string __NAMESPACE__ = "test";
public const string __TRAIT__ = "test";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
enum EnumExample {

public const (A&B)|string abstract = "test";
public const ?string and = "test";
public const array array = array("test", array("foo" => 1)), as = ["test", ["foo" => 1]];
public const A&B break = "test";
public const bool = "test";
public const string bool = "test";
public const string callable = self::{"and"} . self::{self::{"abstract"}};
public const string|\NS\B case = "test";
public const string catch = "test";
public const string clone = "test";
public const string const = "test";
public const string continue = "test";
public const string declare = "test";
public const string default = "test";
public const string define = "test";
public const string die = "test";
public const string do = "test";
public const string echo = "test";
public const string else = "test";
public const string elseif = "test";
public const string enddeclare = "test";
public const string endfor = "test";
public const string endforeach = "test";
public const string endif = "test";
public const string endswitch = "test";
public const string endwhile = "test";
public const string exit = "test";
public const string extends = "test";
public const false = "test";
public const string false = "test";
public const string final = "test";
public const string finally = "test";
public const float = "test";
public const string float = "test";
public const fn = "test";
public const string fn = "test";
public const string for = "test";
public const string foreach = "test";
public const string function = "test";
public const string global = "test";
public const string goto = "test";
public const string if = "test";
public const string implements = "test";
public const string include = "test";
public const string include_once = "test";
public const string instanceof = "test";
public const string insteadof = "test";
public const int = "test";
public const string int = "test";
public const string interface = "test";
public const iterable = "test";
public const string iterable = "test";
public const string list = "test";
public const match = "test";
public const string match = "test";
public const mixed = "test";
public const string mixed = "test";
public const string namespace = "test";
public const string new = "test";
public const never = "test";
public const string never = "test";
public const null = "test";
public const string null = "test";
public const object = "test";
public const string object = "test";
public const string or = "test";
public const string parent = "test";
public const string print = "test";
public const string private = "test";
public const string protected = "test";
public const string public = "test";
public const readonly = "test";
public const string readonly = "test";
public const string require = "test";
public const string require_once = "test";
public const string return = "test";
public const string self = "test";
public const string static = "test";
public const string = "test";
public const string string = "test";
public const string switch = "test";
public const string throw = "test";
public const string trait = "test";
public const true = "test";
public const string true = "test";
public const string try = "test";
public const string use = "test";
public const string var = "test";
public const void = "test";
public const string void = "test";
public const string while = "test";
public const string xor = "test";
public const string yield = "test";
public const string __CLASS__ = "test";
public const string __DIR__ = "test";
public const string __FILE__ = "test";
public const string __FUNCTION__ = "test";
public const string __LINE__ = "test";
public const string __METHOD__ = "test";
public const string __NAMESPACE__ = "test";
public const string __TRAIT__ = "test";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
interface InterfaceExample {

public const (A&B)|string abstract = "test";
public const ?string and = "test";
public const array array = array("test", array("foo" => 1)), as = ["test", ["foo" => 1]];
public const A&B break = "test";
public const bool = "test";
public const string bool = "test";
public const string callable = self::{"and"} . self::{self::{"abstract"}};
public const string|\NS\B case = "test";
public const string catch = "test";
public const string clone = "test";
public const string const = "test";
public const string continue = "test";
public const string declare = "test";
public const string default = "test";
public const string define = "test";
public const string die = "test";
public const string do = "test";
public const string echo = "test";
public const string else = "test";
public const string elseif = "test";
public const string enddeclare = "test";
public const string endfor = "test";
public const string endforeach = "test";
public const string endif = "test";
public const string endswitch = "test";
public const string endwhile = "test";
public const string exit = "test";
public const string extends = "test";
public const false = "test";
public const string false = "test";
public const string final = "test";
public const string finally = "test";
public const float = "test";
public const string float = "test";
public const fn = "test";
public const string fn = "test";
public const string for = "test";
public const string foreach = "test";
public const string function = "test";
public const string global = "test";
public const string goto = "test";
public const string if = "test";
public const string implements = "test";
public const string include = "test";
public const string include_once = "test";
public const string instanceof = "test";
public const string insteadof = "test";
public const int = "test";
public const string int = "test";
public const string interface = "test";
public const iterable = "test";
public const string iterable = "test";
public const string list = "test";
public const match = "test";
public const string match = "test";
public const mixed = "test";
public const string mixed = "test";
public const string namespace = "test";
public const string new = "test";
public const never = "test";
public const string never = "test";
public const null = "test";
public const string null = "test";
public const object = "test";
public const string object = "test";
public const string or = "test";
public const string parent = "test";
public const string print = "test";
public const string private = "test";
public const string protected = "test";
public const string public = "test";
public const readonly = "test";
public const string readonly = "test";
public const string require = "test";
public const string require_once = "test";
public const string return = "test";
public const string self = "test";
public const string static = "test";
public const string = "test";
public const string string = "test";
public const string switch = "test";
public const string throw = "test";
public const string trait = "test";
public const true = "test";
public const string true = "test";
public const string try = "test";
public const string use = "test";
public const string var = "test";
public const void = "test";
public const string void = "test";
public const string while = "test";
public const string xor = "test";
public const string yield = "test";
public const string __CLASS__ = "test";
public const string __DIR__ = "test";
public const string __FILE__ = "test";
public const string __FUNCTION__ = "test";
public const string __LINE__ = "test";
public const string __METHOD__ = "test";
public const string __NAMESPACE__ = "test";
public const string __TRAIT__ = "test";
}
Loading

0 comments on commit 04b0434

Please sign in to comment.