Added support for PascaLIGO (#1947)

This adds support for the [PascaLIGO language](http://ligolang.org).
This commit is contained in:
Brice Aldrich 2019-07-10 21:45:22 -04:00 committed by Michael Schmidt
parent 473f7fbd0d
commit 858201c72c
14 changed files with 341 additions and 12 deletions

File diff suppressed because one or more lines are too long

View File

@ -632,6 +632,10 @@
},
"owner": "Golmote"
},
"pascaligo": {
"title": "Pascaligo",
"owner": "DefinitelyNotAGoat"
},
"pcaxis": {
"title": "PC-Axis",
"alias": "px",

View File

@ -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));

1
components/prism-pascaligo.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(e){var n="(?:\\w+(?:<braces>)?|<braces>)".replace(/<braces>/g,"\\((?:[^()]|\\((?:[^()]|\\([^()]*\\))*\\))*\\)"),i=e.languages.pascaligo={comment:/\(\*[\s\S]+?\*\)|\/\/.*/,string:{pattern:/(["'`])(\\[\s\S]|(?!\1)[^\\])*\1|\^[a-z]/i,greedy:!0},"class-name":[{pattern:RegExp("(\\btype\\s+\\w+\\s+is\\s+)<type>".replace(/<type>/g,n),"i"),lookbehind:!0,inside:null},{pattern:RegExp("<type>(?=\\s+is\\b)".replace(/<type>/g,n),"i"),inside:null},{pattern:RegExp("(:\\s*)<type>".replace(/<type>/g,n)),lookbehind:!0,inside:null}],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:!0},boolean:{pattern:/(^|[^&])\b(?:True|False)\b/i,lookbehind:!0},builtin:{pattern:/(^|[^&])\b(?:bool|int|list|map|nat|record|string|unit)\b/i,lookbehind:!0},function:/\w+(?=\s*\()/i,number:[/%[01]+|&[0-7]+|\$[a-f\d]+/i,/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?(?:mtz|n)?/i],operator:/->|=\/=|\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=|]|\b(?:and|mod|or)\b/,punctuation:/\(\.|\.\)|[()\[\]:;,.{}]/},t=["comment","keyword","builtin","operator","punctuation"].reduce(function(e,n){return e[n]=i[n],e},{});i["class-name"].forEach(function(e){e.inside=t})}(Prism);

View File

@ -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 &lt;= 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 &lt;= 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>

41
package-lock.json generated
View File

@ -1535,7 +1535,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
@ -1556,12 +1557,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -1576,17 +1579,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -1703,7 +1709,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@ -1715,6 +1722,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -1729,6 +1737,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -1736,12 +1745,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -1760,6 +1771,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -1840,7 +1852,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -1852,6 +1865,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -1937,7 +1951,8 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
@ -1973,6 +1988,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -1992,6 +2008,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -2035,12 +2052,14 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
}
}
},

View File

@ -0,0 +1,11 @@
True False
----------------------------------------------------
[
["boolean", "True"], ["boolean", "False"]
]
----------------------------------------------------
Checks for all booleans.

View File

@ -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.

View File

@ -0,0 +1,18 @@
(* foo *)
(* foo
bar *)
//
// foobar
----------------------------------------------------
[
["comment", "(* foo *)"],
["comment", "(* foo\r\nbar *)"],
["comment", "//"],
["comment", "// foobar"]
]
----------------------------------------------------
Checks for comments.

View File

@ -0,0 +1,23 @@
somefunc()
some_func()
somefunc42()
----------------------------------------------------
[
["function", "somefunc"],
["punctuation", "("],
["punctuation", ")"],
["function", "some_func"],
["punctuation", "("],
["punctuation", ")"],
["function", "somefunc42"],
["punctuation", "("],
["punctuation", ")"]
]
----------------------------------------------------
Checks for functions.

View File

@ -0,0 +1,29 @@
if while for
return nil
remove
from else
then skip
with; is function
var
const type
end begin block
case of
----------------------------------------------------
[
["keyword", "if"], ["keyword", "while"], ["keyword", "for"],
["keyword", "return"], ["keyword", "nil"],
["keyword", "remove"],
["keyword", "from"], ["keyword", "else"],
["keyword", "then"], ["keyword", "skip"],
["keyword", "with"], ["punctuation", ";"], ["keyword", "is"], ["keyword", "function"],
["keyword", "var"],
["keyword", "const"], ["keyword", "type"],
["keyword", "end"], ["keyword", "begin"], ["keyword", "block"],
["keyword", "case"], ["keyword", "of"]
]
----------------------------------------------------
Checks for all keywords.

View File

@ -0,0 +1,31 @@
42
3.14159
2.1e4
1.0e-1
3.8e+24
$7aff
&17
%11110101
123n
123mtz
----------------------------------------------------
[
["number", "42"],
["number", "3.14159"],
["number", "2.1e4"],
["number", "1.0e-1"],
["number", "3.8e+24"],
["number", "$7aff"],
["number", "&17"],
["number", "%11110101"],
["number", "123n"],
["number", "123mtz"]
]
----------------------------------------------------
Checks for decimal, hexadecimal, octal and binary numbers.

View File

@ -0,0 +1,25 @@
.. ** :=
< << <= > >> >=
+ - * /
+= -= *= /=
@ ^ = =/=
-> |
mod and or
----------------------------------------------------
[
["operator", ".."], ["operator", "**"], ["operator", ":="],
["operator", "<"], ["operator", "<<"], ["operator", "<="], ["operator", ">"], ["operator", ">>"], ["operator", ">="],
["operator", "+"], ["operator", "-"], ["operator", "*"], ["operator", "/"],
["operator", "+="], ["operator", "-="], ["operator", "*="], ["operator", "/="],
["operator", "@"], ["operator", "^"], ["operator", "="], ["operator", "=/="],
["operator", "->"], ["operator", "|"],
["operator", "mod"], ["operator", "and"], ["operator", "or"]
]
----------------------------------------------------
Checks for operators.

View File

@ -0,0 +1,28 @@
'a'
'ä'
'本'
'\t'
'\xff'
'\u12e4'
"日本語"
"\xff\u00FF"
----------------------------------------------------
[
["string", "'a'"],
["string", "'ä'"],
["string", "'本'"],
["string", "'\\t'"],
["string", "'\\xff'"],
["string", "'\\u12e4'"],
["string", "\"日本語\""],
["string", "\"\\xff\\u00FF\""]
]
----------------------------------------------------
Checks for runes and strings.