diff --git a/.gitmodules b/.gitmodules index 530d4e8585..1a19fed0be 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,9 +52,6 @@ [submodule "vendor/grammars/JSyntax"] path = vendor/grammars/JSyntax url = https://github.com/tikkanz/JSyntax -[submodule "vendor/grammars/Ligo-grammar"] - path = vendor/grammars/Ligo-grammar - url = https://github.com/pewulfman/Ligo-grammar.git [submodule "vendor/grammars/LiveScript.tmbundle"] path = vendor/grammars/LiveScript.tmbundle url = https://github.com/paulmillr/LiveScript.tmbundle @@ -779,6 +776,9 @@ [submodule "vendor/grammars/latex.tmbundle"] path = vendor/grammars/latex.tmbundle url = https://github.com/textmate/latex.tmbundle +[submodule "vendor/grammars/ligo"] + path = vendor/grammars/ligo + url = https://gitlab.com/ligolang/ligo.git [submodule "vendor/grammars/linter-lilypond"] path = vendor/grammars/linter-lilypond url = https://github.com/nwhetsell/linter-lilypond diff --git a/grammars.yml b/grammars.yml index 47c29b5f99..dbfdbd6cd0 100644 --- a/grammars.yml +++ b/grammars.yml @@ -41,10 +41,6 @@ vendor/grammars/Isabelle.tmbundle: - source.isabelle.theory vendor/grammars/JSyntax: - source.j -vendor/grammars/Ligo-grammar: -- source.ligo -- source.mligo -- source.religo vendor/grammars/LiveScript.tmbundle: - source.livescript vendor/grammars/MATLAB-Language-grammar: @@ -725,6 +721,11 @@ vendor/grammars/latex.tmbundle: - text.tex.latex - text.tex.latex.beamer - text.tex.latex.memoir +vendor/grammars/ligo: +- source.jsligo +- source.ligo +- source.mligo +- source.religo vendor/grammars/linter-lilypond: - source.lilypond vendor/grammars/liquid-tm-grammar: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index a47c5ff0f4..8ef104fa2d 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -869,7 +869,7 @@ Cairo: language_id: 620599567 CameLIGO: type: programming - color: "#3be133" + color: "#f08707" extensions: - ".mligo" tm_scope: source.mligo @@ -3101,6 +3101,17 @@ Jolie: ace_mode: text tm_scope: source.jolie language_id: 998078858 +JsLIGO: + type: programming + color: "#f1e05a" + extensions: + - ".jsligo" + tm_scope: source.jsligo + ace_mode: javascript + codemirror_mode: javascript + codemirror_mime_type: text/javascript + group: LigoLANG + language_id: 588633658 Jsonnet: color: "#0064bd" type: programming diff --git a/samples/JsLIGO/FA1.2.jsligo b/samples/JsLIGO/FA1.2.jsligo new file mode 100644 index 0000000000..c1dce21f82 --- /dev/null +++ b/samples/JsLIGO/FA1.2.jsligo @@ -0,0 +1,181 @@ +/* Errors */ +namespace Errors { + export let notEnoughBalance = "NotEnoughBalance"; + export let notEnoughAllowance = "NotEnoughAllowance"; + /* Extra error, see: https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit */ + export let vulnerable_operation = "Switching allowances from N to M is a vulnerability"; +}; + +namespace Allowance { + type spender = address; + type allowed_amount = nat; + export type t = map; + + export let get_allowed_amount = (a:t, spender:spender) : nat => { + return match(Map.find_opt(spender,a), { + Some: (v : allowed_amount) => v, + None: () => 0 as nat + }); + }; + + export let set_allowed_amount = (a:t, spender:spender, allowed_amount:allowed_amount) : t => { + if (allowed_amount > (0 as nat)) { + return Map.add(spender, allowed_amount, a) + } else { + return a; + } + } +}; + + +namespace Ledger { + type owner = address; + type spender = address; + type amount_ = nat; + export type t = big_map; + + export let get_for_user = (ledger:t, owner: owner) : [amount_,Allowance.t] => { + return match(Big_map.find_opt(owner, ledger), { + Some: (tokens : [amount_, Allowance.t]) => tokens, + None: () => [0 as nat,Map.empty as Allowance.t] + }); + }; + + export let update_for_user = (ledger:t, owner: owner, amount_ : amount_, allowances : Allowance.t) : t => { + return Big_map.update(owner, (Some ([amount_,allowances])), ledger) + }; + + export let set_approval = (ledger:t, owner: owner, spender : spender, allowed_amount: amount_) : t => { + let [tokens, allowances] = get_for_user(ledger, owner); + let previous_allowances = Allowance.get_allowed_amount(allowances, spender); + let _ = assert_with_error((previous_allowances == (0 as nat) || allowed_amount == (0 as nat)), Errors.vulnerable_operation); + let allowances = Allowance.set_allowed_amount(allowances, spender, allowed_amount); + let ledger = update_for_user(ledger, owner, tokens, allowances); + return ledger + }; + + export let decrease_token_amount_for_user = (ledger : t, spender : spender, from_ : owner, amount_ : amount_) : t => { + let [tokens, allowances] = get_for_user(ledger, from_); + let allowed_amount = Allowance.get_allowed_amount(allowances, spender); + if (spender == from_) { + allowed_amount = tokens; + }; + let _ = assert_with_error((allowed_amount >= amount_), Errors.notEnoughAllowance); + let _ = assert_with_error((tokens >= amount_), Errors.notEnoughBalance); + let tokens = abs(tokens - amount_); + let ledger = update_for_user(ledger, from_, tokens, allowances); + return ledger + }; + + export let increase_token_amount_for_user = (ledger : t, to_ : owner, amount_ : amount_) : t => { + let [tokens, allowances] = get_for_user(ledger, to_); + let tokens = tokens + amount_; + let ledger = update_for_user(ledger, to_, tokens, allowances); + return ledger + }; +}; + +namespace TokenMetadata { + /** + This should be initialized at origination, conforming to either + TZIP-12 : https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-12/tzip-12.md#token-metadata + or TZIP-16 : https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-12/tzip-12.md#contract-metadata-tzip-016 + */ + type data = { + token_id : nat, + token_info : map + }; + export type t = data; +}; + +namespace Storage { + export type t = { + ledger : Ledger.t, + token_metadata : TokenMetadata.t, + totalSupply : nat, + /* Note: memoizing the sum of all participant balance reduce the cost of getTotalSupply entrypoint. + However, with this pattern the value has to be manually set at origination which can lead to consistency issues. + */ + }; + + export let get_amount_for_owner = (s:t, owner : address) : nat => { + let [amount_, _] = Ledger.get_for_user(s.ledger, owner); + return amount_ + }; + + export let get_allowances_for_owner = (s:t, owner : address) : Allowance.t => { + let [_, allowances] = Ledger.get_for_user(s.ledger, owner); + return allowances + }; + + export let get_ledger = (s:t) : Ledger.t => s.ledger; + export let set_ledger = (s:t, ledger:Ledger.t) : t => { + return {...s, ledger: ledger} + } + +}; + +type storage = Storage.t; + + +/** transfer entrypoint */ +type transfer = [address, [address, nat]]; +const transfer = ([from_, to_value]:transfer, s:storage) : [list, Storage.t] => { + let [to_, value] = to_value; + let ledger1 = Storage.get_ledger(s); + let ledger2 = Ledger.decrease_token_amount_for_user(ledger1, Tezos.sender, from_, value); + let ledger = Ledger.increase_token_amount_for_user(ledger2, to_, value); + let s1 = Storage.set_ledger(s, ledger); + return [(list([]) as list), s1] +}; + +/** approve */ +type approve = [address, nat]; +const approve = ([spender,value] : approve, s:storage) : [list, Storage.t] => { + let ledger1 = Storage.get_ledger(s); + let ledger = Ledger.set_approval(ledger1, Tezos.sender, spender, value); + let s1 = Storage.set_ledger(s, ledger); + return [list([]) as list, s1] +}; + +/** getBalance entrypoint */ +type getAllowance = [[address, address], contract]; +const getAllowance = ([owner_spender,callback]: getAllowance, s: storage) : [list, Storage.t] => { + let [owner,spender] = owner_spender; + let a = Storage.get_allowances_for_owner(s, owner); + let allowed_amount = Allowance.get_allowed_amount(a, spender); + let operation = Tezos.transaction(allowed_amount, 0 as tez, callback); + return [list([operation]) as list, s] +}; + +/** getBalance entrypoint */ +type getBalance = [address, contract]; +const getBalance = ([owner,callback]: getBalance, s: storage) : [list, Storage.t] => { + let balance_ = Storage.get_amount_for_owner(s, owner); + let operation = Tezos.transaction(balance_, 0 as tez, callback); + return [list([operation]) as list, s] +}; + +/** getTotalSupply entrypoint */ +type getTotalSupply = [unit, contract]; +const getTotalSupply = ([_,callback] : getTotalSupply, s:storage) : [list, Storage.t] => { + let operation = Tezos.transaction(s.totalSupply, 0 as tez, callback); + return [list([operation]) as list, s] +}; + +type parameter = + ["Transfer", transfer] +| ["Approve", approve] +| ["GetAllowance", getAllowance] +| ["GetBalance", getBalance] +| ["GetTotalSupply", getTotalSupply]; + +let main = ([p,s]:[parameter, storage]) : [list, Storage.t] => { + return match(p, { + Transfer: (p : transfer) => transfer(p, s), + Approve: (p : approve) => approve(p, s), + GetAllowance: (p : getAllowance) => getAllowance(p, s), + GetBalance: (p : getBalance) => getBalance(p, s), + GetTotalSupply: (p : getTotalSupply) => getTotalSupply(p, s) + }); +} \ No newline at end of file diff --git a/tools/grammars/compiler/data.go b/tools/grammars/compiler/data.go index 0f98bc28a4..164afdd8fb 100644 --- a/tools/grammars/compiler/data.go +++ b/tools/grammars/compiler/data.go @@ -52,15 +52,19 @@ var GrammarsInNonStdPath = map[string]bool{ // IgnoredFiles is a list of files that look like syntax files but aren't, or are known to be broken and never likely to be fixed. var IgnoredFiles = map[string]bool{ - "ballerina-grammar/syntaxes/ballerina.monarch.json": true, - "oz-tmbundle/Originals/Oz.tmLanguage": true, - "abl-tmlanguage/package-lock.json": true, - "abl-tmlanguage/package.json": true, - "avro.tmLanguage/package-lock.json": true, - "avro.tmLanguage/package.json": true, - "avro.tmLanguage/avro-avsc-json-schema.json": true, - "liquid-tm-grammar/tests/syntaxes/css.tmLanguage.json": true, - "liquid-tm-grammar/tests/syntaxes/html.tmLanguage.json": true, - "liquid-tm-grammar/tests/syntaxes/javascript.tmLanguage.json": true, - "liquid-tm-grammar/tests/syntaxes/json.tmLanguage.json": true, + "ballerina-grammar/syntaxes/ballerina.monarch.json": true, + "oz-tmbundle/Originals/Oz.tmLanguage": true, + "abl-tmlanguage/package-lock.json": true, + "abl-tmlanguage/package.json": true, + "avro.tmLanguage/package-lock.json": true, + "avro.tmLanguage/package.json": true, + "avro.tmLanguage/avro-avsc-json-schema.json": true, + "liquid-tm-grammar/tests/syntaxes/css.tmLanguage.json": true, + "liquid-tm-grammar/tests/syntaxes/html.tmLanguage.json": true, + "liquid-tm-grammar/tests/syntaxes/javascript.tmLanguage.json": true, + "liquid-tm-grammar/tests/syntaxes/json.tmLanguage.json": true, + "ligo/tools/lsp/vscode-plugin/syntaxes/religo.configuration.json": true, + "ligo/tools/lsp/vscode-plugin/syntaxes/jsligo.configuration.json": true, + "ligo/tools/lsp/vscode-plugin/syntaxes/mligo.configuration.json": true, + "ligo/tools/lsp/vscode-plugin/syntaxes/ligo.configuration.json": true, } diff --git a/vendor/README.md b/vendor/README.md index 30d9c5b548..60ad801a9a 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -80,7 +80,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **Cabal Config:** [atom-haskell/language-haskell](https://github.com/atom-haskell/language-haskell) - **Cadence:** [onflow/vscode-cadence](https://github.com/onflow/vscode-cadence) - **Cairo:** [xshitaka/atom-language-cairo](https://github.com/xshitaka/atom-language-cairo) -- **CameLIGO:** [pewulfman/Ligo-grammar](https://github.com/pewulfman/Ligo-grammar) +- **CameLIGO:** [gitlab:ligolang/ligo](https://gitlab.com/ligolang/ligo) - **Cap'n Proto:** [textmate/capnproto.tmbundle](https://github.com/textmate/capnproto.tmbundle) - **CartoCSS:** [yohanboniface/carto-atom](https://github.com/yohanboniface/carto-atom) - **Ceylon:** [jeancharles-roger/ceylon-sublimetext](https://github.com/jeancharles-roger/ceylon-sublimetext) @@ -252,6 +252,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **Jison:** [cdibbs/language-jison](https://github.com/cdibbs/language-jison) - **Jison Lex:** [cdibbs/language-jison](https://github.com/cdibbs/language-jison) - **Jolie:** [fmontesi/language-jolie](https://github.com/fmontesi/language-jolie) +- **JsLIGO:** [gitlab:ligolang/ligo](https://gitlab.com/ligolang/ligo) - **Jsonnet:** [google/language-jsonnet](https://github.com/google/language-jsonnet) - **Julia:** [JuliaEditorSupport/atom-language-julia](https://github.com/JuliaEditorSupport/atom-language-julia) - **Jupyter Notebook:** [Nixinova/NovaGrammars](https://github.com/Nixinova/NovaGrammars) @@ -274,7 +275,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **Lean:** [leanprover/vscode-lean](https://github.com/leanprover/vscode-lean) - **Less:** [atom/language-less](https://github.com/atom/language-less) - **Lex:** [Alhadis/language-grammars](https://github.com/Alhadis/language-grammars) -- **LigoLANG:** [pewulfman/Ligo-grammar](https://github.com/pewulfman/Ligo-grammar) +- **LigoLANG:** [gitlab:ligolang/ligo](https://gitlab.com/ligolang/ligo) - **LilyPond:** [nwhetsell/linter-lilypond](https://github.com/nwhetsell/linter-lilypond) - **Liquid:** [Shopify/liquid-tm-grammar](https://github.com/Shopify/liquid-tm-grammar) - **Literate CoffeeScript:** [atom/language-coffee-script](https://github.com/atom/language-coffee-script) @@ -417,7 +418,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **ReScript:** [rescript-lang/rescript-vscode](https://github.com/rescript-lang/rescript-vscode) - **Readline Config:** [Alhadis/language-etc](https://github.com/Alhadis/language-etc) - **Reason:** [reasonml-editor/language-reason](https://github.com/reasonml-editor/language-reason) -- **ReasonLIGO:** [pewulfman/Ligo-grammar](https://github.com/pewulfman/Ligo-grammar) +- **ReasonLIGO:** [gitlab:ligolang/ligo](https://gitlab.com/ligolang/ligo) - **Rebol:** [Oldes/Sublime-REBOL](https://github.com/Oldes/Sublime-REBOL) - **Record Jar:** [Alhadis/language-etc](https://github.com/Alhadis/language-etc) - **Red:** [Oldes/Sublime-Red](https://github.com/Oldes/Sublime-Red) diff --git a/vendor/grammars/Ligo-grammar b/vendor/grammars/Ligo-grammar deleted file mode 160000 index d1338b118b..0000000000 --- a/vendor/grammars/Ligo-grammar +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d1338b118b7509ccad86597bb9eb83f9f9366684 diff --git a/vendor/grammars/ligo b/vendor/grammars/ligo new file mode 160000 index 0000000000..f901f3f382 --- /dev/null +++ b/vendor/grammars/ligo @@ -0,0 +1 @@ +Subproject commit f901f3f382785e38a008b165d106f79f30116446 diff --git a/vendor/licenses/git_submodule/Ligo-grammar.dep.yml b/vendor/licenses/git_submodule/Ligo-grammar.dep.yml deleted file mode 100644 index 81f953f3b0..0000000000 --- a/vendor/licenses/git_submodule/Ligo-grammar.dep.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -name: Ligo-grammar -version: d1338b118b7509ccad86597bb9eb83f9f9366684 -type: git_submodule -homepage: https://github.com/pewulfman/Ligo-grammar.git -license: mit -licenses: -- sources: LICENSE - text: | - MIT License - - Copyright (c) 2022 Pierre-Emmanuel Wulfman - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -notices: [] diff --git a/vendor/licenses/git_submodule/ligo.dep.yml b/vendor/licenses/git_submodule/ligo.dep.yml new file mode 100644 index 0000000000..4463793f7a --- /dev/null +++ b/vendor/licenses/git_submodule/ligo.dep.yml @@ -0,0 +1,17 @@ +--- +name: ligo +version: f901f3f382785e38a008b165d106f79f30116446 +type: git_submodule +homepage: https://gitlab.com/ligolang/ligo.git +license: mit +licenses: +- sources: LICENSE.md + text: | + Copyright 2019 contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +notices: []