Skip to content
This repository was archived by the owner on Sep 9, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 20 additions & 3 deletions src/main/jay/grammars/php.jay
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ annotation:
$$= $yyLex->create(new AnnotationNode());
$$->type= $2;
}
| '@' qualifiedname '(' literal ')' {
| '@' qualifiedname '(' annotationvalue ')' {
$$= $yyLex->create(new AnnotationNode());
$$->type= $2;
$4 && $$->parameters= array('default' => $4);
Expand All @@ -357,10 +357,27 @@ annotationmembers:
;

annotationmember:
T_WORD '=' literal { $$= array($1 => $3); }
| T_CLASS '=' literal { $$= array($1 => $3); }
T_WORD '=' annotationvalue { $$= array($1 => $3); }
| T_CLASS '=' annotationvalue { $$= array($1 => $3); }
;

annotationvalue:
literal
| T_NEW typename '(' expressionlist_opt ')' {
$$= $yyLex->create(new InstanceCreationNode());
$$->type= $2;
$$->parameters= $4;
$$->body= NULL;
}
| qualifiedname T_DOUBLE_COLON T_WORD {
$$= $yyLex->create(new ConstantAccessNode(new TypeName($1), $3));
}
| qualifiedname T_DOUBLE_COLON T_VARIABLE {
$$= $yyLex->create(new StaticMemberAccessNode(new TypeName($1), $3));
}
;


methodbody:
';' { $$= NULL; }
| '{' statements_opt '}' { $$= (array)$2; }
Expand Down
22 changes: 19 additions & 3 deletions src/main/jay/grammars/xp.jay
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ annotation:
'@' annotation_target {
$$= $2;
}
| '@' annotation_target '(' literal ')' {
| '@' annotation_target '(' annotationvalue ')' {
$4 && $2->parameters= array('default' => $4);
$$= $2;
}
Expand Down Expand Up @@ -475,8 +475,24 @@ annotationmembers:
;

annotationmember:
T_WORD '=' literal { $$= array($1 => $3); }
| T_CLASS '=' literal { $$= array($1 => $3); }
T_WORD '=' annotationvalue { $$= array($1 => $3); }
| T_CLASS '=' annotationvalue { $$= array($1 => $3); }
;

annotationvalue:
literal
| T_NEW typename '(' expressionlist_opt ')' {
$$= $yyLex->create(new InstanceCreationNode());
$$->type= $2;
$$->parameters= $4;
$$->body= NULL;
}
| qualifiedname T_DOUBLE_COLON T_WORD {
$$= $yyLex->create(new ConstantAccessNode(new TypeName($1), $3));
}
| qualifiedname T_DOUBLE_COLON T_VARIABLE {
$$= $yyLex->create(new StaticMemberAccessNode(new TypeName($1), $3));
}
;

methodbody:
Expand Down
23 changes: 23 additions & 0 deletions src/main/php/xp/compiler/ast/ConstantAccessNode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,27 @@ public function __construct($type= null, $name= '') {
$this->type= $type;
$this->name= $name;
}

/**
* Returns a hashcode
*
* @return string
*/
public function hashCode() {
return $this->type->compoundName().'::'.$this->name;
}

/**
* Returns whether another object equals this.
*
* @param lang.Generic cmp
* @return bool
*/
public function equals($cmp) {
return
$cmp instanceof self &&
$this->type->equals($cmp->type) &&
$this->name === $cmp->name
;
}
}
Loading