Commits

Georg Brandl  committed 3a1f930 Merge
  • Participants
  • Parent commits 9c749e7, a142971

Comments (0)

Files changed (3)

File pygments/lexers/_mapping.py

     'HttpLexer': ('pygments.lexers.text', 'HTTP', ('http',), (), ()),
     'HxmlLexer': ('pygments.lexers.text', 'Hxml', ('haxeml', 'hxml'), ('*.hxml',), ()),
     'HybrisLexer': ('pygments.lexers.other', 'Hybris', ('hybris', 'hy'), ('*.hy', '*.hyb'), ('text/x-hybris', 'application/x-hybris')),
+    'IDLLexer': ('pygments.lexers.math', 'IDL', ('idl',), ('*.pro',), ('text/idl',)),
     'IniLexer': ('pygments.lexers.text', 'INI', ('ini', 'cfg'), ('*.ini', '*.cfg'), ('text/x-ini',)),
     'IoLexer': ('pygments.lexers.agile', 'Io', ('io',), ('*.io',), ('text/x-iosrc',)),
     'IokeLexer': ('pygments.lexers.jvm', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)),

File pygments/lexers/math.py

 __all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
            'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
            'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
-           'RdLexer']
+           'IDLLexer', 'RdLexer']
 
 
 class JuliaLexer(RegexLexer):
             return 0.0
 
 
