Implement filter loop

This commit is contained in:
Jeff 2023-10-17 17:52:23 -04:00
parent 6aab8e8f65
commit 2f9590e006
5 changed files with 4854 additions and 4387 deletions

79
corpus/filter.txt Normal file
View File

@ -0,0 +1,79 @@
==================
Filter Loop
==================
filter i in [1, 2, 3] {
i <= 1
}
---
(root
(item
(statement
(filter
(identifier)
(expression
(value
(list
(expression
(value
(integer)))
(expression
(value
(integer)))
(expression
(value
(integer))))))
(item
(statement
(expression
(logic
(expression
(identifier))
(logic_operator)
(expression
(value
(integer)))))))))))
==================
Filter Loop Assignment
==================
list = filter i in ["one", "two", "three"] {
i == "one"
}
---
(root
(item
(statement
(assignment
(identifier)
(assignment_operator)
(statement
(filter
(identifier)
(expression
(value
(list
(expression
(value
(string)))
(expression
(value
(string)))
(expression
(value
(string))))))
(item
(statement
(expression
(logic
(expression
(identifier))
(logic_operator)
(expression
(value
(string)))))))))))))

View File

@ -19,6 +19,7 @@ module.exports = grammar({
$.async, $.async,
$.for, $.for,
$.transform, $.transform,
$.filter,
), ),
comment: $ => seq(/[#]+.*/), comment: $ => seq(/[#]+.*/),
@ -195,6 +196,16 @@ module.exports = grammar({
'}', '}',
), ),
filter: $ => seq(
'filter',
$.identifier,
'in',
$.expression,
'{',
$.item,
'}',
),
tool: $ => choice( tool: $ => choice(
'assert', 'assert',
'assert_equal', 'assert_equal',

View File

@ -62,6 +62,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "transform" "name": "transform"
},
{
"type": "SYMBOL",
"name": "filter"
} }
] ]
}, },
@ -792,6 +796,39 @@
} }
] ]
}, },
"filter": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "filter"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "item"
},
{
"type": "STRING",
"value": "}"
}
]
},
"tool": { "tool": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [

View File

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

File diff suppressed because it is too large Load Diff