Merge branch 'api-docs/big_map' into 'dev'

Add syntax specific titles to Big_map

See merge request ligolang/ligo!493
This commit is contained in:
Sander 2020-03-12 13:05:00 +00:00
commit f176d36dd8
20 changed files with 4162 additions and 249 deletions

View File

@ -17,7 +17,7 @@ services:
# - ./website/versioned_docs:/app/website/versioned_docs # - ./website/versioned_docs:/app/website/versioned_docs
- ./website/sidebars.json:/app/website/sidebars.json - ./website/sidebars.json:/app/website/sidebars.json
- ./website/docusaurus.config.js:/app/website/docusaurus.config.js - ./website/docusaurus.config.js:/app/website/docusaurus.config.js
- ./website/versions.json:/app/website/versions.json # - ./website/versions.json:/app/website/versions.json
# - ./website/core/AlgoliaSearch.js:/app/website/core/AlgoliaSearch.js # - ./website/core/AlgoliaSearch.js:/app/website/core/AlgoliaSearch.js
working_dir: /app/website working_dir: /app/website

View File

@ -1,25 +1,36 @@
--- ---
id: big-map-reference id: big-map-reference
title: Big Maps — Scalable Maps title: Big_map
description: A lazily deserialized map that's intended to store large amounts of data.
hide_table_of_contents: true
--- ---
import Syntax from '@theme/Syntax'; import Syntax from '@theme/Syntax';
import SyntaxTitle from '@theme/SyntaxTitle';
Ordinary maps are fine for contracts with a finite lifespan or a A lazily deserialized map that's intended to store large amounts of data.
bounded number of users. For many contracts however, the intention is
to have a map holding *many* entries, potentially millions of
them. The cost of loading those entries into the environment each time
a user executes the contract would eventually become too expensive
were it not for *big maps*. Big maps are a data structure offered by
Michelson which handles the scaling concerns for us. In LIGO, the
interface for big maps is analogous to the one used for ordinary maps.
# Declaring a Map The gast costs of deserialized maps are higher than standard maps as data is lazily deserialized.
<SyntaxTitle syntax="pascaligo">
type big_map (key, value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
type ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
type big_map ('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=big_maps The type of a big map from values of type `key` to
values of type `value` is `big_map (key, value)`.
```pascaligo group=big_map
type move is int * int type move is int * int
type register is big_map (address, move) type register is big_map (address, move)
``` ```
@ -27,67 +38,101 @@ type register is big_map (address, move)
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=big_maps The type of a big map from values of type `key` to values
of type `value` is `(key, value) big_map`.
```cameligo group=big_map
type move = int * int type move = int * int
type register = (address, move) big_map type register = (address, move) big_map
``` ```
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
The type of a big map from values of type `key` to
values of type `value` is `big_map (key, value)`.
```reasonligo group=big_maps ```reasonligo group=big_map
type move = (int, int); type move = (int, int);
type register = big_map (address, move); type register = big_map (address, move);
``` ```
</Syntax> </Syntax>
<SyntaxTitle syntax="pascaligo">
function empty : big_map (key, value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val empty : ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let empty: big_map ('key, 'value)
</SyntaxTitle>
Create an empty big_map.
# Creating an Empty Big Map
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=big_maps ```pascaligo group=big_map
const empty : register = big_map [] const empty : register = Big_map.empty
```
Alternatively, you can also create an empty big_map using:
```pascaligo group=big_map
const empty_alternative : register = big_map []
``` ```
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=big_maps ```cameligo group=big_map
let empty : register = Big_map.empty let empty : register = Big_map.empty
``` ```
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=big_maps ```reasonligo group=big_map
let empty : register = Big_map.empty let empty : register = Big_map.empty
``` ```
</Syntax> </Syntax>
# Creating a Non-empty Map <SyntaxTitle syntax="pascaligo">
function literal : list (key * value) -> big_map (key, value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val literal : ('key * 'value) list -> ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let literal: list(('key, 'value)) => big_map('key, 'value)
</SyntaxTitle>
Create a non-empty big_map.
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=big_maps ```pascaligo group=big_map
const moves : register = const moves : register =
Big_map.literal (list [
(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2));
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (0,3))]);
```
Alternative way of creating an empty big_map:
```pascaligo group=big_map
const moves_alternative : register =
big_map [ big_map [
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2); ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2);
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)] ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (0,3)];
``` ```
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=big_maps ```cameligo group=big_map
let moves : register = let moves : register =
Big_map.literal [ Big_map.literal [
(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2)); (("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), (1,2));
@ -97,7 +142,7 @@ let moves : register =
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=big_maps ```reasonligo group=big_map
let moves : register = let moves : register =
Big_map.literal ([ Big_map.literal ([
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)), ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address, (1,2)),
@ -106,21 +151,40 @@ let moves : register =
</Syntax> </Syntax>
<SyntaxTitle syntax="pascaligo">
function find_opt : key -> big_map (key, value) -> option value
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val find_opt : 'key -> ('key, 'value) big_map -> 'value option
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let find_opt : ('key, big_map ('key, 'value)) => option ('value)
</SyntaxTitle>
# Accessing Values Retrieve a value from a big map with the given key.
Because the key may be missing in the big map, the result is an
*optional value*.
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=big_maps ```pascaligo group=big_map
const my_balance : option (move) = const my_balance : option (move) =
moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)] Big_map.find_opt (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), moves)
```
Alternatively:
```pascaligo group=big_map
const my_balance_alternative : option (move) =
moves [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)];
``` ```
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=big_maps ```cameligo group=big_map
let my_balance : move option = let my_balance : move option =
Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) moves
``` ```
@ -128,33 +192,62 @@ let my_balance : move option =
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=big_maps ```reasonligo group=big_map
let my_balance : option (move) = let my_balance : option (move) =
Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves); Big_map.find_opt ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address, moves);
``` ```
</Syntax> </Syntax>
<SyntaxTitle syntax="pascaligo">
function update : key -> option value -> big_map (key, value) -> big_map (key, value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val update: 'key -> 'value option -> ('key, 'value) big_map -> ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let update: ('key, option('value), big_map ('key, 'value)) => big_map ('key, 'value)
</SyntaxTitle>
Note: when `None` is used as a value, the value is removed from the big_map.
# Updating Big Maps
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=big_maps ```pascaligo group=big_map
function add (var m : register) : register is const updated_big_map : register = Big_map.update(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some (4,9), moves);
```
Alternatively:
```pascaligo group=big_map
function update (var m : register) : register is
block { block {
m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9) m [("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address)] := (4,9);
} with m } with m
const updated_map : register = add (moves)
``` ```
If multiple bindings need to be updated, PascaLIGO offers a *patch
instruction* for maps, similar to that for records.
```pascaligo group=big_map
function assignments (var m : register) : register is
block {
patch m with map [
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) -> (4,9);
("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address) -> (1,2)
]
} with m
```
> Note the use of the keyword `map` instead of `big_map` (which is not
> a keyword).
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=big_maps ```cameligo group=big_map
let updated_map : register = let updated_map : register =
Big_map.update Big_map.update
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (Some (4,9)) moves
@ -163,7 +256,7 @@ let updated_map : register =
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=big_maps ```reasonligo group=big_map
let updated_map : register = let updated_map : register =
Big_map.update Big_map.update
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves); (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), Some ((4,9)), moves);
@ -171,14 +264,64 @@ let updated_map : register =
</Syntax> </Syntax>
<SyntaxTitle syntax="pascaligo">
function add : key -> value -> big_map (key, value) -> big_map (key, value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val add : 'key -> 'value -> ('key, 'value) big_map -> ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let add: ('key, 'value, big_map('key, 'value)) => big_map('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo">
# Removing Bindings ```pascaligo group=big_map
const added_item : register = Big_map.add (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4, 9), moves)
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo group=big_map
let add (m : register) : register =
Big_map.add
("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address) (4,9) m
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo group=big_map
let add = (m: register): register =>
Big_map.add
(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address), (4,9), m);
```
</Syntax>
<SyntaxTitle syntax="pascaligo">
function remove: key -> big_map (key, value) -> big_map (key, value)
</SyntaxTitle>
<SyntaxTitle syntax="cameligo">
val remove: 'key -> ('key, 'value) big_map -> ('key, 'value) big_map
</SyntaxTitle>
<SyntaxTitle syntax="reasonligo">
let remove: (key, big_map ('key, 'value)) => big_map ('key, 'value)
</SyntaxTitle>
<Syntax syntax="pascaligo"> <Syntax syntax="pascaligo">
```pascaligo group=big_maps ```pascaligo group=big_map
const updated_map : register =
Big_map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves)
```
Alternatively, the instruction `remove key from map m` removes the key
`key` from the big map `m` (note that the keyword is `map`, not
`big_map`).
```pascaligo group=big_map
function rem (var m : register) : register is function rem (var m : register) : register is
block { block {
remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) from map moves remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) from map moves
@ -190,17 +333,17 @@ const updated_map : register = rem (moves)
</Syntax> </Syntax>
<Syntax syntax="cameligo"> <Syntax syntax="cameligo">
```cameligo group=big_maps ```cameligo group=big_map
let updated_map : register = let updated_map : register =
Map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves Big_map.remove ("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address) moves
``` ```
</Syntax> </Syntax>
<Syntax syntax="reasonligo"> <Syntax syntax="reasonligo">
```reasonligo group=big_maps ```reasonligo group=big_map
let updated_map : register = let updated_map : register =
Map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves) Big_map.remove (("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN": address), moves)
``` ```
</Syntax> </Syntax>

View File

@ -99,7 +99,6 @@ const siteConfig = {
},*/ },*/
// Add custom scripts here that would be placed in <script> tags. // Add custom scripts here that would be placed in <script> tags.
scripts: ['https://buttons.github.io/buttons.js'],
// On page navigation for the current documentation page. // On page navigation for the current documentation page.
// No .html extensions for paths. // No .html extensions for paths.
@ -113,10 +112,11 @@ const siteConfig = {
// You may provide arbitrary config keys to be used as needed by your // You may provide arbitrary config keys to be used as needed by your
// template. For example, if you need your repo's URL... // template. For example, if you need your repo's URL...
// repoUrl: repoUrl, // repoUrl: repoUrl,
stylesheets: [ plugins: [
'https://fonts.googleapis.com/css?family=DM+Sans:400,400i,500,500i,700,700i|Open+Sans:300,300i,400,600|Source+Code+Pro&display=swap' '@ligo/syntax', {
],
}
],
presets: [ presets: [
[ [

View File

@ -14,11 +14,18 @@
"webpack": "4.41.2" "webpack": "4.41.2"
}, },
"browserslist": { "browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"], "production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [ "development": [
"last 1 chrome version", "last 1 chrome version",
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"dependencies": {
"@ligo/syntax": "file:src/@ligo/syntax"
} }
} }

View File

@ -0,0 +1,12 @@
const path = require('path');
module.exports = function (context, options) {
return {
name: 'ligo-syntax-plugin',
getThemePath() {
return path.resolve(__dirname, './theme');
}
};
};

View File

@ -0,0 +1,3 @@
import React from 'react';
const SyntaxContext = React.createContext('pascaligo');
export default SyntaxContext;

View File

@ -0,0 +1,18 @@
import React from 'react';
import styles from './styles.module.css';
function SyntaxSwitch(props) {
return React.createElement("select", {
className: styles.syntaxSwitch,
defaultValue: props.syntax,
onChange: e => props.onSyntaxChange(e.target.value)
}, React.createElement("option", {
value: "pascaligo"
}, "PascaLIGO"), React.createElement("option", {
value: "cameligo"
}, "CameLIGO"), React.createElement("option", {
value: "reasonligo"
}, "ReasonLIGO"));
}
export default SyntaxSwitch;

View File

@ -0,0 +1,15 @@
import React from 'react';
import SyntaxContext from './SyntaxContext';
function Syntax(props) {
return React.createElement(SyntaxContext.Consumer, null, syntax => {
if (syntax === props.syntax) {
return props.children;
} else {
return React.createElement(React.Fragment, null);
}
});
}
export default Syntax;
export { SyntaxContext };

View File

@ -0,0 +1,111 @@
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { useEffect, useState, useRef } from 'react';
import Highlight, { defaultProps } from "prism-react-renderer"; // THE PROBLEM IS USE THEME CONTEXT ==>>>>
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useThemeContext from '@theme/hooks/useThemeContext';
import { SyntaxContext } from '@theme/Syntax';
import defaultTheme from 'prism-react-renderer/themes/palenight';
const {
Prism
} = require("prism-react-renderer");
Prism.languages = { ...Prism.languages,
pascaligo: {
'comment': [/\(\*[\s\S]+?\*\)/, // /\{[\s\S]+?\}/,
/\/\/.*/],
'string': {
pattern: /(?:'(?:''|[^'\r\n])*'|#[&$%]?[a-f\d]+)+|\^[a-z]/i,
greedy: true
},
'keyword': [{
// Turbo Pascal
pattern: /(^|[^&])\b(?:absolute|array|asm|begin|case|const|constructor|destructor|do|downto|else|end|file|for|function|goto|if|implementation|inherited|inline|interface|label|nil|object|of|operator|packed|procedure|program|record|reintroduce|repeat|self|set|string|then|to|type|unit|until|uses|var|while|with)\b/i,
lookbehind: true
}, {
// Free Pascal
pattern: /(^|[^&])\b(?:dispose|exit|false|new|true)\b/i,
lookbehind: true
}, {
// Object Pascal
pattern: /(^|[^&])\b(?:class|dispinterface|except|exports|finalization|finally|initialization|inline|library|on|out|packed|property|raise|resourcestring|threadvar|try)\b/i,
lookbehind: true
}, {
// Modifiers
pattern: /(^|[^&])\b(?:absolute|abstract|alias|assembler|bitpacked|break|cdecl|continue|cppdecl|cvar|default|deprecated|dynamic|enumerator|experimental|export|external|far|far16|forward|generic|helper|implements|index|interrupt|iochecks|local|message|name|near|nodefault|noreturn|nostackframe|oldfpccall|otherwise|overload|override|pascal|platform|private|protected|public|published|read|register|reintroduce|result|safecall|saveregisters|softfloat|specialize|static|stdcall|stored|strict|unaligned|unimplemented|varargs|virtual|write)\b/i,
lookbehind: true
}],
'number': [// Hexadecimal, octal and binary
/(?:[&%]\d+|\$[a-f\d]+)/i, // Decimal
/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?/i],
'operator': [/\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=]/i, {
pattern: /(^|[^&])\b(?:and|as|div|exclude|in|include|is|mod|not|or|shl|shr|xor)\b/,
lookbehind: true
}],
'punctuation': /\(\.|\.\)|[()\[\]:;,.]/
},
reasonligo: { ...Prism.languages.reason,
'comment': [/(^|[^\\])\/\*[\s\S]*?\*\//, /\(\*[\s\S]*?\*\)/, /\/\/.*/]
},
cameligo: { ...Prism.languages.ocaml,
'comment': [/(^|[^\\])\/\*[\s\S]*?\*\//, /\(\*[\s\S]*?\*\)/, /\/\/.*/]
}
};
function SyntaxTitle(props) {
const {
siteConfig: {
themeConfig: {
prism = {}
}
}
} = useDocusaurusContext();
const {
isDarkTheme
} = useThemeContext();
const lightModeTheme = prism.theme || defaultTheme;
const darkModeTheme = prism.darkTheme || lightModeTheme;
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
return React.createElement(SyntaxContext.Consumer, null, syntax => {
if (syntax === props.syntax) {
return React.createElement(Highlight, _extends({}, defaultProps, {
key: mounted,
language: props.syntax,
code: props.children,
theme: prismTheme
}), ({
className,
style,
tokens,
getLineProps,
getTokenProps
}) => React.createElement("pre", {
className: className,
style: {
backgroundColor: 'var(--ifm-background-color)',
fontSize: '1.1rem',
fontWeight: 'bold',
padding: 0,
whiteSpace: 'break-spaces',
marginTop: '3rem'
}
}, tokens.map((line, i) => React.createElement("div", getLineProps({
line,
key: i
}), line.map((token, key) => React.createElement("span", getTokenProps({
token,
key
})))))));
} else {
return React.createElement("div", null);
}
});
}
export default SyntaxTitle;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
{
"name": "@ligo/syntax",
"description": "Switch between different syntaxes",
"version": "0.0.0",
"main": "output/index.js",
"peerDependencies": {
"@docusaurus/core": "^2.0.0-alpha.43",
"@docusaurus/preset-classic": "^2.0.0-alpha.43",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"webpack": "4.41.2"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@babel/preset-react": "^7.8.3",
"prism-react-renderer": "^1.0.2"
},
"babel": {
"presets": [
"@babel/preset-react"
]
},
"scripts": {
"build": "rm -rf output && mkdir output && node_modules/.bin/babel src/theme/Syntax/*.js -d output/theme/Syntax/ && node_modules/.bin/babel src/theme/SyntaxTitle/*.js -d output/theme/SyntaxTitle/ && node_modules/.bin/babel src/*.js -d output/ && cp ./src/theme/Syntax/styles.module.css output/theme/Syntax/"
}
}

View File

@ -0,0 +1,11 @@
const path = require('path');
module.exports = function(context, options) {
return {
name: 'ligo-syntax-plugin',
getThemePath() {
return path.resolve(__dirname, './theme');
}
}
}

View File

@ -3,4 +3,3 @@ import React from 'react';
const SyntaxContext = React.createContext('pascaligo'); const SyntaxContext = React.createContext('pascaligo');
export default SyntaxContext; export default SyntaxContext;

View File

@ -16,3 +16,5 @@ function Syntax(props) {
} }
export default Syntax export default Syntax
export { SyntaxContext }

View File

@ -0,0 +1,37 @@
.syntaxSwitch {
display: block;
font-size: 1rem;
font-weight: bold;
line-height: 1rem;
padding: .6em 1.4em .5em .8em;
box-sizing: border-box;
border: none;
color: var(--color-primary-text);
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
background-color: transparent;
background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23007CB2%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
background-repeat: no-repeat, repeat;
background-position: right .7em top 50%, 0 0;
background-size: .65em auto, 100%;
}
.syntaxSwitch::-ms-expand {
display: none;
}
.syntaxSwitch:hover {
border-color: #888;
}
.syntaxSwitch:focus {
border-color: #aaa;
box-shadow: 0 0 1px 3px rgba(59, 153, 252, .7);
box-shadow: 0 0 0 3px -moz-mac-focusring;
color: var(--color-primary-text);
outline: none;
}
.syntaxSwitch option {
color: var(--color-primary-text);
font-weight:normal;
}

View File

@ -0,0 +1,126 @@
import React, {useEffect, useState, useRef} from 'react';
import Highlight, { defaultProps } from "prism-react-renderer";
// THE PROBLEM IS USE THEME CONTEXT ==>>>>
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useThemeContext from '@theme/hooks/useThemeContext';
import { SyntaxContext } from '@theme/Syntax';
import defaultTheme from 'prism-react-renderer/themes/palenight';
const {Prism} = require("prism-react-renderer");
Prism.languages = {
...Prism.languages,
pascaligo: {
'comment': [
/\(\*[\s\S]+?\*\)/,
// /\{[\s\S]+?\}/,
/\/\/.*/
],
'string': {
pattern: /(?:'(?:''|[^'\r\n])*'|#[&$%]?[a-f\d]+)+|\^[a-z]/i,
greedy: true
},
'keyword': [
{
// Turbo Pascal
pattern: /(^|[^&])\b(?:absolute|array|asm|begin|case|const|constructor|destructor|do|downto|else|end|file|for|function|goto|if|implementation|inherited|inline|interface|label|nil|object|of|operator|packed|procedure|program|record|reintroduce|repeat|self|set|string|then|to|type|unit|until|uses|var|while|with)\b/i,
lookbehind: true
},
{
// Free Pascal
pattern: /(^|[^&])\b(?:dispose|exit|false|new|true)\b/i,
lookbehind: true
},
{
// Object Pascal
pattern: /(^|[^&])\b(?:class|dispinterface|except|exports|finalization|finally|initialization|inline|library|on|out|packed|property|raise|resourcestring|threadvar|try)\b/i,
lookbehind: true
},
{
// Modifiers
pattern: /(^|[^&])\b(?:absolute|abstract|alias|assembler|bitpacked|break|cdecl|continue|cppdecl|cvar|default|deprecated|dynamic|enumerator|experimental|export|external|far|far16|forward|generic|helper|implements|index|interrupt|iochecks|local|message|name|near|nodefault|noreturn|nostackframe|oldfpccall|otherwise|overload|override|pascal|platform|private|protected|public|published|read|register|reintroduce|result|safecall|saveregisters|softfloat|specialize|static|stdcall|stored|strict|unaligned|unimplemented|varargs|virtual|write)\b/i,
lookbehind: true
}
],
'number': [
// Hexadecimal, octal and binary
/(?:[&%]\d+|\$[a-f\d]+)/i,
// Decimal
/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?/i
],
'operator': [
/\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=]/i,
{
pattern: /(^|[^&])\b(?:and|as|div|exclude|in|include|is|mod|not|or|shl|shr|xor)\b/,
lookbehind: true
}
],
'punctuation': /\(\.|\.\)|[()\[\]:;,.]/
},
reasonligo:
{...Prism.languages.reason,
'comment': [
/(^|[^\\])\/\*[\s\S]*?\*\//,
/\(\*[\s\S]*?\*\)/,
/\/\/.*/
]
},
cameligo: {
...Prism.languages.ocaml,
'comment': [
/(^|[^\\])\/\*[\s\S]*?\*\//,
/\(\*[\s\S]*?\*\)/,
/\/\/.*/
]}
};
function SyntaxTitle(props) {
const {
siteConfig: {
themeConfig: {prism = {}},
}
} = useDocusaurusContext();
const {isDarkTheme} = useThemeContext();
const lightModeTheme = prism.theme || defaultTheme;
const darkModeTheme = prism.darkTheme || lightModeTheme;
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
return (
<SyntaxContext.Consumer>
{(syntax => {
if (syntax === props.syntax) {
return (
<Highlight {...defaultProps} key={mounted} language={props.syntax} code={props.children} theme={prismTheme}>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<pre className={className} style={{backgroundColor: 'var(--ifm-background-color)', fontSize: '1.1rem', fontWeight: 'bold', padding: 0, whiteSpace: 'break-spaces', marginTop: '3rem' }}>
{tokens.map((line, i) => (
<div {...getLineProps({ line, key: i })}>
{line.map((token, key) => (
<span {...getTokenProps({ token, key })} />
))}
</div>
))}
</pre>
)}
</Highlight>
)
} else {
return <div></div>
}
})}
</SyntaxContext.Consumer>
);
}
export default SyntaxTitle;

View File

@ -15,7 +15,7 @@ import isInternalUrl from '@docusaurus/utils'; // eslint-disable-line import/no-
import styles from './styles.module.css'; import styles from './styles.module.css';
import SyntaxSwitch from '../Syntax/SyntaxSwitch'; import SyntaxSwitch from '@theme/Syntax/SyntaxSwitch';
const MOBILE_TOGGLE_SIZE = 24; const MOBILE_TOGGLE_SIZE = 24;

View File

@ -62,42 +62,122 @@ module Simplify = struct
| "contract" -> ok @@ TC_contract unit_expr | "contract" -> ok @@ TC_contract unit_expr
| _ -> simple_fail @@ "Not a built-in type (" ^ s ^ ")." | _ -> simple_fail @@ "Not a built-in type (" ^ s ^ ")."
let pseudo_modules = function
| "Tezos.chain_id" -> ok C_CHAIN_ID
| "Tezos.balance" -> ok C_BALANCE
| "Tezos.now" -> ok C_NOW
| "Tezos.amount" -> ok C_AMOUNT
| "Tezos.sender" -> ok C_SENDER
| "Tezos.address" -> ok C_ADDRESS
| "Tezos.self" -> ok C_SELF
| "Tezos.self_address" -> ok C_SELF_ADDRESS
| "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT
| "Tezos.source" -> ok C_SOURCE
| "Tezos.failwith" -> ok C_FAILWITH
| "Tezos.create_contract" -> ok C_CREATE_CONTRACT
| "Tezos.transaction" -> ok C_CALL
| "Tezos.set_delegate" -> ok C_SET_DELEGATE
| "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT
| "Tezos.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT
(* Crypto module *)
| "Crypto.check" -> ok C_CHECK_SIGNATURE
| "Crypto.hash_key" -> ok C_HASH_KEY
| "Crypto.blake2b" -> ok C_BLAKE2b
| "Crypto.sha256" -> ok C_SHA256
| "Crypto.sha512" -> ok C_SHA512
(* Bytes module *)
| "Bytes.pack" -> ok C_BYTES_PACK
| "Bytes.unpack" -> ok C_BYTES_UNPACK
| "Bytes.length" -> ok C_SIZE
| "Bytes.concat" -> ok C_CONCAT
| "Bytes.sub" -> ok C_SLICE
(* List module *)
| "List.length" -> ok C_SIZE
| "List.size" -> ok C_SIZE
| "List.iter" -> ok C_LIST_ITER
| "List.map" -> ok C_LIST_MAP
| "List.fold" -> ok C_LIST_FOLD
(* Set module *)
| "Set.empty" -> ok C_SET_EMPTY
| "Set.literal" -> ok C_SET_LITERAL
| "Set.cardinal" -> ok C_SIZE
| "Set.mem" -> ok C_SET_MEM
| "Set.add" -> ok C_SET_ADD
| "Set.remove" -> ok C_SET_REMOVE
| "Set.iter" -> ok C_SET_ITER
| "Set.fold" -> ok C_SET_FOLD
(* Map module *)
| "Map.find_opt" -> ok C_MAP_FIND_OPT
| "Map.update" -> ok C_MAP_UPDATE
| "Map.iter" -> ok C_MAP_ITER
| "Map.map" -> ok C_MAP_MAP
| "Map.fold" -> ok C_MAP_FOLD
| "Map.mem" -> ok C_MAP_MEM
| "Map.size" -> ok C_SIZE
| "Map.add" -> ok C_MAP_ADD
| "Map.remove" -> ok C_MAP_REMOVE
| "Map.empty" -> ok C_MAP_EMPTY
| "Map.literal" -> ok C_MAP_LITERAL
(* Big_map module *)
| "Big_map.find" -> ok C_MAP_FIND
| "Big_map.find_opt" -> ok C_MAP_FIND_OPT
| "Big_map.update" -> ok C_MAP_UPDATE
| "Big_map.literal" -> ok C_BIG_MAP_LITERAL
| "Big_map.empty" -> ok C_BIG_MAP_EMPTY
| "Big_map.mem" -> ok C_MAP_MEM
| "Big_map.remove" -> ok C_MAP_REMOVE
| "Big_map.add" -> ok C_MAP_ADD
(* Bitwise module *)
| "Bitwise.or" -> ok C_OR
| "Bitwise.and" -> ok C_AND
| "Bitwise.xor" -> ok C_XOR
| "Bitwise.shift_left" -> ok C_LSL
| "Bitwise.shift_right" -> ok C_LSR
(* String module *)
| "String.length" -> ok C_SIZE
| "String.size" -> ok C_SIZE
| "String.slice" -> ok C_SLICE
| "String.sub" -> ok C_SLICE
| "String.concat" -> ok C_CONCAT
| _ -> simple_fail "Not a built-in"
module Pascaligo = struct module Pascaligo = struct
let constants = function let constants = function
(* Tezos module (ex-Michelson) *) (* Tezos module (ex-Michelson) *)
| "Tezos.chain_id" -> ok C_CHAIN_ID
| "chain_id" -> ok C_CHAIN_ID (* Deprecated *) | "chain_id" -> ok C_CHAIN_ID (* Deprecated *)
| "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *) | "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *)
| "Tezos.balance" -> ok C_BALANCE
| "balance" -> ok C_BALANCE (* Deprecated *) | "balance" -> ok C_BALANCE (* Deprecated *)
| "Tezos.now" -> ok C_NOW
| "now" -> ok C_NOW (* Deprecated *) | "now" -> ok C_NOW (* Deprecated *)
| "Tezos.amount" -> ok C_AMOUNT
| "amount" -> ok C_AMOUNT (* Deprecated *) | "amount" -> ok C_AMOUNT (* Deprecated *)
| "Tezos.sender" -> ok C_SENDER
| "sender" -> ok C_SENDER (* Deprecated *) | "sender" -> ok C_SENDER (* Deprecated *)
| "Tezos.address" -> ok C_ADDRESS
| "address" -> ok C_ADDRESS (* Deprecated *) | "address" -> ok C_ADDRESS (* Deprecated *)
| "Tezos.self" -> ok C_SELF
| "Tezos.self_address" -> ok C_SELF_ADDRESS
| "self_address" -> ok C_SELF_ADDRESS (* Deprecated *) | "self_address" -> ok C_SELF_ADDRESS (* Deprecated *)
| "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT
| "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) | "implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *)
| "Tezos.source" -> ok C_SOURCE
| "source" -> ok C_SOURCE (* Deprecated *) | "source" -> ok C_SOURCE (* Deprecated *)
| "Tezos.failwith" -> ok C_FAILWITH
| "failwith" -> ok C_FAILWITH | "failwith" -> ok C_FAILWITH
| "Tezos.create_contract" -> ok C_CREATE_CONTRACT
| "Tezos.transaction" -> ok C_CALL
| "transaction" -> ok C_CALL (* Deprecated *) | "transaction" -> ok C_CALL (* Deprecated *)
| "Tezos.set_delegate" -> ok C_SET_DELEGATE
| "set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) | "set_delegate" -> ok C_SET_DELEGATE (* Deprecated *)
| "get_contract" -> ok C_CONTRACT (* Deprecated *) | "get_contract" -> ok C_CONTRACT (* Deprecated *)
| "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT
| "get_contract_opt" -> ok C_CONTRACT_OPT (* Deprecated *) | "get_contract_opt" -> ok C_CONTRACT_OPT (* Deprecated *)
| "get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *) | "get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *)
| "Tezos.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT
| "get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *) | "get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *)
| "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *) | "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *)
@ -126,113 +206,64 @@ module Simplify = struct
(* Crypto module *) (* Crypto module *)
| "Crypto.check" -> ok C_CHECK_SIGNATURE
| "crypto_check" -> ok C_CHECK_SIGNATURE (* Deprecated *) | "crypto_check" -> ok C_CHECK_SIGNATURE (* Deprecated *)
| "Crypto.hash_key" -> ok C_HASH_KEY
| "crypto_hash_key" -> ok C_HASH_KEY (* Deprecated *) | "crypto_hash_key" -> ok C_HASH_KEY (* Deprecated *)
| "Crypto.blake2b" -> ok C_BLAKE2b
| "blake2b" -> ok C_BLAKE2b (* Deprecated *) | "blake2b" -> ok C_BLAKE2b (* Deprecated *)
| "Crypto.sha256" -> ok C_SHA256
| "sha_256" -> ok C_SHA256 (* Deprecated *) | "sha_256" -> ok C_SHA256 (* Deprecated *)
| "Crypto.sha512" -> ok C_SHA512
| "sha_512" -> ok C_SHA512 (* Deprecated *) | "sha_512" -> ok C_SHA512 (* Deprecated *)
(* Bytes module *) (* Bytes module *)
| "Bytes.pack" -> ok C_BYTES_PACK
| "bytes_pack" -> ok C_BYTES_PACK (* Deprecated *) | "bytes_pack" -> ok C_BYTES_PACK (* Deprecated *)
| "Bytes.unpack" -> ok C_BYTES_UNPACK
| "bytes_unpack" -> ok C_BYTES_UNPACK (* Deprecated *) | "bytes_unpack" -> ok C_BYTES_UNPACK (* Deprecated *)
| "Bytes.length" -> ok C_SIZE
| "Bytes.size" -> ok C_SIZE (* Deprecated *) | "Bytes.size" -> ok C_SIZE (* Deprecated *)
| "bytes_concat" -> ok C_CONCAT (* Deprecated *) | "bytes_concat" -> ok C_CONCAT (* Deprecated *)
| "Bytes.concat" -> ok C_CONCAT
| "Bytes.slice" -> ok C_SLICE
| "bytes_slice" -> ok C_SLICE (* Deprecated *) | "bytes_slice" -> ok C_SLICE (* Deprecated *)
| "Bytes.sub" -> ok C_SLICE | "Bytes.slice" -> ok C_SLICE (* Deprecated *)
(* List module *) (* List module *)
| "List.length" -> ok C_SIZE
| "List.size" -> ok C_SIZE
| "list_size" -> ok C_SIZE (* Deprecated *) | "list_size" -> ok C_SIZE (* Deprecated *)
| "List.iter" -> ok C_LIST_ITER
| "list_iter" -> ok C_LIST_ITER (* Deprecated *) | "list_iter" -> ok C_LIST_ITER (* Deprecated *)
| "List.map" -> ok C_LIST_MAP
| "list_map" -> ok C_LIST_MAP (* Deprecated *) | "list_map" -> ok C_LIST_MAP (* Deprecated *)
| "List.fold" -> ok C_LIST_FOLD
| "list_fold" -> ok C_LIST_FOLD (* Deprecated *) | "list_fold" -> ok C_LIST_FOLD (* Deprecated *)
(* Set module *) (* Set module *)
| "Set.cardinal" -> ok C_SIZE
| "Set.size" -> ok C_SIZE (* Deprecated *) | "Set.size" -> ok C_SIZE (* Deprecated *)
| "set_size" -> ok C_SIZE (* Deprecated *) | "set_size" -> ok C_SIZE (* Deprecated *)
| "set_empty" -> ok C_SET_EMPTY (* Deprecated *) | "set_empty" -> ok C_SET_EMPTY (* Deprecated *)
| "Set.mem" -> ok C_SET_MEM
| "set_mem" -> ok C_SET_MEM (* Deprecated *) | "set_mem" -> ok C_SET_MEM (* Deprecated *)
| "Set.add" -> ok C_SET_ADD
| "set_add" -> ok C_SET_ADD (* Deprecated *) | "set_add" -> ok C_SET_ADD (* Deprecated *)
| "Set.remove" -> ok C_SET_REMOVE
| "set_remove" -> ok C_SET_REMOVE (* Deprecated *) | "set_remove" -> ok C_SET_REMOVE (* Deprecated *)
| "Set.iter" -> ok C_SET_ITER
| "set_iter" -> ok C_SET_ITER (* Deprecated *) | "set_iter" -> ok C_SET_ITER (* Deprecated *)
| "Set.fold" -> ok C_SET_FOLD
| "set_fold" -> ok C_SET_FOLD (* Deprecated *) | "set_fold" -> ok C_SET_FOLD (* Deprecated *)
(* Map module *) (* Map module *)
| "get_force" -> ok C_MAP_FIND (* Deprecated *) | "get_force" -> ok C_MAP_FIND (* Deprecated *)
| "map_get" -> ok C_MAP_FIND_OPT (* Deprecated *) | "map_get" -> ok C_MAP_FIND_OPT (* Deprecated *)
| "Map.find_opt" -> ok C_MAP_FIND_OPT
| "Map.update" -> ok C_MAP_UPDATE
| "map_update" -> ok C_MAP_UPDATE (* Deprecated *) | "map_update" -> ok C_MAP_UPDATE (* Deprecated *)
| "map_remove" -> ok C_MAP_REMOVE (* Deprecated *) | "map_remove" -> ok C_MAP_REMOVE (* Deprecated *)
| "Map.iter" -> ok C_MAP_ITER
| "map_iter" -> ok C_MAP_ITER (* Deprecated *) | "map_iter" -> ok C_MAP_ITER (* Deprecated *)
| "Map.map" -> ok C_MAP_MAP
| "map_map" -> ok C_MAP_MAP (* Deprecated *) | "map_map" -> ok C_MAP_MAP (* Deprecated *)
| "Map.fold" -> ok C_MAP_FOLD
| "map_fold" -> ok C_MAP_FOLD (* Deprecated *) | "map_fold" -> ok C_MAP_FOLD (* Deprecated *)
| "Map.mem" -> ok C_MAP_MEM
| "map_mem" -> ok C_MAP_MEM (* Deprecated *) | "map_mem" -> ok C_MAP_MEM (* Deprecated *)
| "Map.size" -> ok C_SIZE
| "map_size" -> ok C_SIZE (* Deprecated *) | "map_size" -> ok C_SIZE (* Deprecated *)
(* Big_map module *)
| "Big_map.find_opt" -> ok C_MAP_FIND_OPT
| "Big_map.update" -> ok C_MAP_UPDATE
| "Big_map.literal" -> ok C_BIG_MAP_LITERAL
| "Big_map.empty" -> ok C_BIG_MAP_EMPTY
| "Big_map.size" -> ok C_SIZE
| "Big_map.mem" -> ok C_MAP_MEM
| "Big_map.iter" -> ok C_MAP_ITER
| "Big_map.map" -> ok C_MAP_MAP
| "Big_map.fold" -> ok C_MAP_FOLD
| "Big_map.remove" -> ok C_MAP_REMOVE
(* Bitwise module *) (* Bitwise module *)
| "Bitwise.or" -> ok C_OR
| "bitwise_or" -> ok C_OR (* Deprecated *) | "bitwise_or" -> ok C_OR (* Deprecated *)
| "Bitwise.and" -> ok C_AND
| "bitwise_and" -> ok C_AND (* Deprecated *) | "bitwise_and" -> ok C_AND (* Deprecated *)
| "Bitwise.xor" -> ok C_XOR
| "bitwise_xor" -> ok C_XOR (* Deprecated *) | "bitwise_xor" -> ok C_XOR (* Deprecated *)
| "Bitwise.shift_left" -> ok C_LSL
| "bitwise_lsl" -> ok C_LSL (* Deprecated *) | "bitwise_lsl" -> ok C_LSL (* Deprecated *)
| "Bitwise.shift_right" -> ok C_LSR
| "bitwise_lsr" -> ok C_LSR (* Deprecated *) | "bitwise_lsr" -> ok C_LSR (* Deprecated *)
(* String module *) (* String module *)
| "String.length" -> ok C_SIZE
| "String.size" -> ok C_SIZE
| "String.slice" -> ok C_SLICE
| "string_slice" -> ok C_SLICE (* Deprecated *) | "string_slice" -> ok C_SLICE (* Deprecated *)
| "String.sub" -> ok C_SLICE
| "String.concat" -> ok C_CONCAT
| "string_concat" -> ok C_CONCAT (* Deprecated *) | "string_concat" -> ok C_CONCAT (* Deprecated *)
(* Others *) (* Others *)
@ -240,56 +271,41 @@ module Simplify = struct
| "assert" -> ok C_ASSERTION | "assert" -> ok C_ASSERTION
| "size" -> ok C_SIZE (* Deprecated *) | "size" -> ok C_SIZE (* Deprecated *)
| _ -> simple_fail "Not a PascaLIGO built-in." | _ as c ->
pseudo_modules c
let type_constants = type_constants let type_constants = type_constants
let type_operators = type_operators let type_operators = type_operators
end end
module Cameligo = struct module Cameligo = struct
let constants = function let constants = function
(* Tezos (ex-Michelson, ex-Current, ex-Operation) *) (* Tezos (ex-Michelson, ex-Current, ex-Operation) *)
| "Tezos.chain_id" -> ok C_CHAIN_ID
| "chain_id" -> ok C_CHAIN_ID (* Deprecated *) | "chain_id" -> ok C_CHAIN_ID (* Deprecated *)
| "Tezos.balance" -> ok C_BALANCE
| "Current.balance" -> ok C_BALANCE (* Deprecated *) | "Current.balance" -> ok C_BALANCE (* Deprecated *)
| "balance" -> ok C_BALANCE (* Deprecated *) | "balance" -> ok C_BALANCE (* Deprecated *)
| "Tezos.now" -> ok C_NOW
| "Current.time" -> ok C_NOW (* Deprecated *) | "Current.time" -> ok C_NOW (* Deprecated *)
| "time" -> ok C_NOW (* Deprecated *) | "time" -> ok C_NOW (* Deprecated *)
| "Tezos.amount" -> ok C_AMOUNT
| "Current.amount" -> ok C_AMOUNT (* Deprecated *) | "Current.amount" -> ok C_AMOUNT (* Deprecated *)
| "amount" -> ok C_AMOUNT (* Deprecated *) | "amount" -> ok C_AMOUNT (* Deprecated *)
| "Tezos.sender" -> ok C_SENDER
| "Current.sender" -> ok C_SENDER (* Deprecated *) | "Current.sender" -> ok C_SENDER (* Deprecated *)
| "sender" -> ok C_SENDER (* Deprecated *) | "sender" -> ok C_SENDER (* Deprecated *)
| "Tezos.address" -> ok C_ADDRESS
| "Current.address" -> ok C_ADDRESS (* Deprecated *) | "Current.address" -> ok C_ADDRESS (* Deprecated *)
| "Tezos.self" -> ok C_SELF
| "Tezos.self_address" -> ok C_SELF_ADDRESS
| "Current.self_address" -> ok C_SELF_ADDRESS (* Deprecated *) | "Current.self_address" -> ok C_SELF_ADDRESS (* Deprecated *)
| "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT
| "Current.implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *) | "Current.implicit_account" -> ok C_IMPLICIT_ACCOUNT (* Deprecated *)
| "Tezos.source" -> ok C_SOURCE
| "Current.source" -> ok C_SOURCE (* Deprecated *) | "Current.source" -> ok C_SOURCE (* Deprecated *)
| "source" -> ok C_SOURCE (* Deprecated *) | "source" -> ok C_SOURCE (* Deprecated *)
| "Tezos.failwith" -> ok C_FAILWITH
| "Current.failwith" -> ok C_FAILWITH (* Deprecated *) | "Current.failwith" -> ok C_FAILWITH (* Deprecated *)
| "failwith" -> ok C_FAILWITH | "failwith" -> ok C_FAILWITH
| "Tezos.transaction" -> ok C_CALL
| "Operation.transaction" -> ok C_CALL (* Deprecated *) | "Operation.transaction" -> ok C_CALL (* Deprecated *)
| "Tezos.set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) | "Tezos.set_delegate" -> ok C_SET_DELEGATE (* Deprecated *)
| "Operation.set_delegate" -> ok C_SET_DELEGATE (* Deprecated *) | "Operation.set_delegate" -> ok C_SET_DELEGATE (* Deprecated *)
| "Operation.get_contract" -> ok C_CONTRACT (* Deprecated *) | "Operation.get_contract" -> ok C_CONTRACT (* Deprecated *)
| "Tezos.get_contract_opt" -> ok C_CONTRACT_OPT
| "Operation.get_contract_opt" -> ok C_CONTRACT_OPT (* Deprecated *) | "Operation.get_contract_opt" -> ok C_CONTRACT_OPT (* Deprecated *)
| "Operation.get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *) | "Operation.get_entrypoint" -> ok C_CONTRACT_ENTRYPOINT (* Deprecated *)
| "Tezos.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT
| "Operation.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *) | "Operation.get_entrypoint_opt" -> ok C_CONTRACT_ENTRYPOINT_OPT (* Deprecated *)
| "Tezos.create_contract" -> ok C_CREATE_CONTRACT
| "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *) | "Michelson.is_nat" -> ok C_IS_NAT (* Deprecated *)
| "is_nat" -> ok C_IS_NAT | "is_nat" -> ok C_IS_NAT
@ -314,87 +330,22 @@ module Simplify = struct
| "CONS" -> ok C_CONS | "CONS" -> ok C_CONS
| "NEQ" -> ok C_NEQ | "NEQ" -> ok C_NEQ
(* Crypto module *)
| "Crypto.check" -> ok C_CHECK_SIGNATURE
| "Crypto.hash_key" -> ok C_HASH_KEY
| "Crypto.blake2b" -> ok C_BLAKE2b
| "Crypto.sha256" -> ok C_SHA256
| "Crypto.sha512" -> ok C_SHA512
(* Bytes module *) (* Bytes module *)
| "Bytes.pack" -> ok C_BYTES_PACK
| "Bytes.unpack" -> ok C_BYTES_UNPACK
| "Bytes.length" -> ok C_SIZE
| "Bytes.size" -> ok C_SIZE (* Deprecated *) | "Bytes.size" -> ok C_SIZE (* Deprecated *)
| "Bytes.concat" -> ok C_CONCAT
| "Bytes.slice" -> ok C_SLICE (* Deprecated *) | "Bytes.slice" -> ok C_SLICE (* Deprecated *)
| "Bytes.sub" -> ok C_SLICE
(* List module *)
| "List.length" -> ok C_SIZE
| "List.size" -> ok C_SIZE
| "List.iter" -> ok C_LIST_ITER
| "List.map" -> ok C_LIST_MAP
| "List.fold" -> ok C_LIST_FOLD
(* Set module *) (* Set module *)
| "Set.mem" -> ok C_SET_MEM
| "Set.iter" -> ok C_SET_ITER
| "Set.empty" -> ok C_SET_EMPTY
| "Set.literal" -> ok C_SET_LITERAL
| "Set.add" -> ok C_SET_ADD
| "Set.remove" -> ok C_SET_REMOVE
| "Set.fold" -> ok C_SET_FOLD
| "Set.size" -> ok C_SIZE (* Deprecated *) | "Set.size" -> ok C_SIZE (* Deprecated *)
| "Set.cardinal" -> ok C_SIZE
(* Map module *) (* Map module *)
| "Map.find_opt" -> ok C_MAP_FIND_OPT
| "Map.find" -> ok C_MAP_FIND (* Deprecated *) | "Map.find" -> ok C_MAP_FIND (* Deprecated *)
| "Map.update" -> ok C_MAP_UPDATE
| "Map.add" -> ok C_MAP_ADD
| "Map.remove" -> ok C_MAP_REMOVE
| "Map.iter" -> ok C_MAP_ITER
| "Map.map" -> ok C_MAP_MAP
| "Map.fold" -> ok C_MAP_FOLD
| "Map.mem" -> ok C_MAP_MEM
| "Map.empty" -> ok C_MAP_EMPTY
| "Map.literal" -> ok C_MAP_LITERAL
| "Map.size" -> ok C_SIZE
(* Big_map module *)
| "Big_map.find_opt" -> ok C_MAP_FIND_OPT
| "Big_map.find" -> ok C_MAP_FIND
| "Big_map.update" -> ok C_MAP_UPDATE
| "Big_map.add" -> ok C_MAP_ADD
| "Big_map.remove" -> ok C_MAP_REMOVE
| "Big_map.literal" -> ok C_BIG_MAP_LITERAL
| "Big_map.empty" -> ok C_BIG_MAP_EMPTY
(* Bitwise module *) (* Bitwise module *)
| "Bitwise.or" -> ok C_OR
| "Bitwise.lor" -> ok C_OR (* Deprecated *) | "Bitwise.lor" -> ok C_OR (* Deprecated *)
| "Bitwise.and" -> ok C_AND
| "Bitwise.land" -> ok C_AND (* Deprecated *) | "Bitwise.land" -> ok C_AND (* Deprecated *)
| "Bitwise.xor" -> ok C_XOR
| "Bitwise.lxor" -> ok C_XOR (* Deprecated *) | "Bitwise.lxor" -> ok C_XOR (* Deprecated *)
| "Bitwise.shift_left" -> ok C_LSL
| "Bitwise.shift_right" -> ok C_LSR
(* String module *)
| "String.length" -> ok C_SIZE
| "String.size" -> ok C_SIZE
| "String.slice" -> ok C_SLICE
| "String.sub" -> ok C_SLICE
| "String.concat" -> ok C_CONCAT
(* Loop module *) (* Loop module *)
@ -408,7 +359,8 @@ module Simplify = struct
| "assert" -> ok C_ASSERTION | "assert" -> ok C_ASSERTION
| _ -> simple_fail "Not a CameLIGO built-in." | _ as c ->
pseudo_modules c
let type_constants = type_constants let type_constants = type_constants
let type_operators = type_operators let type_operators = type_operators