2020-03-04 17:19:00 +04:00
|
|
|
import React from 'react';
|
|
|
|
import Highlight, { defaultProps } from "prism-react-renderer";
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
import useThemeContext from '@theme/hooks/useThemeContext';
|
|
|
|
import defaultTheme from 'prism-react-renderer/themes/palenight';
|
|
|
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
|
|
|
|
|
|
const PASCALIGO_EXAMPLE = `
|
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-03-04 17:19:00 +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)
|
2020-03-04 17:19:00 +04:00
|
|
|
`;
|
2019-12-05 20:10:59 +04:00
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
const CAMELIGO_EXAMPLE = `
|
2019-12-05 20:10:59 +04:00
|
|
|
type storage = int
|
|
|
|
|
2020-02-10 22:07:20 +04:00
|
|
|
type parameter =
|
|
|
|
Increment of int
|
2020-01-21 07:42:22 +04:00
|
|
|
| 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)
|
2020-03-04 17:19:00 +04:00
|
|
|
`;
|
2019-12-05 20:10:59 +04:00
|
|
|
|
2019-12-10 17:47:31 +04:00
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
const REASONLIGO_EXAMPLE = `
|
2019-12-10 17:47:31 +04:00
|
|
|
type storage = int;
|
|
|
|
|
2020-02-10 22:07:20 +04:00
|
|
|
type parameter =
|
|
|
|
Increment (int)
|
|
|
|
| Decrement (int)
|
|
|
|
| Reset;
|
|
|
|
|
|
|
|
type return = (list (operation), storage);
|
2020-01-21 07:42:22 +04:00
|
|
|
|
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
|
|
|
};
|
2020-03-04 17:19:00 +04:00
|
|
|
`;
|
2019-12-10 17:47:31 +04:00
|
|
|
|
|
|
|
|
2020-03-04 17:19:00 +04:00
|
|
|
function CodeExamples (props) {
|
|
|
|
const {
|
|
|
|
siteConfig: {
|
|
|
|
themeConfig: {prism = {}},
|
|
|
|
},
|
|
|
|
} = useDocusaurusContext();
|
|
|
|
const {isDarkTheme} = useThemeContext();
|
|
|
|
const lightModeTheme = prism.theme || defaultTheme;
|
|
|
|
const darkModeTheme = prism.darkTheme || lightModeTheme;
|
|
|
|
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
|
2019-12-05 20:10:59 +04:00
|
|
|
|
|
|
|
return (
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
<Tabs
|
|
|
|
defaultValue="pascaligo"
|
|
|
|
values={[
|
|
|
|
{ label: 'PascaLIGO', value: 'pascaligo', },
|
|
|
|
{ label: 'CameLIGO', value: 'cameligo', },
|
|
|
|
{ label: 'ReasonLIGO', value: 'reasonligo', },
|
|
|
|
]
|
|
|
|
}>
|
|
|
|
<TabItem value="pascaligo">
|
|
|
|
<Highlight {...defaultProps} language="pascaligo" code={PASCALIGO_EXAMPLE} theme={prismTheme}>
|
|
|
|
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
|
|
|
<pre className={className} style={style}>
|
|
|
|
{tokens.map((line, i) => (
|
|
|
|
<div {...getLineProps({ line, key: i })}>
|
|
|
|
{line.map((token, key) => (
|
|
|
|
<span {...getTokenProps({ token, key })} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</pre>
|
|
|
|
)}
|
|
|
|
</Highlight>
|
|
|
|
</TabItem>
|
|
|
|
<TabItem value="cameligo">
|
|
|
|
|
|
|
|
<Highlight {...defaultProps} language="cameligo" code={CAMELIGO_EXAMPLE} theme={prismTheme}>
|
|
|
|
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
|
|
|
<pre className={className} style={style}>
|
|
|
|
{tokens.map((line, i) => (
|
|
|
|
<div {...getLineProps({ line, key: i })}>
|
|
|
|
{line.map((token, key) => (
|
|
|
|
<span {...getTokenProps({ token, key })} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</pre>
|
|
|
|
)}
|
|
|
|
</Highlight>
|
|
|
|
</TabItem>
|
|
|
|
<TabItem value="reasonligo">
|
|
|
|
|
|
|
|
<Highlight {...defaultProps} language="reasonligo" code={REASONLIGO_EXAMPLE} theme={prismTheme}>
|
|
|
|
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
|
|
|
<pre className={className} style={style}>
|
|
|
|
{tokens.map((line, i) => (
|
|
|
|
<div {...getLineProps({ line, key: i })}>
|
|
|
|
{line.map((token, key) => (
|
|
|
|
<span {...getTokenProps({ token, key })} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</pre>
|
|
|
|
)}
|
|
|
|
</Highlight>
|
|
|
|
</TabItem>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</Tabs>
|
2019-12-05 20:10:59 +04:00
|
|
|
);
|
|
|
|
};
|
2020-03-04 17:19:00 +04:00
|
|
|
|
|
|
|
export default CodeExamples
|