diff --git a/components/prism-maxscript.js b/components/prism-maxscript.js index 0c775aa88a..ba0a2b218b 100644 --- a/components/prism-maxscript.js +++ b/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)); diff --git a/components/prism-maxscript.min.js b/components/prism-maxscript.min.js index 4716930cf5..910dcb0845 100644 --- a/components/prism-maxscript.min.js +++ b/components/prism-maxscript.min.js @@ -1 +1 @@ -Prism.languages.maxscript={comment:{pattern:/\/\*[\s\S]*?(?:\*\/|$)|--.*/,greedy:!0},string:{pattern:/(^|[^"\\@])(?:"(?:[^"\\]|\\[\s\S])*"|@"[^"]*")/,lookbehind:!0,greedy:!0},path:{pattern:/\$(?:[\w/\\.*?]|'[^']*')*/,greedy:!0,alias:"string"},"function-definition":{pattern:/(\b(?:fn|function)\s+)\w+\b/,lookbehind:!0,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:!0,alias:"number"},number:[{pattern:/(^|[^\w.])(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?|0x[a-fA-F0-9]+)(?![\w.:])/,lookbehind:!0},/\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}; \ No newline at end of file +!function(t){var e=/\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:!0},string:{pattern:/(^|[^"\\@])(?:"(?:[^"\\]|\\[\s\S])*"|@"[^"]*")/,lookbehind:!0,greedy:!0},path:{pattern:/\$(?:[\w/\\.*?]|'[^']*')*/,greedy:!0,alias:"string"},"function-call":{pattern:RegExp("((?:^|[;=<>+\\-*/^({\\[]|\\b(?:and|by|case|catch|collect|do|else|if|in|not|or|return|then|to|try|where|while|with)\\b)[ \t]*)(?!"+e.source+")[a-z_]\\w*\\b(?=[ \t]*(?:(?!"+e.source+")[a-z_]|\\d|-\\.?\\d|[({'\"$@#?]))","im"),lookbehind:!0,greedy:!0,alias:"function"},"function-definition":{pattern:/(\b(?:fn|function)\s+)\w+\b/i,lookbehind:!0,alias:"function"},argument:{pattern:/\b[a-z_]\w*(?=:)/i,alias:"attr-name"},keyword:e,boolean:/\b(?:false|true)\b/,time:{pattern:/(^|[^\w.])(?:(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?[msft])+|\d+:\d+(?:\.\d*)?)(?![\w.:])/,lookbehind:!0,alias:"number"},number:[{pattern:/(^|[^\w.])(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eEdD][+-]\d+|[LP])?|0x[a-fA-F0-9]+)(?![\w.:])/,lookbehind:!0},/\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}}(); \ No newline at end of file diff --git a/tests/languages/maxscript/boolean_feature.test b/tests/languages/maxscript/boolean_feature.test index 42f44fd639..4d678006fc 100644 --- a/tests/languages/maxscript/boolean_feature.test +++ b/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", ";"] ] diff --git a/tests/languages/maxscript/color_feature.test b/tests/languages/maxscript/color_feature.test index df3b1150c4..f2fad5fff9 100644 --- a/tests/languages/maxscript/color_feature.test +++ b/tests/languages/maxscript/color_feature.test @@ -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"] ] diff --git a/tests/languages/maxscript/constant_feature.test b/tests/languages/maxscript/constant_feature.test index e3a82dc998..fc5a9c9ad5 100644 --- a/tests/languages/maxscript/constant_feature.test +++ b/tests/languages/maxscript/constant_feature.test @@ -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"] ] diff --git a/tests/languages/maxscript/function_feature.test b/tests/languages/maxscript/function_feature.test index 6395e994b7..baf28df386 100644 --- a/tests/languages/maxscript/function_feature.test +++ b/tests/languages/maxscript/function_feature.test @@ -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!" + ---------------------------------------------------- [ @@ -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", "-"], @@ -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"], @@ -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!\""] ] diff --git a/tests/languages/maxscript/keyword_feature.test b/tests/languages/maxscript/keyword_feature.test index 1df37aacac..200aac37ca 100644 --- a/tests/languages/maxscript/keyword_feature.test +++ b/tests/languages/maxscript/keyword_feature.test @@ -26,6 +26,8 @@ mapped; max; not; of; +off; +on; or; parameters; persistent; @@ -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", ";"], diff --git a/tests/languages/maxscript/number_feature.test b/tests/languages/maxscript/number_feature.test index 83344a4765..c01246e683 100644 --- a/tests/languages/maxscript/number_feature.test +++ b/tests/languages/maxscript/number_feature.test @@ -5,7 +5,8 @@ 0x0E .1 -e pi +e +pi ---------------------------------------------------- @@ -17,5 +18,6 @@ e pi ["number", "0x0E"], ["number", ".1"], - ["number", "e"], ["number", "pi"] + ["number", "e"], + ["number", "pi"] ] diff --git a/tests/languages/maxscript/path_feature.test b/tests/languages/maxscript/path_feature.test index f57f10720c..a4334f25aa 100644 --- a/tests/languages/maxscript/path_feature.test +++ b/tests/languages/maxscript/path_feature.test @@ -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",