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

MAXScript: Various improvements #3181

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
143 changes: 91 additions & 52 deletions components/prism-maxscript.js
@@ -1,52 +1,91 @@
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(?:fn|function)\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|or|parameters|persistent|plugin|rcmenu|return|rollout|set|struct|then|throw|to|tool|try|undo|utility|when|where|while|with)\b/i,
'boolean': /\b(?:false|off|on|true)\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
};
(function (Prism) {

var keywords = /\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;


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-call': {
pattern: RegExp(
'((?:' + (
// start of line
/^/.source +
'|' +
// operators and other language constructs
/[;=<>+\-*/^({\[]/.source +
'|' +
// keywords as part of statements
/\b(?:and|by|case|catch|collect|do|else|if|in|not|or|return|then|to|try|where|while|with)\b/.source
) + ')[ \t]*)' +

'(?!' + keywords.source + ')' + /[a-z_]\w*\b/.source +

'(?=[ \t]*(?:' + (
// variable
'(?!' + keywords.source + ')' + /[a-z_]/.source +
'|' +
// number
/\d|-\.?\d/.source +
'|' +
// other expressions or literals
/[({'"$@#?]/.source
) + '))',
'im'
),
lookbehind: true,
greedy: true,
alias: 'function'
},

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

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

'keyword': keywords,
'boolean': /\b(?:false|true)\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(?:dontcollect|ok|silentValue|undefined|unsupplied)\b/,
'color': {
pattern: /\b(?:black|blue|brown|gray|green|orange|red|white|yellow)\b/i,
alias: 'constant'
},

'operator': /[-+*/<>=!]=?|[&^?]|#(?!\()/,
'punctuation': /[()\[\]{}.:,;]|#(?=\()|\\$/m
};

}(Prism));
2 changes: 1 addition & 1 deletion components/prism-maxscript.min.js

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

10 changes: 6 additions & 4 deletions tests/languages/maxscript/boolean_feature.test
@@ -1,9 +1,11 @@
true false
on off
true;
false;

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

[
["boolean", "true"], ["boolean", "false"],
["boolean", "on"], ["boolean", "off"]
["boolean", "true"],
["punctuation", ";"],
["boolean", "false"],
["punctuation", ";"]
]
18 changes: 9 additions & 9 deletions tests/languages/maxscript/color_feature.test
Expand Up @@ -11,13 +11,13 @@ yellow
----------------------------------------------------

[
["constant", "black"],
["constant", "blue"],
["constant", "brown"],
["constant", "gray"],
["constant", "green"],
["constant", "orange"],
["constant", "red"],
["constant", "white"],
["constant", "yellow"]
["color", "black"],
["color", "blue"],
["color", "brown"],
["color", "gray"],
["color", "green"],
["color", "orange"],
["color", "red"],
["color", "white"],
["color", "yellow"]
]
10 changes: 5 additions & 5 deletions tests/languages/maxscript/constant_feature.test
Expand Up @@ -7,9 +7,9 @@ unsupplied
----------------------------------------------------

[
["color", "dontcollect"],
["color", "ok"],
["color", "silentValue"],
["color", "undefined"],
["color", "unsupplied"]
["constant", "dontcollect"],
["constant", "ok"],
["constant", "silentValue"],
["constant", "undefined"],
["constant", "unsupplied"]
]
66 changes: 61 additions & 5 deletions tests/languages/maxscript/function_feature.test
Expand Up @@ -10,6 +10,15 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
-- something
)

fn saddle x y = sin x * sin y

print "build math mesh"
in_name = getOpenFileName()
val.x=random -100 100
append vert_array (readValue in_file)
while not eof f do
on pressme pressed do print "Pressed!"

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

[
Expand All @@ -34,7 +43,7 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
["keyword", "else"],
" n ",
["operator", "*"],
" factorial ",
["function-call", "factorial"],
["punctuation", "("],
"n ",
["operator", "-"],
Expand All @@ -51,15 +60,15 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
["punctuation", "."],
"wireColor ",
["operator", "="],
" random ",
["function-call", "random"],
["punctuation", "("],
"color ",
["function-call", "color"],
["number", "0"],
["number", "0"],
["number", "0"],
["punctuation", ")"],
["punctuation", "("],
"color ",
["function-call", "color"],
["number", "255"],
["number", "255"],
["number", "255"],
Expand Down Expand Up @@ -92,5 +101,52 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =

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

["punctuation", ")"]
["punctuation", ")"],

["keyword", "fn"],
["function-definition", "saddle"],
" x y ",
["operator", "="],
["function-call", "sin"],
" x ",
["operator", "*"],
["function-call", "sin"],
" y\r\n\r\n",

["function-call", "print"],
["string", "\"build math mesh\""],

"\r\nin_name ",
["operator", "="],
["function-call", "getOpenFileName"],
["punctuation", "("],
["punctuation", ")"],

"\r\nval",
["punctuation", "."],
"x",
["operator", "="],
["function-call", "random"],
["operator", "-"],
["number", "100"],
["number", "100"],

["function-call", "append"],
" vert_array ",
["punctuation", "("],
["function-call", "readValue"],
" in_file",
["punctuation", ")"],

["keyword", "while"],
["keyword", "not"],
["function-call", "eof"],
" f ",
["keyword", "do"],

["keyword", "on"],
" pressme pressed ",
["keyword", "do"],
["function-call", "print"],
["string", "\"Pressed!\""]
]
4 changes: 4 additions & 0 deletions tests/languages/maxscript/keyword_feature.test
Expand Up @@ -26,6 +26,8 @@ mapped;
max;
not;
of;
off;
on;
or;
parameters;
persistent;
Expand Down Expand Up @@ -78,6 +80,8 @@ with;
["keyword", "max"], ["punctuation", ";"],
["keyword", "not"], ["punctuation", ";"],
["keyword", "of"], ["punctuation", ";"],
["keyword", "off"], ["punctuation", ";"],
["keyword", "on"], ["punctuation", ";"],
["keyword", "or"], ["punctuation", ";"],
["keyword", "parameters"], ["punctuation", ";"],
["keyword", "persistent"], ["punctuation", ";"],
Expand Down
6 changes: 4 additions & 2 deletions tests/languages/maxscript/number_feature.test
Expand Up @@ -5,7 +5,8 @@
0x0E
.1

e pi
e
pi

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

Expand All @@ -17,5 +18,6 @@ e pi
["number", "0x0E"],
["number", ".1"],

["number", "e"], ["number", "pi"]
["number", "e"],
["number", "pi"]
]
4 changes: 2 additions & 2 deletions tests/languages/maxscript/path_feature.test
Expand Up @@ -74,10 +74,10 @@ bodyPart=$Bip01_L_UpperArm
["number", "0"],
["punctuation", "]"],

"\r\nhide ",
["function-call", "hide"],
["path", "$"],

"\r\nrotate ",
["function-call", "rotate"],
["path", "$"],
["number", "35"],
" z_axis\r\n\r\n",
Expand Down