Add attribute parser
This commit is contained in:
parent
d928aaa39c
commit
2f269e32ea
@ -30,6 +30,7 @@ declaration
|
|||||||
<|> do ctor ValueDecl <*> vardecl
|
<|> do ctor ValueDecl <*> vardecl
|
||||||
<|> do ctor ValueDecl <*> constdecl
|
<|> do ctor ValueDecl <*> constdecl
|
||||||
<|> typedecl
|
<|> typedecl
|
||||||
|
<|> do ctor Action <*> attributes
|
||||||
|
|
||||||
typedecl :: Parser (Declaration ASTInfo)
|
typedecl :: Parser (Declaration ASTInfo)
|
||||||
typedecl = do
|
typedecl = do
|
||||||
@ -95,6 +96,7 @@ expr = stubbed "expr" do
|
|||||||
, list_expr
|
, list_expr
|
||||||
, has_type
|
, has_type
|
||||||
, string_literal
|
, string_literal
|
||||||
|
, attributes
|
||||||
-- , constant
|
-- , constant
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
@ -103,6 +105,14 @@ expr = stubbed "expr" do
|
|||||||
-- $.disj_expr,
|
-- $.disj_expr,
|
||||||
-- $.fun_expr,
|
-- $.fun_expr,
|
||||||
|
|
||||||
|
attributes :: Parser (Expr ASTInfo)
|
||||||
|
attributes = do
|
||||||
|
subtree "attr_decl" do
|
||||||
|
ctor Attrs <*> do
|
||||||
|
many "attribute" do
|
||||||
|
inside "attribute" do
|
||||||
|
token "String"
|
||||||
|
|
||||||
string_literal :: Parser (Expr ASTInfo)
|
string_literal :: Parser (Expr ASTInfo)
|
||||||
string_literal = do
|
string_literal = do
|
||||||
ctor Constant <*> do
|
ctor Constant <*> do
|
||||||
@ -223,6 +233,9 @@ opCall = do
|
|||||||
<*> inside "arg1" expr
|
<*> inside "arg1" expr
|
||||||
<*> inside "op" anything
|
<*> inside "op" anything
|
||||||
<*> inside "arg2" expr
|
<*> inside "arg2" expr
|
||||||
|
<|> do ctor UnOp
|
||||||
|
<*> inside "negate" anything
|
||||||
|
<*> inside "arg" expr
|
||||||
|
|
||||||
letExpr = do
|
letExpr = do
|
||||||
subtree "let_expr" do
|
subtree "let_expr" do
|
||||||
@ -323,8 +336,8 @@ typeTuple = do
|
|||||||
-- example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/application.ligo"
|
||||||
-- example = "../../../src/test/contracts/address.ligo"
|
-- example = "../../../src/test/contracts/address.ligo"
|
||||||
-- example = "../../../src/test/contracts/amount.ligo"
|
-- example = "../../../src/test/contracts/amount.ligo"
|
||||||
example = "../../../src/test/contracts/annotation.ligo"
|
-- example = "../../../src/test/contracts/annotation.ligo"
|
||||||
-- example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/arithmetic.ligo"
|
||||||
-- example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/assign.ligo"
|
||||||
-- example = "../../../src/test/contracts/application.ligo"
|
example = "../../../src/test/contracts/attributes.ligo"
|
||||||
-- example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/application.ligo"
|
||||||
|
@ -84,11 +84,13 @@ data Expr info
|
|||||||
| Constant info (Constant info)
|
| Constant info (Constant info)
|
||||||
| Ident info (QualifiedName info)
|
| Ident info (QualifiedName info)
|
||||||
| BinOp info (Expr info) Text (Expr info)
|
| BinOp info (Expr info) Text (Expr info)
|
||||||
|
| UnOp info Text (Expr info)
|
||||||
| Record info [Assignment info]
|
| Record info [Assignment info]
|
||||||
| If info (Expr info) (Expr info) (Expr info)
|
| If info (Expr info) (Expr info) (Expr info)
|
||||||
| Assign info (QualifiedName info) (Expr info)
|
| Assign info (QualifiedName info) (Expr info)
|
||||||
| List info [Expr info]
|
| List info [Expr info]
|
||||||
| Annot info (Expr info) (Type info)
|
| Annot info (Expr info) (Type info)
|
||||||
|
| Attrs info [Text]
|
||||||
| WrongExpr Error
|
| WrongExpr Error
|
||||||
deriving (Show) via PP (Expr info)
|
deriving (Show) via PP (Expr info)
|
||||||
|
|
||||||
@ -238,11 +240,13 @@ instance Pretty (Expr i) where
|
|||||||
Constant _ constant -> pp constant
|
Constant _ constant -> pp constant
|
||||||
Ident _ qname -> pp qname
|
Ident _ qname -> pp qname
|
||||||
BinOp _ l o r -> parens (pp l <+> pp o <+> pp r)
|
BinOp _ l o r -> parens (pp l <+> pp o <+> pp r)
|
||||||
|
UnOp _ o r -> parens (pp o <+> pp r)
|
||||||
Record _ az -> "record [" <> (fsep $ punctuate ";" $ map pp az) <> "]"
|
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]
|
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)
|
Assign _ l r -> hang (pp l <+> ":=") 2 (pp r)
|
||||||
List _ l -> "[" <> fsep (punctuate ";" $ map pp l) <> "]"
|
List _ l -> "[" <> fsep (punctuate ";" $ map pp l) <> "]"
|
||||||
Annot _ n t -> ("(" <> pp n) <+> ":" <+> (pp t <> ")")
|
Annot _ n t -> ("(" <> pp n) <+> ":" <+> (pp t <> ")")
|
||||||
|
Attrs _ ts -> "attributes [" <> fsep (punctuate ";" $ map pp ts) <> "]"
|
||||||
WrongExpr err -> pp err
|
WrongExpr err -> pp err
|
||||||
|
|
||||||
instance Pretty (Assignment i) where
|
instance Pretty (Assignment i) where
|
||||||
|
Loading…
Reference in New Issue
Block a user