Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Add let expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie committed Dec 8, 2022
1 parent b81bb98 commit 80e9365
Show file tree
Hide file tree
Showing 7 changed files with 4,825 additions and 3,729 deletions.
25 changes: 23 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ module.exports = grammar({

value_declaration_name: $ => $._name,

_expression: $ =>
_expression: $ => $._expression4,

_expression4: $ => choice($.expression_let, $._expression3),

_expression3: $ =>
choice(
$.expression_function,
$.expression_if,
Expand Down Expand Up @@ -240,6 +244,23 @@ module.exports = grammar({
$.expression_unit
),

expression_let: $ =>
seq(
"let",
repeat1($.expression_let_value_declaration),
"in",
$._expression
),

expression_let_value_declaration: $ =>
seq(
field("binder", $._pattern),
field("type_annotation", optional($.type_annotation)),
"=",
field("expression", $._expression),
";"
),

expression_right_pipe: $ =>
seq(field("lhs", $._expression2), "|>", field("rhs", $._expression1)),

Expand Down Expand Up @@ -318,7 +339,7 @@ module.exports = grammar({

expression_effect_expression: $ =>
seq(
$._expression,
$._expression3, // `let` expressions should parse as `expression_effect_let`
optional(seq(";", field("rest", $._expression_effect_statement)))
),

Expand Down
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"do"
"alias"
"let"
"in"
] @keyword

[
Expand Down Expand Up @@ -81,6 +82,7 @@

; values
(value_declaration_name) @function
(pattern_variable) @variable
(expression_function ("->" @operator))
(expression_match_arm ("->" @operator))
("<-" @operator)
Expand Down
88 changes: 87 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,23 @@
"name": "_name"
},
"_expression": {
"type": "SYMBOL",
"name": "_expression4"
},
"_expression4": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "expression_let"
},
{
"type": "SYMBOL",
"name": "_expression3"
}
]
},
"_expression3": {
"type": "CHOICE",
"members": [
{
Expand Down Expand Up @@ -1301,6 +1318,75 @@
}
]
},
"expression_let": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "let"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "expression_let_value_declaration"
}
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
"expression_let_value_declaration": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "binder",
"content": {
"type": "SYMBOL",
"name": "_pattern"
}
},
{
"type": "FIELD",
"name": "type_annotation",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_annotation"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "expression",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "STRING",
"value": ";"
}
]
},
"expression_right_pipe": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -1684,7 +1770,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_expression"
"name": "_expression3"
},
{
"type": "CHOICE",
Expand Down
Loading

0 comments on commit 80e9365

Please sign in to comment.