gauss.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. Language: GAUSS
  3. Author: Matt Evans <matt@aptech.com>
  4. Description: GAUSS Mathematical and Statistical language
  5. Website: https://www.aptech.com
  6. Category: scientific
  7. */
  8. function gauss(hljs) {
  9. const KEYWORDS = {
  10. keyword: 'bool break call callexe checkinterrupt clear clearg closeall cls comlog compile '
  11. + 'continue create debug declare delete disable dlibrary dllcall do dos ed edit else '
  12. + 'elseif enable end endfor endif endp endo errorlog errorlogat expr external fn '
  13. + 'for format goto gosub graph if keyword let lib library line load loadarray loadexe '
  14. + 'loadf loadk loadm loadp loads loadx local locate loopnextindex lprint lpwidth lshow '
  15. + 'matrix msym ndpclex new open output outwidth plot plotsym pop prcsn print '
  16. + 'printdos proc push retp return rndcon rndmod rndmult rndseed run save saveall screen '
  17. + 'scroll setarray show sparse stop string struct system trace trap threadfor '
  18. + 'threadendfor threadbegin threadjoin threadstat threadend until use while winprint '
  19. + 'ne ge le gt lt and xor or not eq eqv',
  20. built_in: 'abs acf aconcat aeye amax amean AmericanBinomCall AmericanBinomCall_Greeks AmericanBinomCall_ImpVol '
  21. + 'AmericanBinomPut AmericanBinomPut_Greeks AmericanBinomPut_ImpVol AmericanBSCall AmericanBSCall_Greeks '
  22. + 'AmericanBSCall_ImpVol AmericanBSPut AmericanBSPut_Greeks AmericanBSPut_ImpVol amin amult annotationGetDefaults '
  23. + 'annotationSetBkd annotationSetFont annotationSetLineColor annotationSetLineStyle annotationSetLineThickness '
  24. + 'annualTradingDays arccos arcsin areshape arrayalloc arrayindex arrayinit arraytomat asciiload asclabel astd '
  25. + 'astds asum atan atan2 atranspose axmargin balance band bandchol bandcholsol bandltsol bandrv bandsolpd bar '
  26. + 'base10 begwind besselj bessely beta box boxcox cdfBeta cdfBetaInv cdfBinomial cdfBinomialInv cdfBvn cdfBvn2 '
  27. + 'cdfBvn2e cdfCauchy cdfCauchyInv cdfChic cdfChii cdfChinc cdfChincInv cdfExp cdfExpInv cdfFc cdfFnc cdfFncInv '
  28. + 'cdfGam cdfGenPareto cdfHyperGeo cdfLaplace cdfLaplaceInv cdfLogistic cdfLogisticInv cdfmControlCreate cdfMvn '
  29. + 'cdfMvn2e cdfMvnce cdfMvne cdfMvt2e cdfMvtce cdfMvte cdfN cdfN2 cdfNc cdfNegBinomial cdfNegBinomialInv cdfNi '
  30. + 'cdfPoisson cdfPoissonInv cdfRayleigh cdfRayleighInv cdfTc cdfTci cdfTnc cdfTvn cdfWeibull cdfWeibullInv cdir '
  31. + 'ceil ChangeDir chdir chiBarSquare chol choldn cholsol cholup chrs close code cols colsf combinate combinated '
  32. + 'complex con cond conj cons ConScore contour conv convertsatostr convertstrtosa corrm corrms corrvc corrx corrxs '
  33. + 'cos cosh counts countwts crossprd crout croutp csrcol csrlin csvReadM csvReadSA cumprodc cumsumc curve cvtos '
  34. + 'datacreate datacreatecomplex datalist dataload dataloop dataopen datasave date datestr datestring datestrymd '
  35. + 'dayinyr dayofweek dbAddDatabase dbClose dbCommit dbCreateQuery dbExecQuery dbGetConnectOptions dbGetDatabaseName '
  36. + 'dbGetDriverName dbGetDrivers dbGetHostName dbGetLastErrorNum dbGetLastErrorText dbGetNumericalPrecPolicy '
  37. + 'dbGetPassword dbGetPort dbGetTableHeaders dbGetTables dbGetUserName dbHasFeature dbIsDriverAvailable dbIsOpen '
  38. + 'dbIsOpenError dbOpen dbQueryBindValue dbQueryClear dbQueryCols dbQueryExecPrepared dbQueryFetchAllM dbQueryFetchAllSA '
  39. + 'dbQueryFetchOneM dbQueryFetchOneSA dbQueryFinish dbQueryGetBoundValue dbQueryGetBoundValues dbQueryGetField '
  40. + 'dbQueryGetLastErrorNum dbQueryGetLastErrorText dbQueryGetLastInsertID dbQueryGetLastQuery dbQueryGetPosition '
  41. + 'dbQueryIsActive dbQueryIsForwardOnly dbQueryIsNull dbQueryIsSelect dbQueryIsValid dbQueryPrepare dbQueryRows '
  42. + 'dbQuerySeek dbQuerySeekFirst dbQuerySeekLast dbQuerySeekNext dbQuerySeekPrevious dbQuerySetForwardOnly '
  43. + 'dbRemoveDatabase dbRollback dbSetConnectOptions dbSetDatabaseName dbSetHostName dbSetNumericalPrecPolicy '
  44. + 'dbSetPort dbSetUserName dbTransaction DeleteFile delif delrows denseToSp denseToSpRE denToZero design det detl '
  45. + 'dfft dffti diag diagrv digamma doswin DOSWinCloseall DOSWinOpen dotfeq dotfeqmt dotfge dotfgemt dotfgt dotfgtmt '
  46. + 'dotfle dotflemt dotflt dotfltmt dotfne dotfnemt draw drop dsCreate dstat dstatmt dstatmtControlCreate dtdate dtday '
  47. + 'dttime dttodtv dttostr dttoutc dtvnormal dtvtodt dtvtoutc dummy dummybr dummydn eig eigh eighv eigv elapsedTradingDays '
  48. + 'endwind envget eof eqSolve eqSolvemt eqSolvemtControlCreate eqSolvemtOutCreate eqSolveset erf erfc erfccplx erfcplx error '
  49. + 'etdays ethsec etstr EuropeanBinomCall EuropeanBinomCall_Greeks EuropeanBinomCall_ImpVol EuropeanBinomPut '
  50. + 'EuropeanBinomPut_Greeks EuropeanBinomPut_ImpVol EuropeanBSCall EuropeanBSCall_Greeks EuropeanBSCall_ImpVol '
  51. + 'EuropeanBSPut EuropeanBSPut_Greeks EuropeanBSPut_ImpVol exctsmpl exec execbg exp extern eye fcheckerr fclearerr feq '
  52. + 'feqmt fflush fft ffti fftm fftmi fftn fge fgemt fgets fgetsa fgetsat fgetst fgt fgtmt fileinfo filesa fle flemt '
  53. + 'floor flt fltmt fmod fne fnemt fonts fopen formatcv formatnv fputs fputst fseek fstrerror ftell ftocv ftos ftostrC '
  54. + 'gamma gammacplx gammaii gausset gdaAppend gdaCreate gdaDStat gdaDStatMat gdaGetIndex gdaGetName gdaGetNames gdaGetOrders '
  55. + 'gdaGetType gdaGetTypes gdaGetVarInfo gdaIsCplx gdaLoad gdaPack gdaRead gdaReadByIndex gdaReadSome gdaReadSparse '
  56. + 'gdaReadStruct gdaReportVarInfo gdaSave gdaUpdate gdaUpdateAndPack gdaVars gdaWrite gdaWrite32 gdaWriteSome getarray '
  57. + 'getdims getf getGAUSShome getmatrix getmatrix4D getname getnamef getNextTradingDay getNextWeekDay getnr getorders '
  58. + 'getpath getPreviousTradingDay getPreviousWeekDay getRow getscalar3D getscalar4D getTrRow getwind glm gradcplx gradMT '
  59. + 'gradMTm gradMTT gradMTTm gradp graphprt graphset hasimag header headermt hess hessMT hessMTg hessMTgw hessMTm '
  60. + 'hessMTmw hessMTT hessMTTg hessMTTgw hessMTTm hessMTw hessp hist histf histp hsec imag indcv indexcat indices indices2 '
  61. + 'indicesf indicesfn indnv indsav integrate1d integrateControlCreate intgrat2 intgrat3 inthp1 inthp2 inthp3 inthp4 '
  62. + 'inthpControlCreate intquad1 intquad2 intquad3 intrleav intrleavsa intrsect intsimp inv invpd invswp iscplx iscplxf '
  63. + 'isden isinfnanmiss ismiss key keyav keyw lag lag1 lagn lapEighb lapEighi lapEighvb lapEighvi lapgEig lapgEigh lapgEighv '
  64. + 'lapgEigv lapgSchur lapgSvdcst lapgSvds lapgSvdst lapSvdcusv lapSvds lapSvdusv ldlp ldlsol linSolve listwise ln lncdfbvn '
  65. + 'lncdfbvn2 lncdfmvn lncdfn lncdfn2 lncdfnc lnfact lngammacplx lnpdfmvn lnpdfmvt lnpdfn lnpdft loadd loadstruct loadwind '
  66. + 'loess loessmt loessmtControlCreate log loglog logx logy lower lowmat lowmat1 ltrisol lu lusol machEpsilon make makevars '
  67. + 'makewind margin matalloc matinit mattoarray maxbytes maxc maxindc maxv maxvec mbesselei mbesselei0 mbesselei1 mbesseli '
  68. + 'mbesseli0 mbesseli1 meanc median mergeby mergevar minc minindc minv miss missex missrv moment momentd movingave '
  69. + 'movingaveExpwgt movingaveWgt nextindex nextn nextnevn nextwind ntos null null1 numCombinations ols olsmt olsmtControlCreate '
  70. + 'olsqr olsqr2 olsqrmt ones optn optnevn orth outtyp pacf packedToSp packr parse pause pdfCauchy pdfChi pdfExp pdfGenPareto '
  71. + 'pdfHyperGeo pdfLaplace pdfLogistic pdfn pdfPoisson pdfRayleigh pdfWeibull pi pinv pinvmt plotAddArrow plotAddBar plotAddBox '
  72. + 'plotAddHist plotAddHistF plotAddHistP plotAddPolar plotAddScatter plotAddShape plotAddTextbox plotAddTS plotAddXY plotArea '
  73. + 'plotBar plotBox plotClearLayout plotContour plotCustomLayout plotGetDefaults plotHist plotHistF plotHistP plotLayout '
  74. + 'plotLogLog plotLogX plotLogY plotOpenWindow plotPolar plotSave plotScatter plotSetAxesPen plotSetBar plotSetBarFill '
  75. + 'plotSetBarStacked plotSetBkdColor plotSetFill plotSetGrid plotSetLegend plotSetLineColor plotSetLineStyle plotSetLineSymbol '
  76. + 'plotSetLineThickness plotSetNewWindow plotSetTitle plotSetWhichYAxis plotSetXAxisShow plotSetXLabel plotSetXRange '
  77. + 'plotSetXTicInterval plotSetXTicLabel plotSetYAxisShow plotSetYLabel plotSetYRange plotSetZAxisShow plotSetZLabel '
  78. + 'plotSurface plotTS plotXY polar polychar polyeval polygamma polyint polymake polymat polymroot polymult polyroot '
  79. + 'pqgwin previousindex princomp printfm printfmt prodc psi putarray putf putvals pvCreate pvGetIndex pvGetParNames '
  80. + 'pvGetParVector pvLength pvList pvPack pvPacki pvPackm pvPackmi pvPacks pvPacksi pvPacksm pvPacksmi pvPutParVector '
  81. + 'pvTest pvUnpack QNewton QNewtonmt QNewtonmtControlCreate QNewtonmtOutCreate QNewtonSet QProg QProgmt QProgmtInCreate '
  82. + 'qqr qqre qqrep qr qre qrep qrsol qrtsol qtyr qtyre qtyrep quantile quantiled qyr qyre qyrep qz rank rankindx readr '
  83. + 'real reclassify reclassifyCuts recode recserar recsercp recserrc rerun rescale reshape rets rev rfft rffti rfftip rfftn '
  84. + 'rfftnp rfftp rndBernoulli rndBeta rndBinomial rndCauchy rndChiSquare rndCon rndCreateState rndExp rndGamma rndGeo rndGumbel '
  85. + 'rndHyperGeo rndi rndKMbeta rndKMgam rndKMi rndKMn rndKMnb rndKMp rndKMu rndKMvm rndLaplace rndLCbeta rndLCgam rndLCi rndLCn '
  86. + 'rndLCnb rndLCp rndLCu rndLCvm rndLogNorm rndMTu rndMVn rndMVt rndn rndnb rndNegBinomial rndp rndPoisson rndRayleigh '
  87. + 'rndStateSkip rndu rndvm rndWeibull rndWishart rotater round rows rowsf rref sampleData satostrC saved saveStruct savewind '
  88. + 'scale scale3d scalerr scalinfnanmiss scalmiss schtoc schur searchsourcepath seekr select selif seqa seqm setdif setdifsa '
  89. + 'setvars setvwrmode setwind shell shiftr sin singleindex sinh sleep solpd sortc sortcc sortd sorthc sorthcc sortind '
  90. + 'sortindc sortmc sortr sortrc spBiconjGradSol spChol spConjGradSol spCreate spDenseSubmat spDiagRvMat spEigv spEye spLDL '
  91. + 'spline spLU spNumNZE spOnes spreadSheetReadM spreadSheetReadSA spreadSheetWrite spScale spSubmat spToDense spTrTDense '
  92. + 'spTScalar spZeros sqpSolve sqpSolveMT sqpSolveMTControlCreate sqpSolveMTlagrangeCreate sqpSolveMToutCreate sqpSolveSet '
  93. + 'sqrt statements stdc stdsc stocv stof strcombine strindx strlen strput strrindx strsect strsplit strsplitPad strtodt '
  94. + 'strtof strtofcplx strtriml strtrimr strtrunc strtruncl strtruncpad strtruncr submat subscat substute subvec sumc sumr '
  95. + 'surface svd svd1 svd2 svdcusv svds svdusv sysstate tab tan tanh tempname '
  96. + 'time timedt timestr timeutc title tkf2eps tkf2ps tocart todaydt toeplitz token topolar trapchk '
  97. + 'trigamma trimr trunc type typecv typef union unionsa uniqindx uniqindxsa unique uniquesa upmat upmat1 upper utctodt '
  98. + 'utctodtv utrisol vals varCovMS varCovXS varget vargetl varmall varmares varput varputl vartypef vcm vcms vcx vcxs '
  99. + 'vec vech vecr vector vget view viewxyz vlist vnamecv volume vput vread vtypecv wait waitc walkindex where window '
  100. + 'writer xlabel xlsGetSheetCount xlsGetSheetSize xlsGetSheetTypes xlsMakeRange xlsReadM xlsReadSA xlsWrite xlsWriteM '
  101. + 'xlsWriteSA xpnd xtics xy xyz ylabel ytics zeros zeta zlabel ztics cdfEmpirical dot h5create h5open h5read h5readAttribute '
  102. + 'h5write h5writeAttribute ldl plotAddErrorBar plotAddSurface plotCDFEmpirical plotSetColormap plotSetContourLabels '
  103. + 'plotSetLegendFont plotSetTextInterpreter plotSetXTicCount plotSetYTicCount plotSetZLevels powerm strjoin sylvester '
  104. + 'strtrim',
  105. literal: 'DB_AFTER_LAST_ROW DB_ALL_TABLES DB_BATCH_OPERATIONS DB_BEFORE_FIRST_ROW DB_BLOB DB_EVENT_NOTIFICATIONS '
  106. + 'DB_FINISH_QUERY DB_HIGH_PRECISION DB_LAST_INSERT_ID DB_LOW_PRECISION_DOUBLE DB_LOW_PRECISION_INT32 '
  107. + 'DB_LOW_PRECISION_INT64 DB_LOW_PRECISION_NUMBERS DB_MULTIPLE_RESULT_SETS DB_NAMED_PLACEHOLDERS '
  108. + 'DB_POSITIONAL_PLACEHOLDERS DB_PREPARED_QUERIES DB_QUERY_SIZE DB_SIMPLE_LOCKING DB_SYSTEM_TABLES DB_TABLES '
  109. + 'DB_TRANSACTIONS DB_UNICODE DB_VIEWS __STDIN __STDOUT __STDERR __FILE_DIR'
  110. };
  111. const AT_COMMENT_MODE = hljs.COMMENT('@', '@');
  112. const PREPROCESSOR =
  113. {
  114. className: 'meta',
  115. begin: '#',
  116. end: '$',
  117. keywords: { keyword: 'define definecs|10 undef ifdef ifndef iflight ifdllcall ifmac ifos2win ifunix else endif lineson linesoff srcfile srcline' },
  118. contains: [
  119. {
  120. begin: /\\\n/,
  121. relevance: 0
  122. },
  123. {
  124. beginKeywords: 'include',
  125. end: '$',
  126. keywords: { keyword: 'include' },
  127. contains: [
  128. {
  129. className: 'string',
  130. begin: '"',
  131. end: '"',
  132. illegal: '\\n'
  133. }
  134. ]
  135. },
  136. hljs.C_LINE_COMMENT_MODE,
  137. hljs.C_BLOCK_COMMENT_MODE,
  138. AT_COMMENT_MODE
  139. ]
  140. };
  141. const STRUCT_TYPE =
  142. {
  143. begin: /\bstruct\s+/,
  144. end: /\s/,
  145. keywords: "struct",
  146. contains: [
  147. {
  148. className: "type",
  149. begin: hljs.UNDERSCORE_IDENT_RE,
  150. relevance: 0
  151. }
  152. ]
  153. };
  154. // only for definitions
  155. const PARSE_PARAMS = [
  156. {
  157. className: 'params',
  158. begin: /\(/,
  159. end: /\)/,
  160. excludeBegin: true,
  161. excludeEnd: true,
  162. endsWithParent: true,
  163. relevance: 0,
  164. contains: [
  165. { // dots
  166. className: 'literal',
  167. begin: /\.\.\./
  168. },
  169. hljs.C_NUMBER_MODE,
  170. hljs.C_BLOCK_COMMENT_MODE,
  171. AT_COMMENT_MODE,
  172. STRUCT_TYPE
  173. ]
  174. }
  175. ];
  176. const FUNCTION_DEF =
  177. {
  178. className: "title",
  179. begin: hljs.UNDERSCORE_IDENT_RE,
  180. relevance: 0
  181. };
  182. const DEFINITION = function(beginKeywords, end, inherits) {
  183. const mode = hljs.inherit(
  184. {
  185. className: "function",
  186. beginKeywords: beginKeywords,
  187. end: end,
  188. excludeEnd: true,
  189. contains: [].concat(PARSE_PARAMS)
  190. },
  191. {}
  192. );
  193. mode.contains.push(FUNCTION_DEF);
  194. mode.contains.push(hljs.C_NUMBER_MODE);
  195. mode.contains.push(hljs.C_BLOCK_COMMENT_MODE);
  196. mode.contains.push(AT_COMMENT_MODE);
  197. return mode;
  198. };
  199. const BUILT_IN_REF =
  200. { // these are explicitly named internal function calls
  201. className: 'built_in',
  202. begin: '\\b(' + KEYWORDS.built_in.split(' ').join('|') + ')\\b'
  203. };
  204. const STRING_REF =
  205. {
  206. className: 'string',
  207. begin: '"',
  208. end: '"',
  209. contains: [ hljs.BACKSLASH_ESCAPE ],
  210. relevance: 0
  211. };
  212. const FUNCTION_REF =
  213. {
  214. // className: "fn_ref",
  215. begin: hljs.UNDERSCORE_IDENT_RE + '\\s*\\(',
  216. returnBegin: true,
  217. keywords: KEYWORDS,
  218. relevance: 0,
  219. contains: [
  220. { beginKeywords: KEYWORDS.keyword },
  221. BUILT_IN_REF,
  222. { // ambiguously named function calls get a relevance of 0
  223. className: 'built_in',
  224. begin: hljs.UNDERSCORE_IDENT_RE,
  225. relevance: 0
  226. }
  227. ]
  228. };
  229. const FUNCTION_REF_PARAMS =
  230. {
  231. // className: "fn_ref_params",
  232. begin: /\(/,
  233. end: /\)/,
  234. relevance: 0,
  235. keywords: {
  236. built_in: KEYWORDS.built_in,
  237. literal: KEYWORDS.literal
  238. },
  239. contains: [
  240. hljs.C_NUMBER_MODE,
  241. hljs.C_BLOCK_COMMENT_MODE,
  242. AT_COMMENT_MODE,
  243. BUILT_IN_REF,
  244. FUNCTION_REF,
  245. STRING_REF,
  246. 'self'
  247. ]
  248. };
  249. FUNCTION_REF.contains.push(FUNCTION_REF_PARAMS);
  250. return {
  251. name: 'GAUSS',
  252. aliases: [ 'gss' ],
  253. case_insensitive: true, // language is case-insensitive
  254. keywords: KEYWORDS,
  255. illegal: /(\{[%#]|[%#]\}| <- )/,
  256. contains: [
  257. hljs.C_NUMBER_MODE,
  258. hljs.C_LINE_COMMENT_MODE,
  259. hljs.C_BLOCK_COMMENT_MODE,
  260. AT_COMMENT_MODE,
  261. STRING_REF,
  262. PREPROCESSOR,
  263. {
  264. className: 'keyword',
  265. begin: /\bexternal (matrix|string|array|sparse matrix|struct|proc|keyword|fn)/
  266. },
  267. DEFINITION('proc keyword', ';'),
  268. DEFINITION('fn', '='),
  269. {
  270. beginKeywords: 'for threadfor',
  271. end: /;/,
  272. // end: /\(/,
  273. relevance: 0,
  274. contains: [
  275. hljs.C_BLOCK_COMMENT_MODE,
  276. AT_COMMENT_MODE,
  277. FUNCTION_REF_PARAMS
  278. ]
  279. },
  280. { // custom method guard
  281. // excludes method names from keyword processing
  282. variants: [
  283. { begin: hljs.UNDERSCORE_IDENT_RE + '\\.' + hljs.UNDERSCORE_IDENT_RE },
  284. { begin: hljs.UNDERSCORE_IDENT_RE + '\\s*=' }
  285. ],
  286. relevance: 0
  287. },
  288. FUNCTION_REF,
  289. STRUCT_TYPE
  290. ]
  291. };
  292. }
  293. export { gauss as default };