|
| 1 | +'use strict' |
| 2 | + |
| 3 | +module.exports = avisynth |
| 4 | +avisynth.displayName = 'avisynth' |
| 5 | +avisynth.aliases = ['avs'] |
| 6 | +function avisynth(Prism) { |
| 7 | + // http://avisynth.nl/index.php/The_full_AviSynth_grammar |
| 8 | + ;(function (Prism) { |
| 9 | + function replace(pattern, replacements) { |
| 10 | + return pattern.replace(/<<(\d+)>>/g, function (m, index) { |
| 11 | + return replacements[+index] |
| 12 | + }) |
| 13 | + } |
| 14 | + function re(pattern, replacements, flags) { |
| 15 | + return RegExp(replace(pattern, replacements), flags || '') |
| 16 | + } |
| 17 | + var types = /clip|int|float|string|bool|val/.source |
| 18 | + var internals = [ |
| 19 | + // bools |
| 20 | + /is(?:bool|clip|float|int|string)|defined|(?:var|(?:internal)?function)?exists?/ |
| 21 | + .source, // control |
| 22 | + /apply|assert|default|eval|import|select|nop|undefined/.source, // global |
| 23 | + /set(?:memorymax|cachemode|maxcpu|workingdir|planarlegacyalignment)|opt_(?:allowfloataudio|usewaveextensible|dwchannelmask|avipadscanlines|vdubplanarhack|enable_(?:v210|y3_10_10|y3_10_16|b64a|planartopackedrgb))/ |
| 24 | + .source, // conv |
| 25 | + /hex(?:value)?|value/.source, // numeric |
| 26 | + /max|min|muldiv|floor|ceil|round|fmod|pi|exp|log(?:10)?|pow|sqrt|abs|sign|frac|rand|spline|continued(?:numerator|denominator)?/ |
| 27 | + .source, // trig |
| 28 | + /a?sinh?|a?cosh?|a?tan[2h]?/.source, // 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?))/ |
| 30 | + .source, // 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)/ |
| 32 | + .source, // script |
| 33 | + /script(?:name(?:utf8)?|file(?:utf8)?|dir(?:utf8)?)|setlogparams|logmsg|getprocessinfo/ |
| 34 | + .source, // 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/ |
| 36 | + .source, // version |
| 37 | + /version(?:number|string)|isversionorgreater/.source, // helper |
| 38 | + /buildpixeltype|colorspacenametopixeltype/.source, // avsplus |
| 39 | + /setfiltermtmode|prefetch|addautoloaddir|on(?:cpu|cuda)/.source |
| 40 | + ].join('|') |
| 41 | + var properties = [ |
| 42 | + // content |
| 43 | + /has(?:audio|video)/.source, // resolution |
| 44 | + /width|height/.source, // framerate |
| 45 | + /frame(?:count|rate)|framerate(?:numerator|denominator)/.source, // interlacing |
| 46 | + /is(?:field|frame)based|getparity/.source, // color format |
| 47 | + /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/ |
| 48 | + .source, // audio |
| 49 | + /audio(?:rate|duration|length(?:[fs]|lo|hi)?|channels|bits)|isaudio(?:float|int)/ |
| 50 | + .source |
| 51 | + ].join('|') |
| 52 | + var filters = [ |
| 53 | + // source |
| 54 | + /avi(?:file)?source|opendmlsource|directshowsource|image(?:reader|source|sourceanim)|segmented(?:avisource|directshowsource)|wavsource/ |
| 55 | + .source, // color |
| 56 | + /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/ |
| 57 | + .source, // overlay |
| 58 | + /(?:colorkey|reset)mask|mask(?:hs)?|layer|merge|overlay|subtract/.source, // geometry |
| 59 | + /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)/ |
| 60 | + .source, // pixel |
| 61 | + /blur|sharpen|generalconvolution|(?:spatial|temporal)soften|fixbrokenchromaupsampling/ |
| 62 | + .source, // timeline |
| 63 | + /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)/ |
| 64 | + .source, // interlace |
| 65 | + /assume(?:frame|field)based|assume[bt]ff|bob|complementparity|doubleweave|peculiarblend|pulldown|separate(?:columns|rows|fields)|swapfields|weave(?:columns|rows)?/ |
| 66 | + .source, // audio |
| 67 | + /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/ |
| 68 | + .source, // conditional |
| 69 | + /conditional(?:filter|select|reader)|frameevaluate|scriptclip|writefile(?:if|start|end)?|animate|applyrange|tcp(?:server|source)/ |
| 70 | + .source, // export |
| 71 | + /imagewriter/.source, // debug |
| 72 | + /subtitle|blankclip|blackness|colorbars(?:hd)?|compare|dumpfiltergraph|setgraphanalysis|echo|histogram|info|messageclip|preroll|showfiveversions|show(?:framenumber|smpte|time)|stack(?:horizontal|vertical)|tone|version/ |
| 73 | + .source |
| 74 | + ].join('|') |
| 75 | + var allinternals = [internals, properties, filters].join('|') |
| 76 | + Prism.languages.avisynth = { |
| 77 | + comment: [ |
| 78 | + { |
| 79 | + // Matches [* *] nestable block comments, but only supports 1 level of nested comments |
| 80 | + // /\[\*(?:[^\[*]|\[(?!\*)|\*(?!\])|<self>)*\*\]/ |
| 81 | + pattern: |
| 82 | + /(^|[^\\])\[\*(?:[^\[*]|\[(?!\*)|\*(?!\])|\[\*(?:[^\[*]|\[(?!\*)|\*(?!\]))*\*\])*\*\]/, |
| 83 | + lookbehind: true, |
| 84 | + greedy: true |
| 85 | + }, |
| 86 | + { |
| 87 | + // Matches /* */ block comments |
| 88 | + pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/, |
| 89 | + lookbehind: true, |
| 90 | + greedy: true |
| 91 | + }, |
| 92 | + { |
| 93 | + // Matches # comments |
| 94 | + pattern: /(^|[^\\$])#.*/, |
| 95 | + lookbehind: true, |
| 96 | + greedy: true |
| 97 | + } |
| 98 | + ], |
| 99 | + // Handle before strings because optional arguments are surrounded by double quotes |
| 100 | + argument: { |
| 101 | + pattern: re(/\b(?:<<0>>)\s+("?)\w+\1/.source, [types], 'i'), |
| 102 | + inside: { |
| 103 | + keyword: /^\w+/ |
| 104 | + } |
| 105 | + }, |
| 106 | + // Optional argument assignment |
| 107 | + 'argument-label': { |
| 108 | + pattern: /([,(][\s\\]*)\w+\s*=(?!=)/, |
| 109 | + lookbehind: true, |
| 110 | + inside: { |
| 111 | + 'argument-name': { |
| 112 | + pattern: /^\w+/, |
| 113 | + alias: 'punctuation' |
| 114 | + }, |
| 115 | + punctuation: /=$/ |
| 116 | + } |
| 117 | + }, |
| 118 | + string: [ |
| 119 | + { |
| 120 | + // triple double-quoted |
| 121 | + pattern: /"""[\s\S]*?"""/, |
| 122 | + greedy: true |
| 123 | + }, |
| 124 | + { |
| 125 | + // single double-quoted |
| 126 | + pattern: /"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/, |
| 127 | + greedy: true, |
| 128 | + inside: { |
| 129 | + constant: { |
| 130 | + // These *are* case-sensitive! |
| 131 | + pattern: |
| 132 | + /\b(?:DEFAULT_MT_MODE|(?:SCRIPT|MAINSCRIPT|PROGRAM)DIR|(?:USER|MACHINE)_(?:PLUS|CLASSIC)_PLUGINS)\b/ |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + ], |
| 137 | + // The special "last" variable that takes the value of the last implicitly returned clip |
| 138 | + variable: /\b(?:last)\b/i, |
| 139 | + boolean: /\b(?:true|false|yes|no)\b/i, |
| 140 | + keyword: |
| 141 | + /\b(?:function|global|return|try|catch|if|else|while|for|__END__)\b/i, |
| 142 | + constant: /\bMT_(?:NICE_FILTER|MULTI_INSTANCE|SERIALIZED|SPECIAL_MT)\b/, |
| 143 | + // AviSynth's internal functions, filters, and properties |
| 144 | + 'builtin-function': { |
| 145 | + pattern: re(/\b(?:<<0>>)\b/.source, [allinternals], 'i'), |
| 146 | + alias: 'function' |
| 147 | + }, |
| 148 | + 'type-cast': { |
| 149 | + pattern: re(/\b(?:<<0>>)(?=\s*\()/.source, [types], 'i'), |
| 150 | + alias: 'keyword' |
| 151 | + }, |
| 152 | + // External/user-defined filters |
| 153 | + function: { |
| 154 | + pattern: /\b[a-z_]\w*(?=\s*\()|(\.)[a-z_]\w*\b/i, |
| 155 | + lookbehind: true |
| 156 | + }, |
| 157 | + // Matches a \ as the first or last character on a line |
| 158 | + 'line-continuation': { |
| 159 | + pattern: /(^[ \t]*)\\|\\(?=[ \t]*$)/m, |
| 160 | + lookbehind: true, |
| 161 | + alias: 'punctuation' |
| 162 | + }, |
| 163 | + number: |
| 164 | + /\B\$(?:[\da-f]{6}|[\da-f]{8})\b|(?:(?:\b|\B-)\d+(?:\.\d*)?\b|\B\.\d+\b)/i, |
| 165 | + operator: /\+\+?|[!=<>]=?|&&|\|\||[?:*/%-]/, |
| 166 | + punctuation: /[{}\[\]();,.]/ |
| 167 | + } |
| 168 | + Prism.languages.avs = Prism.languages.avisynth |
| 169 | + })(Prism) |
| 170 | +} |
0 commit comments