diff options
author | Michael Galloy <mgalloy@gmail.com> | 2012-10-08 11:45:34 -0600 |
---|---|---|
committer | Michael Galloy <mgalloy@gmail.com> | 2012-10-08 11:45:34 -0600 |
commit | 485db8bffe118b52c502d4df133011a6a5e4befc (patch) | |
tree | 62e17e28055a71b9299cf593d0b0146043e35ca6 | |
parent | f4fbeca713efdfe7007ad37f7ba3ffe68517798c (diff) | |
download | pygments-485db8bffe118b52c502d4df133011a6a5e4befc.tar.gz |
Adding reference documenting IDL reserved words and library routines. Adding example IDL file, mg_sample.pro, in tests/examplefiles.
The reserved words can be read directly from the web page, though getting the library routine names is quite painful to get this way.
-rw-r--r-- | pygments/lexers/math.py | 7 | ||||
-rw-r--r-- | tests/examplefiles/mg_sample.pro | 73 |
2 files changed, 78 insertions, 2 deletions
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py index 460028b1..ef299531 100644 --- a/pygments/lexers/math.py +++ b/pygments/lexers/math.py @@ -1392,7 +1392,7 @@ class IDLLexer(RegexLexer): aliases = ['idl'] filenames = ['*.pro'] mimetypes = ['text/idl'] - + _RESERVED = ['begin', 'break', 'case', 'catch', 'common', 'compile_opt', 'continue', 'do', 'else', 'end', 'endcase', 'endelse', 'endfor', 'endforeach', 'endif', 'endrep', 'endswitch', @@ -1401,6 +1401,8 @@ class IDLLexer(RegexLexer): 'inherits', 'of', 'pro', 'repeat', 'return', 'stop', 'switch', 'then', 'until', 'while'] + """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', @@ -1603,7 +1605,8 @@ class IDLLexer(RegexLexer): '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), diff --git a/tests/examplefiles/mg_sample.pro b/tests/examplefiles/mg_sample.pro new file mode 100644 index 00000000..814d510d --- /dev/null +++ b/tests/examplefiles/mg_sample.pro @@ -0,0 +1,73 @@ +; 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
\ No newline at end of file |