I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

User talk:BenBE

From Rosetta Code

Tcl[edit]

Thanks for the offer to help with the Tcl formatting. I was really just looking to go back to what we had before as that mostly was working well. ;–)

The Tcl language is a tricky one to do perfectly correctly (I wrote a syntax highlighter for emacs's tcl-mode many years ago, so I know what I'm talking about) so typically it's easier to use an approximation and GeSHi isn't far off what's needed (apart from a few updates to the list of standard commands, which should be trivial anyway and doesn't need to be hurried). No time to go into great depth about it today though; I have a snowstorm to beat home… –Donal Fellows 13:34, 3 February 2010 (UTC)

Well, there was an erronous regexp in the comment section that caused a bit of trouble. I disabled it for now.
Well, I'm also working together with someone on the J language file that looks totally illogical to me ... Tcl at least presents a tiny bit of logic.
I'll have some more time to work on language files soon. --BenBE 23:06, 3 February 2010 (UTC)

VBScript[edit]

Regarding syntax highlighting for vbscript, using the vb or vb.net definitions would be quite adequate to start with. @Axtens

Schuld do. Althoug VBS has some strange changes in regards to VB and VB.net. VB should be the better base. --BenBE 21:19, 4 February 2010 (UTC)

Language file[edit]

Thank you for your message on my file [1]. I fixed the file's issues: the two notices, the two errors, and the first warning all needed to be repaired. The last three warnings are correct as-is: there is a default that shares a name with a function and so forth. (If it's required that there be no overlap the duplicates in groups 2 and 3 could go, but they really should stay if possible.)

I haven't yet figured out how to handle the escapes but will look at the PHP file and see if that helps.

I don't see how to upload a file to SourceForge without opening a new issue, so for now I'll leave it here.

