diff --git a/gitlab-pages/docs/api/cheat-sheet.md b/gitlab-pages/docs/api/cheat-sheet.md index 637d511b5..2d7303138 100644 --- a/gitlab-pages/docs/api/cheat-sheet.md +++ b/gitlab-pages/docs/api/cheat-sheet.md @@ -7,65 +7,61 @@ import Syntax from '@theme/Syntax';
- + -
-
Primitive
-
Example
-
Strings
-
+
+
Strings
+
```pascaligo const name: string = "Tezos"; ```
-
+
Characters
-
+
```pascaligo const t: string = "t"; ```
-
+
Integers
-
+
```pascaligo const i: int = 42; ```
-
+
Natural numbers
-
+
```pascaligo -const n: int = 7n; +const n: nat = 7n; ```
-
+
Unit
-
+
```pascaligo const u: unit = unit; ```
-
+
Boolean
-
+
```pascaligo const hasDriversLicense: bool = False; @@ -73,41 +69,47 @@ const adult: bool = True; ```
-
+
Boolean Logic
-
+
```pascaligo -const booleanLogic: bool = (not True) == False == (False and True) == (False or False); +const booleanLogic: bool = + (not True) = + False = + (False and True) = + (False or False); ```
-
+
Mutez (micro tez)
-
+
```pascaligo -const tez: mutez = 42mutez; +const tez: tez = 42tez; ```
-
+
Address
-
+
```pascaligo -const tz1address: address = ""tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"; -const kt1address: address = ""KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD"; +const tz1address: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); +const kt1address: address = + ("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address); ```
-
+
Addition
-
+
```pascaligo const add_int: int = 3 + 4; @@ -115,10 +117,10 @@ const add_nat: nat = 3n + 4n; ```
-
+
Multiplication & Division
-
+
```pascaligo const mul_int: int = 3 + 4; @@ -129,122 +131,947 @@ const div_nat: nat = 10n / 5n; ```
-
+
Modulo
-
+
```pascaligo -const mod: int = 10 mod 3; +const mod_nat: nat = 10 mod 3; ```
-
+
Tuples
-
+
```pascaligo -const mod: int = 10 mod 3; +type name is (string * string); + +const winner: name = ("John", "Doe"); + +const firstName: string = winner.0; +const lastName: string = winner.1; +``` + +
+
+Types +
+
+ +```pascaligo +type age is int; +type name is string +``` + +
+
+Includes +
+
+ +```#include "library.ligo"``` + +
+
+Functions (short form) +
+
+ +```pascaligo +function add (const a : int ; const b : int) : int is + a + b +``` + +
+
+Functions (long form) +
+
+ +```pascaligo +function add (const a : int ; const b : int) : int is + block { + const result: int = a + b; + } with result +``` + +
+
+If Statement +
+
+ +```pascaligo +function if_statement (const age : int) : int is + block { + var id: int := -1; + if age < 16 then { + failwith ("Too young to drive"); + } else { + id := 1; + } + } with id +``` + +
+
+Options +
+
+ +```pascaligo +type middleName is option(string); +const middleName : middleName = Some("Foo"); +const middleName : middleName = None; +``` + +
+
+Assignment +
+
+ +```pascaligo +const age: int = 5; +``` + +
+
+Assignment on an existing variable +
+
+ +:::caution +This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well. +::: + +```pascaligo +function assignment_existing (const age : int) : int is + block { + var x : int := 2; + x := 3; + } with x +``` + +
+
+Type Annotations +
+
+ +```pascaligo +const someAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); +``` + +
+
+Variants +
+
+ +```pascaligo group=variants +type action is +| Increment of int +| Decrement of int; +``` + +
+
+Variant *(pattern)* matching +
+
+ +```pascaligo group=variants +function main + (const action : action; const input : int) : int is + (case action of + Increment (n) -> input + 1 + | Decrement (n) -> input - 1 + end) +``` + +
+
+Records +
+
+ +```pascaligo +type person is record + age: int; + name: string; +end + +const john : person = record + age = 18; + name = "john doe"; +end + +const name: string = john.name; +``` + +
+
+Maps +
+
+ +```pascaligo +type prices is map(nat, tez); + +const prices: prices = map + 10n -> 60mutez; + 50n -> 30mutez; + 100n -> 10mutez; +end + +const price: option(tez) = prices[50n]; + +function mutate (const u: unit) : unit is block { + prices[200n] := 10mutez; +} with unit; +``` + +
+
+Contracts & Accounts +
+
+ +```pascaligo group=tezos_specific +const destinationAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address); + +const contract : contract (unit) = ( + case (Tezos.get_contract_opt (Tezos.sender) : option(contract(unit))) of + Some (contract) -> contract + | None -> + (failwith ("No contract.") + : contract (unit)) + end); + +``` + +
+
+Transactions +
+
+ +```pascaligo group=tezos_specific + +const payment: operation = + Tezos.transaction(unit, 100mutez, contract); + +``` + +
+
+Exception/Failure +
+
+ +```pascaligo +function fail (const u: unit) : unit is + failwith("a failure message") ```
- - - - - -|Primitive |Example| -|--- |---| -|Modulo| `10 mod 3`| -|Tuples|
type name is (string * string);
const winner: name = ("John", "Doe");
const firstName: string = winner.0;
const lastName: string = winner.1;
| -|Types|`type age is int`, `type name is string` | -|Includes|```#include "library.ligo"```| -|Functions (short form)|
function add (const a : int ; const b : int) : int is
  block { skip } with a + b
