1
0

Add syntax for as expressions

This commit is contained in:
Jeff 2024-02-13 09:19:23 -05:00
parent 3f4c4ff464
commit e9bc16af0d
5 changed files with 29474 additions and 23767 deletions

View 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))))

View File

@ -43,6 +43,7 @@ module.exports = grammar({
_expression_kind: $ => _expression_kind: $ =>
prec.right( prec.right(
choice( choice(
$.as,
$.function_call, $.function_call,
$.identifier, $.identifier,
$.index, $.index,
@ -65,6 +66,9 @@ module.exports = grammar({
), ),
), ),
as: $ =>
seq($.expression, 'as', $.type),
pipe: $ => pipe: $ =>
prec( prec(
1, 1,
@ -181,12 +185,12 @@ module.exports = grammar({
float: $ => float: $ =>
choice( choice(
/[-|+]?\d*[.][\d|e|-]*/, /[-|+]?\d*[.][\d|e|-]*/,
"Infinity", 'Infinity',
"infinity", 'infinity',
"NaN", 'NaN',
"nan", 'nan',
), ),
string: $ => string: $ =>
/("[^"]*?")|('[^']*?')|(`[^`]*?`)/, /("[^"]*?")|('[^']*?')|(`[^`]*?`)/,

View File

@ -115,6 +115,10 @@
"content": { "content": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "as"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "function_call" "name": "function_call"
@ -182,6 +186,23 @@
} }
} }
}, },
"as": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": "as"
},
{
"type": "SYMBOL",
"name": "type"
}
]
},
"pipe": { "pipe": {
"type": "PREC", "type": "PREC",
"value": 1, "value": 1,
@ -507,7 +528,7 @@
"members": [ "members": [
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "[-|+]?\\d*[.][\\d|e|f|-]*" "value": "[-|+]?\\d*[.][\\d|e|-]*"
}, },
{ {
"type": "STRING", "type": "STRING",

View File

@ -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", "type": "assignment",
"named": true, "named": true,
@ -122,6 +141,10 @@
"multiple": false, "multiple": false,
"required": true, "required": true,
"types": [ "types": [
{
"type": "as",
"named": true
},
{ {
"type": "command", "type": "command",
"named": true "named": true
@ -891,6 +914,10 @@
"type": "args", "type": "args",
"named": false "named": false
}, },
{
"type": "as",
"named": false
},
{ {
"type": "assert_equal", "type": "assert_equal",
"named": false "named": false

File diff suppressed because it is too large Load Diff