<?php
/*************************************************************************************
* parigp.php
* --------
* Author: Charles R Greathouse IV ([email protected])
* Copyright: 2011 Charles R Greathouse IV (http://math.crg4.com/)
* Release Version:
* Date Started: 2011/05/11
*
* PARI/GP language file for GeSHi.
*
* CHANGES
* -------
*
* TODO (updated yyyy/mm/dd)
* -------------------------
*
*
*************************************************************************************
*
* This file is part of GeSHi.
*
* GeSHi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GeSHi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GeSHi; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
************************************************************************************/

 
$language_data = array(
'LANG_NAME' => 'PARI/GP',
'COMMENT_SINGLE' => array(1 => '\\\\'),
'COMMENT_MULTI' => array('/*' => '*/'),
'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
'QUOTEMARKS' => array('"'),
'ESCAPE_CHAR' => '\\',
'KEYWORDS' => array(
1 => array('addprimes', 'bestappr', 'bezout', 'bezoutres', 'bigomega', 'binomial', 'chinese',
'content', 'contfrac', 'contfracpnqn', 'core', 'coredisc', 'dirdiv', 'direuler', 'dirmul',
'divisors', 'eulerphi', 'factor', 'factorback', 'factorcantor', 'factorff', 'factorial',
'factorint', 'factormod', 'ffgen', 'ffinit', 'fflog', 'fforder', 'ffprimroot', 'fibonacci',
'gcd', 'hilbert', 'isfundamental', 'ispower', 'isprime', 'ispseudoprime', 'issquare',
'issquarefree', 'kronecker', 'lcm', 'moebius', 'nextprime', 'numbpart', 'numdiv', 'omega',
'partitions', 'polrootsff', 'precprime', 'prime', 'primepi', 'primes', 'qfbclassno',
'qfbcompraw', 'qfbhclassno', 'qfbnucomp', 'qfbnupow', 'qfbpowraw', 'qfbprimeform', 'qfbred',
'qfbsolve', 'quadclassunit', 'quaddisc', 'quadgen', 'quadhilbert', 'quadpoly', 'quadray',
'quadregulator', 'quadunit', 'removeprimes', 'sigma', 'sqrtint', 'stirling', 'sumdedekind',
'zncoppersmith', 'znlog', 'znorder', 'znprimroot', 'znstar', 'Col', 'List', 'Mat', 'Mod',
'Pol', 'Polrev', 'Qfb', 'Ser', 'Set', 'Str', 'Strchr', 'Strexpand', 'Strtex', 'Vec', 'Vecrev',
'Vecsmall', 'binary', 'bitand', 'bitneg', 'bitnegimply', 'bitor', 'bittest', 'bitxor', 'ceil',
'centerlift', 'component', 'conj', 'conjvec', 'denominator', 'floor', 'frac', 'imag', 'length',
'lift', 'norm', 'norml2', 'numerator', 'numtoperm', 'padicprec', 'permtonum', 'precision',
'random', 'real', 'round', 'simplify', 'sizebyte', 'sizedigit', 'truncate', 'valuation',
'variable', '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', 'bnfcertify', 'bnfcompress', 'bnfdecodemodule', 'bnfinit',
'bnfisintnorm', 'bnfisnorm', 'bnfisprincipal', 'bnfissunit', 'bnfisunit', 'bnfnarrow',
'bnfsignunit', 'bnfsunit', 'bnrL1', 'bnrclassno', 'bnrclassnolist', 'bnrconductor',
'bnrconductorofchar', 'bnrdisc', 'bnrdisclist', 'bnrinit', 'bnrisconductor', 'bnrisprincipal',
'bnrrootnumber', 'bnrstark', 'dirzetak', 'factornf', 'galoisexport', 'galoisfixedfield',
'galoisgetpol', 'galoisidentify', 'galoisinit', 'galoisisabelian', 'galoisisnormal',
'galoispermtopol', 'galoissubcyclo', 'galoissubfields', 'galoissubgroups', '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', 'matalgtobasis',
'matbasistoalg', 'modreverse', 'newtonpoly', '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', 'polcompositum', 'polgalois', 'polred',
'polredabs', 'polredord', 'poltschirnhaus', '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', 'subgrouplist', 'zetak', 'zetakinit', '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', 'psdraw', 'psploth', 'psplothraw', 'O',
'deriv', 'diffop', 'eval', 'factorpadic', 'intformal', 'padicappr', 'padicfields',
'polchebyshev', 'polcoeff', 'polcyclo', 'poldegree', 'poldisc', 'poldiscreduced',
'polhensellift', 'polhermite', 'polinterpolate', 'polisirreducible', 'pollead', 'pollegendre',
'polrecip', 'polresultant', 'polroots', 'polrootsmod', 'polrootspadic', 'polsturm',
'polsubcyclo', 'polsylvestermatrix', 'polsym', 'poltchebi', 'polzagier', 'serconvol',
'serlaplace', 'serreverse', 'subst', 'substpol', 'substvec', 'taylor', 'thue', 'thueinit',
'break', 'for', 'fordiv', 'forell', 'forprime', 'forstep', 'forsubgroup', 'forvec', 'if',
'next', 'return', 'until', 'while', 'Strprintf', 'addhelp', 'alarm', 'alias', 'allocatemem',
'apply', 'default', 'error', 'extern', 'externstr', 'getheap', 'getrand', 'getstack',
'gettime', 'global', 'input', 'install', 'kill', 'print1', 'print', 'printf', 'printtex',
'quit', 'read', 'readvec', 'select', 'setrand', 'system', 'trap', 'type', 'version', 'warning',
'whatnow', 'write1', 'write', 'writebin', 'writetex', 'divrem', 'lex', 'max', 'min', 'shift',
'shiftmul', 'sign', 'vecmax', 'vecmin', 'derivnum', 'intcirc', 'intfouriercos', 'intfourierexp',
'intfouriersin', 'intfuncinit', 'intlaplaceinv', 'intmellininv', 'intmellininvshort', 'intnum',
'intnuminit', 'intnuminitgen', 'intnumromb', 'intnumstep', 'prod', 'prodeuler', 'prodinf',
'solve', 'sum', 'sumalt', 'sumdiv', 'suminf', 'sumnum', 'sumnumalt', 'sumnuminit', 'sumpos',
'Euler', 'I', 'Pi', 'abs', 'acos', 'acosh', 'agm', 'arg', 'asin', 'asinh', 'atan', 'atanh',
'bernfrac', 'bernreal', 'bernvec', 'besselh1', 'besselh2', 'besseli', 'besselj', 'besseljh',
'besselk', 'besseln', 'cos', 'cosh', 'cotan', 'dilog', 'eint1', 'erfc', 'eta', 'exp', 'gamma',
'gammah', 'hyperu', 'incgam', 'incgamc', 'lngamma', 'log', 'polylog', 'psi', 'sin', 'sinh',
'sqr', 'sqrt', 'sqrtn', 'tan', 'tanh', 'teichmuller', 'theta', 'thetanullk', 'weber', 'zeta',
'algdep', 'charpoly', 'concat', 'lindep', 'listcreate', 'listinsert', 'listkill', 'listpop',
'listput', 'listsort', 'matadjoint', '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', 'minpoly', 'qfgaussred', 'qfjacobi', 'qflll', 'qflllgram',
'qfminim', 'qfperfection', 'qfrep', 'qfsign', 'setintersect', 'setisset', 'setminus',
'setsearch', 'setunion', 'trace', 'vecextract', 'vecsort', 'vector', 'vectorsmall', 'vectorv'),
2 => array('TeXstyle', 'breakloop', 'colors', 'compatible', 'datadir', 'debug', 'debugfiles',
'debugmem', 'echo', 'factor_add_primes', 'factor_proven', 'format', 'graphcolormap',
'graphcolors', 'help', 'histfile', 'histsize', 'lines', 'log', 'logfile', 'new_galois_format',
'output', 'parisize', 'path', 'prettyprinter', 'primelimit', 'prompt_cont', 'prompt', 'psfile',
'readline', 'realprecision', 'recover', 'secure', 'seriesprecision',
'simplify', 'strictmatch', 'timer'),
3 => array('void', 'bool', 'negbool', 'small', 'int', 'real', 'mp', 'var', 'pol', 'vecsmall',
'vec', 'list', 'str', 'genstr', 'gen', 'lg', 'typ')
),
'SYMBOLS' => array(
1 => array(
'(', ')', '{', '}', '[', ']', '+', '-', '*', '/', '%', '=', '<', '>', '!', '^', '&', '|', '?', ';', ':', ','
)
),
'CASE_SENSITIVE' => array(
GESHI_COMMENTS => false,
1 => true, 2 => true, 3 => true
),
'STYLES' => array(
'KEYWORDS' => array(1 => 'color: #0000FF;', 2 => 'color: #00d2d2;', 3 => 'color: #ff8000;'
),
'COMMENTS' => array(
1 => 'color: #008000;',
'MULTI' => 'color: #008000;'
),
'ESCAPE_CHAR' => array(
0 => 'color: #111111; font-weight: bold;'
),
'BRACKETS' => array(
0 => 'color: #009900;'
),
'STRINGS' => array(
0 => 'color: #800080;'
),
'NUMBERS' => array(
0 => 'color: #000000;',
),
'METHODS' => array(
0 => 'color: #004000;'
),
'SYMBOLS' => array(
1 => 'color: #339933;'
),
'REGEXPS' => array(),
'SCRIPT' => array()
),
'URLS' => array(1 => '', 2 => '', 3 => ''),
'OOLANG' => true,
'OBJECT_SPLITTERS' => array(1 => '.'),
'REGEXPS' => array(),
'STRICT_MODE_APPLIES' => GESHI_NEVER,
'SCRIPT_DELIMITERS' => array(),
'HIGHLIGHT_STRICT_BLOCK' => array()
);
 
