Add while expressions

This commit is contained in:
Bruno BELANYI 2022-06-01 20:19:56 +02:00
parent 19c1f11414
commit 26999482a3
5 changed files with 1825 additions and 1306 deletions

View file

@ -49,6 +49,7 @@ module.exports = grammar({
$.assignment_expression,
$.if_expression,
$.while_expression,
),
nil_literal: (_) => "nil",
@ -184,6 +185,13 @@ module.exports = grammar({
),
),
),
while_expression: ($) => seq(
"while",
field("condition", $._expr),
"do",
field("body", $._expr),
),
}
});

View file

@ -61,6 +61,10 @@
{
"type": "SYMBOL",
"name": "if_expression"
},
{
"type": "SYMBOL",
"name": "while_expression"
}
]
},
@ -847,6 +851,35 @@
}
]
}
},
"while_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "while"
},
{
"type": "FIELD",
"name": "condition",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
},
{
"type": "STRING",
"value": "do"
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "_expr"
}
}
]
}
},
"extras": [

View file

@ -62,6 +62,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -124,6 +128,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -220,6 +228,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
@ -306,6 +318,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
@ -374,6 +390,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -446,6 +466,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
@ -518,6 +542,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -596,6 +624,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -658,6 +690,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -720,6 +756,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
@ -798,6 +838,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -910,6 +954,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
@ -977,6 +1025,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
@ -1059,6 +1111,10 @@
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
@ -1074,6 +1130,144 @@
}
}
},
{
"type": "while_expression",
"named": true,
"fields": {
"body": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "if_expression",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "record_value",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
},
"condition": {
"multiple": false,
"required": true,
"types": [
{
"type": "array_expression",
"named": true
},
{
"type": "array_value",
"named": true
},
{
"type": "assignment_expression",
"named": true
},
{
"type": "binary_expression",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "if_expression",
"named": true
},
{
"type": "integer_literal",
"named": true
},
{
"type": "nil_literal",
"named": true
},
{
"type": "record_expression",
"named": true
},
{
"type": "record_value",
"named": true
},
{
"type": "sequence_expression",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "unary_expression",
"named": true
},
{
"type": "while_expression",
"named": true
}
]
}
}
},
{
"type": "\"",
"named": false
@ -1114,6 +1308,10 @@
"type": "]",
"named": false
},
{
"type": "do",
"named": false
},
{
"type": "else",
"named": false
@ -1150,6 +1348,10 @@
"type": "then",
"named": false
},
{
"type": "while",
"named": false
},
{
"type": "{",
"named": false

File diff suppressed because it is too large Load diff

View file

@ -40,3 +40,16 @@ if 12 then if 27 then 42 else "nope"
condition: (integer_literal)
consequence: (integer_literal)
alternative: (string_literal))))
================================================================================
While
================================================================================
while 12 do 27
--------------------------------------------------------------------------------
(source_file
(while_expression
condition: (integer_literal)
body: (integer_literal)))