Skip to content

Commit

Permalink
Merge pull request #252 from calebdw/attributed_interfaces
Browse files Browse the repository at this point in the history
feat: add attributes to interfaces and traits
  • Loading branch information
calebdw authored Jul 26, 2024
2 parents 575a080 + f71b552 commit 86e3ffe
Show file tree
Hide file tree
Showing 10 changed files with 159,792 additions and 157,935 deletions.
5 changes: 4 additions & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,14 @@ module.exports = function defineGrammar(dialect) {
),

trait_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
keyword('trait'),
field('name', $.name),
field('body', $.declaration_list),
),

interface_declaration: $ => seq(
optional(field('attributes', $.attribute_list)),
keyword('interface'),
field('name', $.name),
optional($.base_clause),
Expand Down Expand Up @@ -496,7 +498,7 @@ module.exports = function defineGrammar(dialect) {
field('visibility', $.visibility_modifier),
field('readonly', optional($.readonly_modifier)),
field('type', optional($.type)), // Note: callable is not a valid type here, but instead of complicating the parser, we defer this checking to any intelligence using the parser
field('name', $.variable_name),
field('name', choice($.by_ref, $.variable_name)),
optional(seq(
'=',
field('default_value', $.expression),
Expand Down Expand Up @@ -1248,6 +1250,7 @@ module.exports = function defineGrammar(dialect) {
keyword('namespace', false),
keyword('null', false),
keyword('static', false),
keyword('throw', false),
'parent',
'self',
/true|false/i,
Expand Down
50 changes: 48 additions & 2 deletions php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,22 @@
"trait_declaration": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "attributes",
"content": {
"type": "SYMBOL",
"name": "attribute_list"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
Expand Down Expand Up @@ -862,6 +878,22 @@
"interface_declaration": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "attributes",
"content": {
"type": "SYMBOL",
"name": "attribute_list"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "ALIAS",
"content": {
Expand Down Expand Up @@ -2361,8 +2393,17 @@
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "variable_name"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "by_ref"
},
{
"type": "SYMBOL",
"name": "variable_name"
}
]
}
},
{
Expand Down Expand Up @@ -6404,6 +6445,11 @@
"value": "static",
"flags": "i"
},
{
"type": "PATTERN",
"value": "throw",
"flags": "i"
},
{
"type": "STRING",
"value": "parent"
Expand Down
24 changes: 24 additions & 0 deletions php/src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,16 @@
"type": "interface_declaration",
"named": true,
"fields": {
"attributes": {
"multiple": false,
"required": false,
"types": [
{
"type": "attribute_list",
"named": true
}
]
},
"body": {
"multiple": false,
"required": true,
Expand Down Expand Up @@ -3901,6 +3911,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "by_ref",
"named": true
},
{
"type": "variable_name",
"named": true
Expand Down Expand Up @@ -4678,6 +4692,16 @@
"type": "trait_declaration",
"named": true,
"fields": {
"attributes": {
"multiple": false,
"required": false,
"types": [
{
"type": "attribute_list",
"named": true
}
]
},
"body": {
"multiple": false,
"required": true,
Expand Down
Loading

0 comments on commit 86e3ffe

Please sign in to comment.