|
| 1 | +// http://avisynth.nl/index.php/The_full_AviSynth_grammar |
| 2 | +(function (Prism) { |
| 3 | + |
| 4 | + function replace(pattern, replacements) { |
| 5 | + return pattern.replace(/<<(\d+)>>/g, function (m, index) { |
| 6 | + return replacements[+index]; |
| 7 | + }); |
| 8 | + } |
| 9 | + |
| 10 | + function re(pattern, replacements, flags) { |
| 11 | + return RegExp(replace(pattern, replacements), flags || ''); |
| 12 | + } |
| 13 | + |
| 14 | + var types = /clip|int|float|string|bool|val/.source; |
| 15 | + var internals = [ |
| 16 | + // bools |
| 17 | + /is(?:bool|clip|float|int|string)|defined|(?:var|(?:internal)?function)?exists?/.source, |
| 18 | + // control |
| 19 | + /apply|assert|default|eval|import|select|nop|undefined/.source, |
| 20 | + // global |
| 21 | + /set(?:memorymax|cachemode|maxcpu|workingdir|planarlegacyalignment)|opt_(?:allowfloataudio|usewaveextensible|dwchannelmask|avipadscanlines|vdubplanarhack|enable_(?:v210|y3_10_10|y3_10_16|b64a|planartopackedrgb))/.source, |
| 22 | + // conv |
| 23 | + /hex(?:value)?|value/.source, |
| 24 | + // numeric |
| 25 | + /max|min|muldiv|floor|ceil|round|fmod|pi|exp|log(?:10)?|pow|sqrt|abs|sign|frac|rand|spline|continued(?:numerator|denominator)?/.source, |
| 26 | + // trig |
| 27 | + /a?sinh?|a?cosh?|a?tan[2h]?/.source, |
| 28 | + // bit |
| 29 | + /(?:bit(?:and|not|x?or|[lr]?shift[aslu]?|sh[lr]|sa[lr]|[lr]rotatel?|ro[rl]|te?st|set(?:count)?|cl(?:ea)?r|ch(?:an)?ge?))/.source, |
| 30 | + // runtime |
| 31 | + /average(?:luma|chroma[uv]|[bgr])|(?:luma|chroma[uv]|rgb|[rgb]|[yuv](?=difference(?:fromprevious|tonext)))difference(?:fromprevious|tonext)?|[yuvrgb]plane(?:median|min|max|minmaxdifference)/.source, |
| 32 | + // script |
| 33 | + /script(?:name(?:utf8)?|file(?:utf8)?|dir(?:utf8)?)|setlogparams|logmsg|getprocessinfo/.source, |
| 34 | + // string |
| 35 | + /[lu]case|str(?:toutf8|fromutf8|len|cmpi?)|(?:rev|left|right|mid|find|replace|fill)str|format|trim(?:left|right|all)|chr|ord|time/.source, |
| 36 | + // version |
| 37 | + /version(?:number|string)|isversionorgreater/.source, |
| 38 | + // helper |
| 39 | + /buildpixeltype|colorspacenametopixeltype/.source, |
| 40 | + // avsplus |
| 41 | + /setfiltermtmode|prefetch|addautoloaddir|on(?:cpu|cuda)/.source |
| 42 | + ].join('|'); |
| 43 | + var properties = [ |
| 44 | + // content |
| 45 | + /has(?:audio|video)/.source, |
| 46 | + // resolution |
| 47 | + /width|height/.source, |
| 48 | + // framerate |
| 49 | + /frame(?:count|rate)|framerate(?:numerator|denominator)/.source, |
| 50 | + // interlacing |
| 51 | + /is(?:field|frame)based|getparity/.source, |
| 52 | + // color format |
| 53 | + /pixeltype|is(?:planar(?:rgba?)?|interleaved|rgb(?:24|32|48|64)?|y(?:8|u(?:y2|va?))?|yv(?:12|16|24|411)|420|422|444|packedrgb)|hasalpha|componentsize|numcomponents|bitspercomponent/.source, |
| 54 | + // audio |
| 55 | + /audio(?:rate|duration|length(?:[fs]|lo|hi)?|channels|bits)|isaudio(?:float|int)/.source |
| 56 | + ].join('|'); |
| 57 | + var filters = [ |
| 58 | + // source |
| 59 | + /avi(?:file)?source|opendmlsource|directshowsource|image(?:reader|source|sourceanim)|segmented(?:avisource|directshowsource)|wavsource/.source, |
| 60 | + // color |
| 61 | + /coloryuv|convertto(?:RGB(?:24|32|48|64)|(?:planar)?RGBA?|Y8?|YV(?:12|16|24|411)|YUVA?(?:444|422|420|411)|YUY2)|convertbacktoyuy2|fixluminance|gr[ae]yscale|invert|levels|limiter|mergea?rgb|merge(?:luma|chroma)|rgbadjust|show(?:red|green|blue|alpha)|swapuv|tweak|[uv]toy8?|ytouv/.source, |
| 62 | + // overlay |
| 63 | + /(?:colorkey|reset)mask|mask(?:hs)?|layer|merge|overlay|subtract/.source, |
| 64 | + // geometry |
| 65 | + /addborders|crop(?:bottom)?|flip(?:horizontal|vertical)|letterbox|(?:horizontal|vertical)?reduceby2|(?:bicubic|bilinear|blackman|gauss|lanczos|lanczos4|point|sinc|spline(?:16|36|64))resize|skewrows|turn(?:left|right|180)/.source, |
| 66 | + // pixel |
| 67 | + /blur|sharpen|generalconvolution|(?:spatial|temporal)soften|fixbrokenchromaupsampling/.source, |
| 68 | + // timeline |
| 69 | + /trim|(?:un)?alignedsplice|(?:assume|assumescaled|change|convert)FPS|(?:delete|duplicate)frame|dissolve|fade(?:in|out|io)[02]?|freezeframe|interleave|loop|reverse|select(?:even|odd|(?:range)?every)/.source, |
| 70 | + // interlace |
| 71 | + /assume(?:frame|field)based|assume[bt]ff|bob|complementparity|doubleweave|peculiarblend|pulldown|separate(?:columns|rows|fields)|swapfields|weave(?:columns|rows)?/.source, |
| 72 | + // audio |
| 73 | + /amplify(?:db)?|assumesamplerate|audiodub(?:ex)?|audiotrim|convertaudioto(?:(?:8|16|24|32)bit|float)|converttomono|delayaudio|ensurevbrmp3sync|get(?:left|right)?channel|kill(?:audio|video)|mergechannels|mixaudio|monotostereo|normalize|resampleaudio|supereq|ssrc|timestretch/.source, |
| 74 | + // conditional |
| 75 | + /conditional(?:filter|select|reader)|frameevaluate|scriptclip|writefile(?:if|start|end)?|animate|applyrange|tcp(?:server|source)/.source, |
| 76 | + // export |
| 77 | + /imagewriter/.source, |
| 78 | + // debug |
| 79 | + /subtitle|blankclip|blackness|colorbars(?:hd)?|compare|dumpfiltergraph|setgraphanalysis|echo|histogram|info|messageclip|preroll|showfiveversions|show(?:framenumber|smpte|time)|stack(?:horizontal|vertical)|tone|version/.source |
| 80 | + ].join('|'); |
| 81 | + var allinternals = [internals, properties, filters].join('|'); |
| 82 | + |
| 83 | + Prism.languages.avisynth = { |
| 84 | + 'comment': [ |
| 85 | + { |
| 86 | + // Matches [* *] nestable block comments, but only supports 1 level of nested comments |
| 87 | + // /\[\*(?:[^\[*]|\[(?!\*)|\*(?!\])|<self>)*\*\]/ |
| 88 | + pattern: /(^|[^\\])\[\*(?:[^\[*]|\[(?!\*)|\*(?!\])|\[\*(?:[^\[*]|\[(?!\*)|\*(?!\]))*\*\])*\*\]/, |
| 89 | + lookbehind: true, |
| 90 | + greedy: true |
| 91 | + }, |
| 92 | + { |
| 93 | + // Matches /* */ block comments |
| 94 | + pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, |
| 95 | + lookbehind: true, |
| 96 | + greedy: true |
| 97 | + }, |
| 98 | + { |
| 99 | + // Matches # comments |
| 100 | + pattern: /(^|[^\\$])#.*/, |
| 101 | + lookbehind: true, |
| 102 | + greedy: true |
| 103 | + } |
| 104 | + ], |
| 105 | + |
| 106 | + // Handle before strings because optional arguments are surrounded by double quotes |
| 107 | + 'argument': { |
| 108 | + pattern: re(/\b(?:<<0>>)\s+("?)\w+\1/.source, [types], 'i'), |
| 109 | + inside: { |
| 110 | + 'keyword': /^\w+/ |
| 111 | + } |
| 112 | + }, |
| 113 | + |
| 114 | + // Optional argument assignment |
| 115 | + 'argument-label': { |
| 116 | + pattern: /([,(][\s\\]*)\w+\s*=(?!=)/, |
| 117 | + lookbehind: true, |
| 118 | + inside: { |
| 119 | + 'argument-name': { |
| 120 | + pattern: /^\w+/, |
| 121 | + alias: 'punctuation' |
| 122 | + }, |
| 123 | + 'punctuation': /=$/ |
| 124 | + } |
| 125 | + }, |
| 126 | + |
| 127 | + 'string': [ |
| 128 | + { |
| 129 | + // triple double-quoted |
| 130 | + pattern: /"""[\s\S]*?"""/, |
| 131 | + greedy: true, |
| 132 | + }, |
| 133 | + { |
| 134 | + // single double-quoted |
| 135 | + pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/, |
| 136 | + greedy: true, |
| 137 | + inside: { |
| 138 | + 'constant': { |
| 139 | + // These *are* case-sensitive! |
| 140 | + pattern: /\b(?:DEFAULT_MT_MODE|(?:SCRIPT|MAINSCRIPT|PROGRAM)DIR|(?:USER|MACHINE)_(?:PLUS|CLASSIC)_PLUGINS)\b/ |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + ], |
| 145 | + |
| 146 | + // The special "last" variable that takes the value of the last implicitly returned clip |
| 147 | + 'variable': /\b(?:last)\b/i, |
| 148 | + |
| 149 | + 'boolean': /\b(?:true|false|yes|no)\b/i, |
| 150 | + |
| 151 | + 'keyword': /\b(?:function|global|return|try|catch|if|else|while|for|__END__)\b/i, |
| 152 | + |
| 153 | + 'constant': /\bMT_(?:NICE_FILTER|MULTI_INSTANCE|SERIALIZED|SPECIAL_MT)\b/, |
| 154 | + |
| 155 | + // AviSynth's internal functions, filters, and properties |
| 156 | + 'builtin-function': { |
| 157 | + pattern: re(/\b(?:<<0>>)\b/.source, [allinternals], 'i'), |
| 158 | + alias: 'function' |
| 159 | + }, |
| 160 | + |
| 161 | + 'type-cast': { |
| 162 | + pattern: re(/\b(?:<<0>>)(?=\s*\()/.source, [types], 'i'), |
| 163 | + alias: 'keyword' |
| 164 | + }, |
| 165 | + |
| 166 | + // External/user-defined filters |
| 167 | + 'function': { |
| 168 | + pattern: /\b[a-z_]\w*(?=\s*\()|(\.)[a-z_]\w*\b/i, |
| 169 | + lookbehind: true |
| 170 | + }, |
| 171 | + |
| 172 | + // Matches a \ as the first or last character on a line |
| 173 | + 'line-continuation': { |
| 174 | + pattern: /(^[ \t]*)\\|\\(?=[ \t]*$)/m, |
| 175 | + lookbehind: true, |
| 176 | + alias: 'punctuation' |
| 177 | + }, |
| 178 | + |
| 179 | + 'number': /\B\$(?:[\da-f]{6}|[\da-f]{8})\b|(?:(?:\b|\B-)\d+(?:\.\d*)?\b|\B\.\d+\b)/i, |
| 180 | + |
| 181 | + 'operator': /\+\+?|[!=<>]=?|&&|\|\||[?:*/%-]/, |
| 182 | + |
| 183 | + 'punctuation': /[{}\[\]();,.]/ |
| 184 | + }; |
| 185 | + |
| 186 | + Prism.languages.avs = Prism.languages.avisynth; |
| 187 | + |
| 188 | +}(Prism)); |
0 commit comments