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