Implement for loops
This commit is contained in:
parent
9ec43a9841
commit
9fb89fcd8b
92
corpus/for.txt
Normal file
92
corpus/for.txt
Normal 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))))))))))))))
|
@ -17,6 +17,7 @@ module.exports = grammar({
|
||||
$.select,
|
||||
$.while,
|
||||
$.async,
|
||||
$.for,
|
||||
),
|
||||
|
||||
comment: $ => seq(/[#]+.*/),
|
||||
@ -242,6 +243,5 @@ module.exports = grammar({
|
||||
repeat($.statement),
|
||||
'}'
|
||||
),
|
||||
|
||||
}
|
||||
});
|
@ -54,6 +54,10 @@
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "async"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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
|
||||
|
7795
src/parser.c
7795
src/parser.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user