+class IDLLexer(RegexLexer):
+    """
+    Pygments Lexer for IDL (Interactive Data Language).
+
+    *New in Pygments 1.6.*
+    """
+    name = 'IDL'
+    aliases = ['idl']
+    filenames = ['*.pro']
+    mimetypes = ['text/idl']
+
+    _RESERVED = ['and', 'begin', 'break', 'case', 'common', 'compile_opt',
+                 'continue', 'do', 'else', 'end', 'endcase', 'elseelse',
+                 'endfor', 'endforeach', 'endif', 'endrep', 'endswitch',
+                 'endwhile', 'eq', 'for', 'foreach', 'forward_function',
+                 'function', 'ge', 'goto', 'gt', 'if', 'inherits', 'le',
+                 'lt', 'mod', 'ne', 'not', 'of', 'on_ioerror', 'or', 'pro',
+                 'repeat', 'switch', 'then', 'until', 'while', 'xor']
+    """Reserved words from: http://www.exelisvis.com/docs/reswords.html"""
+
+    _BUILTIN_LIB = ['abs', 'acos', 'adapt_hist_equal', 'alog', 'alog10',
+                    'amoeba', 'annotate', 'app_user_dir', 'app_user_dir_query',
+                    'arg_present', 'array_equal', 'array_indices', 'arrow',
+                    'ascii_template', 'asin', 'assoc', 'atan', 'axis',
+                    'a_correlate', 'bandpass_filter', 'bandreject_filter',
+                    'barplot', 'bar_plot', 'beseli', 'beselj', 'beselk',
+                    'besely', 'beta', 'bilinear', 'binary_template', 'bindgen',
+                    'binomial', 'bin_date', 'bit_ffs', 'bit_population',
+                    'blas_axpy', 'blk_con', 'box_cursor', 'breakpoint',
+                    'broyden', 'butterworth', 'bytarr', 'byte', 'byteorder',
+                    'bytscl', 'caldat', 'calendar', 'call_external',
+                    'call_function', 'call_method', 'call_procedure', 'canny',
+                    'catch', 'cd', 'cdf_[0-9a-za-z_]*', 'ceil', 'chebyshev',
+                    'check_math',
+                    'chisqr_cvf', 'chisqr_pdf', 'choldc', 'cholsol', 'cindgen',
+                    'cir_3pnt', 'close', 'cluster', 'cluster_tree', 'clust_wts',
+                    'cmyk_convert', 'colorbar', 'colorize_sample',
+                    'colormap_applicable', 'colormap_gradient',
+                    'colormap_rotation', 'colortable', 'color_convert',
+                    'color_exchange', 'color_quan', 'color_range_map', 'comfit',
+                    'command_line_args', 'complex', 'complexarr', 'complexround',
+                    'compute_mesh_normals', 'cond', 'congrid', 'conj',
+                    'constrained_min', 'contour', 'convert_coord', 'convol',
+                    'convol_fft', 'coord2to3', 'copy_lun', 'correlate', 'cos',
+                    'cosh', 'cpu', 'cramer', 'create_cursor', 'create_struct',
+                    'create_view', 'crossp', 'crvlength', 'cti_test',
+                    'ct_luminance', 'cursor', 'curvefit', 'cvttobm', 'cv_coord',
+                    'cw_animate', 'cw_animate_getp', 'cw_animate_load',
+                    'cw_animate_run', 'cw_arcball', 'cw_bgroup', 'cw_clr_index',
+                    'cw_colorsel', 'cw_defroi', 'cw_field', 'cw_filesel',
+                    'cw_form', 'cw_fslider', 'cw_light_editor',
+                    'cw_light_editor_get', 'cw_light_editor_set', 'cw_orient',
+                    'cw_palette_editor', 'cw_palette_editor_get',
+                    'cw_palette_editor_set', 'cw_pdmenu', 'cw_rgbslider',
+                    'cw_tmpl', 'cw_zoom', 'c_correlate', 'dblarr', 'db_exists',
+                    'dcindgen', 'dcomplex', 'dcomplexarr', 'define_key',
+                    'define_msgblk', 'define_msgblk_from_file', 'defroi',
+                    'defsysv', 'delvar', 'dendrogram', 'dendro_plot', 'deriv',
+                    'derivsig', 'determ', 'device', 'dfpmin', 'diag_matrix',
+                    'dialog_dbconnect', 'dialog_message', 'dialog_pickfile',
+                    'dialog_printersetup', 'dialog_printjob',
+                    'dialog_read_image', 'dialog_write_image', 'digital_filter',
+                    'dilate', 'dindgen', 'dissolve', 'dist', 'distance_measure',
+                    'dlm_load', 'dlm_register', 'doc_library', 'double',
+                    'draw_roi', 'edge_dog', 'efont', 'eigenql', 'eigenvec',
+                    'ellipse', 'elmhes', 'emboss', 'empty', 'enable_sysrtn',
+                    'eof', 'eos_[0-9a-za-z_]*', 'erase', 'erf', 'erfc', 'erfcx',
+                    'erode', 'errorplot', 'errplot', 'estimator_filter',
+                    'execute', 'exit', 'exp', 'expand', 'expand_path', 'expint',
+                    'extrac', 'extract_slice', 'factorial', 'fft', 'filepath',
+                    'file_basename', 'file_chmod', 'file_copy', 'file_delete',
+                    'file_dirname', 'file_expand_path', 'file_info',
+                    'file_lines', 'file_link', 'file_mkdir', 'file_move',
+                    'file_poll_input', 'file_readlink', 'file_same',
+                    'file_search', 'file_test', 'file_which', 'findgen',
+                    'finite', 'fix', 'flick', 'float', 'floor', 'flow3',
+                    'fltarr', 'flush', 'format_axis_values', 'free_lun',
+                    'fstat', 'fulstr', 'funct', 'fv_test', 'fx_root',
+                    'fz_roots', 'f_cvf', 'f_pdf', 'gamma', 'gamma_ct',
+                    'gauss2dfit', 'gaussfit', 'gaussian_function', 'gaussint',
+                    'gauss_cvf', 'gauss_pdf', 'gauss_smooth', 'getenv',
+                    'getwindows', 'get_drive_list', 'get_dxf_objects',
+                    'get_kbrd', 'get_login_info', 'get_lun', 'get_screen_size',
+                    'greg2jul', 'grib_[0-9a-za-z_]*', 'grid3', 'griddata',
+                    'grid_input', 'grid_tps', 'gs_iter',
+                    'h5[adfgirst]_[0-9a-za-z_]*', 'h5_browser', 'h5_close',
+                    'h5_create', 'h5_get_libversion', 'h5_open', 'h5_parse',
+                    'hanning', 'hash', 'hdf_[0-9a-za-z_]*', 'heap_free',
+                    'heap_gc', 'heap_nosave', 'heap_refcount', 'heap_save',
+                    'help', 'hilbert', 'histogram', 'hist_2d', 'hist_equal',
+                    'hls', 'hough', 'hqr', 'hsv', 'h_eq_ct', 'h_eq_int',
+                    'i18n_multibytetoutf8', 'i18n_multibytetowidechar',
+                    'i18n_utf8tomultibyte', 'i18n_widechartomultibyte',
+                    'ibeta', 'icontour', 'iconvertcoord', 'idelete', 'identity',
+                    'idlexbr_assistant', 'idlitsys_createtool', 'idl_base64',
+                    'idl_validname', 'iellipse', 'igamma', 'igetcurrent',
+                    'igetdata', 'igetid', 'igetproperty', 'iimage', 'image',
+                    'image_cont', 'image_statistics', 'imaginary', 'imap',
+                    'indgen', 'intarr', 'interpol', 'interpolate',
+                    'interval_volume', 'int_2d', 'int_3d', 'int_tabulated',
+                    'invert', 'ioctl', 'iopen', 'iplot', 'ipolygon',
+                    'ipolyline', 'iputdata', 'iregister', 'ireset', 'iresolve',
+                    'irotate', 'ir_filter', 'isa', 'isave', 'iscale',
+                    'isetcurrent', 'isetproperty', 'ishft', 'isocontour',
+                    'isosurface', 'isurface', 'itext', 'itranslate', 'ivector',
+                    'ivolume', 'izoom', 'i_beta', 'journal', 'json_parse',
+                    'json_serialize', 'jul2greg', 'julday', 'keyword_set',
+                    'krig2d', 'kurtosis', 'kw_test', 'l64indgen', 'label_date',
+                    'label_region', 'ladfit', 'laguerre', 'laplacian',
+                    'la_choldc', 'la_cholmprove', 'la_cholsol', 'la_determ',
+                    'la_eigenproblem', 'la_eigenql', 'la_eigenvec', 'la_elmhes',
+                    'la_gm_linear_model', 'la_hqr', 'la_invert',
+                    'la_least_squares', 'la_least_square_equality',
+                    'la_linear_equation', 'la_ludc', 'la_lumprove', 'la_lusol',
+                    'la_svd', 'la_tridc', 'la_trimprove', 'la_triql',
+                    'la_trired', 'la_trisol', 'least_squares_filter', 'leefilt',
+                    'legend', 'legendre', 'linbcg', 'lindgen', 'linfit',
+                    'linkimage', 'list', 'll_arc_distance', 'lmfit', 'lmgr',
+                    'lngamma', 'lnp_test', 'loadct', 'locale_get',
+                    'logical_and', 'logical_or', 'logical_true', 'lon64arr',
+                    'lonarr', 'long', 'long64', 'lsode', 'ludc', 'lumprove',
+                    'lusol', 'lu_complex', 'machar', 'make_array', 'make_dll',
+                    'make_rt', 'map', 'mapcontinents', 'mapgrid', 'map_2points',
+                    'map_continents', 'map_grid', 'map_image', 'map_patch',
+                    'map_proj_forward', 'map_proj_image', 'map_proj_info',
+                    'map_proj_init', 'map_proj_inverse', 'map_set',
+                    'matrix_multiply', 'matrix_power', 'max', 'md_test',
+                    'mean', 'meanabsdev', 'mean_filter', 'median', 'memory',
+                    'mesh_clip', 'mesh_decimate', 'mesh_issolid', 'mesh_merge',
+                    'mesh_numtriangles', 'mesh_obj', 'mesh_smooth',
+                    'mesh_surfacearea', 'mesh_validate', 'mesh_volume',
+                    'message', 'min', 'min_curve_surf', 'mk_html_help',
+                    'modifyct', 'moment', 'morph_close', 'morph_distance',
+                    'morph_gradient', 'morph_hitormiss', 'morph_open',
+                    'morph_thin', 'morph_tophat', 'multi', 'm_correlate',
+                    'ncdf_[0-9a-za-z_]*', 'newton', 'noise_hurl', 'noise_pick',
+                    'noise_scatter', 'noise_slur', 'norm', 'n_elements',
+                    'n_params', 'n_tags', 'objarr', 'obj_class', 'obj_destroy',
+                    'obj_hasmethod', 'obj_isa', 'obj_new', 'obj_valid',
+                    'online_help', 'on_error', 'open', 'oplot', 'oploterr',
+                    'parse_url', 'particle_trace', 'path_cache', 'path_sep',
+                    'pcomp', 'plot', 'plot3d', 'ploterr', 'plots', 'plot_3dbox',
+                    'plot_field', 'pnt_line', 'point_lun', 'polarplot',
+                    'polar_contour', 'polar_surface', 'poly', 'polyfill',
+                    'polyfillv', 'polygon', 'polyline', 'polyshade', 'polywarp',
+                    'poly_2d', 'poly_area', 'poly_fit', 'popd', 'powell',
+                    'pref_commit', 'pref_get', 'pref_set', 'prewitt', 'primes',
+                    'print', 'printd', 'product', 'profile', 'profiler',
+                    'profiles', 'project_vol', 'psafm', 'pseudo',
+                    'ps_show_fonts', 'ptrarr', 'ptr_free', 'ptr_new',
+                    'ptr_valid', 'pushd', 'p_correlate', 'qgrid3', 'qhull',
+                    'qromb', 'qromo', 'qsimp', 'query_ascii', 'query_bmp',
+                    'query_csv', 'query_dicom', 'query_gif', 'query_image',
+                    'query_jpeg', 'query_jpeg2000', 'query_mrsid', 'query_pict',
+                    'query_png', 'query_ppm', 'query_srf', 'query_tiff',
+                    'query_wav', 'radon', 'randomn', 'randomu', 'ranks',
+                    'rdpix', 'read', 'reads', 'readu', 'read_ascii',
+                    'read_binary', 'read_bmp', 'read_csv', 'read_dicom',
+                    'read_gif', 'read_image', 'read_interfile', 'read_jpeg',
+                    'read_jpeg2000', 'read_mrsid', 'read_pict', 'read_png',
+                    'read_ppm', 'read_spr', 'read_srf', 'read_sylk',
+                    'read_tiff', 'read_wav', 'read_wave', 'read_x11_bitmap',
+                    'read_xwd', 'real_part', 'rebin', 'recall_commands',
+                    'recon3', 'reduce_colors', 'reform', 'region_grow',
+                    'register_cursor', 'regress', 'replicate',
+                    'replicate_inplace', 'resolve_all', 'resolve_routine',
+                    'restore', 'retall', 'return', 'reverse', 'rk4', 'roberts',
+                    'rot', 'rotate', 'round', 'routine_filepath',
+                    'routine_info', 'rs_test', 'r_correlate', 'r_test',
+                    'save', 'savgol', 'scale3', 'scale3d', 'scope_level',
+                    'scope_traceback', 'scope_varfetch', 'scope_varname',
+                    'search2d', 'search3d', 'sem_create', 'sem_delete',
+                    'sem_lock', 'sem_release', 'setenv', 'set_plot',
+                    'set_shading', 'sfit', 'shade_surf', 'shade_surf_irr',
+                    'shade_volume', 'shift', 'shift_diff', 'shmdebug', 'shmmap',
+                    'shmunmap', 'shmvar', 'show3', 'showfont', 'simplex', 'sin',
+                    'sindgen', 'sinh', 'size', 'skewness', 'skip_lun',
+                    'slicer3', 'slide_image', 'smooth', 'sobel', 'socket',
+                    'sort', 'spawn', 'spher_harm', 'sph_4pnt', 'sph_scat',
+                    'spline', 'spline_p', 'spl_init', 'spl_interp', 'sprsab',
+                    'sprsax', 'sprsin', 'sprstp', 'sqrt', 'standardize',
+                    'stddev', 'stop', 'strarr', 'strcmp', 'strcompress',
+                    'streamline', 'stregex', 'stretch', 'string', 'strjoin',
+                    'strlen', 'strlowcase', 'strmatch', 'strmessage', 'strmid',
+                    'strpos', 'strput', 'strsplit', 'strtrim', 'struct_assign',
+                    'struct_hide', 'strupcase', 'surface', 'surfr', 'svdc',
+                    'svdfit', 'svsol', 'swap_endian', 'swap_endian_inplace',
+                    'symbol', 'systime', 's_test', 't3d', 'tag_names', 'tan',
+                    'tanh', 'tek_color', 'temporary', 'tetra_clip',
+                    'tetra_surface', 'tetra_volume', 'text', 'thin', 'threed',
+                    'timegen', 'time_test2', 'tm_test', 'total', 'trace',
+                    'transpose', 'triangulate', 'trigrid', 'triql', 'trired',
+                    'trisol', 'tri_surf', 'truncate_lun', 'ts_coef', 'ts_diff',
+                    'ts_fcast', 'ts_smooth', 'tv', 'tvcrs', 'tvlct', 'tvrd',
+                    'tvscl', 'typename', 't_cvt', 't_pdf', 'uindgen', 'uint',
+                    'uintarr', 'ul64indgen', 'ulindgen', 'ulon64arr', 'ulonarr',
+                    'ulong', 'ulong64', 'uniq', 'unsharp_mask', 'usersym',
+                    'value_locate', 'variance', 'vector', 'vector_field', 'vel',
+                    'velovect', 'vert_t3d', 'voigt', 'voronoi', 'voxel_proj',
+                    'wait', 'warp_tri', 'watershed', 'wdelete', 'wf_draw',
+                    'where', 'widget_base', 'widget_button', 'widget_combobox',
+                    'widget_control', 'widget_displaycontextmen', 'widget_draw',
+                    'widget_droplist', 'widget_event', 'widget_info',
+                    'widget_label', 'widget_list', 'widget_propertysheet',
+                    'widget_slider', 'widget_tab', 'widget_table',
+                    'widget_text', 'widget_tree', 'widget_tree_move',
+                    'widget_window', 'wiener_filter', 'window', 'writeu',
+                    'write_bmp', 'write_csv', 'write_gif', 'write_image',
+                    'write_jpeg', 'write_jpeg2000', 'write_nrif', 'write_pict',
+                    'write_png', 'write_ppm', 'write_spr', 'write_srf',
+                    'write_sylk', 'write_tiff', 'write_wav', 'write_wave',
+                    'wset', 'wshow', 'wtn', 'wv_applet', 'wv_cwt',
+                    'wv_cw_wavelet', 'wv_denoise', 'wv_dwt', 'wv_fn_coiflet',
+                    'wv_fn_daubechies', 'wv_fn_gaussian', 'wv_fn_haar',
+                    'wv_fn_morlet', 'wv_fn_paul', 'wv_fn_symlet',
+                    'wv_import_data', 'wv_import_wavelet', 'wv_plot3d_wps',
+                    'wv_plot_multires', 'wv_pwt', 'wv_tool_denoise',
+                    'xbm_edit', 'xdisplayfile', 'xdxf', 'xfont',
+                    'xinteranimate', 'xloadct', 'xmanager', 'xmng_tmpl',
+                    'xmtool', 'xobjview', 'xobjview_rotate',
+                    'xobjview_write_image', 'xpalette', 'xpcolor', 'xplot3d',
+                    'xregistered', 'xroi', 'xsq_test', 'xsurface', 'xvaredit',
+                    'xvolume', 'xvolume_rotate', 'xvolume_write_image',
+                    'xyouts', 'zoom', 'zoom_24']
+    """Functions from: http://www.exelisvis.com/docs/routines-1.html"""
+
+    tokens = {
+        'root': [
+            (r'^\s*;.*?\n', Comment.Singleline),
+            (r'\b(' + '|'.join(_RESERVED) + r')\b', Keyword),
+            (r'\b(' + '|'.join(_BUILTIN_LIB) + r')\b', Name.Builtin),
+            (r'\+=|-=|\^=|\*=|/=|#=|##=|<=|>=|=', Operator),
+            (r'\+\+|--|->|\+|-|##|#|\*|/|<|>|&&|\^|~|\|\|\?|:', Operator),
+            (r'\b(mod=|lt=|le=|eq=|ne=|ge=|gt=|not=|and=|or=|xor=)', Operator),
+            (r'\b(mod|lt|le|eq|ne|ge|gt|not|and|or|xor)\b', Operator),
+            (r'\b[0-9](L|B|S|UL|ULL|LL)?\b', Number),
+            (r'.', Text),
+        ]
+    }
+
+
 class RdLexer(RegexLexer):
     """
     Pygments Lexer for R documentation (Rd) files

File tests/examplefiles/mg_sample.pro

+; docformat = 'rst'
+
+; Example IDL (Interactive Data Language) source code.
+
+;+
+; Get `nIndices` random indices for an array of size `nValues` (without 
+; repeating an index).
+;
+; :Examples:
+;    Try::
+;
+;       IDL> r = randomu(seed, 10)
+;       IDL> print, r, format='(4F)'
+;             0.6297589      0.7815896      0.2508559      0.7546844
+;             0.1353382      0.1245834      0.8733745      0.0753110
+;             0.8054136      0.9513228
+;       IDL> ind = mg_sample(10, 3, seed=seed)
+;       IDL> print, ind
+;                  2           4           7
+;       IDL> print, r[ind]
+;            0.250856     0.135338    0.0753110
+;
+; :Returns: 
+;    lonarr(`nIndices`)
+;
+; :Params:
+;    nValues : in, required, type=long
+;       size of array to choose indices from
+;    nIndices : in, required, type=long
+;       number of indices needed
+;
+; :Keywords:
+;    seed : in, out, optional, type=integer or lonarr(36)
+;       seed to use for random number generation, leave undefined to use a 
+;       seed generated from the system clock; new seed will be output
+;-
+function mg_sample, nValues, nIndices, seed=seed
+  compile_opt strictarr
+  
+  ; get random nIndices by finding the indices of the smallest nIndices in a 
+  ; array of random values
+  values = randomu(seed, nValues)
+  
+  ; our random values are uniformly distributed, so ideally the nIndices 
+  ; smallest values are in the first bin of the below histogram
+  nBins = nValues / nIndices
+  h = histogram(values, nbins=nBins, reverse_indices=ri)
+
+  ; the candidates for being in the first nIndices will live in bins 0..bin
+  nCandidates = 0L
+  for bin = 0L, nBins - 1L do begin
+    nCandidates += h[bin]
+    if (nCandidates ge nIndices) then break    
+  endfor
+
+  ; get the candidates and sort them
+  candidates = ri[ri[0] : ri[bin + 1L] - 1L]
+  sortedCandidates = sort(values[candidates])
+
+  ; return the first nIndices of them
+  return, (candidates[sortedCandidates])[0:nIndices-1L]
+end
+
+
+; main-level example program
+
+r = randomu(seed, 10)            
+print, r
+ind = mg_sample(10, 3, seed=seed)
+print, ind
+print, r[ind]
+
+end