Skip to content

Commit

Permalink
PHP8.* Support - Highlighters and built-in types
Browse files Browse the repository at this point in the history
* never|static|union|attribute - #148
* intersection|enum|never - #149
* true|false|null - #150
  • Loading branch information
zulus committed May 4, 2023
1 parent 2001593 commit 5761e37
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ PHP_OPERATOR="=>"|"++"|"--"|"==="|"!=="|"=="|"!="|"<>"|"<="|">="|"+="|"-="|"*="|
return PHP_MATCH;
}

<ST_PHP_IN_SCRIPTING>"mixed" {
return PHP_MIXED;
}

<ST_PHP_IN_SCRIPTING>"return" {
return PHP_RETURN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ PHP_OPERATOR="=>"|"++"|"--"|"==="|"!=="|"=="|"!="|"<>"|"<="|">="|"+="|"-="|"*="|
return PHP_MATCH;
}

<ST_PHP_IN_SCRIPTING>"mixed" {
return PHP_MIXED;
}

<ST_PHP_IN_SCRIPTING>"readonly" {
return PHP_READONLY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ PHP_OPERATOR="=>"|"++"|"--"|"==="|"!=="|"=="|"!="|"<>"|"<="|">="|"+="|"-="|"*="|
return PHP_NEVER;
}

<ST_PHP_IN_SCRIPTING>"mixed" {
return PHP_MIXED;
}

