Fix lexer

This commit is contained in:
Sander Spies 2019-10-01 07:49:32 +02:00
commit ccfe58efb8
10 changed files with 62 additions and 59 deletions

View File

@ -13,7 +13,7 @@ Contract below is effectively an empty contract, that takes a `unit` as a parame
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
function main (const p : unit ; const s : unit) : (list(operation) * unit) is
block {skip} with ((nil : list(operation)), s)
```
@ -27,7 +27,7 @@ In the example below we have a simple counter contract, that can be either `Incr
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
// variant defining pseudo multi-entrypoint actions
type action is
| Increment of int

View File

@ -9,7 +9,7 @@ Body of a function consists of two parts, the first part (**`block {}`** or **`b
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
const availableSupply: nat = 15n;
const totalSupply: nat = 100n;
@ -30,7 +30,7 @@ A short hand syntax for the same function as above can inline the price calculat
While this approach can have it's benefits, it can decrease readability.
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
const availableSupply: nat = 15n;
const totalSupply: nat = 100n;

View File

@ -13,7 +13,7 @@ Type aliasing is a great choice when working towards a readable / maintainable s
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
type animalBreed is string;
const dogBreed: animalBreed = "Saluki";
@ -26,7 +26,7 @@ const dogBreed: animalBreed = "Saluki";
### Simple types
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
// accountBalances is a simple type, a map of address <-> tez
type accountBalances is map(address, tez);
@ -46,7 +46,7 @@ In the example below you can see definition of data types for a ledger, that kee
<!--DOCUSAURUS_CODE_TABS-->
<!--Pascaligo-->
```Pascal
```pascaligo
// alias two types
type account is address;
type numberOfTransactions is nat;

View File

@ -17,14 +17,15 @@ In the [previous tutorial](tutorials/get-started/tezos-taco-shop-smart-contract.
## Analyzing the current contract
### **`taco-shop.ligo`**
```
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
end
type taco_shop_storage is map(nat, taco_supply);
function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) : (list(operation) * taco_shop_storage) is
function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_shop_storage) :
(list(operation) * taco_shop_storage) is
begin
// Retrieve the taco_kind from the contract's storage
const taco_kind : taco_supply = get_force(taco_kind_index, taco_shop_storage);
@ -46,7 +47,7 @@ function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_sho
### Purchase price formula
Pedro's Taco Shop contract currently enables customers to buy tacos, at a computed price based on a simple formula.
```
```pascaligo
const current_purchase_price : tez = taco_kind.max_price / taco_kind.current_stock;
```
@ -66,7 +67,7 @@ This means that after all the *purchase conditions* of our contract are met - e.
### Defining the recipient
In order to send tokens, we will need a receiver address - which in our case will be Pedro's personal account. Additionally we'll wrap the given address as a *`contract(unit)`* - which represents either a contract with no parameters, or an implicit account.
```
```pascaligo
const ownerAddress : address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV";
const receiver : contract(unit) = get_contract(ownerAddress);
```
@ -77,7 +78,7 @@ const receiver : contract(unit) = get_contract(ownerAddress);
Now we can transfer the `amount` received by `buy_taco` to Pedro's `ownerAddress`. We will do so by forging a `transaction(unit, amount, receiver)` within a list of operations returned at the end of our contract.
```
```pascaligo
const payoutOperation : operation = transaction(unit, amount, receiver) ;
const operations : list(operation) = list
payoutOperation
@ -89,7 +90,7 @@ end;
## Finalizing the contract
### **`taco-shop.ligo`**
```
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -129,7 +130,7 @@ function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_sho
To confirm that our contract is valid, we can dry run it. As a result we see a *new operation* in the list of returned operations to be executed subsequently.
```
```pascaligo
ligo dry-run taco-shop.ligo --syntax pascaligo --amount 1 buy_taco 1n "map
1n -> record
current_stock = 50n;
@ -157,12 +158,12 @@ end"
Because Pedro is a member of the (STA) Specialty Taco Association, he has decided to donate **10%** of the earnings to the STA. We'll just add a `donationAddress` to the contract, and compute a 10% donation sum from each taco purchase.
```
```pascaligo
const ownerAddress: address = "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV";
const donationAddress: address = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
```
```
```pascaligo
const receiver : contract(unit) = get_contract(ownerAddress);
const donationReceiver : contract(unit) = get_contract(donationAddress);

View File

