Skip to content

Commit ad748a0

Browse files
authoredAug 30, 2020
Added PureScript language definition (#2526)
1 parent e023044 commit ad748a0

19 files changed

+448
-3
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

+6
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,12 @@
913913
"alias": "pbfasm",
914914
"owner": "HeX0R101"
915915
},
916+
"purescript": {
917+
"title": "PureScript",
918+
"require": "haskell",
919+
"alias": "purs",
920+
"owner": "sriharshachilakapati"
921+
},
916922
"python": {
917923
"title": "Python",
918924
"alias": "py",

‎components/prism-purescript.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Prism.languages.purescript = Prism.languages.extend('haskell', {
2+
'keyword': /\b(?:ado|case|class|data|derive|do|else|forall|if|in|infixl|infixr|instance|let|module|newtype|of|primitive|then|type|where)\b/,
3+
4+
'import-statement': {
5+
// The imported or hidden names are not included in this import
6+
// statement. This is because we want to highlight those exactly like
7+
// we do for the names in the program.
8+
pattern: /(^\s*)import\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*(?:\s+as\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
9+
lookbehind: true,
10+
inside: {
11+
'keyword': /\b(?:import|as|hiding)\b/
12+
}
13+
},
14+
15+
// These are builtin functions only. Constructors are highlighted later as a constant.
16+
'builtin': /\b(?:absurd|add|ap|append|apply|between|bind|bottom|clamp|compare|comparing|compose|conj|const|degree|discard|disj|div|eq|flap|flip|gcd|identity|ifM|join|lcm|liftA1|liftM1|map|max|mempty|min|mod|mul|negate|not|notEq|one|otherwise|recip|show|sub|top|unit|unless|unlessM|void|when|whenM|zero)\b/,
17+
});
18+
19+
Prism.languages.purs = Prism.languages.purescript;

‎components/prism-purescript.min.js

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

‎examples/prism-purescript.html

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<h2>Comments</h2>
2+
<pre><code>-- Single line comment
3+
{- Multi-line
4+
comment -}</code></pre>
5+
6+
<h2>Strings and characters</h2>
7+
<pre><code>'a'
8+
'\n'
9+
'\^A'
10+
'\^]'
11+
'\NUL'
12+
'\23'
13+
'\o75'
14+
'\xFE'
15+
"Here is a backslant \\ as well as \137, \
16+
\a numeric escape character, and \^X, a control character."</code></pre>
17+
18+
<h2>Numbers</h2>
19+
<pre><code>42
20+
123.456
21+
123.456e-789
22+
1e+3
23+
0o74
24+
0XAF</code></pre>
25+
26+
<h2>Full example</h2>
27+
<pre><code>module Codewars.Kata.SumFracts (sumFracts) where
28+
29+
import Prelude
30+
31+
import Data.Foldable (foldl)
32+
import Data.BigInt (BigInt, fromInt, toString)
33+
import Data.List (List, length)
34+
import Data.Tuple (Tuple(..))
35+
import Data.Maybe (Maybe(..))
36+
import Data.Ord (abs, signum)
37+
38+
reduce :: Tuple BigInt BigInt -&gt; Tuple BigInt BigInt
39+
reduce (Tuple num den) =
40+
let gcd' = gcd num den
41+
den' = den / gcd'
42+
in Tuple (num / gcd' * (signum den')) (abs den')
43+
44+
sumFracts :: List (Tuple Int Int) -&gt; Maybe String
45+
sumFracts fracts =
46+
let fracts' = fracts &lt;#&gt; (\(Tuple n d) -&gt; Tuple (fromInt n) (fromInt d)) &gt;&gt;&gt; reduce
47+
48+
den = foldl (\acc (Tuple _ d) -&gt; lcm acc d) one fracts'
49+
num = foldl (\acc (Tuple n d) -&gt; acc + n * (den / d)) zero fracts'
50+
51+
Tuple n d = reduce $ Tuple num den
52+
53+
in if length fracts == 0
54+
then Nothing
55+
else if d == one
56+
then Just $ toString n
57+
else Just $ (toString n) &gt;&lt; " " &gt;&lt; (toString d)</code></pre>

‎plugins/autoloader/prism-autoloader.js

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"javascript"
100100
],
101101
"purebasic": "clike",
102+
"purescript": "haskell",
102103
"qml": "javascript",
103104
"qore": "clike",
104105
"racket": "scheme",
@@ -197,6 +198,7 @@
197198
"pq": "powerquery",
198199
"mscript": "powerquery",
199200
"pbfasm": "purebasic",
201+
"purs": "purescript",
200202
"py": "python",
201203
"rkt": "racket",
202204
"rpy": "renpy",

‎plugins/autoloader/prism-autoloader.min.js

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

‎plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"protobuf": "Protocol Buffers",
151151
"purebasic": "PureBasic",
152152
"pbfasm": "PureBasic",
153+
"purs": "PureScript",
153154
"py": "Python",
154155
"q": "Q (kdb+ database)",
155156
"qml": "QML",

‎plugins/show-language/prism-show-language.min.js

+1-1
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,109 @@
1+
when
2+
unless
3+
liftA1
4+
apply
5+
bind
6+
discard
7+
join
8+
ifM
9+
identity
10+
whenM
11+
unlessM
12+
liftM1
13+
ap
14+
compose
15+
otherwise
16+
top
17+
bottom
18+
recip
19+
eq
20+
notEq
21+
degree
22+
div
23+
mod
24+
lcm
25+
gcd
26+
flip
27+
const
28+
map
29+
void
30+
flap
31+
conj
32+
disj
33+
not
34+
mempty
35+
compare
36+
min
37+
max
38+
comparing
39+
clamp
40+
between
41+
sub
42+
negate
43+
append
44+
add
45+
zero
46+
mul
47+
one
48+
show
49+
unit
50+
absurd
51+
52+
----------------------------------------------------
53+
54+
[
55+
["builtin", "when"],
56+
["builtin", "unless"],
57+
["builtin", "liftA1"],
58+
["builtin", "apply"],
59+
["builtin", "bind"],
60+
["builtin", "discard"],
61+
["builtin", "join"],
62+
["builtin", "ifM"],
63+
["builtin", "identity"],
64+
["builtin", "whenM"],
65+
["builtin", "unlessM"],
66+
["builtin", "liftM1"],
67+
["builtin", "ap"],
68+
["builtin", "compose"],
69+
["builtin", "otherwise"],
70+
["builtin", "top"],
71+
["builtin", "bottom"],
72+
["builtin", "recip"],
73+
["builtin", "eq"],
74+
["builtin", "notEq"],
75+
["builtin", "degree"],
76+
["builtin", "div"],
77+
["builtin", "mod"],
78+
["builtin", "lcm"],
79+
["builtin", "gcd"],
80+
["builtin", "flip"],
81+
["builtin", "const"],
82+
["builtin", "map"],
83+
["builtin", "void"],
84+
["builtin", "flap"],
85+
["builtin", "conj"],
86+
["builtin", "disj"],
87+
["builtin", "not"],
88+
["builtin", "mempty"],
89+
["builtin", "compare"],
90+
["builtin", "min"],
91+
["builtin", "max"],
92+
["builtin", "comparing"],
93+
["builtin", "clamp"],
94+
["builtin", "between"],
95+
["builtin", "sub"],
96+
["builtin", "negate"],
97+
["builtin", "append"],
98+
["builtin", "add"],
99+
["builtin", "zero"],
100+
["builtin", "mul"],
101+
["builtin", "one"],
102+
["builtin", "show"],
103+
["builtin", "unit"],
104+
["builtin", "absurd"]
105+
]
106+
107+
----------------------------------------------------
108+
109+
Checks for all builtin.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'a'
2+
'\n'
3+
'\23'
4+
'\xFE'
5+
6+
----------------------------------------------------
7+
8+
[
9+
["char", "'a'"],
10+
["char", "'\\n'"],
11+
["char", "'\\23'"],
12+
["char", "'\\xFE'"]
13+
]
14+
15+
----------------------------------------------------
16+
17+
Checks for chars.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- foo
2+
{- foo
3+
bar -}
4+
5+
----------------------------------------------------
6+
7+
[
8+
["comment", "-- foo"],
9+
["comment", "{- foo\r\nbar -}"]
10+
]
11+
12+
----------------------------------------------------
13+
14+
Checks for single-line and multi-line comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Foo
2+
Foo.Bar
3+
Baz.Foobar_42
4+
5+
----------------------------------------------------
6+
7+
[
8+
["constant", "Foo"],
9+
["constant", "Foo.Bar"],
10+
["constant", "Baz.Foobar_42"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for constants.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
foo
2+
Foo.bar
3+
Baz.foobar_42
4+
5+
----------------------------------------------------
6+
7+
[
8+
["hvariable", "foo"],
9+
["hvariable", "Foo.bar"],
10+
["hvariable", "Baz.foobar_42"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for hvariables.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Foo
2+
import Foo_42.Bar as Foobar
3+
import Foo.Bar as Foo.Baz hiding
4+
import Foo.Bar (test)
5+
6+
----------------------------------------------------
7+
8+
[
9+
["import-statement", [
10+
["keyword", "import"],
11+
" Foo"
12+
]],
13+
["import-statement", [
14+
["keyword", "import"],
15+
" Foo_42.Bar ",
16+
["keyword", "as"],
17+
" Foobar"
18+
]],
19+
["import-statement", [
20+
["keyword", "import"],
21+
" Foo.Bar ",
22+
["keyword", "as"],
23+
" Foo.Baz ",
24+
["keyword", "hiding"]
25+
]],
26+
["import-statement", [
27+
["keyword", "import"],
28+
" Foo.Bar"
29+
]],
30+
["punctuation", "("],
31+
["hvariable", "test"],
32+
["punctuation", ")"]
33+
]
34+
35+
----------------------------------------------------
36+
37+
Checks for import statement.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
ado
2+
case
3+
class
4+
data
5+
derive
6+
do
7+
else
8+
if
9+
in
10+
infixl
11+
infixr
12+
instance
13+
let
14+
module
15+
newtype
16+
of
17+
primitive
18+
then
19+
type
20+
where
21+
22+
----------------------------------------------------
23+
24+
[
25+
["keyword", "ado"],
26+
["keyword", "case"],
27+
["keyword", "class"],
28+
["keyword", "data"],
29+
["keyword", "derive"],
30+
["keyword", "do"],
31+
["keyword", "else"],
32+
["keyword", "if"],
33+
["keyword", "in"],
34+
["keyword", "infixl"],
35+
["keyword", "infixr"],
36+
["keyword", "instance"],
37+
["keyword", "let"],
38+
["keyword", "module"],
39+
["keyword", "newtype"],
40+
["keyword", "of"],
41+
["keyword", "primitive"],
42+
["keyword", "then"],
43+
["keyword", "type"],
44+
["keyword", "where"]
45+
]
46+
47+
----------------------------------------------------
48+
49+
Checks for all keywords.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
42
2+
3.14159
3+
2E3
4+
1.2e-4
5+
0.9e+1
6+
0o47
7+
0xBadFace
8+
9+
----------------------------------------------------
10+
11+
[
12+
["number", "42"],
13+
["number", "3.14159"],
14+
["number", "2E3"],
15+
["number", "1.2e-4"],
16+
["number", "0.9e+1"],
17+
["number", "0o47"],
18+
["number", "0xBadFace"]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for decimal, octal and hexadecimal numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
..
2+
reverse <<< sort
3+
`foo`
4+
`Foo.bar`
5+
+ - * /
6+
^ ^^ **
7+
&& ||
8+
< <= == /=
9+
>= > \ |
10+
++ : !!
11+
\\ <- ->
12+
= :: =>
13+
>> >>= >@>
14+
~ ! @
15+
16+
----------------------------------------------------
17+
18+
[
19+
["operator", ".."],
20+
["hvariable", "reverse"],
21+
["operator", "<<<"],
22+
["hvariable", "sort"],
23+
["operator", "`foo`"],
24+
["operator", "`Foo.bar`"],
25+
["operator", "+"],
26+
["operator", "-"],
27+
["operator", "*"],
28+
["operator", "/"],
29+
["operator", "^"],
30+
["operator", "^^"],
31+
["operator", "**"],
32+
["operator", "&&"],
33+
["operator", "||"],
34+
["operator", "<"],
35+
["operator", "<="],
36+
["operator", "=="],
37+
["operator", "/="],
38+
["operator", ">="],
39+
["operator", ">"],
40+
["operator", "\\"],
41+
["operator", "|"],
42+
["operator", "++"],
43+
["operator", ":"],
44+
["operator", "!!"],
45+
["operator", "\\\\"],
46+
["operator", "<-"],
47+
["operator", "->"],
48+
["operator", "="],
49+
["operator", "::"],
50+
["operator", "=>"],
51+
["operator", ">>"],
52+
["operator", ">>="],
53+
["operator", ">@>"],
54+
["operator", "~"],
55+
["operator", "!"],
56+
["operator", "@"]
57+
]
58+
59+
----------------------------------------------------
60+
61+
Checks for operators.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
""
2+
"fo\"o"
3+
"foo \
4+
\ bar"
5+
"foo -- comment lookalike \
6+
\ bar"
7+
8+
----------------------------------------------------
9+
10+
[
11+
["string", "\"\""],
12+
["string", "\"fo\\\"o\""],
13+
["string", "\"foo \\\r\n \\ bar\""],
14+
["string", "\"foo -- comment lookalike \\\r\n \\ bar\""]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for strings.

0 commit comments

Comments
 (0)
Please sign in to comment.