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