summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES1
-rw-r--r--doc/languages.rst3
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/mosel.py448
-rw-r--r--pygments/lexers/ride.py2
-rw-r--r--tests/examplefiles/test.mos34
6 files changed, 488 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index b61d19c2..9337b5f0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,7 @@ Version 2.6
* Ride (PR#1319, PR#1321)
* USD (PR#1290)
+ * Mosel (PR#1287, PR#1326)
- The 256-color/true-color terminal formatters now support the italic attribute
in styles (PR#1288)
diff --git a/doc/languages.rst b/doc/languages.rst
index 07c454d3..f9492525 100644
--- a/doc/languages.rst
+++ b/doc/languages.rst
@@ -99,6 +99,7 @@ Programming languages
* Monkey
* `Monte <https://monte.readthedocs.io/>`_
* MoonScript
+* Mosel
* MuPad
* NASM
* Nemerle
@@ -134,6 +135,7 @@ Programming languages
* `Red <https://www.red-lang.org>`_
* Redcode
* Rexx
+* Ride
* `Ruby <https://www.ruby-lang.org>`_ (incl. irb sessions)
* `Rust <https://rust-lang.org>`_
* S, S-Plus, R
@@ -265,6 +267,7 @@ Other markup
* `Thrift <https://thrift.apache.org/>`_
* `TOML <https://github.com/toml-lang/toml>`_
* Treetop grammars
+* USD (Universal Scene Description)
* Varnish configs
* VGL
* Vim Script
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index b8917341..1ed7140d 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -278,6 +278,7 @@ LEXERS = {
'MonkeyLexer': ('pygments.lexers.basic', 'Monkey', ('monkey',), ('*.monkey',), ('text/x-monkey',)),
'MonteLexer': ('pygments.lexers.monte', 'Monte', ('monte',), ('*.mt',), ()),
'MoonScriptLexer': ('pygments.lexers.scripting', 'MoonScript', ('moon', 'moonscript'), ('*.moon',), ('text/x-moonscript', 'application/x-moonscript')),
+ 'MoselLexer': ('pygments.lexers.mosel', 'Mosel', ('mosel',), ('*.mos',), ()),
'MozPreprocCssLexer': ('pygments.lexers.markup', 'CSS+mozpreproc', ('css+mozpreproc',), ('*.css.in',), ()),
'MozPreprocHashLexer': ('pygments.lexers.markup', 'mozhashpreproc', ('mozhashpreproc',), (), ()),
'MozPreprocJavascriptLexer': ('pygments.lexers.markup', 'Javascript+mozpreproc', ('javascript+mozpreproc',), ('*.js.in',), ()),
diff --git a/pygments/lexers/mosel.py b/pygments/lexers/mosel.py
new file mode 100644
index 00000000..1dbda1dc
--- /dev/null
+++ b/pygments/lexers/mosel.py
@@ -0,0 +1,448 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.mosel
+ ~~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for the mosel language.
+ http://www.fico.com/en/products/fico-xpress-optimization
+
+ :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+from pygments.lexer import RegexLexer, words
+from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
+ Number, Punctuation
+
+__all__ = ['MoselLexer']
+
+FUNCTIONS = (
+ # core functions
+ '_',
+ 'abs',
+ 'arctan',
+ 'asproc',
+ 'assert',
+ 'bitflip',
+ 'bitneg',
+ 'bitset',
+ 'bitshift',
+ 'bittest',
+ 'bitval',
+ 'ceil',
+ 'cos',
+ 'create',
+ 'currentdate',
+ 'currenttime',
+ 'cutelt',
+ 'cutfirst',
+ 'cuthead',
+ 'cutlast',
+ 'cuttail',
+ 'datablock',
+ 'delcell',
+ 'exists',
+ 'exit',
+ 'exp',
+ 'exportprob',
+ 'fclose',
+ 'fflush',
+ 'finalize',
+ 'findfirst',
+ 'findlast',
+ 'floor',
+ 'fopen',
+ 'fselect',
+ 'fskipline',
+ 'fwrite',
+ 'fwrite_',
+ 'fwriteln',
+ 'fwriteln_',
+ 'getact',
+ 'getcoeff',
+ 'getcoeffs',
+ 'getdual',
+ 'getelt',
+ 'getfid',
+ 'getfirst',
+ 'getfname',
+ 'gethead',
+ 'getlast',
+ 'getobjval',
+ 'getparam',
+ 'getrcost',
+ 'getreadcnt',
+ 'getreverse',
+ 'getsize',
+ 'getslack',
+ 'getsol',
+ 'gettail',
+ 'gettype',
+ 'getvars',
+ 'isdynamic',
+ 'iseof',
+ 'isfinite',
+ 'ishidden',
+ 'isinf',
+ 'isnan',
+ 'isodd',
+ 'ln',
+ 'localsetparam',
+ 'log',
+ 'makesos1',
+ 'makesos2',
+ 'maxlist',
+ 'memoryuse',
+ 'minlist',
+ 'newmuid',
+ 'publish',
+ 'random',
+ 'read',
+ 'readln',
+ 'reset',
+ 'restoreparam',
+ 'reverse',
+ 'round',
+ 'setcoeff',
+ 'sethidden',
+ 'setioerr',
+ 'setmatherr',
+ 'setname',
+ 'setparam',
+ 'setrandseed',
+ 'setrange',
+ 'settype',
+ 'sin',
+ 'splithead',
+ 'splittail',
+ 'sqrt',
+ 'strfmt',
+ 'substr',
+ 'timestamp',
+ 'unpublish',
+ 'versionnum',
+ 'versionstr',
+ 'write',
+ 'write_',
+ 'writeln',
+ 'writeln_',
+
+ # mosel exam mmxprs | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
+ 'addcut',
+ 'addcuts',
+ 'addmipsol',
+ 'basisstability',
+ 'calcsolinfo',
+ 'clearmipdir',
+ 'clearmodcut',
+ 'command',
+ 'copysoltoinit',
+ 'crossoverlpsol',
+ 'defdelayedrows',
+ 'defsecurevecs',
+ 'delcuts',
+ 'dropcuts',
+ 'estimatemarginals',
+ 'fixglobal',
+ 'flushmsgq',
+ 'getbstat',
+ 'getcnlist',
+ 'getcplist',
+ 'getdualray',
+ 'getiis',
+ 'getiissense',
+ 'getiistype',
+ 'getinfcause',
+ 'getinfeas',
+ 'getlb',
+ 'getlct',
+ 'getleft',
+ 'getloadedlinctrs',
+ 'getloadedmpvars',
+ 'getname',
+ 'getprimalray',
+ 'getprobstat',
+ 'getrange',
+ 'getright',
+ 'getsensrng',
+ 'getsize',
+ 'getsol',
+ 'gettype',
+ 'getub',
+ 'getvars',
+ 'gety',
+ 'hasfeature',
+ 'implies',
+ 'indicator',
+ 'initglobal',
+ 'ishidden',
+ 'isiisvalid',
+ 'isintegral',
+ 'loadbasis',
+ 'loadcuts',
+ 'loadlpsol',
+ 'loadmipsol',
+ 'loadprob',
+ 'maximise',
+ 'maximize',
+ 'minimise',
+ 'minimize',
+ 'postsolve',
+ 'readbasis',
+ 'readdirs',
+ 'readsol',
+ 'refinemipsol',
+ 'rejectintsol',
+ 'repairinfeas',
+ 'repairinfeas_deprec',
+ 'resetbasis',
+ 'resetiis',
+ 'resetsol',
+ 'savebasis',
+ 'savemipsol',
+ 'savesol',
+ 'savestate',
+ 'selectsol',
+ 'setarchconsistency',
+ 'setbstat',
+ 'setcallback',
+ 'setcbcutoff',
+ 'setgndata',
+ 'sethidden',
+ 'setlb',
+ 'setmipdir',
+ 'setmodcut',
+ 'setsol',
+ 'setub',
+ 'setucbdata',
+ 'stopoptimise',
+ 'stopoptimize',
+ 'storecut',
+ 'storecuts',
+ 'unloadprob',
+ 'uselastbarsol',
+ 'writebasis',
+ 'writedirs',
+ 'writeprob',
+ 'writesol',
+ 'xor',
+ 'xprs_addctr',
+ 'xprs_addindic',
+
+ # mosel exam mmsystem | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
+ 'addmonths',
+ 'copytext',
+ 'cuttext',
+ 'deltext',
+ 'endswith',
+ 'erase',
+ 'expandpath',
+ 'fcopy',
+ 'fdelete',
+ 'findfiles',
+ 'findtext',
+ 'fmove',
+ 'formattext',
+ 'getasnumber',
+ 'getchar',
+ 'getcwd',
+ 'getdate',
+ 'getday',
+ 'getdaynum',
+ 'getdays',
+ 'getdirsep',
+ 'getdsoparam',
+ 'getendparse',
+ 'getenv',
+ 'getfsize',
+ 'getfstat',
+ 'getftime',
+ 'gethour',
+ 'getminute',
+ 'getmonth',
+ 'getmsec',
+ 'getoserrmsg',
+ 'getoserror',
+ 'getpathsep',
+ 'getqtype',
+ 'getsecond',
+ 'getsepchar',
+ 'getsize',
+ 'getstart',
+ 'getsucc',
+ 'getsysinfo',
+ 'getsysstat',
+ 'gettime',
+ 'gettmpdir',
+ 'gettrim',
+ 'getweekday',
+ 'getyear',
+ 'inserttext',
+ 'isvalid',
+ 'jointext',
+ 'makedir',
+ 'makepath',
+ 'newtar',
+ 'newzip',
+ 'nextfield',
+ 'openpipe',
+ 'parseextn',
+ 'parseint',
+ 'parsereal',
+ 'parsetext',
+ 'pastetext',
+ 'pathmatch',
+ 'pathsplit',
+ 'qsort',
+ 'quote',
+ 'readtextline',
+ 'regmatch',
+ 'regreplace',
+ 'removedir',
+ 'removefiles',
+ 'setchar',
+ 'setdate',
+ 'setday',
+ 'setdsoparam',
+ 'setendparse',
+ 'setenv',
+ 'sethour',
+ 'setminute',
+ 'setmonth',
+ 'setmsec',
+ 'setoserror',
+ 'setqtype',
+ 'setsecond',
+ 'setsepchar',
+ 'setstart',
+ 'setsucc',
+ 'settime',
+ 'settrim',
+ 'setyear',
+ 'sleep',
+ 'splittext',
+ 'startswith',
+ 'system',
+ 'tarlist',
+ 'textfmt',
+ 'tolower',
+ 'toupper',
+ 'trim',
+ 'untar',
+ 'unzip',
+ 'ziplist',
+
+ # mosel exam mmjobs | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
+ 'canceltimer',
+ 'clearaliases',
+ 'compile',
+ 'connect',
+ 'detach',
+ 'disconnect',
+ 'dropnextevent',
+ 'findxsrvs',
+ 'getaliases',
+ 'getannidents',
+ 'getannotations',
+ 'getbanner',
+ 'getclass',
+ 'getdsoprop',
+ 'getdsopropnum',
+ 'getexitcode',
+ 'getfromgid',
+ 'getfromid',
+ 'getfromuid',
+ 'getgid',
+ 'gethostalias',
+ 'getid',
+ 'getmodprop',
+ 'getmodpropnum',
+ 'getnextevent',
+ 'getnode',
+ 'getrmtid',
+ 'getstatus',
+ 'getsysinfo',
+ 'gettimer',
+ 'getuid',
+ 'getvalue',
+ 'isqueueempty',
+ 'load',
+ 'nullevent',
+ 'peeknextevent',
+ 'resetmodpar',
+ 'run',
+ 'send',
+ 'setcontrol',
+ 'setdefstream',
+ 'setgid',
+ 'sethostalias',
+ 'setmodpar',
+ 'settimer',
+ 'setuid',
+ 'setworkdir',
+ 'stop',
+ 'unload',
+ 'wait',
+ 'waitexpired',
+ 'waitfor',
+ 'waitforend',
+)
+
+
+class MoselLexer(RegexLexer):
+ """
+ For the Mosel optimization language.
+
+ .. versionadded:: 2.6
+ """
+ name = 'Mosel'
+ aliases = ['mosel']
+ filenames = ['*.mos']
+
+ tokens = {
+ 'root': [
+ (r'\n', Text),
+ (r'\s+', Text.Whitespace),
+ (r'!.*?\n', Comment.Single),
+ (r'\(!(.|\n)*?!\)', Comment.Multiline),
+ (words((
+ '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', 'record', 'repeat', 'requirements',
+ 'return', 'sum', 'then', 'to', 'true', 'union', 'until', 'uses',
+ 'version', 'while', 'with'), prefix=r'\b', suffix=r'\b'),
+ Keyword.Builtin),
+ (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'), prefix=r'\b', suffix=r'\b'),
+ Keyword.Type),
+ (r'(\+|\-|\*|/|=|<=|>=|\||\^|<|>|<>|\.\.|\.|:=|::|:|in|mod|div)',
+ Operator),
+ (r'[()\[\]{},;]+', Punctuation),
+ (words(FUNCTIONS, prefix=r'\b', suffix=r'\b'), Name.Function),
+ (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float),
+ (r'\d+([eE][+-]?\d+)?', Number.Integer),
+ (r'[+-]?Infinity', Number.Integer),
+ (r'0[xX][0-9a-fA-F]+', Number),
+ (r'"', String.Double, 'double_quote'),
+ (r'\'', String.Single, 'single_quote'),
+ (r'(\w+|(\.(?!\.)))', Text),
+ ],
+ 'single_quote': [
+ (r'\'', String.Single, '#pop'),
+ (r'[^\']+', String.Single),
+ ],
+ 'double_quote': [
+ (r'(\\"|\\[0-7]{1,3}\D|\\[abfnrtv]|\\\\)', String.Escape),
+ (r'\"', String.Double, '#pop'),
+ (r'[^"\\]+', String.Double),
+ ],
+ }
diff --git a/pygments/lexers/ride.py b/pygments/lexers/ride.py
index ce40b53d..17bc2466 100644
--- a/pygments/lexers/ride.py
+++ b/pygments/lexers/ride.py
@@ -56,7 +56,7 @@ class RideLexer(RegexLexer):
'ScriptResult', 'Invocation', 'Asset', 'BlockInfo', 'Issue', 'Reissue',
'Burn', 'NoAlg', 'Md5', 'Sha1', 'Sha224', 'Sha256', 'Sha384', 'Sha512',
'Sha3224', 'Sha3256', 'Sha3384', 'Sha3512', 'BinaryEntry',
- 'BooleanEntry' , 'IntegerEntry', 'StringEntry', 'List', 'Ceiling',
+ 'BooleanEntry', 'IntegerEntry', 'StringEntry', 'List', 'Ceiling',
'Down', 'Floor', 'HalfDown', 'HalfEven', 'HalfUp', 'Up',
)
diff --git a/tests/examplefiles/test.mos b/tests/examplefiles/test.mos
new file mode 100644
index 00000000..ccf17f68
--- /dev/null
+++ b/tests/examplefiles/test.mos
@@ -0,0 +1,34 @@
+(!*******************************************************
+ Multiline comment
+*******************************************************!)
+model 'pygments test'
+ uses "mmxprs"
+
+ 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
+