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 = /bool|clip|float|int|string|val/.source
|
---|
18 | var internals = [
|
---|
19 | // bools
|
---|
20 | /is(?:bool|clip|float|int|string)|defined|(?:(?:internal)?function|var)?exists?/
|
---|
21 | .source, // control
|
---|
22 | /apply|assert|default|eval|import|nop|select|undefined/.source, // global
|
---|
23 | /opt_(?:allowfloataudio|avipadscanlines|dwchannelmask|enable_(?:b64a|planartopackedrgb|v210|y3_10_10|y3_10_16)|usewaveextensible|vdubplanarhack)|set(?:cachemode|maxcpu|memorymax|planarlegacyalignment|workingdir)/
|
---|
24 | .source, // conv
|
---|
25 | /hex(?:value)?|value/.source, // numeric
|
---|
26 | /abs|ceil|continued(?:denominator|numerator)?|exp|floor|fmod|frac|log(?:10)?|max|min|muldiv|pi|pow|rand|round|sign|spline|sqrt/
|
---|
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(?:[bgr]|chroma[uv]|luma)|(?:[rgb]|chroma[uv]|luma|rgb|[yuv](?=difference(?:fromprevious|tonext)))difference(?:fromprevious|tonext)?|[yuvrgb]plane(?:median|min|max|minmaxdifference)/
|
---|
32 | .source, // script
|
---|
33 | /getprocessinfo|logmsg|script(?:dir(?:utf8)?|file(?:utf8)?|name(?:utf8)?)|setlogparams/
|
---|
34 | .source, // string
|
---|
35 | /chr|(?:fill|find|left|mid|replace|rev|right)str|format|[lu]case|ord|str(?:cmpi?|fromutf8|len|toutf8)|time|trim(?:all|left|right)/
|
---|
36 | .source, // version
|
---|
37 | /isversionorgreater|version(?:number|string)/.source, // helper
|
---|
38 | /buildpixeltype|colorspacenametopixeltype/.source, // avsplus
|
---|
39 | /addautoloaddir|on(?:cpu|cuda)|prefetch|setfiltermtmode/.source
|
---|
40 | ].join('|')
|
---|
41 | var properties = [
|
---|
42 | // content
|
---|
43 | /has(?:audio|video)/.source, // resolution
|
---|
44 | /height|width/.source, // framerate
|
---|
45 | /frame(?:count|rate)|framerate(?:denominator|numerator)/.source, // interlacing
|
---|
46 | /getparity|is(?:field|frame)based/.source, // color format
|
---|
47 | /bitspercomponent|componentsize|hasalpha|is(?:planar(?:rgba?)?|interleaved|rgb(?:24|32|48|64)?|y(?:8|u(?:va?|y2))?|yv(?:12|16|24|411)|420|422|444|packedrgb)|numcomponents|pixeltype/
|
---|
48 | .source, // audio
|
---|
49 | /audio(?:bits|channels|duration|length(?:[fs]|hi|lo)?|rate)|isaudio(?:float|int)/
|
---|
50 | .source
|
---|
51 | ].join('|')
|
---|
52 | var filters = [
|
---|
53 | // source
|
---|
54 | /avi(?:file)?source|directshowsource|image(?:reader|source|sourceanim)|opendmlsource|segmented(?:avisource|directshowsource)|wavsource/
|
---|
55 | .source, // color
|
---|
56 | /coloryuv|convertbacktoyuy2|convertto(?:RGB(?:24|32|48|64)|(?:planar)?RGBA?|Y8?|YV(?:12|16|24|411)|YUVA?(?:411|420|422|444)|YUY2)|fixluminance|gr[ae]yscale|invert|levels|limiter|mergea?rgb|merge(?:chroma|luma)|rgbadjust|show(?:alpha|blue|green|red)|swapuv|tweak|[uv]toy8?|ytouv/
|
---|
57 | .source, // overlay
|
---|
58 | /(?:colorkey|reset)mask|layer|mask(?:hs)?|merge|overlay|subtract/.source, // geometry
|
---|
59 | /addborders|(?:bicubic|bilinear|blackman|gauss|lanczos4|lanczos|point|sinc|spline(?:16|36|64))resize|crop(?:bottom)?|flip(?:horizontal|vertical)|(?:horizontal|vertical)?reduceby2|letterbox|skewrows|turn(?:180|left|right)/
|
---|
60 | .source, // pixel
|
---|
61 | /blur|fixbrokenchromaupsampling|generalconvolution|(?:spatial|temporal)soften|sharpen/
|
---|
62 | .source, // timeline
|
---|
63 | /trim|(?:un)?alignedsplice|(?:assume|assumescaled|change|convert)FPS|(?:delete|duplicate)frame|dissolve|fade(?:in|io|out)[02]?|freezeframe|interleave|loop|reverse|select(?:even|odd|(?:range)?every)/
|
---|
64 | .source, // interlace
|
---|
65 | /assume[bt]ff|assume(?:field|frame)based|bob|complementparity|doubleweave|peculiarblend|pulldown|separate(?:columns|fields|rows)|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|ssrc|supereq|timestretch/
|
---|
68 | .source, // conditional
|
---|
69 | /animate|applyrange|conditional(?:filter|reader|select)|frameevaluate|scriptclip|tcp(?:server|source)|writefile(?:end|if|start)?/
|
---|
70 | .source, // export
|
---|
71 | /imagewriter/.source, // debug
|
---|
72 | /blackness|blankclip|colorbars(?:hd)?|compare|dumpfiltergraph|echo|histogram|info|messageclip|preroll|setgraphanalysis|show(?:framenumber|smpte|time)|showfiveversions|stack(?:horizontal|vertical)|subtitle|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|(?:MAINSCRIPT|PROGRAM|SCRIPT)DIR|(?:MACHINE|USER)_(?:CLASSIC|PLUS)_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(?:false|no|true|yes)\b/i,
|
---|
140 | keyword:
|
---|
141 | /\b(?:catch|else|for|function|global|if|return|try|while|__END__)\b/i,
|
---|
142 | constant: /\bMT_(?:MULTI_INSTANCE|NICE_FILTER|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 | }
|
---|