Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
CodeMirror.defineMode("pari", function(config, parserConfig) {
2
var indentUnit = config.indentUnit,
3
statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
4
dontAlignCalls = parserConfig.dontAlignCalls,
5
keywords = parserConfig.keywords || {},
6
builtin = parserConfig.builtin || {},
7
blockKeywords = parserConfig.blockKeywords || {},
8
atoms = parserConfig.atoms || {},
9
hooks = parserConfig.hooks || {},
10
multiLineStrings = parserConfig.multiLineStrings;
11
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
12
13
var curPunc;
14
15
function tokenBase(stream, state) {
16
var ch = stream.next();
17
if (hooks[ch]) {
18
var result = hooks[ch](stream, state);
19
if (result !== false) return result;
20
}
21
if (ch == '"' || ch == "'") {
22
state.tokenize = tokenString(ch);
23
return state.tokenize(stream, state);
24
}
25
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
26
curPunc = ch;
27
return null;
28
}
29
if (/\d/.test(ch)) {
30
stream.eatWhile(/[\w\.]/);
31
return "number";
32
}
33
if (ch == "/") {
34
if (stream.eat("*")) {
35
state.tokenize = tokenComment;
36
return tokenComment(stream, state);
37
}
38
if (stream.eat("/")) {
39
stream.skipToEnd();
40
return "comment";
41
}
42
}
43
if (ch == "\\") {
44
if (stream.eat("\\")) {
45
stream.skipToEnd();
46
return "comment";
47
}
48
}
49
if (isOperatorChar.test(ch)) {
50
stream.eatWhile(isOperatorChar);
51
return "operator";
52
}
53
stream.eatWhile(/[\w\$_]/);
54
var cur = stream.current();
55
if (keywords.propertyIsEnumerable(cur)) {
56
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
57
return "keyword";
58
}
59
if (builtin.propertyIsEnumerable(cur)) {
60
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
61
return "builtin";
62
}
63
if (atoms.propertyIsEnumerable(cur)) return "atom";
64
return "variable";
65
}
66
67
function tokenString(quote) {
68
return function(stream, state) {
69
var escaped = false, next, end = false;
70
while ((next = stream.next()) != null) {
71
if (next == quote && !escaped) {end = true; break;}
72
escaped = !escaped && next == "\\";
73
}
74
if (end || !(escaped || multiLineStrings))
75
state.tokenize = null;
76
return "string";
77
};
78
}
79
80
function tokenComment(stream, state) {
81
var maybeEnd = false, ch;
82
while (ch = stream.next()) {
83
if (ch == "/" && maybeEnd) {
84
state.tokenize = null;
85
break;
86
}
87
maybeEnd = (ch == "*");
88
}
89
return "comment";
90
}
91
92
function Context(indented, column, type, align, prev) {
93
this.indented = indented;
94
this.column = column;
95
this.type = type;
96
this.align = align;
97
this.prev = prev;
98
}
99
function pushContext(state, col, type) {
100
var indent = state.indented;
101
if (state.context && state.context.type == "statement")
102
indent = state.context.indented;
103
return state.context = new Context(indent, col, type, null, state.context);
104
}
105
function popContext(state) {
106
var t = state.context.type;
107
if (t == ")" || t == "]" || t == "}")
108
state.indented = state.context.indented;
109
return state.context = state.context.prev;
110
}
111
112
// Interface
113
114
return {
115
startState: function(basecolumn) {
116
return {
117
tokenize: null,
118
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
119
indented: 0,
120
startOfLine: true
121
};
122
},
123
124
token: function(stream, state) {
125
var ctx = state.context;
126
if (stream.sol()) {
127
if (ctx.align == null) ctx.align = false;
128
state.indented = stream.indentation();
129
state.startOfLine = true;
130
}
131
if (stream.eatSpace()) return null;
132
curPunc = null;
133
var style = (state.tokenize || tokenBase)(stream, state);
134
if (style == "comment" || style == "meta") return style;
135
if (ctx.align == null) ctx.align = true;
136
137
if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
138
else if (curPunc == "{") pushContext(state, stream.column(), "}");
139
else if (curPunc == "[") pushContext(state, stream.column(), "]");
140
else if (curPunc == "(") pushContext(state, stream.column(), ")");
141
else if (curPunc == "}") {
142
while (ctx.type == "statement") ctx = popContext(state);
143
if (ctx.type == "}") ctx = popContext(state);
144
while (ctx.type == "statement") ctx = popContext(state);
145
}
146
else if (curPunc == ctx.type) popContext(state);
147
else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
148
pushContext(state, stream.column(), "statement");
149
state.startOfLine = false;
150
return style;
151
},
152
153
indent: function(state, textAfter) {
154
if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
155
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
156
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
157
var closing = firstChar == ctx.type;
158
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
159
else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1);
160
else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
161
else return ctx.indented + (closing ? 0 : indentUnit);
162
},
163
164
electricChars: "{}",
165
blockCommentStart: "/*",
166
blockCommentEnd: "*/",
167
lineComment: "\\\\",
168
fold: "brace"
169
};
170
});
171
172
(function() {
173
function words(str) {
174
var obj = {}, words = str.split(" ");
175
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
176
return obj;
177
}
178
var cKeywords = "Col Euler I List Mat Mod O Pi Pol Polrev Qfb Ser Set Str Strchr Strexpand Strprintf Strtex Vec Vecrev Vecsmall abs acos acosh addhelp addprimes agm alarm algdep alias allocatemem apply arg asin asinh atan atanh bernfrac bernreal bernvec besselh1 besselh2 besseli besselj besseljh besselk besseln bestappr bezout bezoutres bigomega binary binomial bitand bitneg bitnegimply bitor bittest bitxor bnfcertify bnfcompress bnfdecodemodule bnfinit bnfisintnorm bnfisnorm bnfisprincipal bnfissunit bnfisunit bnfnarrow bnfsignunit bnfsunit bnrL1 bnrclassno bnrclassnolist bnrconductor bnrconductorofchar bnrdisc bnrdisclist bnrinit bnrisconductor bnrisprincipal bnrrootnumber bnrstark break ceil centerlift charpoly chinese component concat conj conjvec content contfrac contfracpnqn core coredisc cos cosh cotan default denominator deriv derivnum diffop dilog dirdiv direuler dirmul dirzetak divisors divrem eint1 ellL1 elladd ellak ellan ellanalyticrank ellap ellbil ellchangecurve ellchangepoint ellconvertname elldivpol elleisnum elleta ellgenerators ellglobalred ellgroup ellheight ellheightmatrix ellidentify ellinit ellisoncurve ellj elllocalred elllog elllseries ellminimalmodel ellmodulareqn ellorder ellordinate ellpointtoz ellpow ellrootno ellsearch ellsigma ellsub elltaniyama elltatepairing elltors ellweilpairing ellwp ellzeta ellztopoint erfc error eta eulerphi eval exp extern externstr factor factorback factorcantor factorff factorial factorint factormod factornf factorpadic ffgen ffinit fflog fforder ffprimroot fibonacci floor for fordiv forell forprime forstep forsubgroup forvec frac galoisexport galoisfixedfield galoisgetpol galoisidentify galoisinit galoisisabelian galoisisnormal galoispermtopol galoissubcyclo galoissubfields galoissubgroups gamma gammah gcd getheap getrand getstack gettime global hilbert hyperu idealadd idealaddtoone idealappr idealchinese idealcoprime idealdiv idealfactor idealfactorback idealfrobenius idealhnf idealintersect idealinv ideallist ideallistarch ideallog idealmin idealmul idealnorm idealpow idealprimedec idealramgroups idealred idealstar idealtwoelt idealval if imag incgam incgamc input install intcirc intformal intfouriercos intfourierexp intfouriersin intfuncinit intlaplaceinv intmellininv intmellininvshort intnum intnuminit intnuminitgen intnumromb intnumstep isfundamental ispower isprime ispseudoprime issquare issquarefree kill kronecker lcm length lex lift lindep listcreate listinsert listkill listpop listput listsort lngamma local log matadjoint matalgtobasis matbasistoalg matcompanion matdet matdetint matdiagonal mateigen matfrobenius mathess mathilbert mathnf mathnfmod mathnfmodid matid matimage matimagecompl matindexrank matintersect matinverseimage matisdiagonal matker matkerint matmuldiagonal matmultodiagonal matpascal matrank matrix matrixqz matsize matsnf matsolve matsolvemod matsupplement mattranspose max min minpoly modreverse moebius my newtonpoly next nextprime nfalgtobasis nfbasis nfbasistoalg nfdetint nfdisc nfeltadd nfeltdiv nfeltdiveuc nfeltdivmodpr nfeltdivrem nfeltmod nfeltmul nfeltmulmodpr nfeltnorm nfeltpow nfeltpowmodpr nfeltreduce nfeltreducemodpr nfelttrace nfeltval nffactor nffactorback nffactormod nfgaloisapply nfgaloisconj nfhilbert nfhnf nfhnfmod nfinit nfisideal nfisincl nfisisom nfkermodpr nfmodprinit nfnewprec nfroots nfrootsof1 nfsnf nfsolvemodpr nfsubfields norm norml2 numbpart numdiv numerator numtoperm omega padicappr padicfields padicprec partitions permtonum plot plotbox plotclip plotcolor plotcopy plotcursor plotdraw ploth plothraw plothsizes plotinit plotkill plotlines plotlinetype plotmove plotpoints plotpointsize plotpointtype plotrbox plotrecth plotrecthraw plotrline plotrmove plotrpoint plotscale plotstring polchebyshev polcoeff polcompositum polcyclo poldegree poldisc poldiscreduced polgalois polhensellift polhermite polinterpolate polisirreducible pollead pollegendre polrecip polred polredabs polredbest polredord polresultant polroots polrootsff polrootsmod polrootspadic polsturm polsubcyclo polsylvestermatrix polsym poltchebi poltschirnhaus polylog polzagier precision precprime prime primepi primes print print1 printf printtex prod prodeuler prodinf psdraw psi psploth psplothraw qfbclassno qfbcompraw qfbhclassno qfbnucomp qfbnupow qfbpowraw qfbprimeform qfbred qfbsolve qfgaussred qfjacobi qflll qflllgram qfminim qfperfection qfrep qfsign quadclassunit quaddisc quadgen quadhilbert quadpoly quadray quadregulator quadunit quit random read readvec real removeprimes return rnfalgtobasis rnfbasis rnfbasistoalg rnfcharpoly rnfconductor rnfdedekind rnfdet rnfdisc rnfeltabstorel rnfeltdown rnfeltreltoabs rnfeltup rnfequation rnfhnfbasis rnfidealabstorel rnfidealdown rnfidealhnf rnfidealmul rnfidealnormabs rnfidealnormrel rnfidealreltoabs rnfidealtwoelt rnfidealup rnfinit rnfisabelian rnfisfree rnfisnorm rnfisnorminit rnfkummer rnflllgram rnfnormgroup rnfpolred rnfpolredabs rnfpseudobasis rnfsteinitz round select serconvol serlaplace serreverse setintersect setisset setminus setrand setsearch setunion shift shiftmul sigma sign simplify sin sinh sizebyte sizedigit solve sqr sqrt sqrtint sqrtn stirling subgrouplist subst substpol substvec sum sumalt sumdedekind sumdiv suminf sumnum sumnumalt sumnuminit sumpos system tan tanh taylor teichmuller theta thetanullk thue thueinit trace trap truncate type until valuation variable vecextract vecmax vecmin vecsort vector vectorsmall vectorv version warning weber whatnow while write write1 writebin writetex zeta zetak zetakinit zncoppersmith znlog znorder znprimroot znstar";
179
180
function cppHook(stream, state) {
181
if (!state.startOfLine) return false;
182
for (;;) {
183
if (stream.skipTo("\\")) {
184
stream.next();
185
if (stream.eol()) {
186
state.tokenize = cppHook;
187
break;
188
}
189
} else {
190
stream.skipToEnd();
191
state.tokenize = null;
192
break;
193
}
194
}
195
return "meta";
196
}
197
198
// C#-style strings where "" escapes a quote.
199
function tokenAtString(stream, state) {
200
var next;
201
while ((next = stream.next()) != null) {
202
if (next == '"' && !stream.eat('"')) {
203
state.tokenize = null;
204
break;
205
}
206
}
207
return "string";
208
}
209
210
function mimes(ms, mode) {
211
for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
212
}
213
214
mimes(["text/pari"], {
215
name: "pari",
216
keywords: words(cKeywords),
217
blockKeywords: words("catch class do else finally for if struct switch try while"),
218
atoms: words("true false null"),
219
hooks: {"#": cppHook}
220
});
221
}());
222
223