| -|Functions (long form)|
function add (const a : int ; const b : int) : int is
  block {
    const result: int = a + b;
  } with result
| -| If Statement |
if age < 16 
then failwith ("Too young to drive.");
else const new_id: int = prev_id + 1;
| -|Options|
type middleName is option(string);
const middleName : middleName = Some("Foo");
const middleName : middleName = None;
| -|Assignment| ```const age: int = 5;```| -|Assignment on an existing variable
*⚠️ This feature is not supported at the top-level scope, you can use it e.g. within functions. Works for Records and Maps as well.*| ```age := 18;```, ```p.age := 21``` | -|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```| -|Variants|
type action is
| Increment of int
| Decrement of int
| -|Variant *(pattern)* matching|
const a: action = Increment(5);
case a of
| Increment(n) -> n + 1
| Decrement(n) -> n - 1
end
| -|Records|
type person is record
  age: int ;
  name: string ;
end

const john : person = record
  age = 18;
  name = "John Doe";
end

const name: string = john.name;
| -|Maps|
type prices is map(nat, tez);

const prices : prices = map
  10n -> 60mutez;
  50n -> 30mutez;
  100n -> 10mutez;
end

const price: option(tez) = prices[50n];

prices[200n] := 5mutez;
| -|Contracts & Accounts|
const destinationAddress : address = "tz1...";
const contract : contract(unit) = get_contract(destinationAddress);
| -|Transactions|
const payment : operation = transaction(unit, amount, receiver);
| -|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| -
-|Primitive |Example| -|--- |---| -|Strings | `"Tezos"`| -|Characters | `"t"`| -|Integers | `42`, `7`| -|Natural numbers | `42n`, `7n`| -|Unit| `unit`| -|Boolean|
let has_drivers_license: bool = false
let adult: bool = true
| -|Boolean Logic|
(not true) = false = (false && true) = (false || false)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | -|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`| -|Addition |`3 + 4`, `3n + 4n`| -|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| -|Modulo| `10 mod 3`| -|Tuples|
type name = (string * string)
let winner: name = "John", "Doe"
let first_name: string = winner.0
let last_name: string = winner.1
| -|Types|`type age = int`, `type name = string` | -|Includes|```#include "library.mligo"```| -|Functions |
let add (a : int) (b : int) : int = a + b 
| -| If Statement |
let new_id: int = if age < 16 
then failwith ("Too young to drive.")
else prev_id + 1
| -|Options|
type middle_name = string option
let middle_name : middle_name = Some "Foo"
let middle_name : middle_name = None
| -|Variable Binding | ```let age: int = 5```| -|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```| -|Variants|
type action =
| Increment of int
| Decrement of int
| -|Variant *(pattern)* matching|
let a: action = Increment 5
match a with
| Increment n -> n + 1
| Decrement n -> n - 1
| -|Records|
type person = {
  age: int ;
  name: string ;
}

let john : person = {
  age = 18;
  name = "John Doe";
}

let name: string = john.name
| -|Maps|
type prices = (nat, tez) map

let prices : prices = Map.literal [
  (10n, 60mutez);
  (50n, 30mutez);
  (100n, 10mutez)
]

let price: tez option = Map.find_opt 50n prices

let prices: prices = Map.update 200n (Some 5mutez) prices
| -|Contracts & Accounts|
let destination_address : address = "tz1..."
let contract : unit contract =
Tezos.get_contract destination_address
| -|Transactions|
let payment : operation = 
Tezos.transaction unit amount receiver
| -|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.")`| +
+
Strings
+
+ +```cameligo +let name: string = "Tezos" +``` + +
+
+Characters +
+
+ +```cameligo +let t: string = "t" +``` + +
+
+Integers +
+
+ +```cameligo +let i: int = 42 +``` + +
+
+Natural numbers +
+
+ +```cameligo +let n: nat = 7n +``` + +
+
+Unit +
+
+ +```cameligo +let u: unit = unit +``` + +
+
+Boolean +
+
+ +```cameligo +let has_drivers_license: bool = false +let adult: bool = true +``` + +
+
+Boolean Logic +
+
+ +```cameligo +let booleanLogic: bool = + (not true) = + false = + (false && true) = + (false || false) +``` + +
+
+Mutez (micro tez) +
+
+ +```cameligo +let tez: tez = 42tez +let tez: tez = 7mutez +``` + +
+
+Address +
+
+ +```cameligo +let tz1address: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +let kt1address: address = + ("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address) +``` + +
+
+Addition +
+
+ +```cameligo +let add_int: int = 3 + 4 +let add_nat: nat = 3n + 4n +``` + +
+
+Multiplication & Division +
+
+ +```cameligo +let mul_int: int = 3 + 4 +let mul_nat: nat = 3n + 4n + +let div_int: int = 10 / 5 +let div_nat: nat = 10n / 5n +``` + +
+
+Modulo +
+
+ +```cameligo +let mod_nat: nat = 10 mod 3 +``` + +
+
+Tuples +
+
+ +```cameligo +type name = (string * string) + +let winner: name = "John", "Doe" + +let firstName: string = winner.0 +let lastName: string = winner.1 +``` + +
+
+Types +
+
+ +```cameligo +type age = int +type name = string +``` + +
+
+Includes +
+
+ +```#include "library.mligo"``` + +
+
+Functions +
+
+ +```cameligo +let add (a : int) (b : int) : int = + a + b +``` + +
+ +
+If Statement +
+
+ +```cameligo +let if_statement (age : int) : int = + if age < 16 then + (failwith ("Too young to drive"): int) + else + 1 +``` + +
+
+Options +
+
+ +```cameligo +type middle_name = string option +let middle_name : middle_name = Some "Foo" +let middle_name : middle_name = None +``` + +
+
+Variable Binding +
+
+ +```cameligo +let age: int = 5 +``` + +
+
+Type Annotations +
+
+ +```cameligo +let someAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +``` + +
+
+Variants +
+
+ +```cameligo group=variants +type action = +| Increment of int +| Decrement of int +``` + +
+
+Variant *(pattern)* matching +
+
+ +```cameligo group=variants +let a: action = Increment 5 +let result: int = match a with +| Increment n -> n + 1 +| Decrement n -> n - 1 +``` + +
+
+Records +
+
+ +```cameligo +type person = { + age: int; + name: string; +} + +let john : person = { + age = 18; + name = "john doe"; +} + +let name: string = john.name +``` + +
+
+Maps +
+
+ +```cameligo +type prices = (nat, tez) map + +let prices: prices = Map.literal [ + (10n, 60mutez); + (50n, 30mutez); + (100n, 10mutez); +] + +let price: tez option = Map.find_opt 50n prices + +let prices : prices = Map.update 200n (Some 5mutez) prices +``` + +
+
+Contracts & Accounts +
+
+ +```cameligo group=tezos_specific +let destinationAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) + +let contract : unit contract = + match (Tezos.get_contract_opt Tezos.sender : unit contract option) with + Some contract -> contract + | None -> (failwith "no contract" : unit contract) +``` + +
+
+Transactions +
+
+ +```cameligo group=tezos_specific + +let payment: operation = + Tezos.transaction unit 100mutez contract + +``` + +
+
+Exception/Failure +
+
+ +```cameligo +let fail (u: unit) : unit = + failwith "a failure message" +``` + +
+
-|Primitive |Example| -|--- |---| -|Strings | `"Tezos"`| -|Characters | `"t"`| -|Integers | `42`, `7`| -|Natural numbers | `42n`, `7n`| -|Unit| `unit`| -|Boolean|
let has_drivers_license: bool = false;
let adult: bool = true;
| -|Boolean Logic|
(not true) = false = (false && true) = (false || false)
| -|Mutez (micro tez)| `42mutez`, `7mutez` | -|Address | `("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)`, `("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address)`| -|Addition |`3 + 4`, `3n + 4n`| -|Multiplication & Division| `3 * 4`, `3n * 4n`, `10 / 5`, `10n / 5n`| -|Modulo| `10 mod 3`| -|Tuples|
type name = (string, string);
let winner: name = ("John", "Doe");
let first_name: string = winner[0];
let last_name: string = winner[1];
| -|Types|`type age = int;`, `type name = string;` | -|Includes|```#include "library.mligo"```| -|Functions |
let add = (a: int, b: int) : int => a + b; 
| -| If Statement |
let new_id: int = if (age < 16) {
failwith ("Too young to drive.");
} else { prev_id + 1; }
| -|Options|
type middle_name = option(string);
let middle_name : middle_name = Some("Foo");
let middle_name : middle_name = None;
| -|Variable Binding | ```let age: int = 5;```| -|Type Annotations| ```("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address)```| -|Variants|
type action =
| Increment(int)
| Decrement(int);
| -|Variant *(pattern)* matching|
let a: action = Increment(5);
switch(a) {
| Increment(n) => n + 1
| Decrement(n) => n - 1;
}
| -|Records|
type person = {
  age: int,
  name: string
}

