Skip to content

Commit 746a4b1

Browse files
authored
Added AviSynth language definition (#3071)
1 parent ffb2043 commit 746a4b1

17 files changed

+1630
-3
lines changed

Diff for: components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components.json

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
"title": "AutoIt",
161161
"owner": "Golmote"
162162
},
163+
"avisynth": {
164+
"title": "AviSynth",
165+
"alias": "avs",
166+
"owner": "Zinfidel"
167+
},
163168
"avro-idl": {
164169
"title":"Avro IDL",
165170
"alias": "avdl",

Diff for: components/prism-avisynth.js

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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));

Diff for: components/prism-avisynth.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/prism-avisynth.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<h2>Full Example</h2>
2+
<pre><code>/*
3+
* Example AviSynth script for PrismJS demonstration.
4+
* By Zinfidel
5+
*/
6+
7+
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
8+
AddAutoloadDir("MAINSCRIPTDIR/programs/plugins")
9+
10+
# Multiplies clip size and changes aspect ratio to 4:3
11+
function CorrectAspectRatio(clip c, int scaleFactor, bool "useNearestNeighbor") {
12+
useNearestNeighbor = default(useNearestNeighbor, false)
13+
stretchFactor = (c.Height * (4 / 3)) / c.Width
14+
15+
return useNearestNeighbor \
16+
? c.PointResize(c.Width * scaleFactor * stretchFactor, c.Height * scaleFactor) \
17+
: c.Lanczos4Resize(c.Width * scaleFactor * stretchFactor, c.Height * scaleFactor)
18+
}
19+
20+
AviSource("myclip.avi")
21+
last.CorrectAspectRatio(3, yes)
22+
23+
24+
Prefetch(4)</code></pre>

Diff for: plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
"js": "javascript",
173173
"g4": "antlr4",
174174
"adoc": "asciidoc",
175+
"avs": "avisynth",
175176
"avdl": "avro-idl",
176177
"shell": "bash",
177178
"shortcode": "bbcode",

0 commit comments

Comments
 (0)