@ -35,7 +35,7 @@ Each taco kind, has its own `max_price` that it sells for, and a finite supply f
Current purchase price is calculated with the following equation:
```
```pascaligo
current_purchase_price = max_price / available_stock
```
@ -71,7 +71,7 @@ The best way to install the dockerized LIGO is as a **global executable** throug
To begin implementing our smart contract, we need an entry point. We'll call it `main` and it'll specify our contract's storage (`int`) and input parameter (`int`). Of course this is not the final storage/parameter of our contract, but it's something to get us started and test our LIGO installation as well.
### `taco-shop.ligo`
```Pascal
```pascaligo
function main (const parameter: int; const contractStorage: int) : (list(operation) * int) is
block {skip} with ((nil : list(operation)), contractStorage + parameter)
```
@ -129,7 +129,7 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main 4 3
We know that Pedro's Taco Shop serves two kinds of tacos, so we'll need to manage stock individually, per kind. Let's define a type, that will keep the `stock` & `max_price` per kind - in a record with two fields. Additionally, we'll want to combine our `taco_supply` type into a map, consisting of the entire offer of Pedro's shop.
**Taco shop's storage**
```Pascal
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -141,7 +141,7 @@ type taco_shop_storage is map(nat, taco_supply);
Next step is to update the `main` entry point to include `taco_shop_storage` as its storage - while doing that let's set the `parameter` to `unit` as well to clear things up.
**`taco-shop.ligo`**
```Pascal
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -208,7 +208,7 @@ Let's start by customizing our contract a bit, we will:
- change `taco_shop_storage` to a `var` instead of a `const`, because we'll want to modify it
**`taco-shop.ligo`**
```Pascal
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -231,7 +231,7 @@ In order to decrease the stock in our contract's storage for a specific taco kin
**`taco-shop.ligo`**
```Pascal
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -266,7 +266,7 @@ To make sure we get paid, we will:
- if yes, stock for the given `taco_kind` will be decreased and the payment accepted
**`taco-shop.ligo`**
```Pascal
```pascaligo
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -327,11 +327,11 @@ end"
If you'd like to accept tips in your contract as well, simply change the following line, depending on which behavior do you prefer.
**Without tips**
```Pascal
```pascaligo
if amount =/= current_purchase_price then
```
**With tips**
```Pascal
```pascaligo
if amount >= current_purchase_price then
```

View File

