Extension and grammar
This commit is contained in:
parent
26d11eea19
commit
1a948bcae7
@ -23,52 +23,47 @@ module.exports = grammar({
|
|||||||
$.include,
|
$.include,
|
||||||
),
|
),
|
||||||
|
|
||||||
include: $ => seq('#include', field("filename", $.String)),
|
include: $ => seq(
|
||||||
|
'#include',
|
||||||
|
field("filename", $.String)
|
||||||
|
),
|
||||||
|
|
||||||
_attribute: $ => /\[@@[a-z]+\]/,
|
_attribute: $ => /\[@@[a-z]+\]/,
|
||||||
|
|
||||||
argument: $ => seq(
|
|
||||||
"(",
|
|
||||||
field("argPattern", $._pattern),
|
|
||||||
":",
|
|
||||||
field("annotExpr", $.type_expr),
|
|
||||||
")"
|
|
||||||
),
|
|
||||||
|
|
||||||
let_decl: $ => seq(
|
let_decl: $ => seq(
|
||||||
"let",
|
"let",
|
||||||
field("binder", $._binder),
|
field("name", $._binder),
|
||||||
optional(seq(
|
optional(seq(
|
||||||
":",
|
":",
|
||||||
field("annotExpr", $.type_expr)
|
field("type", $.type_expr)
|
||||||
)),
|
)),
|
||||||
"=",
|
"=",
|
||||||
field("letExpr",$._let_expr),
|
field("body",$._program),
|
||||||
repeat(field("attribute", $._attribute))
|
repeat(field("attribute", $._attribute))
|
||||||
),
|
),
|
||||||
|
|
||||||
_binder: $ => choice(
|
_binder: $ => choice(
|
||||||
field("letBinds", $.let_binds),
|
$.func_header,
|
||||||
field("letPat", $._pattern)
|
$._pattern
|
||||||
),
|
),
|
||||||
|
|
||||||
//========== EXPR ============
|
//========== EXPR ============
|
||||||
|
|
||||||
_let_expr: $ => choice(
|
_program: $ => choice(
|
||||||
$.let_expr1,
|
$.let_expr1,
|
||||||
$._expr
|
$._expr
|
||||||
),
|
),
|
||||||
|
|
||||||
let_binds: $ => prec(1, seq(
|
func_header: $ => prec(1, seq(
|
||||||
optional(field("recursive", "rec")),
|
optional(field("recursive", "rec")),
|
||||||
field("bindName", $.Name),
|
field("name", $.Name),
|
||||||
repeat(field("bindArgument", $.argument))
|
repeat(field("arg", $.paren_pattern))
|
||||||
)),
|
)),
|
||||||
|
|
||||||
let_expr1: $ => seq(
|
let_expr1: $ => seq(
|
||||||
$.let_decl,
|
$.let_decl,
|
||||||
"in",
|
"in",
|
||||||
field("innerExpr", $._let_expr)
|
field("innerExpr", $._program)
|
||||||
),
|
),
|
||||||
|
|
||||||
// [1;2]
|
// [1;2]
|
||||||
@ -171,10 +166,10 @@ module.exports = grammar({
|
|||||||
"if",
|
"if",
|
||||||
field("condition", $._expr),
|
field("condition", $._expr),
|
||||||
"then",
|
"then",
|
||||||
field("thenBranch", $._let_expr),
|
field("thenBranch", $._program),
|
||||||
optional(seq(
|
optional(seq(
|
||||||
"else",
|
"else",
|
||||||
field("elseBranch", $._let_expr)
|
field("elseBranch", $._program)
|
||||||
))
|
))
|
||||||
)),
|
)),
|
||||||
|
|
||||||
@ -191,12 +186,12 @@ module.exports = grammar({
|
|||||||
matching: $ => seq(
|
matching: $ => seq(
|
||||||
field("pattern", $._pattern),
|
field("pattern", $._pattern),
|
||||||
"->",
|
"->",
|
||||||
field("matchingExpr", $._let_expr)
|
field("matchingExpr", $._program)
|
||||||
),
|
),
|
||||||
|
|
||||||
lambda_expr: $ => seq(
|
lambda_expr: $ => seq(
|
||||||
"fun",
|
"fun",
|
||||||
repeat1(field("arg", $.argument)),
|
repeat1(field("arg", $.paren_pattern)),
|
||||||
"->",
|
"->",
|
||||||
field("body", $._expr)
|
field("body", $._expr)
|
||||||
),
|
),
|
||||||
@ -236,13 +231,13 @@ module.exports = grammar({
|
|||||||
|
|
||||||
block_expr: $ => seq(
|
block_expr: $ => seq(
|
||||||
"begin",
|
"begin",
|
||||||
sepBy(";", field("elem", $._let_expr)),
|
sepBy(";", field("elem", $._program)),
|
||||||
"end",
|
"end",
|
||||||
),
|
),
|
||||||
|
|
||||||
paren_expr: $ => seq(
|
paren_expr: $ => seq(
|
||||||
"(",
|
"(",
|
||||||
field("innerExpr", $._let_expr),
|
field("innerExpr", $._program),
|
||||||
optional(seq(
|
optional(seq(
|
||||||
":",
|
":",
|
||||||
field("annotExpr", $.type_expr)
|
field("annotExpr", $.type_expr)
|
||||||
|
@ -14,3 +14,16 @@ import Parser
|
|||||||
import ParseTree
|
import ParseTree
|
||||||
|
|
||||||
-- import Debug.Trace
|
-- 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
|
||||||
|
@ -15,7 +15,7 @@ import ParseTree
|
|||||||
|
|
||||||
-- import Debug.Trace
|
-- import Debug.Trace
|
||||||
|
|
||||||
example :: FilePath
|
-- example :: FilePath
|
||||||
-- example = "../../../src/test/contracts/arithmetic.ligo"
|
-- example = "../../../src/test/contracts/arithmetic.ligo"
|
||||||
-- example = "../../../src/test/contracts/address.ligo"
|
-- example = "../../../src/test/contracts/address.ligo"
|
||||||
-- example = "../../../src/test/contracts/annotation.ligo"
|
-- example = "../../../src/test/contracts/annotation.ligo"
|
||||||
@ -36,7 +36,6 @@ example :: FilePath
|
|||||||
-- example = "../../../src/test/contracts/bytes_arithmetic.ligo"
|
-- example = "../../../src/test/contracts/bytes_arithmetic.ligo"
|
||||||
-- example = "../../../src/test/contracts/chain_id.ligo"
|
-- example = "../../../src/test/contracts/chain_id.ligo"
|
||||||
-- example = "../../../src/test/contracts/closure-3.ligo"
|
-- example = "../../../src/test/contracts/closure-3.ligo"
|
||||||
example = "../../../src/test/contracts/coase.ligo"
|
|
||||||
|
|
||||||
sample' :: FilePath -> IO (LIGO Info)
|
sample' :: FilePath -> IO (LIGO Info)
|
||||||
sample' f
|
sample' f
|
||||||
@ -49,16 +48,16 @@ source' f
|
|||||||
= toParseTree (Path f)
|
= toParseTree (Path f)
|
||||||
>>= print . pp
|
>>= print . pp
|
||||||
|
|
||||||
sample :: IO ()
|
-- sample :: IO ()
|
||||||
sample
|
-- sample
|
||||||
= toParseTree (Path example)
|
-- = toParseTree (Path example)
|
||||||
>>= runParserM . recognise
|
-- >>= runParserM . recognise
|
||||||
>>= print . pp . fst
|
-- >>= print . pp . fst
|
||||||
|
|
||||||
source :: IO ()
|
-- source :: IO ()
|
||||||
source
|
-- source
|
||||||
= toParseTree (Path example)
|
-- = toParseTree (Path example)
|
||||||
>>= print . pp
|
-- >>= print . pp
|
||||||
|
|
||||||
recognise :: RawTree -> ParserM (LIGO Info)
|
recognise :: RawTree -> ParserM (LIGO Info)
|
||||||
recognise = descent (\_ -> error . show . pp) $ map usingScope
|
recognise = descent (\_ -> error . show . pp) $ map usingScope
|
||||||
|
@ -23,9 +23,9 @@ data UnsupportedExtension = UnsupportedExtension String
|
|||||||
getExt :: MonadThrow m => FilePath -> m Ext
|
getExt :: MonadThrow m => FilePath -> m Ext
|
||||||
getExt path = do
|
getExt path = do
|
||||||
case takeExtension path of
|
case takeExtension path of
|
||||||
"religo" -> return Reason
|
".religo" -> return Reason
|
||||||
"ligo" -> return Pascal
|
".ligo" -> return Pascal
|
||||||
"mligo" -> return Caml
|
".mligo" -> return Caml
|
||||||
ext -> throwM $ UnsupportedExtension ext
|
ext -> throwM $ UnsupportedExtension ext
|
||||||
|
|
||||||
onExt :: ElimExt a -> FilePath -> IO a
|
onExt :: ElimExt a -> FilePath -> IO a
|
||||||
|
@ -113,9 +113,7 @@ toParseTree = unsafeDebounce \fin -> do
|
|||||||
} (srcPath fin)
|
} (srcPath fin)
|
||||||
|
|
||||||
parser <- ts_parser_new
|
parser <- ts_parser_new
|
||||||
-- True <- ts_parser_set_language parser tree_sitter_PascaLigo
|
|
||||||
True <- ts_parser_set_language parser language
|
True <- ts_parser_set_language parser language
|
||||||
|
|
||||||
src <- srcToBytestring fin
|
src <- srcToBytestring fin
|
||||||
|
|
||||||
BS.useAsCStringLen src \(str, len) -> do
|
BS.useAsCStringLen src \(str, len) -> do
|
||||||
@ -166,7 +164,6 @@ toParseTree = unsafeDebounce \fin -> do
|
|||||||
|
|
||||||
return $ make (range :> "" :> Nil, ParseTree
|
return $ make (range :> "" :> Nil, ParseTree
|
||||||
{ ptName = Text.pack ty
|
{ ptName = Text.pack ty
|
||||||
-- , ptChildren = fromList . fmap (Comment,) $ trees -- TODO
|
|
||||||
, ptChildren = trees
|
, ptChildren = trees
|
||||||
, ptSource = cutOut range src
|
, ptSource = cutOut range src
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user