Add lists, if, assignments, string, tez parsers
This commit is contained in:
parent
6e862bf5b9
commit
d928aaa39c
@ -119,7 +119,7 @@ module.exports = grammar({
|
||||
invokeUnary: $ =>
|
||||
seq(
|
||||
field("typeConstr", choice('list', 'set')),
|
||||
field("arguments", par($._type_expr)),
|
||||
par(field("arguments", $._type_expr)),
|
||||
),
|
||||
|
||||
map: $ => 'map',
|
||||
@ -659,9 +659,9 @@ module.exports = grammar({
|
||||
tuple_expr: $ => par(sepBy1(',', field("element", $._expr))),
|
||||
arguments: $ => par(sepBy(',', field("argument", $._expr))),
|
||||
|
||||
list_expr: $ => choice($.list_injection, 'nil'),
|
||||
list_expr: $ => choice($._list_injection, 'nil'),
|
||||
|
||||
list_injection: $ => injection('list', field("element", $._expr)),
|
||||
_list_injection: $ => injection('list', field("element", $._expr)),
|
||||
|
||||
pattern: $ => sepBy1('#', field("arg", $._core_pattern)),
|
||||
|
||||
|
@ -87,9 +87,14 @@ expr = stubbed "expr" do
|
||||
, fun_call
|
||||
, record_expr
|
||||
, int_literal
|
||||
, tez_literal
|
||||
, par_call
|
||||
, method_call
|
||||
-- , if_expr
|
||||
, if_expr
|
||||
, assign
|
||||
, list_expr
|
||||
, has_type
|
||||
, string_literal
|
||||
-- , constant
|
||||
]
|
||||
where
|
||||
@ -98,6 +103,54 @@ expr = stubbed "expr" do
|
||||
-- $.disj_expr,
|
||||
-- $.fun_expr,
|
||||
|
||||
string_literal :: Parser (Expr ASTInfo)
|
||||
string_literal = do
|
||||
ctor Constant <*> do
|
||||
ctor String <*>
|
||||
token "String"
|
||||
|
||||
has_type :: Parser (Expr ASTInfo)
|
||||
has_type = do
|
||||
subtree "annot_expr" do
|
||||
ctor Annot
|
||||
<*> inside "subject" expr
|
||||
<*> inside "type" type_
|
||||
|
||||
list_expr :: Parser (Expr ASTInfo)
|
||||
list_expr = do
|
||||
subtree "list_expr" do
|
||||
ctor List <*> do
|
||||
many "list elem" do
|
||||
inside "element" expr
|
||||
|
||||
qname :: Parser (QualifiedName ASTInfo)
|
||||
qname = do
|
||||
ctor QualifiedName
|
||||
<*> name
|
||||
<*> pure []
|
||||
|
||||
assign :: Parser (Expr ASTInfo)
|
||||
assign = do
|
||||
subtree "assignment" do
|
||||
ctor Assign
|
||||
<*> inside "LHS" do
|
||||
inside ":path" qname
|
||||
<|> projection
|
||||
<*> inside "RHS" expr
|
||||
|
||||
tez_literal :: Parser (Expr ASTInfo)
|
||||
tez_literal = do
|
||||
ctor Constant <*> do
|
||||
ctor Tez <*> token "Tez"
|
||||
|
||||
if_expr :: Parser (Expr ASTInfo)
|
||||
if_expr = do
|
||||
subtree "conditional" do
|
||||
ctor If
|
||||
<*> inside "selector" expr
|
||||
<*> inside "then:if_clause" expr
|
||||
<*> inside "else:if_clause" expr
|
||||
|
||||
method_call :: Parser (Expr ASTInfo)
|
||||
method_call = do
|
||||
subtree "projection_call" do
|
||||
@ -154,9 +207,7 @@ arguments =
|
||||
|
||||
function_id :: Parser (QualifiedName ASTInfo)
|
||||
function_id = select
|
||||
[ ctor QualifiedName
|
||||
<*> name
|
||||
<*> pure []
|
||||
[ qname
|
||||
, do
|
||||
subtree "module_field" do
|
||||
ctor QualifiedName
|
||||
@ -253,8 +304,16 @@ type_ =
|
||||
ctor TApply
|
||||
<*> inside "typeConstr" name
|
||||
<*> inside "arguments" typeTuple
|
||||
, subtree "invokeUnary" do
|
||||
ctor TApply
|
||||
<*> inside "typeConstr" name'
|
||||
<*> do pure <$> inside "arguments" type_
|
||||
]
|
||||
|
||||
name' :: Parser (Name ASTInfo)
|
||||
name' = do
|
||||
ctor Name <*> anything
|
||||
|
||||
typeTuple :: Parser [Type ASTInfo]
|
||||
typeTuple = do
|
||||
subtree "type_tuple" do
|
||||
@ -263,8 +322,8 @@ typeTuple = do
|
||||
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
-- example = "../../../src/test/contracts/address.ligo"
|
||||
example = "../../../src/test/contracts/amount.ligo"
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
-- example = "../../../src/test/contracts/amount.ligo"
|
||||
example = "../../../src/test/contracts/annotation.ligo"
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
|
@ -85,6 +85,10 @@ data Expr info
|
||||
| Ident info (QualifiedName info)
|
||||
| BinOp info (Expr info) Text (Expr info)
|
||||
| Record info [Assignment info]
|
||||
| If info (Expr info) (Expr info) (Expr info)
|
||||
| Assign info (QualifiedName info) (Expr info)
|
||||
| List info [Expr info]
|
||||
| Annot info (Expr info) (Type info)
|
||||
| WrongExpr Error
|
||||
deriving (Show) via PP (Expr info)
|
||||
|
||||
@ -102,6 +106,7 @@ data Constant info
|
||||
| String info Text
|
||||
| Float info Text
|
||||
| Bytes info Text
|
||||
| Tez info Text
|
||||
| WrongConstant Error
|
||||
deriving (Show) via PP (Constant info)
|
||||
|
||||
@ -234,6 +239,10 @@ instance Pretty (Expr i) where
|
||||
Ident _ qname -> pp qname
|
||||
BinOp _ l o r -> parens (pp l <+> pp o <+> pp r)
|
||||
Record _ az -> "record [" <> (fsep $ punctuate ";" $ map pp az) <> "]"
|
||||
If _ b t e -> fsep ["if" <+> pp b, nest 2 $ "then" <+> pp t, nest 2 $ "else" <+> pp e]
|
||||
Assign _ l r -> hang (pp l <+> ":=") 2 (pp r)
|
||||
List _ l -> "[" <> fsep (punctuate ";" $ map pp l) <> "]"
|
||||
Annot _ n t -> ("(" <> pp n) <+> ":" <+> (pp t <> ")")
|
||||
WrongExpr err -> pp err
|
||||
|
||||
instance Pretty (Assignment i) where
|
||||
@ -244,9 +253,10 @@ instance Pretty (Assignment i) where
|
||||
instance Pretty (Constant i) where
|
||||
pp = \case
|
||||
Int _ c -> pp c
|
||||
String _ c -> doubleQuotes (pp c)
|
||||
String _ c -> pp c
|
||||
Float _ c -> pp c
|
||||
Bytes _ c -> pp c
|
||||
Tez _ c -> pp c
|
||||
WrongConstant err -> pp err
|
||||
|
||||
instance Pretty (QualifiedName i) where
|
||||
|
Loading…
Reference in New Issue
Block a user