Skip to content

Commit

Permalink
Added support for PascaLIGO (#1947)
Browse files Browse the repository at this point in the history
This adds support for the [PascaLIGO language](http://ligolang.org).
  • Loading branch information
DefinitelyNotAGoat authored and RunDevelopment committed Jul 11, 2019
1 parent 473f7fb commit 858201c
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@
},
"owner": "Golmote"
},
"pascaligo": {
"title": "Pascaligo",
"owner": "DefinitelyNotAGoat"
},
"pcaxis": {
"title": "PC-Axis",
"alias": "px",
Expand Down
62 changes: 62 additions & 0 deletions components/prism-pascaligo.js
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));
1 change: 1 addition & 0 deletions components/prism-pascaligo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions examples/prism-pascaligo.html
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 &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 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/languages/pascaligo/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
True False

----------------------------------------------------

[
["boolean", "True"], ["boolean", "False"]
]

----------------------------------------------------

Checks for all booleans.
15 changes: 15 additions & 0 deletions tests/languages/pascaligo/builtin_feature.test
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.
18 changes: 18 additions & 0 deletions tests/languages/pascaligo/comment_feature.test
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.
23 changes: 23 additions & 0 deletions tests/languages/pascaligo/function_feature.test
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.
Loading

0 comments on commit 858201c

Please sign in to comment.