Skip to content

Commit

Permalink
Merge pull request #250 from calebdw/for_fields
Browse files Browse the repository at this point in the history
feat: add fields to for_statement
  • Loading branch information
calebdw authored Jul 5, 2024
2 parents 4f124bc + 5888922 commit f2c5ae0
Show file tree
Hide file tree
Showing 8 changed files with 184,867 additions and 165,272 deletions.
10 changes: 5 additions & 5 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,18 +724,18 @@ module.exports = function defineGrammar(dialect) {
for_statement: $ => seq(
keyword('for'),
'(',
optional($._expressions),
field('initialize', optional($._expressions)),
';',
optional($._expressions),
field('condition', optional($._expressions)),
';',
optional($._expressions),
field('update', optional($._expressions)),
')',
choice(
$._semicolon,
$.statement,
field('body', $.statement),
seq(
':',
repeat($.statement),
field('body', repeat($.statement)),
keyword('endfor'),
$._semicolon,
),
Expand Down
90 changes: 55 additions & 35 deletions php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3616,48 +3616,60 @@
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "BLANK"
}
]
"type": "FIELD",
"name": "initialize",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": ";"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "BLANK"
}
]
"type": "FIELD",
"name": "condition",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": ";"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "BLANK"
}
]
"type": "FIELD",
"name": "update",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expressions"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
Expand All @@ -3671,8 +3683,12 @@
"name": "_semicolon"
},
{
"type": "SYMBOL",
"name": "statement"
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "statement"
}
},
{
"type": "SEQ",
Expand All @@ -3682,10 +3698,14 @@
"value": ":"
},
{
"type": "REPEAT",
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "statement"
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "statement"
}
}
},
{
Expand Down
71 changes: 53 additions & 18 deletions php/src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2095,24 +2095,59 @@
{
"type": "for_statement",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "statement",
"named": true
}
]
"fields": {
"body": {
"multiple": true,
"required": false,
"types": [
{
"type": "statement",
"named": true
}
]
},
"condition": {
"multiple": false,
"required": false,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
}
]
},
"initialize": {
"multiple": false,
"required": false,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
}
]
},
"update": {
"multiple": false,
"required": false,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "sequence_expression",
"named": true
}
]
}
}
},
{
Expand Down
Loading

0 comments on commit f2c5ae0

Please sign in to comment.