From 6ff8463db442fdee1cf15838d6fcf53f67a62095 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 00:10:44 +0400 Subject: [PATCH 1/9] Add main contract, contract interface, and guards to the docs syntax --- docs/sophia_syntax.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index a55fa60..6cdd9c8 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -91,7 +91,8 @@ A Sophia file consists of a sequence of *declarations* in a layout block. ```c File ::= Block(TopDecl) -TopDecl ::= ['payable'] 'contract' Con '=' Block(Decl) +TopDecl ::= ['payable'] ['main'] 'contract' Con '=' Block(Decl) + | 'contract' 'interface' Con '=' Block(Decl) | 'namespace' Con '=' Block(Decl) | '@compiler' PragmaOp Version | 'include' String @@ -103,6 +104,9 @@ Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias FunDecl ::= Id ':' Type // Type signature | Id Args [':' Type] '=' Block(Stmt) // Definition + | Id Args [':' Type] Block(GuardedDef) // Guarded definitions + +GuardedDef = '|' Sep(Expr, ',') '=' Block(Stmt) PragmaOp ::= '<' | '=<' | '==' | '>=' | '>' Version ::= Sep1(Int, '.') -- 2.30.2 From c4061701b025583610f7e9e512711ce593f5c0b4 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 00:23:56 +0400 Subject: [PATCH 2/9] Use Sep1 instead of Sep for the GuardedDef --- docs/sophia_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index 6cdd9c8..a49eb0e 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -106,7 +106,7 @@ FunDecl ::= Id ':' Type // Type signature | Id Args [':' Type] '=' Block(Stmt) // Definition | Id Args [':' Type] Block(GuardedDef) // Guarded definitions -GuardedDef = '|' Sep(Expr, ',') '=' Block(Stmt) +GuardedDef = '|' Sep1(Expr, ',') '=' Block(Stmt) PragmaOp ::= '<' | '=<' | '==' | '>=' | '>' Version ::= Sep1(Int, '.') -- 2.30.2 From 7623cc2f350c23dac0981879e5e4b45f609e3655 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 00:26:06 +0400 Subject: [PATCH 3/9] Add guarded case for switches --- docs/sophia_syntax.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index a49eb0e..9a4b748 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -182,6 +182,10 @@ LetDef ::= Id Args [':' Type] '=' Block(Stmt) // Function definition | Pattern '=' Block(Stmt) // Value definition Case ::= Pattern '=>' Block(Stmt) + | Pattern Block(GuardedCase) + +GuardedCase ::= '|' Sep1(Expr, ',') '=>' Block(Stmt) + Pattern ::= Expr ``` -- 2.30.2 From 47d027c73f870d89f7ea09c25a57e43c9e2ce6b2 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 14:11:16 +0400 Subject: [PATCH 4/9] Change '=' to '::=' in GuardedDef --- docs/sophia_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index 9a4b748..d3fb383 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -106,7 +106,7 @@ FunDecl ::= Id ':' Type // Type signature | Id Args [':' Type] '=' Block(Stmt) // Definition | Id Args [':' Type] Block(GuardedDef) // Guarded definitions -GuardedDef = '|' Sep1(Expr, ',') '=' Block(Stmt) +GuardedDef ::= '|' Sep1(Expr, ',') '=' Block(Stmt) PragmaOp ::= '<' | '=<' | '==' | '>=' | '>' Version ::= Sep1(Int, '.') -- 2.30.2 From e6159b8014a20ebac887bd40adb424bbede52bfd Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 14:12:58 +0400 Subject: [PATCH 5/9] Add Using --- docs/sophia_syntax.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index d3fb383..b40d24d 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -96,11 +96,13 @@ TopDecl ::= ['payable'] ['main'] 'contract' Con '=' Block(Decl) | 'namespace' Con '=' Block(Decl) | '@compiler' PragmaOp Version | 'include' String + | Using Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias | 'record' Id ['(' TVar* ')'] '=' RecordType | 'datatype' Id ['(' TVar* ')'] '=' DataType | (EModifier* 'entrypoint' | FModifier* 'function') Block(FunDecl) + | Using FunDecl ::= Id ':' Type // Type signature | Id Args [':' Type] '=' Block(Stmt) // Definition @@ -108,6 +110,10 @@ FunDecl ::= Id ':' Type // Type signature GuardedDef ::= '|' Sep1(Expr, ',') '=' Block(Stmt) +Using ::= 'using' Con ['as' Con] [UsingParts] +UsingParts ::= 'for' '[' Sep1(Id, ',') ']' + | 'hiding' '[' Sep1(Id, ',') ']' + PragmaOp ::= '<' | '=<' | '==' | '>=' | '>' Version ::= Sep1(Int, '.') @@ -176,6 +182,7 @@ Stmt ::= 'switch' '(' Expr ')' Block(Case) | 'elif' '(' Expr ')' Block(Stmt) | 'else' Block(Stmt) | 'let' LetDef + | Using | Expr LetDef ::= Id Args [':' Type] '=' Block(Stmt) // Function definition -- 2.30.2 From 0222c9eda02a729d80887167d73c1fa8bb99256f Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 14:35:51 +0400 Subject: [PATCH 6/9] Add '|>' binary operator to aeso_syntax --- src/aeso_syntax.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeso_syntax.erl b/src/aeso_syntax.erl index c6c0c9d..8b60e38 100644 --- a/src/aeso_syntax.erl +++ b/src/aeso_syntax.erl @@ -106,7 +106,7 @@ -type bin_op() :: '+' | '-' | '*' | '/' | mod | '^' | '++' | '::' | '<' | '>' | '=<' | '>=' | '==' | '!=' - | '||' | '&&' | '..'. + | '||' | '&&' | '..' | '|>'. -type un_op() :: '-' | '!'. -type expr() -- 2.30.2 From edd9348fb14961c1cd0939ead75151ec765303fd Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 14:51:52 +0400 Subject: [PATCH 7/9] Add assign patter --- docs/sophia_syntax.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index b40d24d..ce2a0a8 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -230,6 +230,7 @@ Expr ::= '(' LamArgs ')' '=>' Block(Stmt) // Anonymous function (x) => x + | '[' Expr '..' Expr ']' // List range [1..n] | '{' Sep(FieldUpdate, ',') '}' // Record or map value {x = 0, y = 1}, {[key] = val} | '(' Expr ')' // Parens (1 + 2) * 3 + | '(' Expr '=' Expr ')' // Assign pattern (y = x::_) | Id | Con | QId | QCon // Identifiers x, None, Map.member, AELib.Token | Int | Bytes | String | Char // Literals 123, 0xff, #00abc123, "foo", '%' | AccountAddress | ContractAddress // Chain identifiers -- 2.30.2 From 1de552d713b0c1671257f1951cac2e98e99a446f Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 14:52:32 +0400 Subject: [PATCH 8/9] Fix typos --- docs/sophia_syntax.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index ce2a0a8..08dbee3 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -260,12 +260,12 @@ UnOp ::= '-' | '!' | Operators | Type | --- | --- | `-` `+` `*` `/` `mod` `^` | arithmetic operators -| `!` `&&` `\|\|` | logical operators +| `!` `&&` `||` | logical operators | `==` `!=` `<` `>` `=<` `>=` | comparison operators | `::` `++` | list operators -| `\|>` | functional operators +| `|>` | functional operators -## Operator precendences +## Operator precedence In order of highest to lowest precedence. @@ -279,5 +279,5 @@ In order of highest to lowest precedence. | `::` `++` | right | `<` `>` `=<` `>=` `==` `!=` | none | `&&` | right -| `\|\|` | right -| `\|>` | left +| `||` | right +| `|>` | left -- 2.30.2 From a589adeafea79e3bd47593b457d66f2cfa96fe2c Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 15:10:57 +0400 Subject: [PATCH 9/9] Add polymorphism implmented interface syntax --- docs/sophia_syntax.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/sophia_syntax.md b/docs/sophia_syntax.md index 08dbee3..87b1bee 100644 --- a/docs/sophia_syntax.md +++ b/docs/sophia_syntax.md @@ -91,12 +91,14 @@ A Sophia file consists of a sequence of *declarations* in a layout block. ```c File ::= Block(TopDecl) -TopDecl ::= ['payable'] ['main'] 'contract' Con '=' Block(Decl) - | 'contract' 'interface' Con '=' Block(Decl) - | 'namespace' Con '=' Block(Decl) - | '@compiler' PragmaOp Version - | 'include' String - | Using +TopDecl ::= ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl) + | 'contract' 'interface' Con [Implement] '=' Block(Decl) + | 'namespace' Con '=' Block(Decl) + | '@compiler' PragmaOp Version + | 'include' String + | Using + +Implement ::= ':' Sep1(Con, ',') Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias | 'record' Id ['(' TVar* ')'] '=' RecordType -- 2.30.2