Skip to content

Commit e9b856c

Browse files
MAXScript: Various improvements (#3181)
1 parent 0ecdbdc commit e9b856c

9 files changed

+183
-80
lines changed

components/prism-maxscript.js

+91-52
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,91 @@
1-
Prism.languages.maxscript = {
2-
'comment': {
3-
pattern: /\/\*[\s\S]*?(?:\*\/|$)|--.*/,
4-
greedy: true
5-
},
6-
'string': {
7-
pattern: /(^|[^"\\@])(?:"(?:[^"\\]|\\[\s\S])*"|@"[^"]*")/,
8-
lookbehind: true,
9-
greedy: true
10-
},
11-
'path': {
12-
pattern: /\$(?:[\w/\\.*?]|'[^']*')*/,
13-
greedy: true,
14-
alias: 'string'
15-
},
16-
17-
'function-definition': {
18-
pattern: /(\b(?:fn|function)\s+)\w+\b/,
19-
lookbehind: true,
20-
alias: 'function'
21-
},
22-
23-
'argument': {
24-
pattern: /\b[a-z_]\w*(?=:)/i,
25-
alias: 'attr-name'
26-
},
27-
28-
'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,
29-
'boolean': /\b(?:false|off|on|true)\b/,
30-
31-
'time': {
32-
pattern: /(^|[^\w.])(?:(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?[msft])+|\d+:\d+(?:\.\d*)?)(?![\w.:])/,
33-
lookbehind: true,
34-
alias: 'number'
35-
},
36-
'number': [
37-
{
38-
pattern: /(^|[^\w.])(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?|0x[a-fA-F0-9]+)(?![\w.:])/,
39-
lookbehind: true
40-
},
41-
/\b(?:e|pi)\b/
42-
],
43-
44-
'constant': /\b(?:black|blue|brown|gray|green|orange|red|white|yellow)\b/,
45-
'color': {
46-
pattern: /\b(?:dontcollect|ok|silentValue|undefined|unsupplied)\b/i,
47-
alias: 'constant'
48-
},
49-
50-
'operator': /[-+*/<>=!]=?|[&^]|#(?!\()/,
51-
'punctuation': /[()\[\]{}.:,;]|#(?=\()|\\$/m
52-
};
1+
(function (Prism) {
2+
3+
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;
4+
5+
6+
Prism.languages.maxscript = {
7+
'comment': {
8+
pattern: /\/\*[\s\S]*?(?:\*\/|$)|--.*/,
9+
greedy: true
10+
},
11+
'string': {
12+
pattern: /(^|[^"\\@])(?:"(?:[^"\\]|\\[\s\S])*"|@"[^"]*")/,
13+
lookbehind: true,
14+
greedy: true
15+
},
16+
'path': {
17+
pattern: /\$(?:[\w/\\.*?]|'[^']*')*/,
18+
greedy: true,
19+
alias: 'string'
20+
},
21+
22+
'function-call': {
23+
pattern: RegExp(
24+
'((?:' + (
25+
// start of line
26+
/^/.source +
27+
'|' +
28+
// operators and other language constructs
29+
/[;=<>+\-*/^({\[]/.source +
30+
'|' +
31+
// keywords as part of statements
32+
/\b(?:and|by|case|catch|collect|do|else|if|in|not|or|return|then|to|try|where|while|with)\b/.source
33+
) + ')[ \t]*)' +
34+
35+
'(?!' + keywords.source + ')' + /[a-z_]\w*\b/.source +
36+
37+
'(?=[ \t]*(?:' + (
38+
// variable
39+
'(?!' + keywords.source + ')' + /[a-z_]/.source +
40+
'|' +
41+
// number
42+
/\d|-\.?\d/.source +
43+
'|' +
44+
// other expressions or literals
45+
/[({'"$@#?]/.source
46+
) + '))',
47+
'im'
48+
),
49+
lookbehind: true,
50+
greedy: true,
51+
alias: 'function'
52+
},
53+
54+
'function-definition': {
55+
pattern: /(\b(?:fn|function)\s+)\w+\b/i,
56+
lookbehind: true,
57+
alias: 'function'
58+
},
59+
60+
'argument': {
61+
pattern: /\b[a-z_]\w*(?=:)/i,
62+
alias: 'attr-name'
63+
},
64+
65+
'keyword': keywords,
66+
'boolean': /\b(?:false|true)\b/,
67+
68+
'time': {
69+
pattern: /(^|[^\w.])(?:(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?[msft])+|\d+:\d+(?:\.\d*)?)(?![\w.:])/,
70+
lookbehind: true,
71+
alias: 'number'
72+
},
73+
'number': [
74+
{
75+
pattern: /(^|[^\w.])(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?|0x[a-fA-F0-9]+)(?![\w.:])/,
76+
lookbehind: true
77+
},
78+
/\b(?:e|pi)\b/
79+
],
80+
81+
'constant': /\b(?:dontcollect|ok|silentValue|undefined|unsupplied)\b/,
82+
'color': {
83+
pattern: /\b(?:black|blue|brown|gray|green|orange|red|white|yellow)\b/i,
84+
alias: 'constant'
85+
},
86+
87+
'operator': /[-+*/<>=!]=?|[&^?]|#(?!\()/,
88+
'punctuation': /[()\[\]{}.:,;]|#(?=\()|\\$/m
89+
};
90+
91+
}(Prism));

components/prism-maxscript.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
true false
2-
on off
1+
true;
2+
false;
33

44
----------------------------------------------------
55

66
[
7-
["boolean", "true"], ["boolean", "false"],
8-
["boolean", "on"], ["boolean", "off"]
7+
["boolean", "true"],
8+
["punctuation", ";"],
9+
["boolean", "false"],
10+
["punctuation", ";"]
911
]

tests/languages/maxscript/color_feature.test

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ yellow
1111
----------------------------------------------------
1212

1313
[
14-
["constant", "black"],
15-
["constant", "blue"],
16-
["constant", "brown"],
17-
["constant", "gray"],
18-
["constant", "green"],
19-
["constant", "orange"],
20-
["constant", "red"],
21-
["constant", "white"],
22-
["constant", "yellow"]
14+
["color", "black"],
15+
["color", "blue"],
16+
["color", "brown"],
17+
["color", "gray"],
18+
["color", "green"],
19+
["color", "orange"],
20+
["color", "red"],
21+
["color", "white"],
22+
["color", "yellow"]
2323
]

tests/languages/maxscript/constant_feature.test

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ unsupplied
77
----------------------------------------------------
88

99
[
10-
["color", "dontcollect"],
11-
["color", "ok"],
12-
["color", "silentValue"],
13-
["color", "undefined"],
14-
["color", "unsupplied"]
10+
["constant", "dontcollect"],
11+
["constant", "ok"],
12+
["constant", "silentValue"],
13+
["constant", "undefined"],
14+
["constant", "unsupplied"]
1515
]

tests/languages/maxscript/function_feature.test

+61-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
1010
-- something
1111
)
1212

13+
fn saddle x y = sin x * sin y
14+
15+
print "build math mesh"
16+
in_name = getOpenFileName()
17+
val.x=random -100 100
18+
append vert_array (readValue in_file)
19+
while not eof f do
20+
on pressme pressed do print "Pressed!"
21+
1322
----------------------------------------------------
1423

1524
[
@@ -34,7 +43,7 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
3443
["keyword", "else"],
3544
" n ",
3645
["operator", "*"],
37-
" factorial ",
46+
["function-call", "factorial"],
3847
["punctuation", "("],
3948
"n ",
4049
["operator", "-"],
@@ -51,15 +60,15 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
5160
["punctuation", "."],
5261
"wireColor ",
5362
["operator", "="],
54-
" random ",
63+
["function-call", "random"],
5564
["punctuation", "("],
56-
"color ",
65+
["function-call", "color"],
5766
["number", "0"],
5867
["number", "0"],
5968
["number", "0"],
6069
["punctuation", ")"],
6170
["punctuation", "("],
62-
"color ",
71+
["function-call", "color"],
6372
["number", "255"],
6473
["number", "255"],
6574
["number", "255"],
@@ -92,5 +101,52 @@ fn starfield count extent:[200,200,200] pos:[0,0,0] =
92101

93102
["comment", "-- something"],
94103

95-
["punctuation", ")"]
104+
["punctuation", ")"],
105+
106+
["keyword", "fn"],
107+
["function-definition", "saddle"],
108+
" x y ",
109+
["operator", "="],
110+
["function-call", "sin"],
111+
" x ",
112+
["operator", "*"],
113+
["function-call", "sin"],
114+
" y\r\n\r\n",
115+
116+
["function-call", "print"],
117+
["string", "\"build math mesh\""],
118+
119+
"\r\nin_name ",
120+
["operator", "="],
121+
["function-call", "getOpenFileName"],
122+
["punctuation", "("],
123+
["punctuation", ")"],
124+
125+
"\r\nval",
126+
["punctuation", "."],
127+
"x",
128+
["operator", "="],
129+
["function-call", "random"],
130+
["operator", "-"],
131+
["number", "100"],
132+
["number", "100"],
133+
134+
["function-call", "append"],
135+
" vert_array ",
136+
["punctuation", "("],
137+
["function-call", "readValue"],
138+
" in_file",
139+
["punctuation", ")"],
140+
141+
["keyword", "while"],
142+
["keyword", "not"],
143+
["function-call", "eof"],
144+
" f ",
145+
["keyword", "do"],
146+
147+
["keyword", "on"],
148+
" pressme pressed ",
149+
["keyword", "do"],
150+
["function-call", "print"],
151+
["string", "\"Pressed!\""]
96152
]

tests/languages/maxscript/keyword_feature.test

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ mapped;
2626
max;
2727
not;
2828
of;
29+
off;
30+
on;
2931
or;
3032
parameters;
3133
persistent;
@@ -78,6 +80,8 @@ with;
7880
["keyword", "max"], ["punctuation", ";"],
7981
["keyword", "not"], ["punctuation", ";"],
8082
["keyword", "of"], ["punctuation", ";"],
83+
["keyword", "off"], ["punctuation", ";"],
84+
["keyword", "on"], ["punctuation", ";"],
8185
["keyword", "or"], ["punctuation", ";"],
8286
["keyword", "parameters"], ["punctuation", ";"],
8387
["keyword", "persistent"], ["punctuation", ";"],

tests/languages/maxscript/number_feature.test

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
0x0E
66
.1
77

8-
e pi
8+
e
9+
pi
910

1011
----------------------------------------------------
1112

@@ -17,5 +18,6 @@ e pi
1718
["number", "0x0E"],
1819
["number", ".1"],
1920

20-
["number", "e"], ["number", "pi"]
21+
["number", "e"],
22+
["number", "pi"]
2123
]

tests/languages/maxscript/path_feature.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ bodyPart=$Bip01_L_UpperArm
7474
["number", "0"],
7575
["punctuation", "]"],
7676

77-
"\r\nhide ",
77+
["function-call", "hide"],
7878
["path", "$"],
7979

80-
"\r\nrotate ",
80+
["function-call", "rotate"],
8181
["path", "$"],
8282
["number", "35"],
8383
" z_axis\r\n\r\n",

0 commit comments

Comments
 (0)