Add syntax for as expressions
This commit is contained in:
parent
3f4c4ff464
commit
e9bc16af0d
54
tree-sitter-dust/corpus/as.txt
Normal file
54
tree-sitter-dust/corpus/as.txt
Normal file
@ -0,0 +1,54 @@
|
||||
================================================================================
|
||||
Simple As
|
||||
================================================================================
|
||||
|
||||
1 as int
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(as
|
||||
(expression
|
||||
(value
|
||||
(integer)))
|
||||
(type)))))
|
||||
|
||||
================================================================================
|
||||
As Function
|
||||
================================================================================
|
||||
|
||||
foo as (int) -> int
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(expression
|
||||
(as
|
||||
(expression
|
||||
(identifier))
|
||||
(type
|
||||
(type)
|
||||
(type))))))
|
||||
|
||||
================================================================================
|
||||
As List in For Loop
|
||||
================================================================================
|
||||
|
||||
for i in foobar as list {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(root
|
||||
(statement
|
||||
(for
|
||||
(identifier)
|
||||
(expression
|
||||
(as
|
||||
(expression
|
||||
(identifier))
|
||||
(type
|
||||
(identifier))))
|
||||
(block))))
|
@ -43,6 +43,7 @@ module.exports = grammar({
|
||||
_expression_kind: $ =>
|
||||
prec.right(
|
||||
choice(
|
||||
$.as,
|
||||
$.function_call,
|
||||
$.identifier,
|
||||
$.index,
|
||||
@ -65,6 +66,9 @@ module.exports = grammar({
|
||||
),
|
||||
),
|
||||
|
||||
as: $ =>
|
||||
seq($.expression, 'as', $.type),
|
||||
|
||||
pipe: $ =>
|
||||
prec(
|
||||
1,
|
||||
@ -181,10 +185,10 @@ module.exports = grammar({
|
||||
float: $ =>
|
||||
choice(
|
||||
/[-|+]?\d*[.][\d|e|-]*/,
|
||||
"Infinity",
|
||||
"infinity",
|
||||
"NaN",
|
||||
"nan",
|
||||
'Infinity',
|
||||
'infinity',
|
||||
'NaN',
|
||||
'nan',
|
||||
),
|
||||
|
||||
string: $ =>
|
||||
|
@ -115,6 +115,10 @@
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "as"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_call"
|
||||
@ -182,6 +186,23 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"as": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "as"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "type"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pipe": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
@ -507,7 +528,7 @@
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[-|+]?\\d*[.][\\d|e|f|-]*"
|
||||
"value": "[-|+]?\\d*[.][\\d|e|-]*"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
|
@ -1,4 +1,23 @@
|
||||
[
|
||||
{
|
||||
"type": "as",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "assignment",
|
||||
"named": true,
|
||||
@ -122,6 +141,10 @@
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "as",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"named": true
|
||||
@ -891,6 +914,10 @@
|
||||
"type": "args",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "as",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "assert_equal",
|
||||
"named": false
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user