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 8.0 #11

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
995683a
Add PHP 8.0 to supported versions.
mattacosta Jan 23, 2021
e6e0f22
Reduce the precedence of concatenation operators.
mattacosta Jan 23, 2021
a3f4219
Emulate removal of real and unset type casts.
mattacosta Jan 24, 2021
b91d54c
Emulate removal of brace syntax for element access.
mattacosta Jan 24, 2021
645bb2c
Merge branch 'master' into mattacosta/php-8.0
mattacosta Jan 26, 2021
1a3fdcc
Implement optional catch variables.
mattacosta Jan 26, 2021
c3a2ab1
Improve recovery when parsing lexical variables.
mattacosta Feb 3, 2021
8cb5274
Implement trailing commas in closure use lists.
mattacosta Apr 5, 2021
10ec7b3
Add more trailing comma tests.
mattacosta Apr 5, 2021
a772512
Implement the null-safe object operator.
mattacosta Apr 14, 2021
67cdb14
Add regression test for the null coalescing assignment operator.
mattacosta Apr 14, 2021
3ee7cc0
Fix documentation of ExpressionType.
mattacosta Apr 17, 2021
3c2b52f
Fix unsorted node.
mattacosta Apr 17, 2021
5eb9d7d
Improve test organization.
mattacosta Apr 18, 2021
4673ab9
Implement match expressions.
mattacosta Apr 23, 2021
8913afd
Implement constructor parameter promotion.
mattacosta Apr 24, 2021
9b897a2
Standardize assert messages.
mattacosta Apr 24, 2021
4a239b2
Replace the deprecated assert.notEqual() method.
mattacosta Apr 24, 2021
96d4d66
Improve property element tests.
mattacosta Apr 29, 2021
afb70fb
Implement type unions.
mattacosta May 1, 2021
8d3ddd8
Implement static keyword as return type.
mattacosta May 1, 2021
86b4a45
Implement trailing commas in parameter lists.
mattacosta May 2, 2021
74f9969
Update php-ast parse version.
mattacosta May 3, 2021
6ff5477
Implement throw expressions.
mattacosta May 3, 2021
8eba21a
Implement parser reset points.
mattacosta May 5, 2021
78c563b
Implement named arguments.
mattacosta May 10, 2021
face40d
Remove unused method.
mattacosta May 10, 2021
a5cc8f3
Only use getModifierFlag() if a flag is needed.
mattacosta May 10, 2021
7eddee5
Merge branch 'master' into mattacosta/php-8.0
mattacosta May 10, 2021
916658d
Fix arrow function regression tests.
mattacosta May 10, 2021
1293368
Update test matrix.
mattacosta May 10, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:

strategy:
matrix:
node-version: [12.x]
php-version: [7_4, 7_3, 7_2, 7_1, 7_0]
node-version: [12.x, 14.x]
php-version: [8_0, 7_4, 7_3, 7_2, 7_1, 7_0]

steps:
- uses: actions/checkout@v2
Expand Down
24 changes: 23 additions & 1 deletion src/diagnostics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ diagnostics:
- name: ERR_FeatureTypedProperties
text: "The feature 'typed properties' requires PHP 7.4 or later"

# --- PHP 8.0 -----------------------------------------------------------------
- name: ERR_FeatureConstructorParameterPromotion
text: "The feature 'constructor parameter promotion' requires PHP 8.0 or later"
- name: ERR_FeatureNamedArguments
text: "The feature 'named arguments' requires PHP 8.0 or later"
- name: ERR_FeatureStaticReturnType
text: "The feature 'static return type' requires PHP 8.0 or later"
- name: ERR_FeatureTrailingCommasInClosureUseLists
text: "The feature 'trailing commas in closure use lists' requires PHP 8.0 or later"
- name: ERR_FeatureTrailingCommasInParameterLists
text: "The feature 'trailing commas in parameter lists' requires PHP 8.0 or later"
- name: ERR_FeatureUnionTypes
text: "The feature 'union types' requires PHP 8.0 or later"

# -----------------------------------------------------------------------------
# Lexer diagnostics
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -124,7 +138,7 @@ diagnostics:
- name: ERR_AbstractMethodHasBody
text: "An abstract method cannot have a body"
- name: ERR_ArgumentAfterUnpack
text: "A positional argument must be used prior to unpacked arguments"
text: "Positional and named arguments must be used prior to unpacked arguments"
- name: ERR_BadConstantModifier
text: "Class constants cannot be abstract, final, or static"
- name: ERR_BadInterfaceModifier
Expand Down Expand Up @@ -355,3 +369,11 @@ diagnostics:
- name: WRN_UnsetCast
text: "The '(unset)' type cast is deprecated, use 'null' instead"
severity: 2

