Stabilise parsing of let-expressions

This commit is contained in:
Kirill Andreev 2020-05-01 22:10:10 +04:00
parent 0cec59988e
commit ad7650ea48
No known key found for this signature in database
GPG Key ID: CF7DA79DE4785A47

View File

@ -56,9 +56,7 @@ module.exports = grammar({
extras: $ => [$.ocaml_comment, $.comment, /\s/], extras: $ => [$.ocaml_comment, $.comment, /\s/],
rules: { rules: {
// debug: $ => $.block, contract: $ => sepBy(optional(';'), field("declaration", $._declaration)),
contract: $ => repeat(field("declaration", $._declaration)),
_declaration: $ => _declaration: $ =>
choice( choice(
@ -70,14 +68,9 @@ module.exports = grammar({
), ),
attr_decl: $ => attr_decl: $ =>
seq(
$._open_attr_decl,
optional(';'),
),
_open_attr_decl: $ =>
injection("attributes", injection("attributes",
field("attribute", $.String)), field("attribute", $.String)
),
type_decl: $ => type_decl: $ =>
seq( seq(
@ -85,7 +78,6 @@ module.exports = grammar({
field("typeName", $.Name), field("typeName", $.Name),
"is", "is",
field("typeValue", $._type_expr), field("typeValue", $._type_expr),
optional(';'),
), ),
type_expr : $ => $._type_expr, type_expr : $ => $._type_expr,
@ -189,15 +181,20 @@ module.exports = grammar({
':', ':',
field("type", $._type_expr), field("type", $._type_expr),
'is', 'is',
optional(seq( field("body", $._let_expr),
field("locals", $.block),
'with',
)),
field("body", $._expr),
optional(';'),
), ),
), ),
_let_expr: $ =>
choice(
seq(
field("locals", $.block),
'with',
field("body", $._expr),
),
field("body", $._expr),
),
parameters: $ => par(sepBy(';', field("parameter", $.param_decl))), parameters: $ => par(sepBy(';', field("parameter", $.param_decl))),
param_decl: $ => param_decl: $ =>
@ -216,7 +213,7 @@ module.exports = grammar({
choice( choice(
$._instruction, $._instruction,
$._open_data_decl, $._open_data_decl,
$._open_attr_decl, $.attr_decl,
), ),
_open_data_decl: $ => _open_data_decl: $ =>
@ -249,7 +246,6 @@ module.exports = grammar({
const_decl: $ => const_decl: $ =>
seq( seq(
$.open_const_decl, $.open_const_decl,
optional(';'),
), ),
_instruction: $ => _instruction: $ =>