?>

CRGreathouse 01:32, 8 July 2011 (UTC)

Oh, and you had asked for sample source code:

fibmod(n:int, m:int)={
my(f,t);
if (m < 6,
if (m < 0, m = -m);
if (m == 0, error("division by 0"));
if (m == 1, return(0));
if (m == 2, return(n%3>0));
if (m == 3, return(fibonacci(n%8)%3));
if (m == 4, return(fibonacci(n%6)%4));
if (m == 5, return(fibonacci(n%20)%5));
);
if (n < 1000,
return(fibonacci(n)%m);
);
f = factor(m);
t = Mod(fibonacci(n%Pisano(f[1,1], f[1,2])),f[1,1]^f[1,2]);
for(i=2,#f[,1],
t = chinese(t,Mod(fibonacci(n%Pisano(f[i,1], f[i,2])),f[i,1]^f[i,2]));
);
lift(t)
};
addhelp(fibmod,"fibmod(n,m): Returns the nth Fibonacci number mod m. Same as finonacci(n)%m, but faster for large n.");
 
 
\\ Helper function for fibmod; returns a multiple of the period of Fibonacci numbers mod p^e.
\\ Assumes p is prime and e > 0.
Pisano(p:int,e:small)={
my(t);
if(p==5, return(4 * 5^e));
t = p%5;
if (t == 2 || t == 3,
t = 2 * (p + 1)
,
t = p - 1
);
t * p^(e-1)
};
 
