diff --git a/tools/lsp/squirrel/grammar/camligo/grammar.js b/tools/lsp/squirrel/grammar/camligo/grammar.js index 7d1ebbd7e..c11c94315 100644 --- a/tools/lsp/squirrel/grammar/camligo/grammar.js +++ b/tools/lsp/squirrel/grammar/camligo/grammar.js @@ -11,7 +11,7 @@ function mkOp($, opExpr) { module.exports = grammar({ name: 'CameLigo', - word: $ => $.Keyword, + word: $ => $.Keyword, extras: $ => [$.ocaml_comment, $.comment, /\s/], rules: { @@ -23,52 +23,47 @@ module.exports = grammar({ $.include, ), - include: $ => seq('#include', field("filename", $.String)), + include: $ => seq( + '#include', + field("filename", $.String) + ), _attribute: $ => /\[@@[a-z]+\]/, - argument: $ => seq( - "(", - field("argPattern", $._pattern), - ":", - field("annotExpr", $.type_expr), - ")" - ), - let_decl: $ => seq( "let", - field("binder", $._binder), + field("name", $._binder), optional(seq( ":", - field("annotExpr", $.type_expr) + field("type", $.type_expr) )), "=", - field("letExpr",$._let_expr), + field("body",$._program), repeat(field("attribute", $._attribute)) ), _binder: $ => choice( - field("letBinds", $.let_binds), - field("letPat", $._pattern) + $.func_header, + $._pattern ), //========== EXPR ============ - _let_expr: $ => choice( + _program: $ => choice( $.let_expr1, $._expr ), - let_binds: $ => prec(1, seq( + func_header: $ => prec(1, seq( optional(field("recursive", "rec")), - field("bindName", $.Name), - repeat(field("bindArgument", $.argument)) + field("name", $.Name), + repeat(field("arg", $.paren_pattern)) )), let_expr1: $ => seq( $.let_decl, "in", - field("innerExpr", $._let_expr) + field("innerExpr", $._program) ), // [1;2] @@ -171,10 +166,10 @@ module.exports = grammar({ "if", field("condition", $._expr), "then", - field("thenBranch", $._let_expr), + field("thenBranch", $._program), optional(seq( "else", - field("elseBranch", $._let_expr) + field("elseBranch", $._program) )) )), @@ -191,12 +186,12 @@ module.exports = grammar({ matching: $ => seq( field("pattern", $._pattern), "->", - field("matchingExpr", $._let_expr) + field("matchingExpr", $._program) ), lambda_expr: $ => seq( "fun", - repeat1(field("arg", $.argument)), + repeat1(field("arg", $.paren_pattern)), "->", field("body", $._expr) ), @@ -236,13 +231,13 @@ module.exports = grammar({ block_expr: $ => seq( "begin", - sepBy(";", field("elem", $._let_expr)), + sepBy(";", field("elem", $._program)), "end", ), paren_expr: $ => seq( "(", - field("innerExpr", $._let_expr), + field("innerExpr", $._program), optional(seq( ":", field("annotExpr", $.type_expr) diff --git a/tools/lsp/squirrel/src/AST/Camligo/Parser.hs b/tools/lsp/squirrel/src/AST/Camligo/Parser.hs index 0783697f9..3df1b998d 100644 --- a/tools/lsp/squirrel/src/AST/Camligo/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Camligo/Parser.hs @@ -13,4 +13,17 @@ import Product import Parser import ParseTree --- import Debug.Trace \ No newline at end of file +-- import Debug.Trace + +example :: FilePath +example = "../../../src/test/contracts/address.mligo" + +raw :: IO () +raw = toParseTree (Path example) + >>= print . pp + +-- sample :: IO () +-- sample +-- = toParseTree (Path example) +-- >>= runParserM . recognise +-- >>= print . pp . fst diff --git a/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs b/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs index 8b75126e8..7cf3e7d04 100644 --- a/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs +++ b/tools/lsp/squirrel/src/AST/Pascaligo/Parser.hs @@ -15,7 +15,7 @@ import ParseTree -- import Debug.Trace -example :: FilePath +-- example :: FilePath -- example = "../../../src/test/contracts/arithmetic.ligo" -- example = "../../../src/test/contracts/address.ligo" -- example = "../../../src/test/contracts/annotation.ligo" @@ -36,7 +36,6 @@ example :: FilePath -- example = "../../../src/test/contracts/bytes_arithmetic.ligo" -- example = "../../../src/test/contracts/chain_id.ligo" -- example = "../../../src/test/contracts/closure-3.ligo" -example = "../../../src/test/contracts/coase.ligo" sample' :: FilePath -> IO (LIGO Info) sample' f @@ -49,16 +48,16 @@ source' f = toParseTree (Path f) >>= print . pp -sample :: IO () -sample - = toParseTree (Path example) - >>= runParserM . recognise - >>= print . pp . fst +-- sample :: IO () +-- sample +-- = toParseTree (Path example) +-- >>= runParserM . recognise +-- >>= print . pp . fst -source :: IO () -source - = toParseTree (Path example) - >>= print . pp +-- source :: IO () +-- source +-- = toParseTree (Path example) +-- >>= print . pp recognise :: RawTree -> ParserM (LIGO Info) recognise = descent (\_ -> error . show . pp) $ map usingScope diff --git a/tools/lsp/squirrel/src/Extension.hs b/tools/lsp/squirrel/src/Extension.hs index 8359dcdc8..bcc73c3a0 100644 --- a/tools/lsp/squirrel/src/Extension.hs +++ b/tools/lsp/squirrel/src/Extension.hs @@ -23,9 +23,9 @@ data UnsupportedExtension = UnsupportedExtension String getExt :: MonadThrow m => FilePath -> m Ext getExt path = do case takeExtension path of - "religo" -> return Reason - "ligo" -> return Pascal - "mligo" -> return Caml + ".religo" -> return Reason + ".ligo" -> return Pascal + ".mligo" -> return Caml ext -> throwM $ UnsupportedExtension ext onExt :: ElimExt a -> FilePath -> IO a diff --git a/tools/lsp/squirrel/src/ParseTree.hs b/tools/lsp/squirrel/src/ParseTree.hs index c187bad4e..260cfc425 100644 --- a/tools/lsp/squirrel/src/ParseTree.hs +++ b/tools/lsp/squirrel/src/ParseTree.hs @@ -113,10 +113,8 @@ toParseTree = unsafeDebounce \fin -> do } (srcPath fin) parser <- ts_parser_new - -- True <- ts_parser_set_language parser tree_sitter_PascaLigo - True <- ts_parser_set_language parser language - - src <- srcToBytestring fin + True <- ts_parser_set_language parser language + src <- srcToBytestring fin BS.useAsCStringLen src \(str, len) -> do tree <- ts_parser_parse_string parser nullPtr str len @@ -136,7 +134,7 @@ toParseTree = unsafeDebounce \fin -> do trees <- for nodes \node' -> do (only -> (r :> _, tree :: ParseTree RawTree)) <- go fin src node' field <- - if nodeFieldName node' == nullPtr + if nodeFieldName node' == nullPtr then return "" else peekCString $ nodeFieldName node' return $ make (r :> Text.pack field :> Nil, tree) @@ -146,7 +144,7 @@ toParseTree = unsafeDebounce \fin -> do let start2D = nodeStartPoint node finish2D = nodeEndPoint node - i = fromIntegral + i = fromIntegral let range = Range @@ -166,7 +164,6 @@ toParseTree = unsafeDebounce \fin -> do return $ make (range :> "" :> Nil, ParseTree { ptName = Text.pack ty - -- , ptChildren = fromList . fmap (Comment,) $ trees -- TODO , ptChildren = trees , ptSource = cutOut range src })