Skip to content

Commit

Permalink
Added support for Moonscript (#2100)
Browse files Browse the repository at this point in the history
This adds support for the Moonscript language.
  • Loading branch information
RunDevelopment authored Oct 25, 2019
1 parent aaf13aa commit f31946b
Show file tree
Hide file tree
Showing 19 changed files with 542 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@
"title": "Monkey",
"owner": "Golmote"
},
"moonscript": {
"title": "MoonScript",
"alias": "moon",
"owner": "RunDevelopment"
},
"n1ql": {
"title": "N1QL",
"owner": "TMWilds"
Expand Down
57 changes: 57 additions & 0 deletions components/prism-moonscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Prism.languages.moonscript = {
'comment': /--.*/,
'string': [
{
pattern: /'[^']*'|\[(=*)\[[\s\S]*?\]\1\]/,
greedy: true
},
{
pattern: /"[^"]*"/,
greedy: true,
inside: {
'interpolation': {
pattern: /#\{[^{}]*\}/,
inside: {
'moonscript': {
pattern: /(^#\{)[\s\S]+(?=\})/,
lookbehind: true,
inside: null // see beow
},
'interpolation-punctuation': {
pattern: /#\{|\}/,
alias: 'punctuation'
}
}
}
}
}
],
'class-name': [
{
pattern: /(\b(?:class|extends)[ \t]+)\w+/,
lookbehind: true
},
// class-like names start with a capital letter
/\b[A-Z]\w*/
],
'keyword': /\b(?:class|continue|do|else|elseif|export|extends|for|from|if|import|in|local|nil|return|self|super|switch|then|unless|using|when|while|with)\b/,
'variable': /@@?\w*/,
'property': {
pattern: /\b(?!\d)\w+(?=:)|(:)(?!\d)\w+/,
lookbehind: true
},
'function': {
pattern: /\b(?:_G|_VERSION|assert|collectgarbage|coroutine\.(?:running|create|resume|status|wrap|yield)|debug\.(?:debug|gethook|getinfo|getlocal|getupvalue|setlocal|setupvalue|sethook|traceback|getfenv|getmetatable|getregistry|setfenv|setmetatable)|dofile|error|getfenv|getmetatable|io\.(?:stdin|stdout|stderr|close|flush|input|lines|open|output|popen|read|tmpfile|type|write)|ipairs|load|loadfile|loadstring|math\.(?:abs|acos|asin|atan|atan2|ceil|sin|cos|tan|deg|exp|floor|log|log10|max|min|fmod|modf|cosh|sinh|tanh|pow|rad|sqrt|frexp|ldexp|random|randomseed|pi)|module|next|os\.(?:clock|date|difftime|execute|exit|getenv|remove|rename|setlocale|time|tmpname)|package\.(?:cpath|loaded|loadlib|path|preload|seeall)|pairs|pcall|print|rawequal|rawget|rawset|require|select|setfenv|setmetatable|string\.(?:byte|char|dump|find|len|lower|rep|sub|upper|format|gsub|gmatch|match|reverse)|table\.(?:maxn|concat|sort|insert|remove)|tonumber|tostring|type|unpack|xpcall)\b/,
inside: {
'punctuation': /\./
}
},
'boolean': /\b(?:false|true)\b/,
'number': /(?:\B\.\d+|\b\d+\.\d+|\b\d+(?=[eE]))(?:[eE][-+]?\d+)?\b|\b(?:0x[a-fA-F\d]+|\d+)(?:U?LL)?\b/,
'operator': /\.{3}|[-=]>|~=|(?:[-+*/%<>!=]|\.\.)=?|[:#^]|\b(?:and|or)\b=?|\b(?:not)\b/,
'punctuation': /[.,()[\]{}\\]/
};

Prism.languages.moonscript.string[1].inside.interpolation.inside.moonscript.inside = Prism.languages.moonscript;

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

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

64 changes: 64 additions & 0 deletions examples/prism-moonscript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<h2>Full example</h2>
<pre><code>class List
new: (t) =>
if t then return t

append: table.insert
join: table.concat

map: (f,...) => List [f x,... for x in *self]

-- apply a function on a list in-place
apply: (f,...) =>
for i = 1,#@ do @[i] = f @[i],...
self

clone: => @slice 1

slice: (i1,i2=#@) =>
-- workaround for MS slice bug
if i2 &lt; 0 then i2 = #@ + i2 + 1
List [x for x in *self[i1,i2]]

extend: (other) =>
i = #self + 1
for o in *other
self[i] = o
i += 1
self

partition: (pred,...) =>
res = {}
for x in *@
k = pred x,...
if not res[k] then res[k] = List!
res[k]\append x
res

lpartition: (n,npred,...) =>
res = List[List{} for i = 1,n]
for x in *@
k = npred x,...
if k >= 1 and k &lt;= n
res[k]\append x
res

__concat: (l1,l2) ->
List.clone(l1)\extend l2

__tostring: =>
tmp = @slice(1,10)\apply tostring
if #@ > 10 then tmp\append '...'
"["..tmp\join(',').."]"

-- hack to modify class so its constructor may return a new self
patch = (klass) -> getmetatable(klass).__call = (cls,...) ->
self = setmetatable {}, cls.__base
newself = cls.__init self, ...
if newself
self = setmetatable newself, cls.__base
self

patch List

return List</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"elisp": "lisp",
"emacs-lisp": "lisp",
"md": "markdown",
"moon": "moonscript",
"n4jsd": "n4js",
"objectpascal": "pascal",
"px": "pcaxis",
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 @@ -96,6 +96,7 @@
"markup-templating": "Markup templating",
"matlab": "MATLAB",
"mel": "MEL",
"moon": "MoonScript",
"n1ql": "N1QL",
"n4js": "N4JS",
"n4jsd": "N4JS",
Expand Down
Loading

0 comments on commit f31946b

Please sign in to comment.