UNPKG

7.23 kBJavaScriptView Raw
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 = /bool|clip|float|int|string|val/.source;
15 var internals = [
16 // bools
17 /is(?:bool|clip|float|int|string)|defined|(?:(?:internal)?function|var)?exists?/.source,
18 // control
19 /apply|assert|default|eval|import|nop|select|undefined/.source,
20 // global
21 /opt_(?:allowfloataudio|avipadscanlines|dwchannelmask|enable_(?:b64a|planartopackedrgb|v210|y3_10_10|y3_10_16)|usewaveextensible|vdubplanarhack)|set(?:cachemode|maxcpu|memorymax|planarlegacyalignment|workingdir)/.source,
22 // conv
23 /hex(?:value)?|value/.source,
24 // numeric
25 /abs|ceil|continued(?:denominator|numerator)?|exp|floor|fmod|frac|log(?:10)?|max|min|muldiv|pi|pow|rand|round|sign|spline|sqrt/.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(?:[bgr]|chroma[uv]|luma)|(?:[rgb]|chroma[uv]|luma|rgb|[yuv](?=difference(?:fromprevious|tonext)))difference(?:fromprevious|tonext)?|[yuvrgb]plane(?:median|min|max|minmaxdifference)/.source,
32 // script
33 /getprocessinfo|logmsg|script(?:dir(?:utf8)?|file(?:utf8)?|name(?:utf8)?)|setlogparams/.source,
34 // 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)/.source,
36 // version
37 /isversionorgreater|version(?:number|string)/.source,
38 // helper
39 /buildpixeltype|colorspacenametopixeltype/.source,
40 // avsplus
41 /addautoloaddir|on(?:cpu|cuda)|prefetch|setfiltermtmode/.source
42 ].join('|');
43 var properties = [
44 // content
45 /has(?:audio|video)/.source,
46 // resolution
47 /height|width/.source,
48 // framerate
49 /frame(?:count|rate)|framerate(?:denominator|numerator)/.source,
50 // interlacing
51 /getparity|is(?:field|frame)based/.source,
52 // color format
53 /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/.source,
54 // audio
55 /audio(?:bits|channels|duration|length(?:[fs]|hi|lo)?|rate)|isaudio(?:float|int)/.source
56 ].join('|');
57 var filters = [
58 // source
59 /avi(?:file)?source|directshowsource|image(?:reader|source|sourceanim)|opendmlsource|segmented(?:avisource|directshowsource)|wavsource/.source,
60 // color
61 /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/.source,
62 // overlay
63 /(?:colorkey|reset)mask|layer|mask(?:hs)?|merge|overlay|subtract/.source,
64 // geometry
65 /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)/.source,
66 // pixel
67 /blur|fixbrokenchromaupsampling|generalconvolution|(?:spatial|temporal)soften|sharpen/.source,
68 // timeline
69 /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)/.source,
70 // interlace
71 /assume[bt]ff|assume(?:field|frame)based|bob|complementparity|doubleweave|peculiarblend|pulldown|separate(?:columns|fields|rows)|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|ssrc|supereq|timestretch/.source,
74 // conditional
75 /animate|applyrange|conditional(?:filter|reader|select)|frameevaluate|scriptclip|tcp(?:server|source)|writefile(?:end|if|start)?/.source,
76 // export
77 /imagewriter/.source,
78 // debug
79 /blackness|blankclip|colorbars(?:hd)?|compare|dumpfiltergraph|echo|histogram|info|messageclip|preroll|setgraphanalysis|show(?:framenumber|smpte|time)|showfiveversions|stack(?:horizontal|vertical)|subtitle|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|(?:MAINSCRIPT|PROGRAM|SCRIPT)DIR|(?:MACHINE|USER)_(?:CLASSIC|PLUS)_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(?:false|no|true|yes)\b/i,
150
151 'keyword': /\b(?:catch|else|for|function|global|if|return|try|while|__END__)\b/i,
152
153 'constant': /\bMT_(?:MULTI_INSTANCE|NICE_FILTER|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));