-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for the [PascaLIGO language](http://ligolang.org).
- Loading branch information
1 parent
473f7fb
commit 858201c
Showing
14 changed files
with
341 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(function (Prism) { | ||
|
||
// Pascaligo is a layer 2 smart contract language for the tezos blockchain | ||
|
||
var braces = /\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/.source; | ||
var type = /(?:\w+(?:<braces>)?|<braces>)/.source.replace(/<braces>/g, braces); | ||
|
||
var pascaligo = Prism.languages.pascaligo = { | ||
'comment': /\(\*[\s\S]+?\*\)|\/\/.*/, | ||
'string': { | ||
pattern: /(["'`])(\\[\s\S]|(?!\1)[^\\])*\1|\^[a-z]/i, | ||
greedy: true | ||
}, | ||
'class-name': [ | ||
{ | ||
pattern: RegExp(/(\btype\s+\w+\s+is\s+)<type>/.source.replace(/<type>/g, type), 'i'), | ||
lookbehind: true, | ||
inside: null // see below | ||
}, | ||
{ | ||
pattern: RegExp(/<type>(?=\s+is\b)/.source.replace(/<type>/g, type), 'i'), | ||
inside: null // see below | ||
}, | ||
{ | ||
pattern: RegExp(/(:\s*)<type>/.source.replace(/<type>/g, type)), | ||
lookbehind: true, | ||
inside: null // see below | ||
} | ||
], | ||
'keyword': { | ||
pattern: /(^|[^&])\b(?:begin|block|case|const|else|end|fail|for|from|function|if|is|nil|of|remove|return|skip|then|type|var|while|with)\b/i, | ||
lookbehind: true | ||
}, | ||
'boolean': { | ||
pattern: /(^|[^&])\b(?:True|False)\b/i, | ||
lookbehind: true | ||
}, | ||
'builtin': { | ||
pattern: /(^|[^&])\b(?:bool|int|list|map|nat|record|string|unit)\b/i, | ||
lookbehind: true | ||
}, | ||
'function': /\w+(?=\s*\()/i, | ||
'number': [ | ||
// Hexadecimal, octal and binary | ||
/%[01]+|&[0-7]+|\$[a-f\d]+/i, | ||
// Decimal | ||
/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?(?:mtz|n)?/i | ||
], | ||
'operator': /->|=\/=|\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=|]|\b(?:and|mod|or)\b/, | ||
'punctuation': /\(\.|\.\)|[()\[\]:;,.{}]/ | ||
}; | ||
|
||
var classNameInside = ['comment', 'keyword', 'builtin', 'operator', 'punctuation'].reduce(function (accum, key) { | ||
accum[key] = pascaligo[key]; | ||
return accum; | ||
}, {}); | ||
|
||
pascaligo["class-name"].forEach(function (p) { | ||
p.inside = classNameInside; | ||
}); | ||
|
||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<h2>Comments</h2> | ||
<pre><code>// Single line comment | ||
(* Multi-line | ||
comment *)</code></pre> | ||
|
||
<h2>Strings</h2> | ||
<pre><code>"foo \"bar\" baz"; | ||
'foo \'bar\' baz';</code></pre> | ||
|
||
<h2>Numbers</h2> | ||
<pre><code>123 | ||
123.456 | ||
-123.456 | ||
1e-23 | ||
123.456E789 | ||
0xaf | ||
0xAF | ||
</code></pre> | ||
|
||
<h2>Functions</h2> | ||
<pre><code>foo() | ||
Bar() | ||
_456() | ||
</code></pre> | ||
|
||
<h2>Full Example</h2> | ||
<pre><code> | ||
function pop (const h : heap) : (heap * heap_element * nat) is | ||
begin | ||
const result : heap_element = get_top (h) ; | ||
var s : nat := size(h) ; | ||
const last : heap_element = get_force(s, h) ; | ||
remove s from map h ; | ||
h[1n] := last ; | ||
s := size(h) ; | ||
var i : nat := 0n ; | ||
var largest : nat := 1n ; | ||
var left : nat := 0n ; | ||
var right : nat := 0n ; | ||
var c : nat := 0n ; | ||
while (largest =/= i) block { | ||
c := c + 1n ; | ||
i := largest ; | ||
left := 2n * i ; | ||
right := left + 1n ; | ||
if (left <= s) then begin | ||
if (heap_element_lt(get_force(left , h) , get_force(i , h))) then begin | ||
largest := left ; | ||
const tmp : heap_element = get_force(i , h) ; | ||
h[i] := get_force(left , h) ; | ||
h[left] := tmp ; | ||
end else skip ; | ||
end else if (right <= s) then begin | ||
if (heap_element_lt(get_force(right , h) , get_force(i , h))) then begin | ||
largest := right ; | ||
const tmp : heap_element = get_force(i , h) ; | ||
h[i] := get_force(right , h) ; | ||
h[left] := tmp ; | ||
end else skip ; | ||
end else skip ; | ||
} | ||
end with (h , result , c) | ||
</code></pre> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
True False | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "True"], ["boolean", "False"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for all booleans. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
int unit | ||
string nat map | ||
list record bool | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["builtin", "int"], ["builtin", "unit"], | ||
["builtin", "string"], ["builtin", "nat"], ["builtin", "map"], | ||
["builtin", "list"], ["builtin", "record"], ["builtin", "bool"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for builtins. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(* foo *) | ||
(* foo | ||
bar *) | ||
// | ||
// foobar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "(* foo *)"], | ||
["comment", "(* foo\r\nbar *)"], | ||
["comment", "//"], | ||
["comment", "// foobar"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
somefunc() | ||
some_func() | ||
somefunc42() | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", "somefunc"], | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
|
||
["function", "some_func"], | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
|
||
["function", "somefunc42"], | ||
["punctuation", "("], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for functions. |
Oops, something went wrong.