OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 by Amro <amroamroamro@gmail.com> | |
2 // | |
3 // Permission is hereby granted, free of charge, to any person obtaining a copy | |
4 // of this software and associated documentation files (the "Software"), to deal | |
5 // in the Software without restriction, including without limitation the rights | |
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
7 // copies of the Software, and to permit persons to whom the Software is | |
8 // furnished to do so, subject to the following conditions: | |
9 // | |
10 // The above copyright notice and this permission notice shall be included in | |
11 // all copies or substantial portions of the Software. | |
12 // | |
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
19 // THE SOFTWARE. | |
20 | |
21 /** | |
22 * @fileoverview | |
23 * Registers a language handler for MATLAB. | |
24 * | |
25 * To use, include prettify.js and this file in your HTML page. | |
26 * Then put your code inside an HTML tag like | |
27 * <pre class="prettyprint lang-matlab"> | |
28 * </pre> | |
29 * | |
30 * @see https://github.com/amroamroamro/prettify-matlab | |
31 */ | |
32 (function (PR) { | |
33 /* | |
34 PR_PLAIN: plain text | |
35 PR_STRING: string literals | |
36 PR_KEYWORD: keywords | |
37 PR_COMMENT: comments | |
38 PR_TYPE: types | |
39 PR_LITERAL: literal values (1, null, true, ..) | |
40 PR_PUNCTUATION: punctuation string | |
41 PR_SOURCE: embedded source | |
42 PR_DECLARATION: markup declaration such as a DOCTYPE | |
43 PR_TAG: sgml tag | |
44 PR_ATTRIB_NAME: sgml attribute name | |
45 PR_ATTRIB_VALUE: sgml attribute value | |
46 */ | |
47 var PR_IDENTIFIER = "ident", | |
48 PR_CONSTANT = "const", | |
49 PR_FUNCTION = "fun", | |
50 PR_FUNCTION_TOOLBOX = "fun_tbx", | |
51 PR_SYSCMD = "syscmd", | |
52 PR_CODE_OUTPUT = "codeoutput", | |
53 PR_ERROR = "err", | |
54 PR_WARNING = "wrn", | |
55 PR_TRANSPOSE = "transpose", | |
56 PR_LINE_CONTINUATION = "linecont"; | |
57 | |
58 // Refer to: http://www.mathworks.com/help/matlab/functionlist-alpha.html | |
59 var coreFunctions = [ | |
60 'abs|accumarray|acos(?:d|h)?|acot(?:d|h)?|acsc(?:d|h)?|actxcontrol(?:list|se
lect)?|actxGetRunningServer|actxserver|addlistener|addpath|addpref|addtodate|air
y|align|alim|all|allchild|alpha|alphamap|amd|ancestor|and|angle|annotation|any|a
rea|arrayfun|asec(?:d|h)?|asin(?:d|h)?|assert|assignin|atan(?:2|d|h)?|audiodevin
fo|audioplayer|audiorecorder|aufinfo|auread|autumn|auwrite|avifile|aviinfo|avire
ad|axes|axis|balance|bar(?:3|3h|h)?|base2dec|beep|BeginInvoke|bench|bessel(?:h|i
|j|k|y)|beta|betainc|betaincinv|betaln|bicg|bicgstab|bicgstabl|bin2dec|bitand|bi
tcmp|bitget|bitmax|bitnot|bitor|bitset|bitshift|bitxor|blanks|blkdiag|bone|box|b
righten|brush|bsxfun|builddocsearchdb|builtin|bvp4c|bvp5c|bvpget|bvpinit|bvpset|
bvpxtend|calendar|calllib|callSoapService|camdolly|cameratoolbar|camlight|camloo
kat|camorbit|campan|campos|camproj|camroll|camtarget|camup|camva|camzoom|cart2po
l|cart2sph|cast|cat|caxis|cd|cdf2rdf|cdfepoch|cdfinfo|cdflib(?:\.(?:close|closeV
ar|computeEpoch|computeEpoch16|create|createAttr|createVar|delete|deleteAttr|del
eteAttrEntry|deleteAttrgEntry|deleteVar|deleteVarRecords|epoch16Breakdown|epochB
reakdown|getAttrEntry|getAttrgEntry|getAttrMaxEntry|getAttrMaxgEntry|getAttrName
|getAttrNum|getAttrScope|getCacheSize|getChecksum|getCompression|getCompressionC
acheSize|getConstantNames|getConstantValue|getCopyright|getFileBackward|getForma
t|getLibraryCopyright|getLibraryVersion|getMajority|getName|getNumAttrEntries|ge
tNumAttrgEntries|getNumAttributes|getNumgAttributes|getReadOnlyMode|getStageCach
eSize|getValidate|getVarAllocRecords|getVarBlockingFactor|getVarCacheSize|getVar
Compression|getVarData|getVarMaxAllocRecNum|getVarMaxWrittenRecNum|getVarName|ge
tVarNum|getVarNumRecsWritten|getVarPadValue|getVarRecordData|getVarReservePercen
t|getVarsMaxWrittenRecNum|getVarSparseRecords|getVersion|hyperGetVarData|hyperPu
tVarData|inquire|inquireAttr|inquireAttrEntry|inquireAttrgEntry|inquireVar|open|
putAttrEntry|putAttrgEntry|putVarData|putVarRecordData|renameAttr|renameVar|setC
acheSize|setChecksum|setCompression|setCompressionCacheSize|setFileBackward|setF
ormat|setMajority|setReadOnlyMode|setStageCacheSize|setValidate|setVarAllocBlock
Records|setVarBlockingFactor|setVarCacheSize|setVarCompression|setVarInitialRecs
|setVarPadValue|SetVarReservePercent|setVarsCacheSize|setVarSparseRecords))?|cdf
read|cdfwrite|ceil|cell2mat|cell2struct|celldisp|cellfun|cellplot|cellstr|cgs|ch
eckcode|checkin|checkout|chol|cholinc|cholupdate|circshift|cla|clabel|class|clc|
clear|clearvars|clf|clipboard|clock|close|closereq|cmopts|cmpermute|cmunique|col
amd|colon|colorbar|colordef|colormap|colormapeditor|colperm|Combine|comet|comet3
|commandhistory|commandwindow|compan|compass|complex|computer|cond|condeig|conde
st|coneplot|conj|containers\.Map|contour(?:3|c|f|slice)?|contrast|conv|conv2|con
vhull|convhulln|convn|cool|copper|copyfile|copyobj|corrcoef|cos(?:d|h)?|cot(?:d|
h)?|cov|cplxpair|cputime|createClassFromWsdl|createSoapMessage|cross|csc(?:d|h)?
|csvread|csvwrite|ctranspose|cumprod|cumsum|cumtrapz|curl|customverctrl|cylinder
|daqread|daspect|datacursormode|datatipinfo|date|datenum|datestr|datetick|dateve
c|dbclear|dbcont|dbdown|dblquad|dbmex|dbquit|dbstack|dbstatus|dbstep|dbstop|dbty
pe|dbup|dde23|ddeget|ddesd|ddeset|deal|deblank|dec2base|dec2bin|dec2hex|decic|de
conv|del2|delaunay|delaunay3|delaunayn|DelaunayTri|delete|demo|depdir|depfun|det
|detrend|deval|diag|dialog|diary|diff|diffuse|dir|disp|display|dither|divergence
|dlmread|dlmwrite|dmperm|doc|docsearch|dos|dot|dragrect|drawnow|dsearch|dsearchn
|dynamicprops|echo|echodemo|edit|eig|eigs|ellipj|ellipke|ellipsoid|empty|enableN
ETfromNetworkDrive|enableservice|EndInvoke|enumeration|eomday|eq|erf|erfc|erfcin
v|erfcx|erfinv|error|errorbar|errordlg|etime|etree|etreeplot|eval|evalc|evalin|e
vent\.(?:EventData|listener|PropertyEvent|proplistener)|exifread|exist|exit|exp|
expint|expm|expm1|export2wsdlg|eye|ezcontour|ezcontourf|ezmesh|ezmeshc|ezplot|ez
plot3|ezpolar|ezsurf|ezsurfc|factor|factorial|fclose|feather|feature|feof|ferror
|feval|fft|fft2|fftn|fftshift|fftw|fgetl|fgets|fieldnames|figure|figurepalette|f
ileattrib|filebrowser|filemarker|fileparts|fileread|filesep|fill|fill3|filter|fi
lter2|find|findall|findfigs|findobj|findstr|finish|fitsdisp|fitsinfo|fitsread|fi
tswrite|fix|flag|flipdim|fliplr|flipud|floor|flow|fminbnd|fminsearch|fopen|forma
t|fplot|fprintf|frame2im|fread|freqspace|frewind|fscanf|fseek|ftell|FTP|full|ful
lfile|func2str|functions|funm|fwrite|fzero|gallery|gamma|gammainc|gammaincinv|ga
mmaln|gca|gcbf|gcbo|gcd|gcf|gco|ge|genpath|genvarname|get|getappdata|getenv|getf
ield|getframe|getpixelposition|getpref|ginput|gmres|gplot|grabcode|gradient|gray
|graymon|grid|griddata(?:3|n)?|griddedInterpolant|gsvd|gt|gtext|guidata|guide|gu
ihandles|gunzip|gzip|h5create|h5disp|h5info|h5read|h5readatt|h5write|h5writeatt|
hadamard|handle|hankel|hdf|hdf5|hdf5info|hdf5read|hdf5write|hdfinfo|hdfread|hdft
ool|help|helpbrowser|helpdesk|helpdlg|helpwin|hess|hex2dec|hex2num|hgexport|hggr
oup|hgload|hgsave|hgsetget|hgtransform|hidden|hilb|hist|histc|hold|home|horzcat|
hostid|hot|hsv|hsv2rgb|hypot|ichol|idivide|ifft|ifft2|ifftn|ifftshift|ilu|im2fra
me|im2java|imag|image|imagesc|imapprox|imfinfo|imformats|import|importdata|imrea
d|imwrite|ind2rgb|ind2sub|inferiorto|info|inline|inmem|inpolygon|input|inputdlg|
inputname|inputParser|inspect|instrcallback|instrfind|instrfindall|int2str|integ
ral(?:2|3)?|interp(?:1|1q|2|3|ft|n)|interpstreamspeed|intersect|intmax|intmin|in
v|invhilb|ipermute|isa|isappdata|iscell|iscellstr|ischar|iscolumn|isdir|isempty|
isequal|isequaln|isequalwithequalnans|isfield|isfinite|isfloat|isglobal|ishandle
|ishghandle|ishold|isinf|isinteger|isjava|iskeyword|isletter|islogical|ismac|ism
atrix|ismember|ismethod|isnan|isnumeric|isobject|isocaps|isocolors|isonormals|is
osurface|ispc|ispref|isprime|isprop|isreal|isrow|isscalar|issorted|isspace|isspa
rse|isstr|isstrprop|isstruct|isstudent|isunix|isvarname|isvector|javaaddpath|jav
aArray|javachk|javaclasspath|javacomponent|javaMethod|javaMethodEDT|javaObject|j
avaObjectEDT|javarmpath|jet|keyboard|kron|lasterr|lasterror|lastwarn|lcm|ldivide
|ldl|le|legend|legendre|length|libfunctions|libfunctionsview|libisloaded|libpoin
ter|libstruct|license|light|lightangle|lighting|lin2mu|line|lines|linkaxes|linkd
ata|linkprop|linsolve|linspace|listdlg|listfonts|load|loadlibrary|loadobj|log|lo
g10|log1p|log2|loglog|logm|logspace|lookfor|lower|ls|lscov|lsqnonneg|lsqr|lt|lu|
luinc|magic|makehgtform|mat2cell|mat2str|material|matfile|matlab\.io\.MatFile|ma
tlab\.mixin\.(?:Copyable|Heterogeneous(?:\.getDefaultScalarElement)?)|matlabrc|m
atlabroot|max|maxNumCompThreads|mean|median|membrane|memmapfile|memory|menu|mesh
|meshc|meshgrid|meshz|meta\.(?:class(?:\.fromName)?|DynamicProperty|EnumeratedVa
lue|event|MetaData|method|package(?:\.(?:fromName|getAllPackages))?|property)|me
taclass|methods|methodsview|mex(?:\.getCompilerConfigurations)?|MException|mexex
t|mfilename|min|minres|minus|mislocked|mkdir|mkpp|mldivide|mlint|mlintrpt|mlock|
mmfileinfo|mmreader|mod|mode|more|move|movefile|movegui|movie|movie2avi|mpower|m
rdivide|msgbox|mtimes|mu2lin|multibandread|multibandwrite|munlock|namelengthmax|
nargchk|narginchk|nargoutchk|native2unicode|nccreate|ncdisp|nchoosek|ncinfo|ncre
ad|ncreadatt|ncwrite|ncwriteatt|ncwriteschema|ndgrid|ndims|ne|NET(?:\.(?:addAsse
mbly|Assembly|convertArray|createArray|createGeneric|disableAutoRelease|enableAu
toRelease|GenericClass|invokeGenericMethod|NetException|setStaticProperty))?|net
cdf\.(?:abort|close|copyAtt|create|defDim|defGrp|defVar|defVarChunking|defVarDef
late|defVarFill|defVarFletcher32|delAtt|endDef|getAtt|getChunkCache|getConstant|
getConstantNames|getVar|inq|inqAtt|inqAttID|inqAttName|inqDim|inqDimID|inqDimIDs
|inqFormat|inqGrpName|inqGrpNameFull|inqGrpParent|inqGrps|inqLibVers|inqNcid|inq
UnlimDims|inqVar|inqVarChunking|inqVarDeflate|inqVarFill|inqVarFletcher32|inqVar
ID|inqVarIDs|open|putAtt|putVar|reDef|renameAtt|renameDim|renameVar|setChunkCach
e|setDefaultFormat|setFill|sync)|newplot|nextpow2|nnz|noanimate|nonzeros|norm|no
rmest|not|notebook|now|nthroot|null|num2cell|num2hex|num2str|numel|nzmax|ode(?:1
13|15i|15s|23|23s|23t|23tb|45)|odeget|odeset|odextend|onCleanup|ones|open|openfi
g|opengl|openvar|optimget|optimset|or|ordeig|orderfields|ordqz|ordschur|orient|o
rth|pack|padecoef|pagesetupdlg|pan|pareto|parseSoapResponse|pascal|patch|path|pa
th2rc|pathsep|pathtool|pause|pbaspect|pcg|pchip|pcode|pcolor|pdepe|pdeval|peaks|
perl|perms|permute|pie|pink|pinv|planerot|playshow|plot|plot3|plotbrowser|ploted
it|plotmatrix|plottools|plotyy|plus|pol2cart|polar|poly|polyarea|polyder|polyeig
|polyfit|polyint|polyval|polyvalm|pow2|power|ppval|prefdir|preferences|primes|pr
int|printdlg|printopt|printpreview|prod|profile|profsave|propedit|propertyeditor
|psi|publish|PutCharArray|PutFullMatrix|PutWorkspaceData|pwd|qhull|qmr|qr|qrdele
te|qrinsert|qrupdate|quad|quad2d|quadgk|quadl|quadv|questdlg|quit|quiver|quiver3
|qz|rand|randi|randn|randperm|RandStream(?:\.(?:create|getDefaultStream|getGloba
lStream|list|setDefaultStream|setGlobalStream))?|rank|rat|rats|rbbox|rcond|rdivi
de|readasync|real|reallog|realmax|realmin|realpow|realsqrt|record|rectangle|rect
int|recycle|reducepatch|reducevolume|refresh|refreshdata|regexp|regexpi|regexpre
p|regexptranslate|rehash|rem|Remove|RemoveAll|repmat|reset|reshape|residue|resto
redefaultpath|rethrow|rgb2hsv|rgb2ind|rgbplot|ribbon|rmappdata|rmdir|rmfield|rmp
ath|rmpref|rng|roots|rose|rosser|rot90|rotate|rotate3d|round|rref|rsf2csf|run|sa
ve|saveas|saveobj|savepath|scatter|scatter3|schur|sec|secd|sech|selectmoveresize
|semilogx|semilogy|sendmail|serial|set|setappdata|setdiff|setenv|setfield|setpix
elposition|setpref|setstr|setxor|shading|shg|shiftdim|showplottool|shrinkfaces|s
ign|sin(?:d|h)?|size|slice|smooth3|snapnow|sort|sortrows|sound|soundsc|spalloc|s
paugment|spconvert|spdiags|specular|speye|spfun|sph2cart|sphere|spinmap|spline|s
pones|spparms|sprand|sprandn|sprandsym|sprank|spring|sprintf|spy|sqrt|sqrtm|sque
eze|ss2tf|sscanf|stairs|startup|std|stem|stem3|stopasync|str2double|str2func|str
2mat|str2num|strcat|strcmp|strcmpi|stream2|stream3|streamline|streamparticles|st
reamribbon|streamslice|streamtube|strfind|strjust|strmatch|strncmp|strncmpi|strr
ead|strrep|strtok|strtrim|struct2cell|structfun|strvcat|sub2ind|subplot|subsasgn
|subsindex|subspace|subsref|substruct|subvolume|sum|summer|superclasses|superior
to|support|surf|surf2patch|surface|surfc|surfl|surfnorm|svd|svds|swapbytes|symam
d|symbfact|symmlq|symrcm|symvar|system|tan(?:d|h)?|tar|tempdir|tempname|tetrames
h|texlabel|text|textread|textscan|textwrap|tfqmr|throw|tic|Tiff(?:\.(?:getTagNam
es|getVersion))?|timer|timerfind|timerfindall|times|timeseries|title|toc|todaten
um|toeplitz|toolboxdir|trace|transpose|trapz|treelayout|treeplot|tril|trimesh|tr
iplequad|triplot|TriRep|TriScatteredInterp|trisurf|triu|tscollection|tsearch|tse
archn|tstool|type|typecast|uibuttongroup|uicontextmenu|uicontrol|uigetdir|uigetf
ile|uigetpref|uiimport|uimenu|uiopen|uipanel|uipushtool|uiputfile|uiresume|uisav
e|uisetcolor|uisetfont|uisetpref|uistack|uitable|uitoggletool|uitoolbar|uiwait|u
minus|undocheckout|unicode2native|union|unique|unix|unloadlibrary|unmesh|unmkpp|
untar|unwrap|unzip|uplus|upper|urlread|urlwrite|usejava|userpath|validateattribu
tes|validatestring|vander|var|vectorize|ver|verctrl|verLessThan|version|vertcat|
VideoReader(?:\.isPlatformSupported)?|VideoWriter(?:\.getProfiles)?|view|viewmtx
|visdiff|volumebounds|voronoi|voronoin|wait|waitbar|waitfor|waitforbuttonpress|w
arndlg|warning|waterfall|wavfinfo|wavplay|wavread|wavrecord|wavwrite|web|weekday
|what|whatsnew|which|whitebg|who|whos|wilkinson|winopen|winqueryreg|winter|wk1fi
nfo|wk1read|wk1write|workspace|xlabel|xlim|xlsfinfo|xlsread|xlswrite|xmlread|xml
write|xor|xslt|ylabel|ylim|zeros|zip|zlabel|zlim|zoom' | |
61 ].join("|"); | |
62 var statsFunctions = [ | |
63 'addedvarplot|andrewsplot|anova(?:1|2|n)|ansaribradley|aoctool|barttest|bbde
sign|beta(?:cdf|fit|inv|like|pdf|rnd|stat)|bino(?:cdf|fit|inv|pdf|rnd|stat)|bipl
ot|bootci|bootstrp|boxplot|candexch|candgen|canoncorr|capability|capaplot|casere
ad|casewrite|categorical|ccdesign|cdfplot|chi2(?:cdf|gof|inv|pdf|rnd|stat)|cholc
ov|Classification(?:BaggedEnsemble|Discriminant(?:\.(?:fit|make|template))?|Ense
mble|KNN(?:\.(?:fit|template))?|PartitionedEnsemble|PartitionedModel|Tree(?:\.(?
:fit|template))?)|classify|classregtree|cluster|clusterdata|cmdscale|combnk|Comp
act(?:Classification(?:Discriminant|Ensemble|Tree)|Regression(?:Ensemble|Tree)|T
reeBagger)|confusionmat|controlchart|controlrules|cophenet|copula(?:cdf|fit|para
m|pdf|rnd|stat)|cordexch|corr|corrcov|coxphfit|createns|crosstab|crossval|cvpart
ition|datasample|dataset|daugment|dcovary|dendrogram|dfittool|disttool|dummyvar|
dwtest|ecdf|ecdfhist|ev(?:cdf|fit|inv|like|pdf|rnd|stat)|ExhaustiveSearcher|exp(
?:cdf|fit|inv|like|pdf|rnd|stat)|factoran|fcdf|ff2n|finv|fitdist|fitensemble|fpd
f|fracfact|fracfactgen|friedman|frnd|fstat|fsurfht|fullfact|gagerr|gam(?:cdf|fit
|inv|like|pdf|rnd|stat)|GeneralizedLinearModel(?:\.fit)?|geo(?:cdf|inv|mean|pdf|
rnd|stat)|gev(?:cdf|fit|inv|like|pdf|rnd|stat)|gline|glmfit|glmval|glyphplot|gmd
istribution(?:\.fit)?|gname|gp(?:cdf|fit|inv|like|pdf|rnd|stat)|gplotmatrix|grp2
idx|grpstats|gscatter|haltonset|harmmean|hist3|histfit|hmm(?:decode|estimate|gen
erate|train|viterbi)|hougen|hyge(?:cdf|inv|pdf|rnd|stat)|icdf|inconsistent|inter
actionplot|invpred|iqr|iwishrnd|jackknife|jbtest|johnsrnd|KDTreeSearcher|kmeans|
knnsearch|kruskalwallis|ksdensity|kstest|kstest2|kurtosis|lasso|lassoglm|lassoPl
ot|leverage|lhsdesign|lhsnorm|lillietest|LinearModel(?:\.fit)?|linhyptest|linkag
e|logn(?:cdf|fit|inv|like|pdf|rnd|stat)|lsline|mad|mahal|maineffectsplot|manova1
|manovacluster|mdscale|mhsample|mle|mlecov|mnpdf|mnrfit|mnrnd|mnrval|moment|mult
compare|multivarichart|mvn(?:cdf|pdf|rnd)|mvregress|mvregresslike|mvt(?:cdf|pdf|
rnd)|NaiveBayes(?:\.fit)?|nan(?:cov|max|mean|median|min|std|sum|var)|nbin(?:cdf|
fit|inv|pdf|rnd|stat)|ncf(?:cdf|inv|pdf|rnd|stat)|nct(?:cdf|inv|pdf|rnd|stat)|nc
x2(?:cdf|inv|pdf|rnd|stat)|NeighborSearcher|nlinfit|nlintool|nlmefit|nlmefitsa|n
lparci|nlpredci|nnmf|nominal|NonLinearModel(?:\.fit)?|norm(?:cdf|fit|inv|like|pd
f|rnd|stat)|normplot|normspec|ordinal|outlierMeasure|parallelcoords|paretotails|
partialcorr|pcacov|pcares|pdf|pdist|pdist2|pearsrnd|perfcurve|perms|piecewisedis
tribution|plsregress|poiss(?:cdf|fit|inv|pdf|rnd|tat)|polyconf|polytool|prctile|
princomp|ProbDist(?:Kernel|Parametric|UnivKernel|UnivParam)?|probplot|procrustes
|qqplot|qrandset|qrandstream|quantile|randg|random|randsample|randtool|range|ran
gesearch|ranksum|rayl(?:cdf|fit|inv|pdf|rnd|stat)|rcoplot|refcurve|refline|regre
ss|Regression(?:BaggedEnsemble|Ensemble|PartitionedEnsemble|PartitionedModel|Tre
e(?:\.(?:fit|template))?)|regstats|relieff|ridge|robustdemo|robustfit|rotatefact
ors|rowexch|rsmdemo|rstool|runstest|sampsizepwr|scatterhist|sequentialfs|signran
k|signtest|silhouette|skewness|slicesample|sobolset|squareform|statget|statset|s
tepwise|stepwisefit|surfht|tabulate|tblread|tblwrite|tcdf|tdfread|tiedrank|tinv|
tpdf|TreeBagger|treedisp|treefit|treeprune|treetest|treeval|trimmean|trnd|tstat|
ttest|ttest2|unid(?:cdf|inv|pdf|rnd|stat)|unif(?:cdf|inv|it|pdf|rnd|stat)|vartes
t(?:2|n)?|wbl(?:cdf|fit|inv|like|pdf|rnd|stat)|wblplot|wishrnd|x2fx|xptread|zsco
re|ztest' | |
64 ].join("|"); | |
65 var imageFunctions = [ | |
66 'adapthisteq|analyze75info|analyze75read|applycform|applylut|axes2pix|bestbl
k|blockproc|bwarea|bwareaopen|bwboundaries|bwconncomp|bwconvhull|bwdist|bwdistge
odesic|bweuler|bwhitmiss|bwlabel|bwlabeln|bwmorph|bwpack|bwperim|bwselect|bwtrac
eboundary|bwulterode|bwunpack|checkerboard|col2im|colfilt|conndef|convmtx2|corne
r|cornermetric|corr2|cp2tform|cpcorr|cpselect|cpstruct2pairs|dct2|dctmtx|deconvb
lind|deconvlucy|deconvreg|deconvwnr|decorrstretch|demosaic|dicom(?:anon|dict|inf
o|lookup|read|uid|write)|edge|edgetaper|entropy|entropyfilt|fan2para|fanbeam|fin
dbounds|fliptform|freqz2|fsamp2|fspecial|ftrans2|fwind1|fwind2|getheight|getimag
e|getimagemodel|getline|getneighbors|getnhood|getpts|getrangefromclass|getrect|g
etsequence|gray2ind|graycomatrix|graycoprops|graydist|grayslice|graythresh|hdrre
ad|hdrwrite|histeq|hough|houghlines|houghpeaks|iccfind|iccread|iccroot|iccwrite|
idct2|ifanbeam|im2bw|im2col|im2double|im2int16|im2java2d|im2single|im2uint16|im2
uint8|imabsdiff|imadd|imadjust|ImageAdapter|imageinfo|imagemodel|imapplymatrix|i
mattributes|imbothat|imclearborder|imclose|imcolormaptool|imcomplement|imcontour
|imcontrast|imcrop|imdilate|imdisplayrange|imdistline|imdivide|imellipse|imerode
|imextendedmax|imextendedmin|imfill|imfilter|imfindcircles|imfreehand|imfuse|img
ca|imgcf|imgetfile|imhandles|imhist|imhmax|imhmin|imimposemin|imlincomb|imline|i
mmagbox|immovie|immultiply|imnoise|imopen|imoverview|imoverviewpanel|impixel|imp
ixelinfo|impixelinfoval|impixelregion|impixelregionpanel|implay|impoint|impoly|i
mpositionrect|improfile|imputfile|impyramid|imreconstruct|imrect|imregconfig|imr
egionalmax|imregionalmin|imregister|imresize|imroi|imrotate|imsave|imscrollpanel
|imshow|imshowpair|imsubtract|imtool|imtophat|imtransform|imview|ind2gray|ind2rg
b|interfileinfo|interfileread|intlut|ippl|iptaddcallback|iptcheckconn|iptcheckha
ndle|iptcheckinput|iptcheckmap|iptchecknargin|iptcheckstrs|iptdemos|iptgetapi|ip
tGetPointerBehavior|iptgetpref|ipticondir|iptnum2ordinal|iptPointerManager|iptpr
efs|iptremovecallback|iptSetPointerBehavior|iptsetpref|iptwindowalign|iradon|isb
w|isflat|isgray|isicc|isind|isnitf|isrgb|isrset|lab2double|lab2uint16|lab2uint8|
label2rgb|labelmatrix|makecform|makeConstrainToRectFcn|makehdr|makelut|makeresam
pler|maketform|mat2gray|mean2|medfilt2|montage|nitfinfo|nitfread|nlfilter|normxc
orr2|ntsc2rgb|openrset|ordfilt2|otf2psf|padarray|para2fan|phantom|poly2mask|psf2
otf|qtdecomp|qtgetblk|qtsetblk|radon|rangefilt|reflect|regionprops|registration\
.metric\.(?:MattesMutualInformation|MeanSquares)|registration\.optimizer\.(?:One
PlusOneEvolutionary|RegularStepGradientDescent)|rgb2gray|rgb2ntsc|rgb2ycbcr|roic
olor|roifill|roifilt2|roipoly|rsetwrite|std2|stdfilt|strel|stretchlim|subimage|t
formarray|tformfwd|tforminv|tonemap|translate|truesize|uintlut|viscircles|warp|w
atershed|whitepoint|wiener2|xyz2double|xyz2uint16|ycbcr2rgb' | |
67 ].join("|"); | |
68 var optimFunctions = [ | |
69 'bintprog|color|fgoalattain|fminbnd|fmincon|fminimax|fminsearch|fminunc|fsem
inf|fsolve|fzero|fzmult|gangstr|ktrlink|linprog|lsqcurvefit|lsqlin|lsqnonlin|lsq
nonneg|optimget|optimset|optimtool|quadprog' | |
70 ].join("|"); | |
71 | |
72 // identifiers: variable/function name, or a chain of variable names joined by
dots (obj.method, struct.field1.field2, etc..) | |
73 // valid variable names (start with letter, and contains letters, digits, and
underscores). | |
74 // we match "xx.yy" as a whole so that if "xx" is plain and "yy" is not, we do
nt get a false positive for "yy" | |
75 //var reIdent = '(?:[a-zA-Z][a-zA-Z0-9_]*)'; | |
76 //var reIdentChain = '(?:' + reIdent + '(?:\.' + reIdent + ')*' + ')'; | |
77 | |
78 // patterns that always start with a known character. Must have a shortcut str
ing. | |
79 var shortcutStylePatterns = [ | |
80 // whitespaces: space, tab, carriage return, line feed, line tab, form-feed,
non-break space | |
81 [PR.PR_PLAIN, /^[ \t\r\n\v\f\xA0]+/, null, " \t\r\n\u000b\u000c\u00a0"], | |
82 | |
83 // block comments | |
84 //TODO: chokes on nested block comments | |
85 //TODO: false positives when the lines with %{ and %} contain non-spaces | |
86 //[PR.PR_COMMENT, /^%(?:[^\{].*|\{(?:%|%*[^\}%])*(?:\}+%?)?)/, null], | |
87 [PR.PR_COMMENT, /^%\{[^%]*%+(?:[^\}%][^%]*%+)*\}/, null], | |
88 | |
89 // single-line comments | |
90 [PR.PR_COMMENT, /^%[^\r\n]*/, null, "%"], | |
91 | |
92 // system commands | |
93 [PR_SYSCMD, /^![^\r\n]*/, null, "!"] | |
94 ]; | |
95 | |
96 // patterns that will be tried in order if the shortcut ones fail. May have sh
ortcuts. | |
97 var fallthroughStylePatterns = [ | |
98 // line continuation | |
99 [PR_LINE_CONTINUATION, /^\.\.\.\s*[\r\n]/, null], | |
100 | |
101 // error message | |
102 [PR_ERROR, /^\?\?\? [^\r\n]*/, null], | |
103 | |
104 // warning message | |
105 [PR_WARNING, /^Warning: [^\r\n]*/, null], | |
106 | |
107 // command prompt/output | |
108 //[PR_CODE_OUTPUT, /^>>\s+[^\r\n]*[\r\n]{1,2}[^=]*=[^\r\n]*[\r\n]{1,2}[^\r\n
]*/, null], // full command output (both loose/compact format): `>> EXP\nVAR
=\n VAL` | |
109 [PR_CODE_OUTPUT, /^>>\s+/, null], // only the command prompt `>> ` | |
110 [PR_CODE_OUTPUT, /^octave:\d+>\s+/, null], // Octave command prompt `octave
:1> ` | |
111 | |
112 // identifier (chain) or closing-parenthesis/brace/bracket, and IS followed
by transpose operator | |
113 // this way we dont misdetect the transpose operator ' as the start of a str
ing | |
114 ["lang-matlab-operators", /^((?:[a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z][a-zA-Z0-9
_]*)*|\)|\]|\}|\.)')/, null], | |
115 | |
116 // identifier (chain), and NOT followed by transpose operator | |
117 // this must come AFTER the "is followed by transpose" step (otherwise it ch
ops the last char of identifier) | |
118 ["lang-matlab-identifiers", /^([a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z][a-zA-Z0-9_
]*)*)(?!')/, null], | |
119 | |
120 // single-quoted strings: allow for escaping with '', no multilines | |
121 //[PR.PR_STRING, /(?:(?<=(?:\(|\[|\{|\s|=|;|,|:))|^)'(?:[^']|'')*'(?=(?:\)|\
]|\}|\s|=|;|,|:|~|<|>|&|-|\+|\*|\.|\^|\|))/, null], // string vs. transpose (ch
eck before/after context using negative/positive lookbehind/lookahead) | |
122 [PR.PR_STRING, /^'(?:[^']|'')*'/, null], // "'" | |
123 | |
124 // floating point numbers: 1, 1.0, 1i, -1.1E-1 | |
125 [PR.PR_LITERAL, /^[+\-]?\.?\d+(?:\.\d*)?(?:[Ee][+\-]?\d+)?[ij]?/, null], | |
126 | |
127 // parentheses, braces, brackets | |
128 [PR.PR_TAG, /^(?:\{|\}|\(|\)|\[|\])/, null], // "{}()[]" | |
129 | |
130 // other operators | |
131 [PR.PR_PUNCTUATION, /^(?:<|>|=|~|@|&|;|,|:|!|\-|\+|\*|\^|\.|\||\\|\/)/, null
] | |
132 ]; | |
133 | |
134 var identifiersPatterns = [ | |
135 // list of keywords (`iskeyword`) | |
136 [PR.PR_KEYWORD, /^\b(?:break|case|catch|classdef|continue|else|elseif|end|fo
r|function|global|if|otherwise|parfor|persistent|return|spmd|switch|try|while)\b
/, null], | |
137 | |
138 // some specials variables/constants | |
139 [PR_CONSTANT, /^\b(?:true|false|inf|Inf|nan|NaN|eps|pi|ans|nargin|nargout|va
rargin|varargout)\b/, null], | |
140 | |
141 // some data types | |
142 [PR.PR_TYPE, /^\b(?:cell|struct|char|double|single|logical|u?int(?:8|16|32|6
4)|sparse)\b/, null], | |
143 | |
144 // commonly used builtin functions from core MATLAB and a few popular toolbo
xes | |
145 [PR_FUNCTION, new RegExp('^\\b(?:' + coreFunctions + ')\\b'), null], | |
146 [PR_FUNCTION_TOOLBOX, new RegExp('^\\b(?:' + statsFunctions + ')\\b'), null]
, | |
147 [PR_FUNCTION_TOOLBOX, new RegExp('^\\b(?:' + imageFunctions + ')\\b'), null]
, | |
148 [PR_FUNCTION_TOOLBOX, new RegExp('^\\b(?:' + optimFunctions + ')\\b'), null]
, | |
149 | |
150 // plain identifier (user-defined variable/function name) | |
151 [PR_IDENTIFIER, /^[a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z][a-zA-Z0-9_]*)*/, null] | |
152 ]; | |
153 | |
154 var operatorsPatterns = [ | |
155 // forward to identifiers to match | |
156 ["lang-matlab-identifiers", /^([a-zA-Z][a-zA-Z0-9_]*(?:\.[a-zA-Z][a-zA-Z0-9_
]*)*)/, null], | |
157 | |
158 // parentheses, braces, brackets | |
159 [PR.PR_TAG, /^(?:\{|\}|\(|\)|\[|\])/, null], // "{}()[]" | |
160 | |
161 // other operators | |
162 [PR.PR_PUNCTUATION, /^(?:<|>|=|~|@|&|;|,|:|!|\-|\+|\*|\^|\.|\||\\|\/)/, null
], | |
163 | |
164 // transpose operators | |
165 [PR_TRANSPOSE, /^'/, null] | |
166 ]; | |
167 | |
168 PR.registerLangHandler( | |
169 PR.createSimpleLexer([], identifiersPatterns), | |
170 ["matlab-identifiers"] | |
171 ); | |
172 PR.registerLangHandler( | |
173 PR.createSimpleLexer([], operatorsPatterns), | |
174 ["matlab-operators"] | |
175 ); | |
176 PR.registerLangHandler( | |
177 PR.createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns), | |
178 ["matlab"] | |
179 ); | |
180 })(window['PR']); | |
OLD | NEW |