Skip to content

Commit 858201c

Browse files
DefinitelyNotAGoatRunDevelopment
authored andcommitted
Added support for PascaLIGO (#1947)
This adds support for the [PascaLIGO language](http://ligolang.org).
1 parent 473f7fb commit 858201c

14 files changed

+341
-12
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@
632632
},
633633
"owner": "Golmote"
634634
},
635+
"pascaligo": {
636+
"title": "Pascaligo",
637+
"owner": "DefinitelyNotAGoat"
638+
},
635639
"pcaxis": {
636640
"title": "PC-Axis",
637641
"alias": "px",

components/prism-pascaligo.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(function (Prism) {
2+
3+
// Pascaligo is a layer 2 smart contract language for the tezos blockchain
4+
5+
var braces = /\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/.source;
6+
var type = /(?:\w+(?:<braces>)?|<braces>)/.source.replace(/<braces>/g, braces);
7+
8+
var pascaligo = Prism.languages.pascaligo = {
9+
'comment': /\(\*[\s\S]+?\*\)|\/\/.*/,
10+
'string': {
11+
pattern: /(["'`])(\\[\s\S]|(?!\1)[^\\])*\1|\^[a-z]/i,
12+
greedy: true
13+
},
14+
'class-name': [
15+
{
16+
pattern: RegExp(/(\btype\s+\w+\s+is\s+)<type>/.source.replace(/<type>/g, type), 'i'),
17+
lookbehind: true,
18+
inside: null // see below
19+
},
20+
{
21+
pattern: RegExp(/<type>(?=\s+is\b)/.source.replace(/<type>/g, type), 'i'),
22+
inside: null // see below
23+
},
24+
{
25+
pattern: RegExp(/(:\s*)<type>/.source.replace(/<type>/g, type)),
26+
lookbehind: true,
27+
inside: null // see below
28+
}
29+
],
30+
'keyword': {
31+
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,
32+
lookbehind: true
33+
},
34+
'boolean': {
35+
pattern: /(^|[^&])\b(?:True|False)\b/i,
36+
lookbehind: true
37+
},
38+
'builtin': {
39+
pattern: /(^|[^&])\b(?:bool|int|list|map|nat|record|string|unit)\b/i,
40+
lookbehind: true
41+
},
42+
'function': /\w+(?=\s*\()/i,
43+
'number': [
44+
// Hexadecimal, octal and binary
45+
/%[01]+|&[0-7]+|\$[a-f\d]+/i,
46+
// Decimal
47+
/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?(?:mtz|n)?/i
48+
],
49+
'operator': /->|=\/=|\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=|]|\b(?:and|mod|or)\b/,
50+
'punctuation': /\(\.|\.\)|[()\[\]:;,.{}]/
51+
};
52+
53+
var classNameInside = ['comment', 'keyword', 'builtin', 'operator', 'punctuation'].reduce(function (accum, key) {
54+
accum[key] = pascaligo[key];
55+
return accum;
56+
}, {});
57+
58+
pascaligo["class-name"].forEach(function (p) {
59+
p.inside = classNameInside;
60+
});
61+
62+
}(Prism));

components/prism-pascaligo.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-pascaligo.html

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<h2>Comments</h2>
2+
<pre><code>// Single line comment
3+
(* Multi-line
4+
comment *)</code></pre>
5+
6+
<h2>Strings</h2>
7+
<pre><code>"foo \"bar\" baz";
8+
'foo \'bar\' baz';</code></pre>
9+
10+
<h2>Numbers</h2>
11+
<pre><code>123
12+
123.456
13+
-123.456
14+
1e-23
15+
123.456E789
16+
0xaf
17+
0xAF
18+
</code></pre>
19+
20+
<h2>Functions</h2>
21+
<pre><code>foo()
22+
Bar()
23+
_456()
24+
</code></pre>
25+
26+
<h2>Full Example</h2>
27+
<pre><code>
28+
function pop (const h : heap) : (heap * heap_element * nat) is
29+
begin
30+
const result : heap_element = get_top (h) ;
31+
var s : nat := size(h) ;
32+
const last : heap_element = get_force(s, h) ;
33+
remove s from map h ;
34+
h[1n] := last ;
35+
s := size(h) ;
36+
var i : nat := 0n ;
37+
var largest : nat := 1n ;
38+
var left : nat := 0n ;
39+
var right : nat := 0n ;
40+
var c : nat := 0n ;
41+
while (largest =/= i) block {
42+
c := c + 1n ;
43+
i := largest ;
44+
left := 2n * i ;
45+
right := left + 1n ;
46+
if (left &lt;= s) then begin
47+
if (heap_element_lt(get_force(left , h) , get_force(i , h))) then begin
48+
largest := left ;
49+
const tmp : heap_element = get_force(i , h) ;
50+
h[i] := get_force(left , h) ;
51+
h[left] := tmp ;
52+
end else skip ;
53+
end else if (right &lt;= s) then begin
54+
if (heap_element_lt(get_force(right , h) , get_force(i , h))) then begin
55+
largest := right ;
56+
const tmp : heap_element = get_force(i , h) ;
57+
h[i] := get_force(right , h) ;
58+
h[left] := tmp ;
59+
end else skip ;
60+
end else skip ;
61+
}
62+
end with (h , result , c)
63+
</code></pre>

package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
True False
2+
3+
----------------------------------------------------
4+
5+
[
6+
["boolean", "True"], ["boolean", "False"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks for all booleans.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
int unit
2+
string nat map
3+
list record bool
4+
5+
----------------------------------------------------
6+
7+
[
8+
["builtin", "int"], ["builtin", "unit"],
9+
["builtin", "string"], ["builtin", "nat"], ["builtin", "map"],
10+
["builtin", "list"], ["builtin", "record"], ["builtin", "bool"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for builtins.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(* foo *)
2+
(* foo
3+
bar *)
4+
//
5+
// foobar
6+
7+
----------------------------------------------------
8+
9+
[
10+
["comment", "(* foo *)"],
11+
["comment", "(* foo\r\nbar *)"],
12+
["comment", "//"],
13+
["comment", "// foobar"]
14+
]
15+
16+
----------------------------------------------------
17+
18+
Checks for comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
somefunc()
2+
some_func()
3+
somefunc42()
4+
5+
----------------------------------------------------
6+
7+
[
8+
["function", "somefunc"],
9+
["punctuation", "("],
10+
["punctuation", ")"],
11+
12+
["function", "some_func"],
13+
["punctuation", "("],
14+
["punctuation", ")"],
15+
16+
["function", "somefunc42"],
17+
["punctuation", "("],
18+
["punctuation", ")"]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for functions.

0 commit comments

Comments
 (0)