idl.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. function wordRegexp(words) {
  13. return new RegExp('^((' + words.join(')|(') + '))\\b', 'i');
  14. };
  15. var builtinArray = [
  16. 'a_correlate', 'abs', 'acos', 'adapt_hist_equal', 'alog',
  17. 'alog2', 'alog10', 'amoeba', 'annotate', 'app_user_dir',
  18. 'app_user_dir_query', 'arg_present', 'array_equal', 'array_indices',
  19. 'arrow', 'ascii_template', 'asin', 'assoc', 'atan',
  20. 'axis', 'axis', 'bandpass_filter', 'bandreject_filter', 'barplot',
  21. 'bar_plot', 'beseli', 'beselj', 'beselk', 'besely',
  22. 'beta', 'biginteger', 'bilinear', 'bin_date', 'binary_template',
  23. 'bindgen', 'binomial', 'bit_ffs', 'bit_population', 'blas_axpy',
  24. 'blk_con', 'boolarr', 'boolean', 'boxplot', 'box_cursor',
  25. 'breakpoint', 'broyden', 'bubbleplot', 'butterworth', 'bytarr',
  26. 'byte', 'byteorder', 'bytscl', 'c_correlate', 'calendar',
  27. 'caldat', 'call_external', 'call_function', 'call_method',
  28. 'call_procedure', 'canny', 'catch', 'cd', 'cdf', 'ceil',
  29. 'chebyshev', 'check_math', 'chisqr_cvf', 'chisqr_pdf', 'choldc',
  30. 'cholsol', 'cindgen', 'cir_3pnt', 'clipboard', 'close',
  31. 'clust_wts', 'cluster', 'cluster_tree', 'cmyk_convert', 'code_coverage',
  32. 'color_convert', 'color_exchange', 'color_quan', 'color_range_map',
  33. 'colorbar', 'colorize_sample', 'colormap_applicable',
  34. 'colormap_gradient', 'colormap_rotation', 'colortable',
  35. 'comfit', 'command_line_args', 'common', 'compile_opt', 'complex',
  36. 'complexarr', 'complexround', 'compute_mesh_normals', 'cond', 'congrid',
  37. 'conj', 'constrained_min', 'contour', 'contour', 'convert_coord',
  38. 'convol', 'convol_fft', 'coord2to3', 'copy_lun', 'correlate',
  39. 'cos', 'cosh', 'cpu', 'cramer', 'createboxplotdata',
  40. 'create_cursor', 'create_struct', 'create_view', 'crossp', 'crvlength',
  41. 'ct_luminance', 'cti_test', 'cursor', 'curvefit', 'cv_coord',
  42. 'cvttobm', 'cw_animate', 'cw_animate_getp', 'cw_animate_load',
  43. 'cw_animate_run', 'cw_arcball', 'cw_bgroup', 'cw_clr_index',
  44. 'cw_colorsel', 'cw_defroi', 'cw_field', 'cw_filesel', 'cw_form',
  45. 'cw_fslider', 'cw_light_editor', 'cw_light_editor_get',
  46. 'cw_light_editor_set', 'cw_orient', 'cw_palette_editor',
  47. 'cw_palette_editor_get', 'cw_palette_editor_set', 'cw_pdmenu',
  48. 'cw_rgbslider', 'cw_tmpl', 'cw_zoom', 'db_exists',
  49. 'dblarr', 'dcindgen', 'dcomplex', 'dcomplexarr', 'define_key',
  50. 'define_msgblk', 'define_msgblk_from_file', 'defroi', 'defsysv',
  51. 'delvar', 'dendro_plot', 'dendrogram', 'deriv', 'derivsig',
  52. 'determ', 'device', 'dfpmin', 'diag_matrix', 'dialog_dbconnect',
  53. 'dialog_message', 'dialog_pickfile', 'dialog_printersetup',
  54. 'dialog_printjob', 'dialog_read_image',
  55. 'dialog_write_image', 'dictionary', 'digital_filter', 'dilate', 'dindgen',
  56. 'dissolve', 'dist', 'distance_measure', 'dlm_load', 'dlm_register',
  57. 'doc_library', 'double', 'draw_roi', 'edge_dog', 'efont',
  58. 'eigenql', 'eigenvec', 'ellipse', 'elmhes', 'emboss',
  59. 'empty', 'enable_sysrtn', 'eof', 'eos', 'erase',
  60. 'erf', 'erfc', 'erfcx', 'erode', 'errorplot',
  61. 'errplot', 'estimator_filter', 'execute', 'exit', 'exp',
  62. 'expand', 'expand_path', 'expint', 'extract', 'extract_slice',
  63. 'f_cvf', 'f_pdf', 'factorial', 'fft', 'file_basename',
  64. 'file_chmod', 'file_copy', 'file_delete', 'file_dirname',
  65. 'file_expand_path', 'file_gunzip', 'file_gzip', 'file_info',
  66. 'file_lines', 'file_link', 'file_mkdir', 'file_move',
  67. 'file_poll_input', 'file_readlink', 'file_same',
  68. 'file_search', 'file_tar', 'file_test', 'file_untar', 'file_unzip',
  69. 'file_which', 'file_zip', 'filepath', 'findgen', 'finite',
  70. 'fix', 'flick', 'float', 'floor', 'flow3',
  71. 'fltarr', 'flush', 'format_axis_values', 'forward_function', 'free_lun',
  72. 'fstat', 'fulstr', 'funct', 'function', 'fv_test',
  73. 'fx_root', 'fz_roots', 'gamma', 'gamma_ct', 'gauss_cvf',
  74. 'gauss_pdf', 'gauss_smooth', 'gauss2dfit', 'gaussfit',
  75. 'gaussian_function', 'gaussint', 'get_drive_list', 'get_dxf_objects',
  76. 'get_kbrd', 'get_login_info',
  77. 'get_lun', 'get_screen_size', 'getenv', 'getwindows', 'greg2jul',
  78. 'grib', 'grid_input', 'grid_tps', 'grid3', 'griddata',
  79. 'gs_iter', 'h_eq_ct', 'h_eq_int', 'hanning', 'hash',
  80. 'hdf', 'hdf5', 'heap_free', 'heap_gc', 'heap_nosave',
  81. 'heap_refcount', 'heap_save', 'help', 'hilbert', 'hist_2d',
  82. 'hist_equal', 'histogram', 'hls', 'hough', 'hqr',
  83. 'hsv', 'i18n_multibytetoutf8',
  84. 'i18n_multibytetowidechar', 'i18n_utf8tomultibyte',
  85. 'i18n_widechartomultibyte',
  86. 'ibeta', 'icontour', 'iconvertcoord', 'idelete', 'identity',
  87. 'idl_base64', 'idl_container', 'idl_validname',
  88. 'idlexbr_assistant', 'idlitsys_createtool',
  89. 'idlunit', 'iellipse', 'igamma', 'igetcurrent', 'igetdata',
  90. 'igetid', 'igetproperty', 'iimage', 'image', 'image_cont',
  91. 'image_statistics', 'image_threshold', 'imaginary', 'imap', 'indgen',
  92. 'int_2d', 'int_3d', 'int_tabulated', 'intarr', 'interpol',
  93. 'interpolate', 'interval_volume', 'invert', 'ioctl', 'iopen',
  94. 'ir_filter', 'iplot', 'ipolygon', 'ipolyline', 'iputdata',
  95. 'iregister', 'ireset', 'iresolve', 'irotate', 'isa',
  96. 'isave', 'iscale', 'isetcurrent', 'isetproperty', 'ishft',
  97. 'isocontour', 'isosurface', 'isurface', 'itext', 'itranslate',
  98. 'ivector', 'ivolume', 'izoom', 'journal', 'json_parse',
  99. 'json_serialize', 'jul2greg', 'julday', 'keyword_set', 'krig2d',
  100. 'kurtosis', 'kw_test', 'l64indgen', 'la_choldc', 'la_cholmprove',
  101. 'la_cholsol', 'la_determ', 'la_eigenproblem', 'la_eigenql', 'la_eigenvec',
  102. 'la_elmhes', 'la_gm_linear_model', 'la_hqr', 'la_invert',
  103. 'la_least_square_equality', 'la_least_squares', 'la_linear_equation',
  104. 'la_ludc', 'la_lumprove', 'la_lusol',
  105. 'la_svd', 'la_tridc', 'la_trimprove', 'la_triql', 'la_trired',
  106. 'la_trisol', 'label_date', 'label_region', 'ladfit', 'laguerre',
  107. 'lambda', 'lambdap', 'lambertw', 'laplacian', 'least_squares_filter',
  108. 'leefilt', 'legend', 'legendre', 'linbcg', 'lindgen',
  109. 'linfit', 'linkimage', 'list', 'll_arc_distance', 'lmfit',
  110. 'lmgr', 'lngamma', 'lnp_test', 'loadct', 'locale_get',
  111. 'logical_and', 'logical_or', 'logical_true', 'lon64arr', 'lonarr',
  112. 'long', 'long64', 'lsode', 'lu_complex', 'ludc',
  113. 'lumprove', 'lusol', 'm_correlate', 'machar', 'make_array',
  114. 'make_dll', 'make_rt', 'map', 'mapcontinents', 'mapgrid',
  115. 'map_2points', 'map_continents', 'map_grid', 'map_image', 'map_patch',
  116. 'map_proj_forward', 'map_proj_image', 'map_proj_info',
  117. 'map_proj_init', 'map_proj_inverse',
  118. 'map_set', 'matrix_multiply', 'matrix_power', 'max', 'md_test',
  119. 'mean', 'meanabsdev', 'mean_filter', 'median', 'memory',
  120. 'mesh_clip', 'mesh_decimate', 'mesh_issolid',
  121. 'mesh_merge', 'mesh_numtriangles',
  122. 'mesh_obj', 'mesh_smooth', 'mesh_surfacearea',
  123. 'mesh_validate', 'mesh_volume',
  124. 'message', 'min', 'min_curve_surf', 'mk_html_help', 'modifyct',
  125. 'moment', 'morph_close', 'morph_distance',
  126. 'morph_gradient', 'morph_hitormiss',
  127. 'morph_open', 'morph_thin', 'morph_tophat', 'multi', 'n_elements',
  128. 'n_params', 'n_tags', 'ncdf', 'newton', 'noise_hurl',
  129. 'noise_pick', 'noise_scatter', 'noise_slur', 'norm', 'obj_class',
  130. 'obj_destroy', 'obj_hasmethod', 'obj_isa', 'obj_new', 'obj_valid',
  131. 'objarr', 'on_error', 'on_ioerror', 'online_help', 'openr',
  132. 'openu', 'openw', 'oplot', 'oploterr', 'orderedhash',
  133. 'p_correlate', 'parse_url', 'particle_trace', 'path_cache', 'path_sep',
  134. 'pcomp', 'plot', 'plot3d', 'plot', 'plot_3dbox',
  135. 'plot_field', 'ploterr', 'plots', 'polar_contour', 'polar_surface',
  136. 'polyfill', 'polyshade', 'pnt_line', 'point_lun', 'polarplot',
  137. 'poly', 'poly_2d', 'poly_area', 'poly_fit', 'polyfillv',
  138. 'polygon', 'polyline', 'polywarp', 'popd', 'powell',
  139. 'pref_commit', 'pref_get', 'pref_set', 'prewitt', 'primes',
  140. 'print', 'printf', 'printd', 'pro', 'product',
  141. 'profile', 'profiler', 'profiles', 'project_vol', 'ps_show_fonts',
  142. 'psafm', 'pseudo', 'ptr_free', 'ptr_new', 'ptr_valid',
  143. 'ptrarr', 'pushd', 'qgrid3', 'qhull', 'qromb',
  144. 'qromo', 'qsimp', 'query_*', 'query_ascii', 'query_bmp',
  145. 'query_csv', 'query_dicom', 'query_gif', 'query_image', 'query_jpeg',
  146. 'query_jpeg2000', 'query_mrsid', 'query_pict', 'query_png', 'query_ppm',
  147. 'query_srf', 'query_tiff', 'query_video', 'query_wav', 'r_correlate',
  148. 'r_test', 'radon', 'randomn', 'randomu', 'ranks',
  149. 'rdpix', 'read', 'readf', 'read_ascii', 'read_binary',
  150. 'read_bmp', 'read_csv', 'read_dicom', 'read_gif', 'read_image',
  151. 'read_interfile', 'read_jpeg', 'read_jpeg2000', 'read_mrsid', 'read_pict',
  152. 'read_png', 'read_ppm', 'read_spr', 'read_srf', 'read_sylk',
  153. 'read_tiff', 'read_video', 'read_wav', 'read_wave', 'read_x11_bitmap',
  154. 'read_xwd', 'reads', 'readu', 'real_part', 'rebin',
  155. 'recall_commands', 'recon3', 'reduce_colors', 'reform', 'region_grow',
  156. 'register_cursor', 'regress', 'replicate',
  157. 'replicate_inplace', 'resolve_all',
  158. 'resolve_routine', 'restore', 'retall', 'return', 'reverse',
  159. 'rk4', 'roberts', 'rot', 'rotate', 'round',
  160. 'routine_filepath', 'routine_info', 'rs_test', 's_test', 'save',
  161. 'savgol', 'scale3', 'scale3d', 'scatterplot', 'scatterplot3d',
  162. 'scope_level', 'scope_traceback', 'scope_varfetch',
  163. 'scope_varname', 'search2d',
  164. 'search3d', 'sem_create', 'sem_delete', 'sem_lock', 'sem_release',
  165. 'set_plot', 'set_shading', 'setenv', 'sfit', 'shade_surf',
  166. 'shade_surf_irr', 'shade_volume', 'shift', 'shift_diff', 'shmdebug',
  167. 'shmmap', 'shmunmap', 'shmvar', 'show3', 'showfont',
  168. 'signum', 'simplex', 'sin', 'sindgen', 'sinh',
  169. 'size', 'skewness', 'skip_lun', 'slicer3', 'slide_image',
  170. 'smooth', 'sobel', 'socket', 'sort', 'spawn',
  171. 'sph_4pnt', 'sph_scat', 'spher_harm', 'spl_init', 'spl_interp',
  172. 'spline', 'spline_p', 'sprsab', 'sprsax', 'sprsin',
  173. 'sprstp', 'sqrt', 'standardize', 'stddev', 'stop',
  174. 'strarr', 'strcmp', 'strcompress', 'streamline', 'streamline',
  175. 'stregex', 'stretch', 'string', 'strjoin', 'strlen',
  176. 'strlowcase', 'strmatch', 'strmessage', 'strmid', 'strpos',
  177. 'strput', 'strsplit', 'strtrim', 'struct_assign', 'struct_hide',
  178. 'strupcase', 'surface', 'surface', 'surfr', 'svdc',
  179. 'svdfit', 'svsol', 'swap_endian', 'swap_endian_inplace', 'symbol',
  180. 'systime', 't_cvf', 't_pdf', 't3d', 'tag_names',
  181. 'tan', 'tanh', 'tek_color', 'temporary', 'terminal_size',
  182. 'tetra_clip', 'tetra_surface', 'tetra_volume', 'text', 'thin',
  183. 'thread', 'threed', 'tic', 'time_test2', 'timegen',
  184. 'timer', 'timestamp', 'timestamptovalues', 'tm_test', 'toc',
  185. 'total', 'trace', 'transpose', 'tri_surf', 'triangulate',
  186. 'trigrid', 'triql', 'trired', 'trisol', 'truncate_lun',
  187. 'ts_coef', 'ts_diff', 'ts_fcast', 'ts_smooth', 'tv',
  188. 'tvcrs', 'tvlct', 'tvrd', 'tvscl', 'typename',
  189. 'uindgen', 'uint', 'uintarr', 'ul64indgen', 'ulindgen',
  190. 'ulon64arr', 'ulonarr', 'ulong', 'ulong64', 'uniq',
  191. 'unsharp_mask', 'usersym', 'value_locate', 'variance', 'vector',
  192. 'vector_field', 'vel', 'velovect', 'vert_t3d', 'voigt',
  193. 'volume', 'voronoi', 'voxel_proj', 'wait', 'warp_tri',
  194. 'watershed', 'wdelete', 'wf_draw', 'where', 'widget_base',
  195. 'widget_button', 'widget_combobox', 'widget_control',
  196. 'widget_displaycontextmenu', 'widget_draw',
  197. 'widget_droplist', 'widget_event', 'widget_info',
  198. 'widget_label', 'widget_list',
  199. 'widget_propertysheet', 'widget_slider', 'widget_tab',
  200. 'widget_table', 'widget_text',
  201. 'widget_tree', 'widget_tree_move', 'widget_window',
  202. 'wiener_filter', 'window',
  203. 'window', 'write_bmp', 'write_csv', 'write_gif', 'write_image',
  204. 'write_jpeg', 'write_jpeg2000', 'write_nrif', 'write_pict', 'write_png',
  205. 'write_ppm', 'write_spr', 'write_srf', 'write_sylk', 'write_tiff',
  206. 'write_video', 'write_wav', 'write_wave', 'writeu', 'wset',
  207. 'wshow', 'wtn', 'wv_applet', 'wv_cwt', 'wv_cw_wavelet',
  208. 'wv_denoise', 'wv_dwt', 'wv_fn_coiflet',
  209. 'wv_fn_daubechies', 'wv_fn_gaussian',
  210. 'wv_fn_haar', 'wv_fn_morlet', 'wv_fn_paul',
  211. 'wv_fn_symlet', 'wv_import_data',
  212. 'wv_import_wavelet', 'wv_plot3d_wps', 'wv_plot_multires',
  213. 'wv_pwt', 'wv_tool_denoise',
  214. 'xbm_edit', 'xdisplayfile', 'xdxf', 'xfont', 'xinteranimate',
  215. 'xloadct', 'xmanager', 'xmng_tmpl', 'xmtool', 'xobjview',
  216. 'xobjview_rotate', 'xobjview_write_image',
  217. 'xpalette', 'xpcolor', 'xplot3d',
  218. 'xregistered', 'xroi', 'xsq_test', 'xsurface', 'xvaredit',
  219. 'xvolume', 'xvolume_rotate', 'xvolume_write_image',
  220. 'xyouts', 'zlib_compress', 'zlib_uncompress', 'zoom', 'zoom_24'
  221. ];
  222. var builtins = wordRegexp(builtinArray);
  223. var keywordArray = [
  224. 'begin', 'end', 'endcase', 'endfor',
  225. 'endwhile', 'endif', 'endrep', 'endforeach',
  226. 'break', 'case', 'continue', 'for',
  227. 'foreach', 'goto', 'if', 'then', 'else',
  228. 'repeat', 'until', 'switch', 'while',
  229. 'do', 'pro', 'function'
  230. ];
  231. var keywords = wordRegexp(keywordArray);
  232. CodeMirror.registerHelper("hintWords", "idl", builtinArray.concat(keywordArray));
  233. var identifiers = new RegExp('^[_a-z\xa1-\uffff][_a-z0-9\xa1-\uffff]*', 'i');
  234. var singleOperators = /[+\-*&=<>\/@#~$]/;
  235. var boolOperators = new RegExp('(and|or|eq|lt|le|gt|ge|ne|not)', 'i');
  236. function tokenBase(stream) {
  237. // whitespaces
  238. if (stream.eatSpace()) return null;
  239. // Handle one line Comments
  240. if (stream.match(';')) {
  241. stream.skipToEnd();
  242. return 'comment';
  243. }
  244. // Handle Number Literals
  245. if (stream.match(/^[0-9\.+-]/, false)) {
  246. if (stream.match(/^[+-]?0x[0-9a-fA-F]+/))
  247. return 'number';
  248. if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?/))
  249. return 'number';
  250. if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?/))
  251. return 'number';
  252. }
  253. // Handle Strings
  254. if (stream.match(/^"([^"]|(""))*"/)) { return 'string'; }
  255. if (stream.match(/^'([^']|(''))*'/)) { return 'string'; }
  256. // Handle words
  257. if (stream.match(keywords)) { return 'keyword'; }
  258. if (stream.match(builtins)) { return 'builtin'; }
  259. if (stream.match(identifiers)) { return 'variable'; }
  260. if (stream.match(singleOperators) || stream.match(boolOperators)) {
  261. return 'operator'; }
  262. // Handle non-detected items
  263. stream.next();
  264. return null;
  265. };
  266. CodeMirror.defineMode('idl', function() {
  267. return {
  268. token: function(stream) {
  269. return tokenBase(stream);
  270. }
  271. };
  272. });
  273. CodeMirror.defineMIME('text/x-idl', 'idl');
  274. });