From da6ca97a9d7abc41b128b48c4bae40569fb00fa9 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Mon, 24 Aug 2020 20:05:24 +0400 Subject: [PATCH] Fix 'field name not found' for reasonligo --- src/test/contracts/refs.religo | 5 +++++ .../squirrel/grammar/reasonligo/grammar.js | 12 +++++----- tools/lsp/squirrel/src/AST/Camligo/Parser.hs | 22 +------------------ .../lsp/squirrel/src/AST/Pascaligo/Parser.hs | 22 ------------------- .../lsp/squirrel/src/AST/Reasonligo/Parser.hs | 15 ++++--------- 5 files changed, 16 insertions(+), 60 deletions(-) create mode 100644 src/test/contracts/refs.religo diff --git a/src/test/contracts/refs.religo b/src/test/contracts/refs.religo new file mode 100644 index 000000000..7b24e7a74 --- /dev/null +++ b/src/test/contracts/refs.religo @@ -0,0 +1,5 @@ +let f = (good : int) : (int, int) => { + let bad1: int = 1; + let bad: int = 1; + (good, bad, bad) +}; \ No newline at end of file diff --git a/tools/lsp/squirrel/grammar/reasonligo/grammar.js b/tools/lsp/squirrel/grammar/reasonligo/grammar.js index bfd4ec0b4..a9b2b7bac 100644 --- a/tools/lsp/squirrel/grammar/reasonligo/grammar.js +++ b/tools/lsp/squirrel/grammar/reasonligo/grammar.js @@ -159,7 +159,7 @@ module.exports = grammar({ $.capture, ), - capture: $ => $.Name, + capture: $ => field("name", $.Name), record_field: $ => seq( field("name", $.lhs), @@ -183,7 +183,7 @@ module.exports = grammar({ spread: $ => seq( '...', - $._expr, + field("name", $._expr), ), if: $ => seq( @@ -304,13 +304,13 @@ module.exports = grammar({ michelson_tuple: $ => seq( '(', - $._type_expr, + field("arg1", $._type_expr), ',', - $.String, + field("label1", $.String), ',', - $._type_expr, + field("arg2", $._type_expr), ',', - $.String, + field("label2", $.String), ')', ), diff --git a/tools/lsp/squirrel/src/AST/Camligo/Parser.hs b/tools/lsp/squirrel/src/AST/Camligo/Parser.hs index be281d7ae..3bfbfbf7c 100644 --- a/tools/lsp/squirrel/src/AST/Camligo/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Camligo/Parser.hs @@ -66,27 +66,7 @@ example :: FilePath -- example = "../../../src/test/contracts/lambda2.mligo" -- example = "../../../src/test/contracts/loop.mligo" -- example = "../../../src/test/contracts/let_in_multi_bind.mligo" -example = "../../../src/test/contracts/fibo2.mligo" - --- raw :: IO () --- raw = toParseTree (Path example) --- >>= print . pp - --- raw' :: FilePath -> IO () --- raw' example = toParseTree (Path example) --- >>= print . pp - -sample :: IO () -sample - = toParseTree (Path example) - >>= runParserM . recognise - >>= print . pp . fst - -sample' :: FilePath -> IO () -sample' example - = toParseTree (Path example) - >>= runParserM . recognise - >>= print . pp . fst +-- example = "../../../src/test/contracts/fibo2.mligo" recognise :: RawTree -> ParserM (LIGO Info) recognise = descent (error "Reasonligo.recognise") $ map usingScope diff --git a/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs b/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs index 8ae8cc03f..96d6e4fe1 100644 --- a/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs @@ -37,28 +37,6 @@ import ParseTree -- example = "../../../src/test/contracts/chain_id.ligo" -- example = "../../../src/test/contracts/closure-3.ligo" --- sample' :: FilePath -> IO (LIGO Info) --- sample' f --- = toParseTree (Path f) --- >>= runParserM . recognise --- >>= return . fst - --- source' :: FilePath -> IO () --- source' f --- = toParseTree (Path f) --- >>= print . pp - --- sample :: IO () --- sample --- = toParseTree (Path example) --- >>= runParserM . recognise --- >>= print . pp . fst - --- source :: IO () --- source --- = toParseTree (Path example) --- >>= print . pp - recognise :: RawTree -> ParserM (LIGO Info) recognise = descent (error "Reasonligo.recognise") $ map usingScope [ -- Contract diff --git a/tools/lsp/squirrel/src/AST/Reasonligo/Parser.hs b/tools/lsp/squirrel/src/AST/Reasonligo/Parser.hs index a71a0ac02..04f83a624 100644 --- a/tools/lsp/squirrel/src/AST/Reasonligo/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Reasonligo/Parser.hs @@ -37,12 +37,6 @@ import Product -- example = "./contracts/arithmetic.religo" -- example = "./contracts/FA2.religo" --- sample''' :: IO () --- sample''' --- = toParseTree (Path example) --- >>= runParserM . recognise --- >>= print . pp . fst - recognise :: RawTree -> ParserM (LIGO Info) recognise = descent (error "Reasonligo.recognise") $ map usingScope [ -- Contract @@ -63,7 +57,6 @@ recognise = descent (error "Reasonligo.recognise") $ map usingScope "indexing" -> ListAccess <$> field "box" <*> fields "index" "annot_expr" -> Annot <$> field "subject" <*> field "type" "if" -> If <$> field "selector" <*> field "then" <*> fieldOpt "else" - -- TODO: possible support for multiple spreads "record" -> Record <$> fields "assignment" "tuple" -> Tuple <$> fields "item" "switch" -> Case <$> field "subject" <*> fields "alt" @@ -73,10 +66,10 @@ recognise = descent (error "Reasonligo.recognise") $ map usingScope -- Pattern , Descent do boilerplate $ \case - "tuple_pattern" -> IsTuple <$> fields "pattern" + "tuple_pattern" -> IsTuple <$> fields "pattern" "annot_pattern" -> IsAnnot <$> field "subject" <*> field "type" - "list_pattern" -> IsList <$> fields "pattern" - "var_pattern" -> IsVar <$> field "var" + "list_pattern" -> IsList <$> fields "pattern" + "var_pattern" -> IsVar <$> field "var" "wildcard" -> return IsWildcard "nullary_constr_pattern" -> IsConstr <$> field "constructor" <*> return Nothing "unary_constr_pattern" -> IsConstr <$> field "constructor" <*> fieldOpt "arg" @@ -95,7 +88,7 @@ recognise = descent (error "Reasonligo.recognise") $ map usingScope boilerplate $ \case "record_field" -> FieldAssignment <$> field "name" <*> field "value" "spread" -> Spread <$> field "name" - _ -> fallthrough + _ -> fallthrough -- MapBinding , Descent do