Update Sophia syntax docs to include missing information about existing syntax (#405)
* Add main contract, contract interface, and guards to the docs syntax * Use Sep1 instead of Sep for the GuardedDef * Add guarded case for switches * Change '=' to '::=' in GuardedDef * Add Using * Add '|>' binary operator to aeso_syntax * Add assign patter * Fix typos * Add polymorphism implmented interface syntax
This commit is contained in:
parent
c98ea25e8b
commit
8d8d9c6b83
@ -91,18 +91,30 @@ A Sophia file consists of a sequence of *declarations* in a layout block.
|
|||||||
```c
|
```c
|
||||||
File ::= Block(TopDecl)
|
File ::= Block(TopDecl)
|
||||||
|
|
||||||
TopDecl ::= ['payable'] 'contract' Con '=' Block(Decl)
|
TopDecl ::= ['payable'] ['main'] 'contract' Con [Implement] '=' Block(Decl)
|
||||||
|
| 'contract' 'interface' Con [Implement] '=' Block(Decl)
|
||||||
| 'namespace' Con '=' Block(Decl)
|
| 'namespace' Con '=' Block(Decl)
|
||||||
| '@compiler' PragmaOp Version
|
| '@compiler' PragmaOp Version
|
||||||
| 'include' String
|
| 'include' String
|
||||||
|
| Using
|
||||||
|
|
||||||
|
Implement ::= ':' Sep1(Con, ',')
|
||||||
|
|
||||||
Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias
|
Decl ::= 'type' Id ['(' TVar* ')'] '=' TypeAlias
|
||||||
| 'record' Id ['(' TVar* ')'] '=' RecordType
|
| 'record' Id ['(' TVar* ')'] '=' RecordType
|
||||||
| 'datatype' Id ['(' TVar* ')'] '=' DataType
|
| 'datatype' Id ['(' TVar* ')'] '=' DataType
|
||||||
| (EModifier* 'entrypoint' | FModifier* 'function') Block(FunDecl)
|
| (EModifier* 'entrypoint' | FModifier* 'function') Block(FunDecl)
|
||||||
|
| Using
|
||||||
|
|
||||||
FunDecl ::= Id ':' Type // Type signature
|
FunDecl ::= Id ':' Type // Type signature
|
||||||
| Id Args [':' Type] '=' Block(Stmt) // Definition
|
| Id Args [':' Type] '=' Block(Stmt) // Definition
|
||||||
|
| Id Args [':' Type] Block(GuardedDef) // Guarded definitions
|
||||||
|
|
||||||
|
GuardedDef ::= '|' Sep1(Expr, ',') '=' Block(Stmt)
|
||||||
|
|
||||||
|
Using ::= 'using' Con ['as' Con] [UsingParts]
|
||||||
|
UsingParts ::= 'for' '[' Sep1(Id, ',') ']'
|
||||||
|
| 'hiding' '[' Sep1(Id, ',') ']'
|
||||||
|
|
||||||
PragmaOp ::= '<' | '=<' | '==' | '>=' | '>'
|
PragmaOp ::= '<' | '=<' | '==' | '>=' | '>'
|
||||||
Version ::= Sep1(Int, '.')
|
Version ::= Sep1(Int, '.')
|
||||||
@ -172,12 +184,17 @@ Stmt ::= 'switch' '(' Expr ')' Block(Case)
|
|||||||
| 'elif' '(' Expr ')' Block(Stmt)
|
| 'elif' '(' Expr ')' Block(Stmt)
|
||||||
| 'else' Block(Stmt)
|
| 'else' Block(Stmt)
|
||||||
| 'let' LetDef
|
| 'let' LetDef
|
||||||
|
| Using
|
||||||
| Expr
|
| Expr
|
||||||
|
|
||||||
LetDef ::= Id Args [':' Type] '=' Block(Stmt) // Function definition
|
LetDef ::= Id Args [':' Type] '=' Block(Stmt) // Function definition
|
||||||
| Pattern '=' Block(Stmt) // Value definition
|
| Pattern '=' Block(Stmt) // Value definition
|
||||||
|
|
||||||
Case ::= Pattern '=>' Block(Stmt)
|
Case ::= Pattern '=>' Block(Stmt)
|
||||||
|
| Pattern Block(GuardedCase)
|
||||||
|
|
||||||
|
GuardedCase ::= '|' Sep1(Expr, ',') '=>' Block(Stmt)
|
||||||
|
|
||||||
Pattern ::= Expr
|
Pattern ::= Expr
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -215,6 +232,7 @@ Expr ::= '(' LamArgs ')' '=>' Block(Stmt) // Anonymous function (x) => x +
|
|||||||
| '[' Expr '..' Expr ']' // List range [1..n]
|
| '[' Expr '..' Expr ']' // List range [1..n]
|
||||||
| '{' Sep(FieldUpdate, ',') '}' // Record or map value {x = 0, y = 1}, {[key] = val}
|
| '{' Sep(FieldUpdate, ',') '}' // Record or map value {x = 0, y = 1}, {[key] = val}
|
||||||
| '(' Expr ')' // Parens (1 + 2) * 3
|
| '(' Expr ')' // Parens (1 + 2) * 3
|
||||||
|
| '(' Expr '=' Expr ')' // Assign pattern (y = x::_)
|
||||||
| Id | Con | QId | QCon // Identifiers x, None, Map.member, AELib.Token
|
| Id | Con | QId | QCon // Identifiers x, None, Map.member, AELib.Token
|
||||||
| Int | Bytes | String | Char // Literals 123, 0xff, #00abc123, "foo", '%'
|
| Int | Bytes | String | Char // Literals 123, 0xff, #00abc123, "foo", '%'
|
||||||
| AccountAddress | ContractAddress // Chain identifiers
|
| AccountAddress | ContractAddress // Chain identifiers
|
||||||
@ -244,12 +262,12 @@ UnOp ::= '-' | '!'
|
|||||||
| Operators | Type
|
| Operators | Type
|
||||||
| --- | ---
|
| --- | ---
|
||||||
| `-` `+` `*` `/` `mod` `^` | arithmetic operators
|
| `-` `+` `*` `/` `mod` `^` | arithmetic operators
|
||||||
| `!` `&&` `\|\|` | logical operators
|
| `!` `&&` `||` | logical operators
|
||||||
| `==` `!=` `<` `>` `=<` `>=` | comparison operators
|
| `==` `!=` `<` `>` `=<` `>=` | comparison operators
|
||||||
| `::` `++` | list operators
|
| `::` `++` | list operators
|
||||||
| `\|>` | functional operators
|
| `|>` | functional operators
|
||||||
|
|
||||||
## Operator precendences
|
## Operator precedence
|
||||||
|
|
||||||
In order of highest to lowest precedence.
|
In order of highest to lowest precedence.
|
||||||
|
|
||||||
@ -263,5 +281,5 @@ In order of highest to lowest precedence.
|
|||||||
| `::` `++` | right
|
| `::` `++` | right
|
||||||
| `<` `>` `=<` `>=` `==` `!=` | none
|
| `<` `>` `=<` `>=` `==` `!=` | none
|
||||||
| `&&` | right
|
| `&&` | right
|
||||||
| `\|\|` | right
|
| `||` | right
|
||||||
| `\|>` | left
|
| `|>` | left
|
||||||
|
@ -106,7 +106,7 @@
|
|||||||
|
|
||||||
-type bin_op() :: '+' | '-' | '*' | '/' | mod | '^'
|
-type bin_op() :: '+' | '-' | '*' | '/' | mod | '^'
|
||||||
| '++' | '::' | '<' | '>' | '=<' | '>=' | '==' | '!='
|
| '++' | '::' | '<' | '>' | '=<' | '>=' | '==' | '!='
|
||||||
| '||' | '&&' | '..'.
|
| '||' | '&&' | '..' | '|>'.
|
||||||
-type un_op() :: '-' | '!'.
|
-type un_op() :: '-' | '!'.
|
||||||
|
|
||||||
-type expr()
|
-type expr()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user