gauss.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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: {
  118. 'meta-keyword': 'define definecs|10 undef ifdef ifndef iflight ifdllcall ifmac ifos2win ifunix else endif lineson linesoff srcfile srcline'
  119. },
  120. contains: [
  121. {
  122. begin: /\\\n/,
  123. relevance: 0
  124. },
  125. {
  126. beginKeywords: 'include',
  127. end: '$',
  128. keywords: {
  129. 'meta-keyword': 'include'
  130. },
  131. contains: [
  132. {
  133. className: 'meta-string',
  134. begin: '"',
  135. end: '"',
  136. illegal: '\\n'
  137. }
  138. ]
  139. },
  140. hljs.C_LINE_COMMENT_MODE,
  141. hljs.C_BLOCK_COMMENT_MODE,
  142. AT_COMMENT_MODE
  143. ]
  144. };
  145. const STRUCT_TYPE =
  146. {
  147. begin: /\bstruct\s+/,
  148. end: /\s/,
  149. keywords: "struct",
  150. contains: [
  151. {
  152. className: "type",
  153. begin: hljs.UNDERSCORE_IDENT_RE,
  154. relevance: 0
  155. }
  156. ]
  157. };
  158. // only for definitions
  159. const PARSE_PARAMS = [
  160. {
  161. className: 'params',
  162. begin: /\(/,
  163. end: /\)/,
  164. excludeBegin: true,
  165. excludeEnd: true,
  166. endsWithParent: true,
  167. relevance: 0,
  168. contains: [
  169. { // dots
  170. className: 'literal',
  171. begin: /\.\.\./
  172. },
  173. hljs.C_NUMBER_MODE,
  174. hljs.C_BLOCK_COMMENT_MODE,
  175. AT_COMMENT_MODE,
  176. STRUCT_TYPE
  177. ]
  178. }
  179. ];
  180. const FUNCTION_DEF =
  181. {
  182. className: "title",
  183. begin: hljs.UNDERSCORE_IDENT_RE,
  184. relevance: 0
  185. };
  186. const DEFINITION = function(beginKeywords, end, inherits) {
  187. const mode = hljs.inherit(
  188. {
  189. className: "function",
  190. beginKeywords: beginKeywords,
  191. end: end,
  192. excludeEnd: true,
  193. contains: [].concat(PARSE_PARAMS)
  194. },
  195. inherits || {}
  196. );
  197. mode.contains.push(FUNCTION_DEF);
  198. mode.contains.push(hljs.C_NUMBER_MODE);
  199. mode.contains.push(hljs.C_BLOCK_COMMENT_MODE);
  200. mode.contains.push(AT_COMMENT_MODE);
  201. return mode;
  202. };
  203. const BUILT_IN_REF =
  204. { // these are explicitly named internal function calls
  205. className: 'built_in',
  206. begin: '\\b(' + KEYWORDS.built_in.split(' ').join('|') + ')\\b'
  207. };
  208. const STRING_REF =
  209. {
  210. className: 'string',
  211. begin: '"',
  212. end: '"',
  213. contains: [hljs.BACKSLASH_ESCAPE],
  214. relevance: 0
  215. };
  216. const FUNCTION_REF =
  217. {
  218. // className: "fn_ref",
  219. begin: hljs.UNDERSCORE_IDENT_RE + '\\s*\\(',
  220. returnBegin: true,
  221. keywords: KEYWORDS,
  222. relevance: 0,
  223. contains: [
  224. {
  225. beginKeywords: KEYWORDS.keyword
  226. },
  227. BUILT_IN_REF,
  228. { // ambiguously named function calls get a relevance of 0
  229. className: 'built_in',
  230. begin: hljs.UNDERSCORE_IDENT_RE,
  231. relevance: 0
  232. }
  233. ]
  234. };
  235. const FUNCTION_REF_PARAMS =
  236. {
  237. // className: "fn_ref_params",
  238. begin: /\(/,
  239. end: /\)/,
  240. relevance: 0,
  241. keywords: {
  242. built_in: KEYWORDS.built_in,
  243. literal: KEYWORDS.literal
  244. },
  245. contains: [
  246. hljs.C_NUMBER_MODE,
  247. hljs.C_BLOCK_COMMENT_MODE,
  248. AT_COMMENT_MODE,
  249. BUILT_IN_REF,
  250. FUNCTION_REF,
  251. STRING_REF,
  252. 'self'
  253. ]
  254. };
  255. FUNCTION_REF.contains.push(FUNCTION_REF_PARAMS);
  256. return {
  257. name: 'GAUSS',
  258. aliases: ['gss'],
  259. case_insensitive: true, // language is case-insensitive
  260. keywords: KEYWORDS,
  261. illegal: /(\{[%#]|[%#]\}| <- )/,
  262. contains: [
  263. hljs.C_NUMBER_MODE,
  264. hljs.C_LINE_COMMENT_MODE,
  265. hljs.C_BLOCK_COMMENT_MODE,
  266. AT_COMMENT_MODE,
  267. STRING_REF,
  268. PREPROCESSOR,
  269. {
  270. className: 'keyword',
  271. begin: /\bexternal (matrix|string|array|sparse matrix|struct|proc|keyword|fn)/
  272. },
  273. DEFINITION('proc keyword', ';'),
  274. DEFINITION('fn', '='),
  275. {
  276. beginKeywords: 'for threadfor',
  277. end: /;/,
  278. // end: /\(/,
  279. relevance: 0,
  280. contains: [
  281. hljs.C_BLOCK_COMMENT_MODE,
  282. AT_COMMENT_MODE,
  283. FUNCTION_REF_PARAMS
  284. ]
  285. },
  286. { // custom method guard
  287. // excludes method names from keyword processing
  288. variants: [
  289. {
  290. begin: hljs.UNDERSCORE_IDENT_RE + '\\.' + hljs.UNDERSCORE_IDENT_RE
  291. },
  292. {
  293. begin: hljs.UNDERSCORE_IDENT_RE + '\\s*='
  294. }
  295. ],
  296. relevance: 0
  297. },
  298. FUNCTION_REF,
  299. STRUCT_TYPE
  300. ]
  301. };
  302. }
  303. module.exports = gauss;