let john : person = {
  age: 18,
  name: "John Doe"
};

let name: string = john.name;
| -|Maps|
type prices = map(nat, tez);

let prices : prices = Map.literal([
  (10n, 60mutez),
  (50n, 30mutez),
  (100n, 10mutez)
]);

let price: option(tez) = Map.find_opt(50n, prices);

let prices: prices = Map.update(200n, Some (5mutez), prices);
| -|Contracts & Accounts|
let destination_address : address = "tz1...";
let contract : contract(unit) =
Tezos.get_contract(destination_address);
| -|Transactions|
let payment : operation = 
Tezos.transaction (unit, amount, receiver);
| -|Exception/Failure|`failwith ("Your descriptive error message for the user goes here.");`| +
+
Strings
+
+ +```reasonligo +let name: string = "Tezos" +``` + +
+
+Characters +
+
+ +```reasonligo +let t: string = "t" +``` + +
+
+Integers +
+
+ +```reasonligo +let i: int = 42 +``` + +
+
+Natural numbers +
+
+ +```reasonligo +let n: nat = 7n +``` + +
+
+Unit +
+
+ +```reasonligo +let u: unit = unit +``` + +
+
+Boolean +
+
+ +```reasonligo +let has_drivers_license: bool = false +let adult: bool = true +``` + +
+
+Boolean Logic +
+
+ +```reasonligo +let booleanLogic: bool = + (!true) == + false == + (false && true) == + (false || false) +``` + +
+
+Mutez (micro tez) +
+
+ +```reasonligo +let tez: tez = 42tez +let tez: tez = 7mutez +``` + +
+
+Address +
+
+ +```reasonligo +let tz1address: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +let kt1address: address = + ("KT1JepfBfMSqkQyf9B1ndvURghGsSB8YCLMD": address) +``` + +
+
+Addition +
+
+ +```reasonligo +let add_int: int = 3 + 4 +let add_nat: nat = 3n + 4n +``` + +
+
+Multiplication & Division +
+
+ +```reasonligo +let mul_int: int = 3 + 4 +let mul_nat: nat = 3n + 4n + +let div_int: int = 10 / 5 +let div_nat: nat = 10n / 5n +``` + +
+
+Modulo +
+
+ +```reasonligo +let mod_nat: nat = 10 mod 3 +``` + +
+
+Tuples +
+
+ +```reasonligo +type name = (string, string) + +let winner: name = ("John", "Doe") + +let firstName: string = winner[0] +let lastName: string = winner[1] +``` + +
+
+Types +
+
+ +```reasonligo +type age = int +type name = string +``` + +
+
+Includes +
+
+ +```#include "library.religo"``` + +
+
+Functions (short form) +
+
+ +```reasonligo +let add = (a: int, b: int): int => + a + b +``` + +
+
+Functions (long form) +
+
+ +```reasonligo +let add = (a: int, b: int): int => { + let c = a; + let d = b; + c + d +}; +``` + +
+
+If Statement +
+
+ +```reasonligo +let if_statement = (age : int) : int => + if (age < 16) { + (failwith ("Too young to drive"): int) + } else { + 1 + } +``` + +
+
+Options +
+
+ +```reasonligo +type middle_name = option(string); +let middle_name : middle_name = Some ("Foo"); +let middle_name : middle_name = None; +``` + +
+
+Variable Binding +
+
+ +```reasonligo +let age: int = 5 +``` + +
+
+Type Annotations +
+
+ +```reasonligo +let someAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) +``` + +
+
+Variants +
+
+ +```reasonligo group=variants +type action = +| Increment (int) +| Decrement (int) +``` + +
+
+Variant *(pattern)* matching +
+
+ +```reasonligo group=variants +let a: action = Increment(5) +let result: int = switch (a) { +| Increment(n) => n + 1 +| Decrement(n) => n - 1 +} +``` + +
+
+Records +
+
+ +```reasonligo +type person = { + age: int, + name: string +} + +let john : person = { + age: 18, + name: "john doe" +} + +let name: string = john.name +``` + +
+
+Maps +
+
+ +```reasonligo +type prices = map (nat, tez) + +let prices: prices = Map.literal ([ + (10n, 60mutez), + (50n, 30mutez), + (100n, 10mutez), +]) + +let price: option(tez) = Map.find_opt(50n, prices) + +let prices : prices = Map.update(200n, (Some 5mutez), prices) +``` + +
+
+Contracts & Accounts +
+
+ +```reasonligo group=tezos_specific +let destinationAddress: address = + ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address) + +let contract : contract(unit) = + switch (Tezos.get_contract_opt(Tezos.sender) : option(contract(unit))) { + | Some(contract) => contract + | None => (failwith("no contract") : contract(unit)) + } +``` + +
+
+Transactions +
+
+ +```reasonligo group=tezos_specific + +let payment: operation = + Tezos.transaction(unit, 100mutez, contract); + +``` + +
+
+Exception/Failure +
+
+ +```reasonligo +let fail = (u: unit) : unit => + failwith("a failure message") +``` + +
+
-
diff --git a/gitlab-pages/website/src/theme/CodeBlock/index.js b/gitlab-pages/website/src/theme/CodeBlock/index.js index ca90f0cb0..4c705b717 100644 --- a/gitlab-pages/website/src/theme/CodeBlock/index.js +++ b/gitlab-pages/website/src/theme/CodeBlock/index.js @@ -166,7 +166,7 @@ export default ({children, className: languageClassName, metastring}) => { {showCopied ? 'Copied' : 'Copy'} - + {tokens.map((line, i) => { if (line.length === 1 && line[0].content === '') { line[0].content = '\n'; // eslint-disable-line no-param-reassign diff --git a/gitlab-pages/website/static/css/custom.css b/gitlab-pages/website/static/css/custom.css index b779c2e69..476f1da98 100644 --- a/gitlab-pages/website/static/css/custom.css +++ b/gitlab-pages/website/static/css/custom.css @@ -989,21 +989,43 @@ a:hover { } } - -/* ReasonLIGO specific syntax highlighting */ -.language-reasonligo .hljs-operator { - color: #a626a4; -} -.language-reasonligo .hljs-character { - color: #50a14f; -} -.language-reasonligo .hljs-module-identifier { - color: #00f; -} -.language-reasonligo .hljs-constructor { - color: #a31515; -} - .badge { display: none; } + +.codeTable { + display: grid; + grid-template-columns: 30% 70%; + align-items: center; +} + +.codeTable > .primitive { + width: 100%; + height: 100%; + display: flex; + justify-content: right; + text-align: right; + align-items: center; + font-weight: bold; + padding-right: 1rem; +} + + +.codeTable > div:nth-child(4n+1) { + background-color: var(--ifm-table-stripe-background); +} + +.codeTable > div:nth-child(4n+2) { + background-color: var(--ifm-table-stripe-background); +} + + +.codeTable > .example { + padding-top: var(--ifm-leading); +} + +.codeTable > .example pre, +.codeTable > .example .codeBlockLines_src-theme-CodeBlock- { + background-color: transparent; +} +