From ad7650ea48d50ee8e52ae97e0c4ce728c05a1649 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Fri, 1 May 2020 22:10:10 +0400 Subject: [PATCH] Stabilise parsing of let-expressions --- tools/lsp/pascaligo/grammar.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tools/lsp/pascaligo/grammar.js b/tools/lsp/pascaligo/grammar.js index 2ceb2dc68..4b2b411fd 100644 --- a/tools/lsp/pascaligo/grammar.js +++ b/tools/lsp/pascaligo/grammar.js @@ -56,9 +56,7 @@ module.exports = grammar({ extras: $ => [$.ocaml_comment, $.comment, /\s/], rules: { - // debug: $ => $.block, - - contract: $ => repeat(field("declaration", $._declaration)), + contract: $ => sepBy(optional(';'), field("declaration", $._declaration)), _declaration: $ => choice( @@ -70,14 +68,9 @@ module.exports = grammar({ ), attr_decl: $ => - seq( - $._open_attr_decl, - optional(';'), - ), - - _open_attr_decl: $ => injection("attributes", - field("attribute", $.String)), + field("attribute", $.String) + ), type_decl: $ => seq( @@ -85,7 +78,6 @@ module.exports = grammar({ field("typeName", $.Name), "is", field("typeValue", $._type_expr), - optional(';'), ), type_expr : $ => $._type_expr, @@ -189,15 +181,20 @@ module.exports = grammar({ ':', field("type", $._type_expr), 'is', - optional(seq( - field("locals", $.block), - 'with', - )), - field("body", $._expr), - optional(';'), + field("body", $._let_expr), ), ), + _let_expr: $ => + choice( + seq( + field("locals", $.block), + 'with', + field("body", $._expr), + ), + field("body", $._expr), + ), + parameters: $ => par(sepBy(';', field("parameter", $.param_decl))), param_decl: $ => @@ -216,7 +213,7 @@ module.exports = grammar({ choice( $._instruction, $._open_data_decl, - $._open_attr_decl, + $.attr_decl, ), _open_data_decl: $ => @@ -249,7 +246,6 @@ module.exports = grammar({ const_decl: $ => seq( $.open_const_decl, - optional(';'), ), _instruction: $ =>