ligo/gitlab-pages/website/core/CodeExamples.js

121 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-12-05 20:10:59 +04:00
const React = require('react');
const pre = '```';
const PASCALIGO_EXAMPLE = `${pre}pascaligo
2020-02-10 22:07:20 +04:00
type storage is int
type parameter is
Increment of int
2019-12-05 20:10:59 +04:00
| Decrement of int
2020-02-10 22:07:20 +04:00
| Reset
type return is list (operation) * storage
2019-12-05 20:10:59 +04:00
2020-02-10 22:07:20 +04:00
// Two entrypoints
2019-12-05 20:10:59 +04:00
2020-02-10 22:07:20 +04:00
function add (const store : storage; const delta : int) : storage is store + delta
function sub (const store : storage; const delta : int) : storage is store - delta
2019-12-05 20:10:59 +04:00
2020-02-10 22:07:20 +04:00
(* Main access point that dispatches to the entrypoints according to
the smart contract parameter. *)
function main (const action : parameter; const store : storage) : return is
((nil : list (operation)), // No operations
case action of
Increment (n) -> add (store, n)
| Decrement (n) -> sub (store, n)
| Reset -> 0
end)
2019-12-05 20:10:59 +04:00
${pre}`;
const CAMELIGO_EXAMPLE = `${pre}ocaml
type storage = int
2020-02-10 22:07:20 +04:00
type parameter =
Increment of int
| Decrement of int
2020-02-10 22:07:20 +04:00
| Reset
2019-12-05 20:10:59 +04:00
2020-02-10 22:07:20 +04:00
type return = operation list * storage
2019-12-05 20:10:59 +04:00
2020-02-10 22:07:20 +04:00
// Two entrypoints
2019-12-05 20:10:59 +04:00
2020-02-10 22:07:20 +04:00
let add (store, delta : storage * int) : storage = store + delta
let sub (store, delta : storage * int) : storage = store - delta
(* Main access point that dispatches to the entrypoints according to
the smart contract parameter. *)
let main (action, store : parameter * storage) : return =
([] : operation list), // No operations
(match action with
Increment (n) -> add (store, n)
| Decrement (n) -> sub (store, n)
| Reset -> 0)
2019-12-05 20:10:59 +04:00
${pre}`;
2019-12-10 17:47:31 +04:00
const REASONLIGO_EXAMPLE = `${pre}reasonligo
type storage = int;
2020-02-10 22:07:20 +04:00
type parameter =
Increment (int)
| Decrement (int)
| Reset;
type return = (list (operation), storage);
2020-02-10 22:07:20 +04:00
(* Two entrypoints *)
2019-12-10 17:47:31 +04:00
2020-02-10 22:07:20 +04:00
let add = ((store, delta) : (storage, int)) : storage => store + delta;
let sub = ((store, delta) : (storage, int)) : storage => store - delta;
2019-12-10 17:47:31 +04:00
2020-02-10 22:07:20 +04:00
(* Main access point that dispatches to the entrypoints according to
the smart contract parameter. *)
2019-12-10 17:47:31 +04:00
2020-02-10 22:07:20 +04:00
let main = ((action, store) : (parameter, storage)) : return => {
(([] : list (operation)), // No operations
(switch (action) {
| Increment (n) => add ((store, n))
| Decrement (n) => sub ((store, n))
| Reset => 0}))
2019-12-10 17:47:31 +04:00
};
${pre}`;
2019-12-05 20:10:59 +04:00
module.exports = props => {
const MarkdownBlock = props.MarkdownBlock;
return (
<div className="tabs">
<div className="nav-tabs">
<div
className="nav-link active"
data-group="examples"
data-tab="pascaligo"
>
PascaLIGO
</div>
<div className="nav-link" data-group="examples" data-tab="cameligo">
CameLIGO
</div>
2019-12-10 17:47:31 +04:00
<div className="nav-link" data-group="examples" data-tab="reasonligo">
ReasonLIGO
</div>
2019-12-05 20:10:59 +04:00
</div>
<div className="tab-content">
<div id="pascaligo" className="tab-pane active" data-group="examples">
<MarkdownBlock>{PASCALIGO_EXAMPLE}</MarkdownBlock>
</div>
<div id="cameligo" className="tab-pane" data-group="examples">
<MarkdownBlock>{CAMELIGO_EXAMPLE}</MarkdownBlock>
</div>
2019-12-10 17:47:31 +04:00
<div id="reasonligo" className="tab-pane" data-group="examples">
<MarkdownBlock>{REASONLIGO_EXAMPLE}</MarkdownBlock>
</div>
2019-12-05 20:10:59 +04:00
</div>
</div>
);
};