rad(n:int)={
if(n < 0, n = -n);
if (issquarefree(n), return(n));
vecprod(factor(n)[,1])
};
addhelp(rad, "rad(n): Radical of n, the largest squarefree number dividing n. Sloane's A007947.");
 
 
isprimepower(n:int)={
ispower(n,,&n);
isprime(n)
};
addhelp(isprimepower, "isprimepower(n): Is n a prime power? Characteristic sequence of Sloane's A000961.");
 
 
isPowerful(n:int)={
if (bitand(n,3)==2,return(0));
if (n%3 == 0 && n%9 > 0, return(0));
if (n%5 == 0 && n%25 > 0, return(0));
vecmin(factor(n)[,2])>1
};
addhelp(isPowerful, "isPowerful(n): Is n powerful (min exponent 2)? Sloane's A112526; characteristic function of Sloane's A001694.");
 
 
prp(n:int,b:int=2)={
Mod(b,n)^(n-1)==1
};
addhelp(prp, "prp(n,b=2): Is n a b-probable prime?");
 
 
sprp(n:int,b:int=2)={
my(d = n, s = 0);
until(bitand(d,1), d >>= 1; s++);
d = Mod(b, n)^d;
if (d == 1, return(1));
for(i=1,s-1,
if (d == -1, return(1));
d = d^2;
);
d == -1
};
addhelp(sprp, "sprp(n,b=2): Is n a b-strong probable prime?");
 
 
sopfr(n:int)={
my(f=factor(n));
sum(i=1,#f[,1],f[i,1]*f[i,2])
};
addhelp(sopfr, "sopfr(n): Sum of prime factors of n (with multiplicity). Sloane's A001414.");
 
 
primorial(n)={
my(t1=1,t2=1,t3=1,t4=1);
forprime(p=2,n>>3,t1=t1*p);
forprime(p=(n>>3)+1,n>>2,t2=t2*p);
t1=t1*t2;t2=1;
forprime(p=(n>>2)+1,(3*n)>>3,t2=t2*p);
forprime(p=((3*n)>>3)+1,n>>1,t3=t3*p);
t1=t1*(t2*t3);t2=1;t3=1;
forprime(p=(n>>1)+1,(5*n)>>3,t2=t2*p);
forprime(p=((5*n)>>3)+1,(3*n)>>2,t3=t3*p);
t2=t2*t3;t3=1;
forprime(p=((3*n)>>2)+1,(7*n)>>3,t3=t3*p);
forprime(p=((7*n)>>3)+1,n,t4=t4*p);
t1*(t2*(t3*t4))
};
addhelp(primorial, "Returns the product of each prime less than or equal to n. Sloane's A034386.");
 
 
gpf(n:int)={
my(f=factor(n)[,1]);
if (n <= 1,
if (n >= -1, return (1)); \\ Convention
n = -n
);
f[#f]
};
addhelp(gpf, "The greatest prime factor of a number. Sloane's A006530.");
 
 
lpf(n:int)={
if (n <= 1,
if (n >= -1, return (1)); \\ Convention
n = -n
);
forprime(p=2,2e4,
if(n%p==0,return(p));
);
factor(n)[1,1]
};
addhelp(lpf,"The least prime factor of a number. Sloane's A020639.");
 
isTriangular(n:int)={
issquare(n<<3+1)
};
addhelp(isTriangular, "isTriangular(n): Is n a triangular number? Sloane's A010054.");
 
 
isFibonacci(n:int)={
my(k=n^2);
k+=((k + 1) << 2);
issquare(k) || (n > 0 && issquare(k-8))
};
addhelp(isFibonacci, "isFibonacci(n): Is n a Fibonacci number? Sloane's A010056; characteristic function of Sloane's A000045.");
 
 
largestSquareFactor(n:int)={
my(f=factor(n));
prod(i=1,#f[,1],f[i,1]^(f[i,2]>>1))^2
};
addhelp(largestSquareFactor, "largestSquareFactor(n): Largest square dividing n. Sloane's A008833.");
 
 
hamming(n:int)={
my(v=binary(n));
sum(i=1,#v,v[i])
};
addhelp(hamming, "hamming(n): Hamming weight of n (considered as a binary number). Sloane's A000120.");
 
 
istwo(n:int)={
my(f);
if (n < 3,
return (n >= 0);
);
f = factor(oddres(n));
for (i=1,#f[,1],
if(bitand(f[i,2],1)==1 && bitand(f[i, 1], 3)==3, return(0))
);
1
};
addhelp(istwo, "Is the number a sum of two squares? Characteristic function of Sloane's A001481.");
 
 
ways2(n:int)={
\\sum(k=0,sqrtint(n>>1),issquare(n-k^2))
my(f=factor(oddres(n)),t=1);
for(i=1,#f[,1],
if (f[i,1]%4==3,
if (f[i,2]%2, return(0))
,
t *= f[i,2] + 1;
)
);
(t + 1) >> 1
};
addhelp(ways2, "Number of ways that n can be represented as a sum of two squares. Sloane's A000161.");
 
 
isthree(n:int)={
my(tmp=valuation(n, 2));
bitand(tmp, 1) || bitand(n >> tmp, 7) != 7
};
addhelp(isthree, "isthree(n): Is the number the sum of three squares? Sloane's A071374; characteristic function of Sloane's A000378.");
 
 
ways3(n:int)={
my(t);
sum(k=0,sqrtint(n\3),
t=n-k^2;
sum(m=k,sqrtint(t>>1),
issquare(t-m^2)
)
)
};
addhelp(ways3, "Number of ways that n can be represented as a sum of three squares. Sloane's A000164.");
 
 
msb(n:int)={
my(k:int=0);
n=floor(n);
while(n>15,
n>>=4;
k+=4
);
if(n>3,
n>>=2;
k+=2
);
min(n,2)<<k
};
addhelp(msb, "msb(n): Most significant bit of n: returns the greatest power of 2 <= the number. Sloane's A053644.");
 
 
Faulhaber(e:small,a='x)={
substpol(sum(i=0,e,binomial(e+1,i)*bernfrac(i)*'x^(e+1-i))/(e+1) + 'x^e, 'x, a)
};
addhelp(Faulhaber, "Faulhaber(e,{a='x}): Returns the polynomial for the sum 1^e + 2^e + ... + x^e, evaluated at a.");

Hang on -- you actually added it to RC? That's fantastic! Thank you very much!

CRGreathouse 01:45, 8 July 2011 (UTC)

It's not the latest version yet, but a roughtly fixed version of the version you sent earlier.
Regarding the duplicates: Only the first keyword group a keyword is in actually gets highlighted thus having the keyword appear in any other keyword group is wasted performance. You might comment those keywords out or (if there's a way to distinguish the various cases) set some (well, undocumented ^^) options to e.g. require a ( after a function's name or something like this. The preferred solution in this case might be just commenting them out with /* 'keyword', */ in this case though. The other solution would require you to write some (distinct regexp where if one of them matches the other won't). An example for this is the MySQL language file which uses this solution.
--BenBE 02:08, 8 July 2011 (UTC)
Yes, I know it's not the latest -- no hurry on that since I have two language files to read over before I fix the various other issues.
On the issue of \, a basic regex like
'/"([^\\"]|\\.)*"/'
matches PARI strings, and all backslashes outside of strings can be treated as operators. Is there a good way to do this?
CRGreathouse 02:25, 8 July 2011 (UTC)
If I understand your regexp correctly: Everything after \ should be treated as escaped, thus \\, \" and \n (and even \- are escapes? IIRC that's what the settings in the language file already say (see ESCAPE_CHAR and QUOTES.
For further information you also might want to join #GeSHi on Freenode.
--BenBE 02:30, 8 July 2011 (UTC)
Yes, everything after a backslash is escaped, but only inside a string. So in
foo = "\"";
bar = "3\2";
baz = 3\2;
the first two are escapes but the last is an integer division operator. The values of the variables are, respectively, a string containing ", a string containing 32, and the integer 1.
Another issue I just thought of: the apostrophe. It would be good if 'foo was highlighted differently. The initial ' essentially says "treat the following variable literally", technically as a polynomial with a one-term variable of its own name raised to the first power and multiplied by 1. So x might have some value like 7, but 'x is 'just' the variable x.
CRGreathouse 02:39, 8 July 2011 (UTC)
OK, I'm on #GeSHi. CRGreathouse 02:53, 8 July 2011 (UTC)

New language file[edit]

This attempts to fix all the issues we've discussed. I'm sure there are still issues, but it should be a step forward.

I had to use custom number formats because I saw that the definitions all had negative lookbehind forbidding \ before numbers, but constructs like 10\3 are pretty common so shouldn't be disallowed. Also, they allow unusual exponents like 11e/7 which is decidedly a syntax error in GP. I kept the definitions reasonably simple.

I added \ and ' as symbols; not sure how much trouble that might cause.

Now that I feel I better understand GeSHi REGEXPS I added two, one for types and the other for literal variables. At least one of these will have problems, since the first must highlight inside strings and the second should not. That is, in

y1 = "t_INT";
y2 = 'x;
n1 = t_INT;
n2 = "shouldn't highlight";

both values assigned to y1 and y2 should get highlighting, while neither assigned to n1 and n2 should. I don't know how this can be expressed in GeSHi, or indeed if it can at all.

I'm not sure about where to use SCRIPT_DELIMITERS vs. PARSER_CONTROL. I tried implementing keyword groups 2, 3, and 4 with the former, but perhaps these should be done with PARSER_CONTROL or even REGEXPS.

Oh, and I changed the highlighting and added more keywords. Whew.

<?php
/*************************************************************************************
* parigp.php
* --------
* Author: Charles R Greathouse IV ([email protected])
* Copyright: 2011 Charles R Greathouse IV (http://math.crg4.com/)
* Release Version:
* Date Started: 2011/05/11
*
* PARI/GP language file for GeSHi.
*
* CHANGES
* -------
*
* TODO (updated yyyy/mm/dd)
* -------------------------
*
*
*************************************************************************************
*
* This file is part of GeSHi.
*
* GeSHi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GeSHi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GeSHi; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
************************************************************************************/

 
$language_data = array(
'LANG_NAME' => 'PARI/GP',
'COMMENT_SINGLE' => array(1 => '\\\\'),
'COMMENT_MULTI' => array('/*' => '*/'),
'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
'QUOTEMARKS' => array('"'),
'ESCAPE_CHAR' => '\\',
 
 
'NUMBERS' => array(
# Integers
0 => '\b\d+\b',
# Reals
1 => '\b(?:-?(?:\d+\.\d*|\.\d+)(?:[eE]\d+)?|\d+[eE]\d+)\b'
),
 
'KEYWORDS' => array(
1 => array('addprimes', 'bestappr', 'bezout', 'bezoutres', 'bigomega', 'binomial', 'chinese',
'content', 'contfrac', 'contfracpnqn', 'core', 'coredisc', 'dirdiv', 'direuler', 'dirmul',
'divisors', 'eulerphi', 'factor', 'factorback', 'factorcantor', 'factorff', 'factorial',
'factorint', 'factormod', 'ffgen', 'ffinit', 'fflog', 'fforder', 'ffprimroot', 'fibonacci',
'gcd', 'hilbert', 'isfundamental', 'ispower', 'isprime', 'ispseudoprime', 'issquare',
'issquarefree', 'kronecker', 'lcm', 'moebius', 'nextprime', 'numbpart', 'numdiv', 'omega',
'partitions', 'polrootsff', 'precprime', 'prime', 'primepi', 'primes', 'qfbclassno',
'qfbcompraw', 'qfbhclassno', 'qfbnucomp', 'qfbnupow', 'qfbpowraw', 'qfbprimeform', 'qfbred',
'qfbsolve', 'quadclassunit', 'quaddisc', 'quadgen', 'quadhilbert', 'quadpoly', 'quadray',
'quadregulator', 'quadunit', 'removeprimes', 'sigma', 'sqrtint', 'stirling', 'sumdedekind',
'zncoppersmith', 'znlog', 'znorder', 'znprimroot', 'znstar', 'Col', 'List', 'Mat', 'Mod',
'Pol', 'Polrev', 'Qfb', 'Ser', 'Set', 'Str', 'Strchr', 'Strexpand', 'Strtex', 'Vec', 'Vecrev',
'Vecsmall', 'binary', 'bitand', 'bitneg', 'bitnegimply', 'bitor', 'bittest', 'bitxor', 'ceil',
'centerlift', 'component', 'conj', 'conjvec', 'denominator', 'floor', 'frac', 'imag', 'length',
'lift', 'norm', 'norml2', 'numerator', 'numtoperm', 'padicprec', 'permtonum', 'precision',
'random', 'real', 'round', 'simplify', 'sizebyte', 'sizedigit', 'truncate', 'valuation',
'variable', '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', 'bnfcertify', 'bnfcompress', 'bnfdecodemodule', 'bnfinit',
'bnfisintnorm', 'bnfisnorm', 'bnfisprincipal', 'bnfissunit', 'bnfisunit', 'bnfnarrow',
'bnfsignunit', 'bnfsunit', 'bnrL1', 'bnrclassno', 'bnrclassnolist', 'bnrconductor',
'bnrconductorofchar', 'bnrdisc', 'bnrdisclist', 'bnrinit', 'bnrisconductor', 'bnrisprincipal',
'bnrrootnumber', 'bnrstark', 'dirzetak', 'factornf', 'galoisexport', 'galoisfixedfield',
'galoisgetpol', 'galoisidentify', 'galoisinit', 'galoisisabelian', 'galoisisnormal',
'galoispermtopol', 'galoissubcyclo', 'galoissubfields', 'galoissubgroups', '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', 'matalgtobasis',
'matbasistoalg', 'modreverse', 'newtonpoly', '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', 'polcompositum', 'polgalois', 'polred',
'polredabs', 'polredord', 'poltschirnhaus', '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', 'subgrouplist', 'zetak', 'zetakinit', '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', 'psdraw', 'psploth', 'psplothraw', 'O',
'deriv', 'diffop', 'eval', 'factorpadic', 'intformal', 'padicappr', 'padicfields',
'polchebyshev', 'polcoeff', 'polcyclo', 'poldegree', 'poldisc', 'poldiscreduced',
'polhensellift', 'polhermite', 'polinterpolate', 'polisirreducible', 'pollead', 'pollegendre',
'polrecip', 'polresultant', 'polroots', 'polrootsmod', 'polrootspadic', 'polsturm',
'polsubcyclo', 'polsylvestermatrix', 'polsym', 'poltchebi', 'polzagier', 'serconvol',
'serlaplace', 'serreverse', 'subst', 'substpol', 'substvec', 'taylor', 'thue', 'thueinit',
'break', 'for', 'fordiv', 'forell', 'forprime', 'forstep', 'forsubgroup', 'forvec', 'if',
'next', 'return', 'until', 'while', 'Strprintf', 'addhelp', 'alarm', 'alias', 'allocatemem',
'apply', 'default', 'error', 'extern', 'externstr', 'getheap', 'getrand', 'getstack',
'gettime', 'global', 'input', 'install', 'kill', 'print1', 'print', 'printf', 'printtex',
'quit', 'read', 'readvec', 'select', 'setrand', 'system', 'trap', 'type', 'version', 'warning',
'whatnow', 'write1', 'write', 'writebin', 'writetex', 'divrem', 'lex', 'max', 'min', 'shift',
'shiftmul', 'sign', 'vecmax', 'vecmin', 'derivnum', 'intcirc', 'intfouriercos', 'intfourierexp',
'intfouriersin', 'intfuncinit', 'intlaplaceinv', 'intmellininv', 'intmellininvshort', 'intnum',
'intnuminit', 'intnuminitgen', 'intnumromb', 'intnumstep', 'prod', 'prodeuler', 'prodinf',
'solve', 'sum', 'sumalt', 'sumdiv', 'suminf', 'sumnum', 'sumnumalt', 'sumnuminit', 'sumpos',
'Euler', 'I', 'Pi', 'abs', 'acos', 'acosh', 'agm', 'arg', 'asin', 'asinh', 'atan', 'atanh',
'bernfrac', 'bernreal', 'bernvec', 'besselh1', 'besselh2', 'besseli', 'besselj', 'besseljh',
'besselk', 'besseln', 'cos', 'cosh', 'cotan', 'dilog', 'eint1', 'erfc', 'eta', 'exp', 'gamma',
'gammah', 'hyperu', 'incgam', 'incgamc', 'lngamma', 'log', 'polylog', 'psi', 'sin', 'sinh',
'sqr', 'sqrt', 'sqrtn', 'tan', 'tanh', 'teichmuller', 'theta', 'thetanullk', 'weber', 'zeta',
'algdep', 'charpoly', 'concat', 'lindep', 'listcreate', 'listinsert', 'listkill', 'listpop',
'listput', 'listsort', 'matadjoint', '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', 'minpoly', 'qfgaussred', 'qfjacobi', 'qflll', 'qflllgram',
'qfminim', 'qfperfection', 'qfrep', 'qfsign', 'setintersect', 'setisset', 'setminus',
'setsearch', 'setunion', 'trace', 'vecextract', 'vecsort', 'vector', 'vectorsmall',
'vectorv', 'ellheegner', 'cmp'),
2 => array('void', 'bool', 'negbool', 'small', 'int', 'real', 'mp', 'var', 'pol', 'vecsmall',
'vec', 'list', 'str', 'genstr', 'gen', 'lg', 'typ')
3 => array('TeXstyle', 'breakloop', 'colors', 'compatible', 'datadir', 'debug', 'debugfiles',
'debugmem', 'echo', 'factor_add_primes', 'factor_proven', 'format', 'graphcolormap',
'graphcolors', 'help', 'histfile', 'histsize', 'lines', 'linewrap', 'log', 'logfile',
'new_galois_format', 'output', 'parisize', 'path', 'prettyprinter', 'primelimit',
'prompt_cont', 'prompt', 'psfile', 'readline', 'realprecision', 'recover', 'secure',
'seriesprecision', 'simplify', 'strictmatch', 'timer'),
4 => array('alarmer','archer','errpile','gdiver','impl','invmoder','overflower','syntaxer',
'talker','typeer','user')
),
'SYMBOLS' => array(
1 => array(
'(', ')', '{', '}', '[', ']', '+', '-', '*', '/', '%', '=', '<', '>', '!', '^', '&', '|', '?', ';', ':', ',', '\\', '\''
)
),
'CASE_SENSITIVE' => array(
GESHI_COMMENTS => false,
1 => true, 2 => true, 3 => true, 4 => true
),
'STYLES' => array(
'KEYWORDS' => array(
1 => 'color: #0000ff;',
2 => 'color: #e07022;',
3 => 'color: #00d2d2;',
4 => 'color: #00d2d2;'
),
'COMMENTS' => array(
1 => 'color: #008000;',
'MULTI' => 'color: #008000;'
),
'ESCAPE_CHAR' => array(
0 => 'color: #111111; font-weight: bold;'
),
'BRACKETS' => array(
0 => 'color: #002222;'
),
'STRINGS' => array(
0 => 'color: #800080;'
),
'NUMBERS' => array(
0 => 'color: #111111;',
1 => 'color: #111111;'
),
'METHODS' => array(
0 => 'color: #004000;'
),
'SYMBOLS' => array(
1 => 'color: #339933;'
),
'REGEXPS' => array(
0 => 'color: #e07022', # Should be the same as keyword group 2
1 => 'color: #555555'
),
'SCRIPT' => array()
),
'URLS' => array(1 => '', 2 => '', 3 => '', 4 => ''),
'OOLANG' => true,
'OBJECT_SPLITTERS' => array(1 => '.'),
'REGEXPS' => array(
0 => array( # types marked on variables
GESHI_SEARCH => '(?<!\\)"(t_INT|REAL|INTMOD|FRAC|FFELT|COMPLEX|PADIC|QUAD|POLMOD|POL|SER|RFRAC|QFR|QFI|VEC|COL|MAT|LIST|STR|VECSMALL|CLOSURE)"',
GESHI_REPLACE => '\\1',
GESHI_MODIFIERS => '',
GESHI_BEFORE => '"',
GESHI_AFTER => '"'
),
1 => array( # literal variables
GESHI_SEARCH => '(?<!\\)(\'[a-zA-Z][a-zA-Z0-9_]*)',
GESHI_REPLACE => '\\1',
GESHI_MODIFIERS => '',
GESHI_BEFORE => '',
GESHI_AFTER => ''
)
),
'STRICT_MODE_APPLIES' => GESHI_NEVER,
'SCRIPT_DELIMITERS' => array(
2 => array(
'[a-zA-Z][a-zA-Z0-9_]*:' => ''
),
3 => array(
'default(' => ''
),
4 => array(
'trap(' => ''
),
),
'HIGHLIGHT_STRICT_BLOCK' => array()
);
 
?>