<ST_PHP_IN_SCRIPTING>"return" {
return PHP_RETURN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,96 @@ public boolean visit(FinallyClause node) {
@Override
public void endVisit(FinallyClause node) {
}

// php8.0
@Override
public boolean visit(Attribute attribute) {
return true;
}

@Override
public void endvisit(Attribute attribute) {
}

@Override
public boolean visit(AttributeGroup attributeGroup) {
return true;
}

@Override
public void endvisit(AttributeGroup attributeGroup) {
}

@Override
public boolean visit(NamedExpression namedExpresion) {
return true;
}

@Override
public void endvisit(NamedExpression namedExpression) {
}

@Override
public boolean visit(MatchExpression matchExpression) {
return true;
}

@Override
public void endvisit(MatchExpression matchExpression) {
}

@Override
public boolean visit(MatchArm matchArm) {
return true;
}

@Override
public void endvisit(MatchArm matchArm) {
}

@Override
public boolean visit(ThrowExpression throwExpression) {
return true;
}

@Override
public void endvisit(ThrowExpression throwExpression) {
}

@Override
public boolean visit(DNFType dnfType) {
return true;
}

@Override
public void endvisit(DNFType dnfType) {
}

// php8.1
@Override
public boolean visit(EnumDeclaration enumDeclaration) {
return true;
}

@Override
public void endvisit(EnumDeclaration enumDeclaration) {
}

@Override
public boolean visit(EnumCaseDeclaration enumCaseDeclaration) {
return true;
}

@Override
public void endvisit(EnumCaseDeclaration enumCaseDeclaration) {
}

@Override
public boolean visit(AsCallableExpression asCallableExpression) {
return true;
}

@Override
public void endvisit(AsCallableExpression asCallableExpression) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,106 @@ public void endVisit(FinallyClause node) {
endVisitNode(node);
}

// php8.0
@Override
public boolean visit(Attribute node) {
return apply(node);
}

@Override
public void endvisit(Attribute node) {
endVisitNode(node);
}

@Override
public boolean visit(AttributeGroup node) {
return apply(node);
}

@Override
public void endvisit(AttributeGroup node) {
endVisitNode(node);
}

@Override
public boolean visit(NamedExpression node) {
return apply(node);
}

@Override
public void endvisit(NamedExpression node) {
endVisitNode(node);
}

@Override
public boolean visit(MatchExpression node) {
return apply(node);
}

@Override
public void endvisit(MatchExpression node) {
endVisitNode(node);
}

@Override
public boolean visit(MatchArm node) {
return apply(node);
}

@Override
public void endvisit(MatchArm node) {
endVisitNode(node);
}

@Override
public boolean visit(ThrowExpression node) {
return apply(node);
}

@Override
public void endvisit(ThrowExpression node) {
endVisitNode(node);
}

@Override
public boolean visit(DNFType node) {
return apply(node);
}

@Override
public void endvisit(DNFType node) {
endVisitNode(node);
}

// php8.1
@Override
public boolean visit(EnumDeclaration node) {
return apply(node);
}

@Override
public void endvisit(EnumDeclaration node) {
endVisitNode(node);
}

@Override
public boolean visit(EnumCaseDeclaration node) {
return apply(node);
}

@Override
public void endvisit(EnumCaseDeclaration node) {
endVisitNode(node);
}

@Override
public boolean visit(AsCallableExpression node) {
return apply(node);
}

@Override
public void endvisit(AsCallableExpression node) {
endVisitNode(node);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,46 @@ default void endVisit(EmptyExpression emptyExpression) {
boolean visit(AnonymousClassDeclaration anonymousClassDeclaration);

void endVisit(AnonymousClassDeclaration anonymousClassDeclaration);

// php8.0
boolean visit(Attribute attribute);

void endvisit(Attribute attribute);

boolean visit(AttributeGroup attributeGroup);

void endvisit(AttributeGroup attributeGroup);

boolean visit(NamedExpression namedExpresion);

void endvisit(NamedExpression namedExpression);

boolean visit(MatchExpression matchExpression);

void endvisit(MatchExpression matchExpression);

boolean visit(MatchArm matchArm);

void endvisit(MatchArm matchArm);

boolean visit(ThrowExpression throwExpression);

void endvisit(ThrowExpression throwExpression);

boolean visit(DNFType dnfType);

void endvisit(DNFType dnfType);

// php8.1
boolean visit(EnumDeclaration enumDeclaration);

void endvisit(EnumDeclaration enumDeclaration);

boolean visit(EnumCaseDeclaration enumCaseDeclaration);

void endvisit(EnumCaseDeclaration enumCaseDeclaration);

boolean visit(AsCallableExpression asCallableExpression);

void endvisit(AsCallableExpression asCallableExpression);
}
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,6 @@ public interface PHPRegionTypes {
static final String PHP_ENUM = "PHP_ENUM"; //$NON-NLS-1$
static final String PHP_READONLY = "PHP_READONLY"; //$NON-NLS-1$
static final String PHP_NEVER = "PHP_NEVER"; //$NON-NLS-1$
static final String PHP_MIXED = "PHP_MIXED"; //$NON-NLS-1$

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ public final String getTypeName() {
SIMPLE_TYPES.put("resource", new TypeInfo(RESOURCE, null)); //$NON-NLS-1$
SIMPLE_TYPES.put("object", new TypeInfo(OBJECT, PHPVersion.PHP7_2)); //$NON-NLS-1$
SIMPLE_TYPES.put("void", new TypeInfo(VOID, PHPVersion.PHP7_1)); //$NON-NLS-1$
SIMPLE_TYPES.put("null", new TypeInfo(NULL, null)); //$NON-NLS-1$
SIMPLE_TYPES.put("mixed", new TypeInfo(MIXED, null)); //$NON-NLS-1$
SIMPLE_TYPES.put("null", new TypeInfo(NULL, PHPVersion.PHP8_2)); //$NON-NLS-1$
SIMPLE_TYPES.put("mixed", new TypeInfo(MIXED, PHPVersion.PHP8_0)); //$NON-NLS-1$
SIMPLE_TYPES.put("callable", new TypeInfo(CALLABLE, PHPVersion.PHP5_4)); //$NON-NLS-1$
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=531379
// "callback" is a (less complete) synonym of "callable"
SIMPLE_TYPES.put("callback", new TypeInfo(CALLABLE, null)); //$NON-NLS-1$
SIMPLE_TYPES.put("iterable", new TypeInfo(ITERABLE, PHPVersion.PHP7_1)); //$NON-NLS-1$

SIMPLE_TYPES.put("static", new TypeInfo(MIXED, PHPVersion.PHP8_0)); //$NON-NLS-1$

SIMPLE_TYPES.put("never", new TypeInfo(VOID, PHPVersion.PHP8_1)); //$NON-NLS-1$
SIMPLE_TYPES.put("false", new TypeInfo(BOOLEAN, PHPVersion.PHP8_2)); //$NON-NLS-1$
SIMPLE_TYPES.put("true", new TypeInfo(BOOLEAN, PHPVersion.PHP8_2)); //$NON-NLS-1$
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public class LineStyleProviderForPHP extends AbstractLineStyleProvider implement
fColorTypes.put(PHPRegionTypes.PHP_READONLY, PreferenceConstants.EDITOR_KEYWORD_COLOR);
fColorTypes.put(PHPRegionTypes.PHP_MATCH, PreferenceConstants.EDITOR_KEYWORD_COLOR);
fColorTypes.put(PHPRegionTypes.PHP_ENUM, PreferenceConstants.EDITOR_KEYWORD_COLOR);
fColorTypes.put(PHPRegionTypes.PHP_NEVER, PreferenceConstants.EDITOR_KEYWORD_COLOR);
fColorTypes.put(PHPRegionTypes.PHP_MIXED, PreferenceConstants.EDITOR_KEYWORD_COLOR);

// fColorTypes.put(PHPRegionTypes.TASK,
// PreferenceConstants.EDITOR_TASK_COLOR);
Expand Down

0 comments on commit 5761e37

Please sign in to comment.