idl.py 15 KB

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