@ -15,35 +15,6 @@ const MarkdownBlock = CompLibrary.MarkdownBlock; /* Used to read markdown */
const Container = CompLibrary.Container;
const GridBlock = CompLibrary.GridBlock;
function pascaligo(hljs) {
return {
// case_insensitive: true,
beginKeywords: '',
keywords: {
keyword: 'and begin block case const contains down else end fail for ' +
'from function if in is list map mod nil not of or patch ' +
'procedure record remove set skip step then to type var while with',
literal: 'true false unit int string some none bool nat list'
},
lexemes: '[a-zA-Z][a-zA-Z0-9_]*',
contains: [
hljs.C_LINE_COMMENT_MODE,
{
className: 'type',
begin: /[A-Z][a-z]+/
},
{
begin: /[*+-:;\(\)\{\}|\>\<]/,
// className: 'ignore'
}
]
}
}
hljs.registerLanguage('pascaligo', pascaligo);
const pre = "```";
const pascaligoExampleSmall = `${pre}pascaligo

View File

@ -144,7 +144,34 @@ const siteConfig = {
highlight: {
// Highlight.js theme to use for syntax highlighting in code blocks.
theme: "default"
theme: "default",
hljs: function (hljs) {
hljs.registerLanguage('pascaligo', function (hljs) {
return {
// case_insensitive: true,
beginKeywords: '',
keywords: {
keyword: 'and begin block case const contains down else end fail for ' +
'from function if in is list map mod nil not of or patch ' +
'procedure record remove set skip step then to type var while with',
literal: 'true false unit int string some none bool nat list'
},
lexemes: '[a-zA-Z][a-zA-Z0-9_]*',
contains: [
hljs.C_LINE_COMMENT_MODE,
{
className: 'type',
begin: /[A-Z][a-z]+/
},
{
begin: /[*+-:;\(\)\{\}|\>\<]/,
// className: 'ignore'
}
]
}
});
}
},
// Add custom scripts here that would be placed in <script> tags.

View File

@ -648,7 +648,7 @@ body
color: #3AA0FF;
}
.tab-pane {
.home-container .tab-pane {
height: 500px;
}
@ -817,3 +817,7 @@ input#search_input_react::placeholder {
font-weight:bold
}
.docMainWrapper .hljs {
border: solid 1px lightgray;
overflow-x: auto;
}

View File

@ -1 +1 @@
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 245 240"><style>.st0{fill:#FFFFFF;}</style><path class="st0" d="M104.4 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1.1-6.1-4.5-11.1-10.2-11.1zM140.9 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1s-4.5-11.1-10.2-11.1z"/><path class="st0" d="M189.5 20h-134C44.2 20 35 29.2 35 40.6v135.2c0 11.4 9.2 20.6 20.5 20.6h113.4l-5.3-18.5 12.8 11.9 12.1 11.2 21.5 19V40.6c0-11.4-9.2-20.6-20.5-20.6zm-38.6 130.6s-3.6-4.3-6.6-8.1c13.1-3.7 18.1-11.9 18.1-11.9-4.1 2.7-8 4.6-11.5 5.9-5 2.1-9.8 3.5-14.5 4.3-9.6 1.8-18.4 1.3-25.9-.1-5.7-1.1-10.6-2.7-14.7-4.3-2.3-.9-4.8-2-7.3-3.4-.3-.2-.6-.3-.9-.5-.2-.1-.3-.2-.4-.3-1.8-1-2.8-1.7-2.8-1.7s4.8 8 17.5 11.8c-3 3.8-6.7 8.3-6.7 8.3-22.1-.7-30.5-15.2-30.5-15.2 0-32.2 14.4-58.3 14.4-58.3 14.4-10.8 28.1-10.5 28.1-10.5l1 1.2c-18 5.2-26.3 13.1-26.3 13.1s2.2-1.2 5.9-2.9c10.7-4.7 19.2-6 22.7-6.3.6-.1 1.1-.2 1.7-.2 6.1-.8 13-1 20.2-.2 9.5 1.1 19.7 3.9 30.1 9.6 0 0-7.9-7.5-24.9-12.7l1.4-1.6s13.7-.3 28.1 10.5c0 0 14.4 26.1 14.4 58.3 0 0-8.5 14.5-30.6 15.2z"/></svg>
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 245 240"><style>.st0{fill:#3aa0ff;}</style><path class="st0" d="M104.4 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1.1-6.1-4.5-11.1-10.2-11.1zM140.9 103.9c-5.7 0-10.2 5-10.2 11.1s4.6 11.1 10.2 11.1c5.7 0 10.2-5 10.2-11.1s-4.5-11.1-10.2-11.1z"/><path class="st0" d="M189.5 20h-134C44.2 20 35 29.2 35 40.6v135.2c0 11.4 9.2 20.6 20.5 20.6h113.4l-5.3-18.5 12.8 11.9 12.1 11.2 21.5 19V40.6c0-11.4-9.2-20.6-20.5-20.6zm-38.6 130.6s-3.6-4.3-6.6-8.1c13.1-3.7 18.1-11.9 18.1-11.9-4.1 2.7-8 4.6-11.5 5.9-5 2.1-9.8 3.5-14.5 4.3-9.6 1.8-18.4 1.3-25.9-.1-5.7-1.1-10.6-2.7-14.7-4.3-2.3-.9-4.8-2-7.3-3.4-.3-.2-.6-.3-.9-.5-.2-.1-.3-.2-.4-.3-1.8-1-2.8-1.7-2.8-1.7s4.8 8 17.5 11.8c-3 3.8-6.7 8.3-6.7 8.3-22.1-.7-30.5-15.2-30.5-15.2 0-32.2 14.4-58.3 14.4-58.3 14.4-10.8 28.1-10.5 28.1-10.5l1 1.2c-18 5.2-26.3 13.1-26.3 13.1s2.2-1.2 5.9-2.9c10.7-4.7 19.2-6 22.7-6.3.6-.1 1.1-.2 1.7-.2 6.1-.8 13-1 20.2-.2 9.5 1.1 19.7 3.9 30.1 9.6 0 0-7.9-7.5-24.9-12.7l1.4-1.6s13.7-.3 28.1 10.5c0 0 14.4 26.1 14.4 58.3 0 0-8.5 14.5-30.6 15.2z"/></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -520,7 +520,7 @@ let esc = "\\n" | "\\\"" | "\\\\" | "\\b"
| "\\r" | "\\t" | "\\x" byte
let symbol = ';' | ',' | '(' | ')'| '[' | ']' | '{' | '}'
| '#' | '|' | "->" | ":=" | '=' | ':'
| '<' | "<=" | '>' | ">=" | "=/="
| '<' | "<=" | '>' | ">=" | "=/=" | "<>"
| '+' | '-' | '*' | '/' | '.' | '_' | '^'
| "::" | "||" | "&&"
let string = [^'"' '\\' '\n']* (* For strings of #include *)