diff options
author | jcmuel <JohannesMueller@fico.com> | 2019-12-03 23:23:08 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2019-12-08 10:58:21 +0100 |
commit | e07f99a24c1621033df3ca554962bd382c7ca2b1 (patch) | |
tree | 01d1ea58571b710cc2e63f02c1a6e3bd60bffeb6 | |
parent | b0e98663d4f84962ee48775b6a92181324f7a98c (diff) | |
download | pygments-git-e07f99a24c1621033df3ca554962bd382c7ca2b1.tar.gz |
Add keywords, define types and operators. Remove parameters. Delete test file with incompatible license.
-rw-r--r-- | pygments/lexers/mosel.py | 49 | ||||
-rw-r--r-- | tests/examplefiles/test.mos | 38 | ||||
-rw-r--r-- | tests/examplefiles/test2.mos | 162 |
3 files changed, 56 insertions, 193 deletions
diff --git a/pygments/lexers/mosel.py b/pygments/lexers/mosel.py index 3dddbfe4..1692dea7 100644 --- a/pygments/lexers/mosel.py +++ b/pygments/lexers/mosel.py @@ -27,25 +27,29 @@ class MoselLexer(RegexLexer): (r'!.*?\n', Comment.Single), (r'\(!(.|\n)*?!\)', Comment.Multiline), (words(( - 'and', 'array', 'as', - 'boolean', 'break', - 'case', 'count', 'counter', - 'declarations', 'div', 'do', 'dynamic', - 'elif', 'else', 'end-', 'end', 'evaluation', 'exit', - 'false', 'forall', 'forward', 'from', 'function', - 'if', 'imports', 'in', 'include', 'initialisations', 'initializations', 'integer', 'inter', 'is_binary', 'is_continuous', 'is_free', 'is_integer', 'is_partint', 'is_semcont', 'is_semint', 'is_sos1', 'is_sos2', - 'linctr', 'list', - 'max', 'min', 'mod', 'model', 'mpvar', - 'next', 'not', 'of', 'options', 'or', + 'and', 'as', 'break', + 'case', 'count', + 'declarations', 'do', 'dynamic', + 'elif', 'else', 'end-', 'end', 'evaluation', + 'false', 'forall', 'forward', 'from', 'function', 'hashmap', + 'if', 'imports', 'include', 'initialisations', 'initializations', 'inter', + 'max', 'min', 'model', + 'namespace', 'next', 'not', 'nsgroup', 'nssearch', 'of', 'options', 'or', 'package', 'parameters', 'procedure', - 'public', 'prod', 'range', 'real', 'record', 'repeat', 'requirements', - 'set', 'string', 'sum', + 'public', 'prod', 'record', 'repeat', 'requirements', 'return', + 'sum', 'then', 'to', 'true', 'union', 'until', 'uses', 'version', 'while', 'with'), prefix=r'\b', suffix=r'\b'), Keyword.Builtin), - (r'(integer|is_binary|real)', Keyword.Type), - (r'(\+|\-|\*|/|=|<=|>=|==|\||\^|<|>|<>|\.\.|:=|:)', Operator), + (words(( + 'range', 'array', 'set', 'list', 'mpvar', 'mpproblem', 'linctr', 'nlctr', 'integer', + 'string', 'real', 'boolean', 'text', 'time', 'date', 'datetime', 'returned', 'Model', + 'Mosel', 'counter', 'xmldoc', + 'is_sos1', 'is_sos2', 'is_integer', 'is_binary', 'is_continuous', + 'is_free', 'is_semcont', 'is_semint', 'is_partint' + )), Keyword.Type), + (r'(\+|\-|\*|/|=|<=|>=|==|\||\^|<|>|<>|\.\.|\.|:=|:|::|in|mod|div)', Operator), (r'[()\[\]{},;:]+', Punctuation), (words(( # core functions @@ -62,7 +66,11 @@ class MoselLexer(RegexLexer): 'setcoeff', 'sethidden', 'setioerr', 'setname', 'setparam', 'setrandseed', 'settype', 'sin', 'splithead', 'splittail', 'sqrt', 'strfmt', 'substr', 'timestamp', 'unpublish', - 'write', 'writeln' + 'write', 'writeln', + '_', 'asproc', 'cutelt', 'cutfirst', 'cutlast', 'datablock', 'fwrite', 'fwriteln', 'fwrite_', + 'fwriteln_', 'getelt', 'isdynamic', 'isfinite', 'isinf', 'isnan', 'localsetparam', 'memoryuse', + 'newmuid', 'restoreparam', 'setmatherr', 'setrange', 'versionnum', 'versionstr', 'write_', 'writeln_', + 'maximize', 'minimize', 'maximise', 'minimise', # mmxpress_functions 'addmipsol', @@ -74,7 +82,6 @@ class MoselLexer(RegexLexer): 'getbstat', 'getdualray', 'getiis', 'getiissense', 'getiistype', 'getinfcause', 'getinfeas', 'getlb', 'getloadedlinctrs', 'getloadedmpvars', 'getname', 'getprimalray', 'getprobstat', 'getrange', 'getsensrng', 'getsize', 'getsol', 'getub', 'getvars', 'implies', 'indicator', 'isiisvalid', 'isintegral', 'loadbasis', 'loadmipsol', 'loadprob', - 'maximize', 'minimize', 'postsolve', 'readbasis', 'readdirs', 'readsol', 'refinemipsol', 'rejectintsol', 'repairinfeas', 'resetbasis', 'resetiis', 'resetsol', 'savebasis', 'savemipsol', 'savesol', 'savestate', 'selectsol', 'setbstat', 'setcallback', 'setcbcutoff', 'setgndata', 'setlb', 'setmipdir', 'setmodcut', 'setsol', 'setub', 'setucbdata', 'stopoptimize', @@ -114,9 +121,6 @@ class MoselLexer(RegexLexer): 'untar', 'unzip', 'ziplist', - # mmsystem_parameters - 'datefmt', 'datetimefmt', 'monthnames', 'sys_endparse', 'sys_fillchar', 'sys_pid', 'sys_qtype', 'sys_regcache', 'sys_sepchar', - # mmjobs_instance_mgmt_functions 'clearaliases', 'connect', 'disconnect', @@ -132,7 +136,7 @@ class MoselLexer(RegexLexer): 'reset', 'resetmodpar', 'run', 'setcontrol', 'setdefstream', 'setmodpar', 'setworkdir', 'stop', 'unload', - + # mmjobs_synchornization_functions 'dropnextevent', 'getclass', 'getfromgid', 'getfromid', 'getfromuid', 'getnextevent', 'getvalue', @@ -140,10 +144,7 @@ class MoselLexer(RegexLexer): 'nullevent', 'peeknextevent', 'send', 'setgid', 'setuid', - 'wait', 'waitfor', - - # 'mmjobs_parameters', - 'conntmpl', 'defaultnode', 'fsrvdelay', 'fsrvnbiter', 'fsrvport', 'jobid', 'keepalive', 'nodenumber', 'parentnumber' + 'wait', 'waitfor' ), prefix=r'\b', suffix=r'\b'), Name.Function), (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float), (r'\d+([eE][+-]?\d+)?', Number.Integer), diff --git a/tests/examplefiles/test.mos b/tests/examplefiles/test.mos index e1b81d6b..ccf17f68 100644 --- a/tests/examplefiles/test.mos +++ b/tests/examplefiles/test.mos @@ -1,10 +1,34 @@ -(!****************************************************** - Mosel Example Problems +(!******************************************************* + Multiline comment *******************************************************!) +model 'pygments test' + uses "mmxprs" -! Objective function: total daily cost - Cost:= sum(p in TYPES, t in TIME) (CSTART(p)*start(p,t) + - LEN(t)*(CMIN(p)*work(p,t) + CADD(p)*padd(p,t))) + forward public procedure main ! Test forward declaration + + public procedure main + declarations + MySet = {1, 2} + I: range + Coefficients: array(I) of real + Vars: array(I) of mpvar + end-declarations + + Coefficients :: [2.2, -3.3, 4.4, 5.5, 1.1, -3.3, 7.7] + + ! Single line comment + forall (i in I) Vars(i) is_binary + + ! Constraint + sum (i in I) Vars(i) <= 3 + + maximize(sum(i in I) Coefficients(i) * Vars(i)) + + forall (i in I| Vars(i).sol <> 0) do + writeln("Vars(", i,") = ", Vars(i).sol) + end-do + end-procedure + + main +end-model -! Limit on power production above minimum level - forall(p in TYPES, t in TIME) padd(p,t) <= (PMAX(p)-PMIN(p))*work(p,t) diff --git a/tests/examplefiles/test2.mos b/tests/examplefiles/test2.mos deleted file mode 100644 index 99d4cb55..00000000 --- a/tests/examplefiles/test2.mos +++ /dev/null @@ -1,162 +0,0 @@ -(!****************************************************** - Mosel Example Problems - ====================== - - file runfolio.mos - ````````````````` - Master model running portfolio optimization model. - - Runs model foliomemio.mos. - -- Data input/output in memory -- - - (c) 2009 Fair Isaac Corporation - author: S.Heipcke, Jan. 2009 -*******************************************************!) - -model "Run portfolio optimization model" - uses "mmjobs" ! Use multiple model handling - uses "mmsystem", "mmxprs" - - parameters - MODELFILE = "foliomemio.mos" ! Optimization model - INPUTFILE = "folio10.dat" ! File with problem data - - MAXRISK = 1/3 ! Max. investment into high-risk values - MINREG = 0.2 ! Min. investment per geogr. region - MAXREG = 0.5 ! Max. investment per geogr. region - MAXSEC = 0.25 ! Max. investment per ind. sector - MAXVAL = 0.2 ! Max. investment per share - MINVAL = 0.1 ! Min. investment per share - MAXNUM = 15 ! Max. number of different assets - end-parameters - - forward procedure write_html_results - - declarations - SHARES: set of string ! Set of shares - RISK: set of string ! Set of high-risk values among shares - REGIONS: set of string ! Geographical regions - TYPES: set of string ! Share types (ind. sectors) - LOCTAB: dynamic array(REGIONS,SHARES) of boolean ! Shares per geogr. region - RET: array(SHARES) of real ! Estimated return in investment - SECTAB: dynamic array(TYPES,SHARES) of boolean ! Shares per industry sector - - returnsol: real ! Solution values - numsharessol,status: integer - fracsol: array(SHARES) of real ! Fraction of capital used per share - buysol: array(SHARES) of real ! 1 if asset is in portfolio, 0 otherwise - - foliomod: Model - end-declarations - -! Compile and load the optimization model - if compile("", MODELFILE, "shmem:bim") <> 0 then - writeln("Error during model compilation") - exit(1) - end-if - load(foliomod, "shmem:bim") - fdelete("shmem:bim") - -! Read in data from file - initializations from INPUTFILE - RISK RET LOCTAB SECTAB - end-initializations - -! Save data to memory - initializations to "raw:" - RISK as 'shmem:RISK' - RET as 'shmem:RET' - LOCTAB as 'shmem:LOCTAB' - SECTAB as 'shmem:SECTAB' - end-initializations - - run(foliomod, "MAXRISK=" + MAXRISK + ",MINREG=" + MINREG + - ",MAXREG=" + MAXREG + ",MAXSEC=" + MAXSEC + - ",MAXVAL=" + MAXVAL + ",MINVAL=" + MINVAL + - ",MAXNUM=" + MAXNUM + ",DATAFILE='raw:',OUTPUTFILE='raw:'," + - "RISKDATA='shmem:RISK',RETDATA='shmem:RET',LOCDATA='shmem:LOCTAB'," + - "SECDATA='shmem:SECTAB',FRACSOL='shmem:FRAC',BUYSOL='shmem:BUY'," + - "NUMSHARES='shmem:NUMSHARES',RETSOL='shmem:RETSOL'," + - "SOLSTATUS='shmem:SOLSTATUS'") - wait ! Wait for model termination - dropnextevent ! Ignore termination event message - - initializations from "raw:" - returnsol as 'shmem:RETSOL' - numsharessol as 'shmem:NUMSHARES' - fracsol as 'shmem:FRAC' - buysol as 'shmem:BUY' - status as 'shmem:SOLSTATUS' - end-initializations - - case status of - XPRS_OPT: writeln("Problem solved to optimality") - XPRS_UNF: writeln("Problem solving unfinished") - XPRS_INF: writeln("Problem is infeasible") - XPRS_UNB,XPRS_OTH: writeln("No solution available") - end-case - - ! Solution printing - writeln("Total return: ", returnsol) - writeln("Number of shares: ", numsharessol) - forall(s in SHARES | fracsol(s)>0) - writeln(s, ": ", fracsol(s)*100, "% (", buysol(s), ")") - - write_html_results - -! *********** Writing an HTML result file *********** - procedure write_html_results - setparam("datetimefmt", "%0d-%N-%y, %0H:%0M:%0S") - - HTMLFILE:= INPUTFILE + "_sol.html" - fopen(HTMLFILE, F_OUTPUT) - writeln("<html>") - writeln("<head>") - writeln("<style type='text/css'>") - writeln("body {font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; color: 000055 }") - writeln("table td {background-color: ffffaa; text-align: left }") - writeln("table th {background-color: 053055; color: ffcc88}") - writeln("</style>") - writeln("</head>") - - writeln("<body>") - writeln("<center><h2>Portfolio Optimization Results</h2></center>") - writeln("<table width='100%' cellpadding='5' cellspacing='0' border=0>") - writeln("<tr><td width='55%'><font color='#000055'><b>Total return: ", - returnsol, "</b></font></td><td><font color='#885533'><b>Problem instance: ", - INPUTFILE,"</b></font></td></tr>") - writeln("<tr><td><font color='#000055'><b>Number of shares: ", numsharessol, "</b></font></td><td><font color='#885533'><b>Date: ", datetime(SYS_NOW),"</b></font></td></tr>") - writeln("<tr><td colspan='2'> </td></tr>") - writeln("</table>") - - writeln("<table cellpadding='2' cellspacing='1' width='100%'>") - writeln("<tr><th>Value</th><th>Percentage</th></tr>") - forall(s in SHARES | fracsol(s)>0) - writeln("<tr><td>", s, "</td><td>", strfmt(fracsol(s)*100,4,2), - "%</td></tr>") - writeln("</table>") - writeln("</body>") - writeln("</html>") - fclose(F_OUTPUT) - end-procedure - -! Test multiple strings escaping - - writeln("Reading 'KnapsackData.txt' ... ") - writeln("Reading \"KnapsackData.txt\" ... ") - writeln('Reading "KnapsackData.txt" ... ') - writeln("A double-quote string with a escape\nbreakline") - writeln('A single-quote string with a escape\nbreakline which should be ignored') - writeln("The letter q has octal code 161 can written as \161. But \229 is not a valid octal number") -! Multiline strings - writeln("This is - a multi-line - string with three lines") - writeln("Reading - file 'KnapsackData.txt' ... ") - writeln('Reading - file "KnapsackData.txt" ... ') - ! function highlighting test - y := sin(x) - -end-model |