Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PureScript language definition #2526

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,12 @@
"alias": "pbfasm",
"owner": "HeX0R101"
},
"purescript": {
"title": "PureScript",
"require": "haskell",
"alias": "purs",
"owner": "sriharshachilakapati"
},
"python": {
"title": "Python",
"alias": "py",
Expand Down
19 changes: 19 additions & 0 deletions components/prism-purescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Prism.languages.purescript = Prism.languages.extend('haskell', {
'keyword': /\b(?:ado|case|class|data|derive|do|else|forall|if|in|infixl|infixr|instance|let|module|newtype|of|primitive|then|type|where)\b/,

'import-statement': {
// The imported or hidden names are not included in this import
// statement. This is because we want to highlight those exactly like
// we do for the names in the program.
pattern: /(^\s*)import\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*(?:\s+as\s+[A-Z][\w']*(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
lookbehind: true,
inside: {
'keyword': /\b(?:import|as|hiding)\b/
}
},

// These are builtin functions only. Constructors are highlighted later as a constant.
'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/,
});

Prism.languages.purs = Prism.languages.purescript;
1 change: 1 addition & 0 deletions components/prism-purescript.min.js

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

57 changes: 57 additions & 0 deletions examples/prism-purescript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<h2>Comments</h2>
<pre><code>-- Single line comment
{- Multi-line
comment -}</code></pre>

<h2>Strings and characters</h2>
<pre><code>'a'
'\n'
'\^A'
'\^]'
'\NUL'
'\23'
'\o75'
'\xFE'
"Here is a backslant \\ as well as \137, \
\a numeric escape character, and \^X, a control character."</code></pre>

<h2>Numbers</h2>
<pre><code>42
123.456
123.456e-789
1e+3
0o74
0XAF</code></pre>

<h2>Full example</h2>
<pre><code>module Codewars.Kata.SumFracts (sumFracts) where

import Prelude

import Data.Foldable (foldl)
import Data.BigInt (BigInt, fromInt, toString)
import Data.List (List, length)
import Data.Tuple (Tuple(..))
import Data.Maybe (Maybe(..))
import Data.Ord (abs, signum)

reduce :: Tuple BigInt BigInt -&gt; Tuple BigInt BigInt
reduce (Tuple num den) =
let gcd' = gcd num den
den' = den / gcd'
in Tuple (num / gcd' * (signum den')) (abs den')

sumFracts :: List (Tuple Int Int) -&gt; Maybe String
sumFracts fracts =
let fracts' = fracts &lt;#&gt; (\(Tuple n d) -&gt; Tuple (fromInt n) (fromInt d)) &gt;&gt;&gt; reduce

den = foldl (\acc (Tuple _ d) -&gt; lcm acc d) one fracts'
num = foldl (\acc (Tuple n d) -&gt; acc + n * (den / d)) zero fracts'

Tuple n d = reduce $ Tuple num den

in if length fracts == 0
then Nothing
else if d == one
then Just $ toString n
else Just $ (toString n) &gt;&lt; " " &gt;&lt; (toString d)</code></pre>
2 changes: 2 additions & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"javascript"
],
"purebasic": "clike",
"purescript": "haskell",
"qml": "javascript",
"qore": "clike",
"racket": "scheme",
Expand Down Expand Up @@ -197,6 +198,7 @@
"pq": "powerquery",
"mscript": "powerquery",
"pbfasm": "purebasic",
"purs": "purescript",
"py": "python",
"rkt": "racket",
"rpy": "renpy",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"protobuf": "Protocol Buffers",
"purebasic": "PureBasic",
"pbfasm": "PureBasic",
"purs": "PureScript",
"py": "Python",
"q": "Q (kdb+ database)",
"qml": "QML",
Expand Down
Loading