Implement for loops

This commit is contained in:
Jeff 2023-10-17 13:46:10 -04:00
parent 9ec43a9841
commit 9fb89fcd8b
5 changed files with 4170 additions and 3750 deletions

92
corpus/for.txt Normal file
View File

@ -0,0 +1,92 @@
==================
Simple For Loop
==================
for i in [1, 2, 3] {
(output i)
}
---
(root
(item
(statement
(for
(identifier)
(expression
(value
(list
(expression
(value
(integer)))
(expression
(value
(integer)))
(expression
(value
(integer))))))
(item
(statement
(expression
(function_call
(tool)
(expression
(identifier))))))))))
==================
Complex For Loop
==================
for list in list_of_lists {
for item in list {
(output item)
}
if (length list) > 1 {
(output "List is long...")
}
}
---
(root
(item
(statement
(for
(identifier)
(expression
(identifier))
(item
(statement
(for
(identifier)
(expression
(identifier))
(item
(statement
(expression
(function_call
(tool)
(expression
(identifier))))))))
(statement
(if_else
(if
(expression
(logic
(expression
(function_call
(tool)
(expression
(identifier))))
(logic_operator)
(expression
(value
(integer)))))
(statement
(expression
(function_call
(tool)
(expression
(value
(string))))))))))))))

View File

@ -17,6 +17,7 @@ module.exports = grammar({
$.select,
$.while,
$.async,
$.for,
),
comment: $ => seq(/[#]+.*/),
@ -242,6 +243,5 @@ module.exports = grammar({
repeat($.statement),
'}'
),
}
});

View File

@ -54,6 +54,10 @@
{
"type": "SYMBOL",
"name": "async"
},
{
"type": "SYMBOL",
"name": "for"
}
]
},

View File

@ -117,6 +117,29 @@
]
}
},
{
"type": "for",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "item",
"named": true
}
]
}
},
{
"type": "function",
"named": true,
@ -379,6 +402,10 @@
"type": "expression",
"named": true
},
{
"type": "for",
"named": true
},
{
"type": "if_else",
"named": true

File diff suppressed because it is too large Load Diff