Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for MAXScript (#3060)
  • Loading branch information
RunDevelopment committed Sep 15, 2021
1 parent 746a4b1 commit 4fbdd2f
Show file tree
Hide file tree
Showing 19 changed files with 573 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -812,6 +812,10 @@
"title": "MATLAB",
"owner": "Golmote"
},
"maxscript": {
"title": "MAXScript",
"owner": "RunDevelopment"
},
"mel": {
"title": "MEL",
"owner": "Golmote"
Expand Down
52 changes: 52 additions & 0 deletions components/prism-maxscript.js
@@ -0,0 +1,52 @@
Prism.languages.maxscript = {
'comment': {
pattern: /\/\*[\s\S]*?(?:\*\/|$)|--.*/,
greedy: true
},
'string': {
pattern: /(^|[^"\\@])(?:"(?:[^"\\]|\\[\s\S])*"|@"[^"]*")/,
lookbehind: true,
greedy: true
},
'path': {
pattern: /\$(?:[\w/\\.*?]|'[^']*')*/,
greedy: true,
alias: 'string'
},

'function-definition': {
pattern: /(\b(?:function|fn)\s+)\w+\b/,
lookbehind: true,
alias: 'function'
},

'argument': {
pattern: /\b[a-z_]\w*(?=:)/i,
alias: 'attr-name'
},

'keyword': /\b(?:about|and|animate|as|at|attributes|by|case|catch|collect|continue|coordsys|do|else|exit|fn|for|from|function|global|if|in|local|macroscript|mapped|max|not|of|off|on|or|parameters|persistent|plugin|rcmenu|return|rollout|set|struct|then|throw|to|tool|try|undo|utility|when|where|while|with)\b/i,
'boolean': /\b(?:true|false|on|off)\b/,

'time': {
pattern: /(^|[^\w.])(?:(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?[msft])+|\d+:\d+(?:\.\d*)?)(?![\w.:])/,
lookbehind: true,
alias: 'number'
},
'number': [
{
pattern: /(^|[^\w.])(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?|0x[a-fA-F0-9]+)(?![\w.:])/,
lookbehind: true
},
/\b(?:e|pi)\b/
],

'constant': /\b(?:black|blue|brown|gray|green|orange|red|white|yellow)\b/,
'color': {
pattern: /\b(?:dontcollect|ok|silentValue|undefined|unsupplied)\b/i,
alias: 'constant'
},

'operator': /[-+*/<>=!]=?|[&^]|#(?!\()/,
'punctuation': /[()\[\]{}.:,;]|#(?=\()|\\$/m
};
1 change: 1 addition & 0 deletions components/prism-maxscript.min.js

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

33 changes: 33 additions & 0 deletions examples/prism-maxscript.html
@@ -0,0 +1,33 @@
<h2>Strings</h2>
<pre><code>-- Source: https://help.autodesk.com/view/MAXDEV/2022/ENU/?guid=GUID-5E5E1A71-24E2-4605-9720-2178B941DECC

plugin RenderEffect MonoChrome
name:"MonoChrome"
classID:#(0x9e6e9e77, 0xbe815df4)
(
rollout about_rollout "About..."
(
label about_label "MonoChrome Filter"
)
on apply r_image progressCB: do
(
progressCB.setTitle "MonoChrome Effect"
local oldEscapeEnable = escapeEnable
escapeEnable = false
bmp_w = r_image.width
bmp_h = r_image.height
for y = 0 to bmp_h-1 do
(
if progressCB.progress y (bmp_h-1) then exit
pixel_line = getPixels r_image [0,y] bmp_w
for x = 1 to bmp_w do
(
p_v = pixel_line[x].value
pixel_line[x] = color p_v p_v p_v pixel_line[x].alpha
)--end x loop
setPixels r_image [0,y] pixel_line
)--end y loop
escapeEnable = oldEscapeEnable
)--end on apply
)--end plugin
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -143,6 +143,7 @@
"md": "Markdown",
"markup-templating": "Markup templating",
"matlab": "MATLAB",
"maxscript": "MAXScript",
"mel": "MEL",
"mongodb": "MongoDB",
"moon": "MoonScript",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

7 changes: 7 additions & 0 deletions tests/languages/maxscript/boolean_feature.test
@@ -0,0 +1,7 @@
true false

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

[
["boolean", "true"], ["boolean", "false"]
]
23 changes: 23 additions & 0 deletions tests/languages/maxscript/color_feature.test
@@ -0,0 +1,23 @@
black
blue
brown
gray
green
orange
red
white
yellow

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

[
["constant", "black"],
["constant", "blue"],
["constant", "brown"],
["constant", "gray"],
["constant", "green"],
["constant", "orange"],
["constant", "red"],
["constant", "white"],
["constant", "yellow"]
]
29 changes: 29 additions & 0 deletions tests/languages/maxscript/comment_feature.test
@@ -0,0 +1,29 @@
/* this is a long comment
blah blah
print "debug 1" -- code commented out
more comments
*/

for i in 1 to 10 do(/* messageBox "in loop"; */frabulate i )

-- comment

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

[
["comment", "/* this is a long comment\r\nblah blah\r\nprint \"debug 1\" -- code commented out\r\nmore comments\r\n*/"],

["keyword", "for"],
" i ",
["keyword", "in"],
["number", "1"],
["keyword", "to"],
["number", "10"],
["keyword", "do"],
["punctuation", "("],
["comment", "/* messageBox \"in loop\"; */"],
"frabulate i ",
["punctuation", ")"],

["comment", "-- comment"]
]
15 changes: 15 additions & 0 deletions tests/languages/maxscript/constant_feature.test
@@ -0,0 +1,15 @@
dontcollect
ok
silentValue
undefined
unsupplied

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

[
["color", "dontcollect"],
["color", "ok"],
["color", "silentValue"],
["color", "undefined"],
["color", "unsupplied"]
]
96 changes: 96 additions & 0 deletions tests/languages/maxscript/function_feature.test
@@ -0,0 +1,96 @@
function my_add a b = a + b

fn factorial n = if n <= 0 then 1 else n * factorial (n - 1)

mapped function rand_color x =
x.wireColor = random (color 0 0 0) (color 255 255 255)

fn starfield count extent:[200,200,200] pos:[0,0,0] =
(
-- something
)

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

[
["keyword", "function"],
["function-definition", "my_add"],
" a b ",
["operator", "="],
" a ",
["operator", "+"],
" b\r\n\r\n",

["keyword", "fn"],
["function-definition", "factorial"],
" n ",
["operator", "="],
["keyword", "if"],
" n ",
["operator", "<="],
["number", "0"],
["keyword", "then"],
["number", "1"],
["keyword", "else"],
" n ",
["operator", "*"],
" factorial ",
["punctuation", "("],
"n ",
["operator", "-"],
["number", "1"],
["punctuation", ")"],

["keyword", "mapped"],
["keyword", "function"],
["function-definition", "rand_color"],
" x ",
["operator", "="],

"\r\n x",
["punctuation", "."],
"wireColor ",
["operator", "="],
" random ",
["punctuation", "("],
"color ",
["number", "0"],
["number", "0"],
["number", "0"],
["punctuation", ")"],
["punctuation", "("],
"color ",
["number", "255"],
["number", "255"],
["number", "255"],
["punctuation", ")"],

["keyword", "fn"],
["function-definition", "starfield"],
" count ",
["argument", "extent"],
["punctuation", ":"],
["punctuation", "["],
["number", "200"],
["punctuation", ","],
["number", "200"],
["punctuation", ","],
["number", "200"],
["punctuation", "]"],
["argument", "pos"],
["punctuation", ":"],
["punctuation", "["],
["number", "0"],
["punctuation", ","],
["number", "0"],
["punctuation", ","],
["number", "0"],
["punctuation", "]"],
["operator", "="],

["punctuation", "("],

["comment", "-- something"],

["punctuation", ")"]
]
105 changes: 105 additions & 0 deletions tests/languages/maxscript/keyword_feature.test
@@ -0,0 +1,105 @@
about;
and;
animate;
as;
at;
attributes;
by;
case;
catch;
collect;
continue;
coordsys;
do;
else;
exit;
fn;
for;
from;
function;
global;
if;
in;
local;
macroscript;
mapped;
max;
not;
of;
off;
on;
or;
parameters;
persistent;
plugin;
rcmenu;
return;
rollout;
set;
struct;
then;
throw;
to;
tool;
try;
undo;
utility;
when;
where;
while;
with;

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

[
["keyword", "about"], ["punctuation", ";"],
["keyword", "and"], ["punctuation", ";"],
["keyword", "animate"], ["punctuation", ";"],
["keyword", "as"], ["punctuation", ";"],
["keyword", "at"], ["punctuation", ";"],
["keyword", "attributes"], ["punctuation", ";"],
["keyword", "by"], ["punctuation", ";"],
["keyword", "case"], ["punctuation", ";"],
["keyword", "catch"], ["punctuation", ";"],
["keyword", "collect"], ["punctuation", ";"],
["keyword", "continue"], ["punctuation", ";"],
["keyword", "coordsys"], ["punctuation", ";"],
["keyword", "do"], ["punctuation", ";"],
["keyword", "else"], ["punctuation", ";"],
["keyword", "exit"], ["punctuation", ";"],
["keyword", "fn"], ["punctuation", ";"],
["keyword", "for"], ["punctuation", ";"],
["keyword", "from"], ["punctuation", ";"],
["keyword", "function"], ["punctuation", ";"],
["keyword", "global"], ["punctuation", ";"],
["keyword", "if"], ["punctuation", ";"],
["keyword", "in"], ["punctuation", ";"],
["keyword", "local"], ["punctuation", ";"],
["keyword", "macroscript"], ["punctuation", ";"],
["keyword", "mapped"], ["punctuation", ";"],
["keyword", "max"], ["punctuation", ";"],
["keyword", "not"], ["punctuation", ";"],
["keyword", "of"], ["punctuation", ";"],
["keyword", "off"], ["punctuation", ";"],
["keyword", "on"], ["punctuation", ";"],
["keyword", "or"], ["punctuation", ";"],
["keyword", "parameters"], ["punctuation", ";"],
["keyword", "persistent"], ["punctuation", ";"],
["keyword", "plugin"], ["punctuation", ";"],
["keyword", "rcmenu"], ["punctuation", ";"],
["keyword", "return"], ["punctuation", ";"],
["keyword", "rollout"], ["punctuation", ";"],
["keyword", "set"], ["punctuation", ";"],
["keyword", "struct"], ["punctuation", ";"],
["keyword", "then"], ["punctuation", ";"],
["keyword", "throw"], ["punctuation", ";"],
["keyword", "to"], ["punctuation", ";"],
["keyword", "tool"], ["punctuation", ";"],
["keyword", "try"], ["punctuation", ";"],
["keyword", "undo"], ["punctuation", ";"],
["keyword", "utility"], ["punctuation", ";"],
["keyword", "when"], ["punctuation", ";"],
["keyword", "where"], ["punctuation", ";"],
["keyword", "while"], ["punctuation", ";"],
["keyword", "with"], ["punctuation", ";"]
]

0 comments on commit 4fbdd2f

Please sign in to comment.