# --- PHP 8.0 -----------------------------------------------------------------
- name: ERR_IncompleteClosureUseList
text: "Variable, '&' or ')' expected"
- name: ERR_TryCatchUnionOrOptionalVariableExpected
text: "Type union, variable, or ')' expected"
- name: ERR_TypeUnionHasNullableType
text: "Nullable types cannot be used in a type union"
6 changes: 6 additions & 0 deletions src/language/TokenKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export enum TokenKind {
MagicMethod, // T_METHOD_C
MagicNamespace, // T_NS_C
MagicTrait, // T_TRAIT_C
Match,
Namespace,
New,
Print,
Expand Down Expand Up @@ -158,6 +159,7 @@ export enum TokenKind {
MinusEqual,
ModEqual,
MultiplyEqual,
NullSafeObjectOperator,
ObjectOperator,
OpenBraceDollar, // Not used.
OrEqual,
Expand Down Expand Up @@ -356,6 +358,8 @@ export class TokenKindInfo {
return '__namespace__';
case TokenKind.MagicTrait:
return '__trait__';
case TokenKind.Match:
return 'match';
case TokenKind.Namespace:
return 'namespace';
case TokenKind.New:
Expand Down Expand Up @@ -502,6 +506,8 @@ export class TokenKindInfo {
return '%=';
case TokenKind.MultiplyEqual:
return '*=';
case TokenKind.NullSafeObjectOperator:
return '?->';
case TokenKind.ObjectOperator:
return '->';
case TokenKind.OpenBraceDollar:
Expand Down
145 changes: 122 additions & 23 deletions src/nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ nodes:
type:
- NamedType
- PredefinedType
- CompositeType
optional: true
- name: statements
type: StatementBlock
Expand Down Expand Up @@ -184,6 +185,7 @@ nodes:
type:
- NamedType
- PredefinedType
- CompositeType
optional: true
- name: doubleArrow
type: TokenNode
Expand Down Expand Up @@ -548,6 +550,25 @@ nodes:
- name: variable
type: TokenNode
visitorName: visitLocalVariable
- name: Match
extends: Expression
properties:
- name: matchKeyword
type: TokenNode
- name: openParen
type: TokenNode
- name: expression
type: Expression
- name: closeParen
type: TokenNode
- name: openBrace
type: TokenNode
- name: arms
type: NodeList
optional: true
- name: closeBrace
type: TokenNode
visitorName: visitMatch
- name: NamedMemberAccess
extends: MemberAccess
properties:
Expand Down Expand Up @@ -726,6 +747,14 @@ nodes:
- name: closeQuote
type: TokenNode
visitorName: visitStringTemplate
- name: ThrowExpression
extends: Expression
properties:
- name: throwKeyword
type: TokenNode
- name: expression
type: Expression
visitorName: visitThrowExpression
- name: Unary
extends: Expression
properties:
Expand Down Expand Up @@ -874,15 +903,6 @@ nodes:
- name: semicolon
type: TokenNode
visitorName: visitContinue
- name: ExpressionStatement
extends: Statement
properties:
- name: expression
type: Expression
optional: true
- name: semicolon
type: TokenNode
visitorName: visitExpressionStatement
- name: Declare
extends: Statement
properties:
Expand Down Expand Up @@ -949,6 +969,15 @@ nodes:
type: TokenNode
optional: true
visitorName: visitEcho
- name: ExpressionStatement
extends: Statement
properties:
- name: expression
type: Expression
optional: true
- name: semicolon
type: TokenNode
visitorName: visitExpressionStatement
- name: For
extends: Iteration
properties:
Expand Down Expand Up @@ -1095,6 +1124,7 @@ nodes:
type:
- NamedType
- PredefinedType
- CompositeType
optional: true
- name: statements
type: StatementBlock
Expand Down Expand Up @@ -1244,6 +1274,7 @@ nodes:
type:
- NamedType
- PredefinedType
- CompositeType
optional: true
- name: statements
type: StatementBlock
Expand Down Expand Up @@ -1288,6 +1319,7 @@ nodes:
type:
- NamedType
- PredefinedType
- CompositeType
optional: true
- name: properties
type: NodeList
Expand Down Expand Up @@ -1526,12 +1558,28 @@ nodes:
# Clauses
# -----------------------------------------------------------------------------

# Used by named and positional arguments.
- name: Argument
abstract: true
properties:
- name: value
type: Expression
# Used by fully qualified, partially qualified, and relative names.
- name: Name
abstract: true
properties:
- name: namespaceName
type: NodeList
# Used by named and predefined types.
- name: NullableType
abstract: true
extends: Type
properties:
- name: question
type: TokenNode
optional: true
- name: Pattern
abstract: true
# Used by named and referenced trait aliases.
- name: TraitAlias
abstract: true
Expand All @@ -1548,10 +1596,6 @@ nodes:
type: TokenNode
- name: Type
abstract: true
properties:
- name: question
type: TokenNode
optional: true

# -----------------------------------------------------------------------------

Expand Down Expand Up @@ -1588,14 +1632,6 @@ nodes:
- name: closeBrace
type: TokenNode
visitorName: visitAnonymousClass
- name: Argument
properties:
- name: ellipsis
type: TokenNode
optional: true
- name: value
type: Expression
visitorName: visitArgument
- name: ArrayElement
properties:
- name: key
Expand Down Expand Up @@ -1631,6 +1667,13 @@ nodes:
- name: closeParen
type: TokenNode
visitorName: visitClosureUse
- name: CompositeType
extends: Type
properties:
- name: types
type: NodeList
visitorName: visitType
visitorType: Type
# Unlike ClassConstantElement, the name cannot be a semi-reserved keyword.
- name: ConstantElement
properties:
Expand All @@ -1641,6 +1684,16 @@ nodes:
- name: expression
type: Expression
visitorName: visitConstantElement
# This is also known as the discard pattern in other languages. Only time will
# tell if PHP's maintainers consistently use the default keyword or adopt the
# underscore token like those languages in future use-cases.
- name: DefaultPattern
extends: Pattern
properties:
- name: defaultKeyword
type: TokenNode
visitorName: visitPattern
visitorType: Pattern
- name: Else
properties:
- name: elseKeyword
Expand Down Expand Up @@ -1687,6 +1740,13 @@ nodes:
type: NodeList
optional: true
visitorName: visitElseIfBlock
- name: ExpressionPattern
extends: Pattern
properties:
- name: expression
type: Expression
visitorName: visitPattern
visitorType: Pattern
- name: FlexibleHeredocElement
properties:
- name: indent
Expand Down Expand Up @@ -1742,6 +1802,15 @@ nodes:
- Expression
- ListDestructure
visitorName: visitListDestructureElement
- name: MatchArm
properties:
- name: patterns
type: NodeList
- name: doubleArrow
type: TokenNode
- name: expression
type: Expression
visitorName: visitMatchArm
# See also: TraitAlias, TraitPrecedence
- name: MethodReference
properties:
Expand All @@ -1752,6 +1821,19 @@ nodes:
- name: methodName
type: TokenNode
visitorName: visitMethodReference
# See also: PositionalArgument
- name: NamedArgument
extends: Argument
properties:
- name: identifier
type: TokenNode
- name: colon
type: TokenNode
- name: value
type: Expression
inherited: true
visitorName: visitArgument
visitorType: Argument
# See also: ReferencedTraitAlias
- name: NamedTraitAlias
extends: TraitAlias
Expand All @@ -1776,7 +1858,7 @@ nodes:
visitorType: TraitAlias
# See also: PredefinedType
- name: NamedType
extends: Type
extends: NullableType
properties:
- name: question
type: TokenNode
Expand All @@ -1788,10 +1870,14 @@ nodes:
visitorType: Type
- name: Parameter
properties:
- name: modifiers
type: NodeList
optional: true
- name: type
type:
- NamedType
- PredefinedType
- CompositeType
optional: true
- name: ampersand
type: TokenNode
Expand All @@ -1816,9 +1902,21 @@ nodes:
type: NodeList
inherited: true
visitorName: visitPartiallyQualifiedName
# See also: NamedArgument
- name: PositionalArgument
extends: Argument
properties:
- name: ellipsis
type: TokenNode
optional: true
- name: value
type: Expression
inherited: true
visitorName: visitArgument
visitorType: Argument
# See also: NamedType
- name: PredefinedType
extends: Type
extends: NullableType
properties:
- name: question
type: TokenNode
Expand Down Expand Up @@ -1920,6 +2018,7 @@ nodes:
type: NodeList
- name: variable
type: TokenNode
optional: true
- name: closeParen
type: TokenNode
- name: statements
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ExpressionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* The "value categories" of an expression.
*
* For those familiar with C++, this is similar its `lvalue` and `rvalue`
* For those familiar with C++, this is similar to its `lvalue` and `rvalue`
* categories (which are actually much more complicated), but instead of
* being used to handle temporary objects, it is used to determine which
* action the parser should take.
Expand Down
Loading