idl.py 15 KB

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