Skip to content

Commit ad748a0

Browse files
Added PureScript language definition (#2526)
1 parent e023044 commit ad748a0

19 files changed

+448
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 6 additions & 0 deletions
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

Lines changed: 19 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-purescript.html

Lines changed: 57 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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",

0 commit comments

Comments
 (0)