prism-avisynth.js 7.1 KB

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