mosel.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. # -*- coding: utf-8 -*-
  2. """
  3. pygments.lexers.mosel
  4. ~~~~~~~~~~~~~~~~~~~~~
  5. Lexers for the mosel language.
  6. http://www.fico.com/en/products/fico-xpress-optimization
  7. :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
  8. :license: BSD, see LICENSE for details.
  9. """
  10. from pygments.lexer import RegexLexer, words
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation
  13. __all__ = ['MoselLexer']
  14. FUNCTIONS = (
  15. # core functions
  16. '_',
  17. 'abs',
  18. 'arctan',
  19. 'asproc',
  20. 'assert',
  21. 'bitflip',
  22. 'bitneg',
  23. 'bitset',
  24. 'bitshift',
  25. 'bittest',
  26. 'bitval',
  27. 'ceil',
  28. 'cos',
  29. 'create',
  30. 'currentdate',
  31. 'currenttime',
  32. 'cutelt',
  33. 'cutfirst',
  34. 'cuthead',
  35. 'cutlast',
  36. 'cuttail',
  37. 'datablock',
  38. 'delcell',
  39. 'exists',
  40. 'exit',
  41. 'exp',
  42. 'exportprob',
  43. 'fclose',
  44. 'fflush',
  45. 'finalize',
  46. 'findfirst',
  47. 'findlast',
  48. 'floor',
  49. 'fopen',
  50. 'fselect',
  51. 'fskipline',
  52. 'fwrite',
  53. 'fwrite_',
  54. 'fwriteln',
  55. 'fwriteln_',
  56. 'getact',
  57. 'getcoeff',
  58. 'getcoeffs',
  59. 'getdual',
  60. 'getelt',
  61. 'getfid',
  62. 'getfirst',
  63. 'getfname',
  64. 'gethead',
  65. 'getlast',
  66. 'getobjval',
  67. 'getparam',
  68. 'getrcost',
  69. 'getreadcnt',
  70. 'getreverse',
  71. 'getsize',
  72. 'getslack',
  73. 'getsol',
  74. 'gettail',
  75. 'gettype',
  76. 'getvars',
  77. 'isdynamic',
  78. 'iseof',
  79. 'isfinite',
  80. 'ishidden',
  81. 'isinf',
  82. 'isnan',
  83. 'isodd',
  84. 'ln',
  85. 'localsetparam',
  86. 'log',
  87. 'makesos1',
  88. 'makesos2',
  89. 'maxlist',
  90. 'memoryuse',
  91. 'minlist',
  92. 'newmuid',
  93. 'publish',
  94. 'random',
  95. 'read',
  96. 'readln',
  97. 'reset',
  98. 'restoreparam',
  99. 'reverse',
  100. 'round',
  101. 'setcoeff',
  102. 'sethidden',
  103. 'setioerr',
  104. 'setmatherr',
  105. 'setname',
  106. 'setparam',
  107. 'setrandseed',
  108. 'setrange',
  109. 'settype',
  110. 'sin',
  111. 'splithead',
  112. 'splittail',
  113. 'sqrt',
  114. 'strfmt',
  115. 'substr',
  116. 'timestamp',
  117. 'unpublish',
  118. 'versionnum',
  119. 'versionstr',
  120. 'write',
  121. 'write_',
  122. 'writeln',
  123. 'writeln_',
  124. # mosel exam mmxprs | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
  125. 'addcut',
  126. 'addcuts',
  127. 'addmipsol',
  128. 'basisstability',
  129. 'calcsolinfo',
  130. 'clearmipdir',
  131. 'clearmodcut',
  132. 'command',
  133. 'copysoltoinit',
  134. 'crossoverlpsol',
  135. 'defdelayedrows',
  136. 'defsecurevecs',
  137. 'delcuts',
  138. 'dropcuts',
  139. 'estimatemarginals',
  140. 'fixglobal',
  141. 'flushmsgq',
  142. 'getbstat',
  143. 'getcnlist',
  144. 'getcplist',
  145. 'getdualray',
  146. 'getiis',
  147. 'getiissense',
  148. 'getiistype',
  149. 'getinfcause',
  150. 'getinfeas',
  151. 'getlb',
  152. 'getlct',
  153. 'getleft',
  154. 'getloadedlinctrs',
  155. 'getloadedmpvars',
  156. 'getname',
  157. 'getprimalray',
  158. 'getprobstat',
  159. 'getrange',
  160. 'getright',
  161. 'getsensrng',
  162. 'getsize',
  163. 'getsol',
  164. 'gettype',
  165. 'getub',
  166. 'getvars',
  167. 'gety',
  168. 'hasfeature',
  169. 'implies',
  170. 'indicator',
  171. 'initglobal',
  172. 'ishidden',
  173. 'isiisvalid',
  174. 'isintegral',
  175. 'loadbasis',
  176. 'loadcuts',
  177. 'loadlpsol',
  178. 'loadmipsol',
  179. 'loadprob',
  180. 'maximise',
  181. 'maximize',
  182. 'minimise',
  183. 'minimize',
  184. 'postsolve',
  185. 'readbasis',
  186. 'readdirs',
  187. 'readsol',
  188. 'refinemipsol',
  189. 'rejectintsol',
  190. 'repairinfeas',
  191. 'repairinfeas_deprec',
  192. 'resetbasis',
  193. 'resetiis',
  194. 'resetsol',
  195. 'savebasis',
  196. 'savemipsol',
  197. 'savesol',
  198. 'savestate',
  199. 'selectsol',
  200. 'setarchconsistency',
  201. 'setbstat',
  202. 'setcallback',
  203. 'setcbcutoff',
  204. 'setgndata',
  205. 'sethidden',
  206. 'setlb',
  207. 'setmipdir',
  208. 'setmodcut',
  209. 'setsol',
  210. 'setub',
  211. 'setucbdata',
  212. 'stopoptimise',
  213. 'stopoptimize',
  214. 'storecut',
  215. 'storecuts',
  216. 'unloadprob',
  217. 'uselastbarsol',
  218. 'writebasis',
  219. 'writedirs',
  220. 'writeprob',
  221. 'writesol',
  222. 'xor',
  223. 'xprs_addctr',
  224. 'xprs_addindic',
  225. # mosel exam mmsystem | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
  226. 'addmonths',
  227. 'copytext',
  228. 'cuttext',
  229. 'deltext',
  230. 'endswith',
  231. 'erase',
  232. 'expandpath',
  233. 'fcopy',
  234. 'fdelete',
  235. 'findfiles',
  236. 'findtext',
  237. 'fmove',
  238. 'formattext',
  239. 'getasnumber',
  240. 'getchar',
  241. 'getcwd',
  242. 'getdate',
  243. 'getday',
  244. 'getdaynum',
  245. 'getdays',
  246. 'getdirsep',
  247. 'getdsoparam',
  248. 'getendparse',
  249. 'getenv',
  250. 'getfsize',
  251. 'getfstat',
  252. 'getftime',
  253. 'gethour',
  254. 'getminute',
  255. 'getmonth',
  256. 'getmsec',
  257. 'getoserrmsg',
  258. 'getoserror',
  259. 'getpathsep',
  260. 'getqtype',
  261. 'getsecond',
  262. 'getsepchar',
  263. 'getsize',
  264. 'getstart',
  265. 'getsucc',
  266. 'getsysinfo',
  267. 'getsysstat',
  268. 'gettime',
  269. 'gettmpdir',
  270. 'gettrim',
  271. 'getweekday',
  272. 'getyear',
  273. 'inserttext',
  274. 'isvalid',
  275. 'jointext',
  276. 'makedir',
  277. 'makepath',
  278. 'newtar',
  279. 'newzip',
  280. 'nextfield',
  281. 'openpipe',
  282. 'parseextn',
  283. 'parseint',
  284. 'parsereal',
  285. 'parsetext',
  286. 'pastetext',
  287. 'pathmatch',
  288. 'pathsplit',
  289. 'qsort',
  290. 'quote',
  291. 'readtextline',
  292. 'regmatch',
  293. 'regreplace',
  294. 'removedir',
  295. 'removefiles',
  296. 'setchar',
  297. 'setdate',
  298. 'setday',
  299. 'setdsoparam',
  300. 'setendparse',
  301. 'setenv',
  302. 'sethour',
  303. 'setminute',
  304. 'setmonth',
  305. 'setmsec',
  306. 'setoserror',
  307. 'setqtype',
  308. 'setsecond',
  309. 'setsepchar',
  310. 'setstart',
  311. 'setsucc',
  312. 'settime',
  313. 'settrim',
  314. 'setyear',
  315. 'sleep',
  316. 'splittext',
  317. 'startswith',
  318. 'system',
  319. 'tarlist',
  320. 'textfmt',
  321. 'tolower',
  322. 'toupper',
  323. 'trim',
  324. 'untar',
  325. 'unzip',
  326. 'ziplist',
  327. # mosel exam mmjobs | sed -n -e "s/ [pf][a-z]* \([a-zA-Z0-9_]*\).*/'\1',/p" | sort -u
  328. 'canceltimer',
  329. 'clearaliases',
  330. 'compile',
  331. 'connect',
  332. 'detach',
  333. 'disconnect',
  334. 'dropnextevent',
  335. 'findxsrvs',
  336. 'getaliases',
  337. 'getannidents',
  338. 'getannotations',
  339. 'getbanner',
  340. 'getclass',
  341. 'getdsoprop',
  342. 'getdsopropnum',
  343. 'getexitcode',
  344. 'getfromgid',
  345. 'getfromid',
  346. 'getfromuid',
  347. 'getgid',
  348. 'gethostalias',
  349. 'getid',
  350. 'getmodprop',
  351. 'getmodpropnum',
  352. 'getnextevent',
  353. 'getnode',
  354. 'getrmtid',
  355. 'getstatus',
  356. 'getsysinfo',
  357. 'gettimer',
  358. 'getuid',
  359. 'getvalue',
  360. 'isqueueempty',
  361. 'load',
  362. 'nullevent',
  363. 'peeknextevent',
  364. 'resetmodpar',
  365. 'run',
  366. 'send',
  367. 'setcontrol',
  368. 'setdefstream',
  369. 'setgid',
  370. 'sethostalias',
  371. 'setmodpar',
  372. 'settimer',
  373. 'setuid',
  374. 'setworkdir',
  375. 'stop',
  376. 'unload',
  377. 'wait',
  378. 'waitexpired',
  379. 'waitfor',
  380. 'waitforend',
  381. )
  382. class MoselLexer(RegexLexer):
  383. """
  384. For the Mosel optimization language.
  385. .. versionadded:: 2.6
  386. """
  387. name = 'Mosel'
  388. aliases = ['mosel']
  389. filenames = ['*.mos']
  390. tokens = {
  391. 'root': [
  392. (r'\n', Text),
  393. (r'\s+', Text.Whitespace),
  394. (r'!.*?\n', Comment.Single),
  395. (r'\(!(.|\n)*?!\)', Comment.Multiline),
  396. (words((
  397. 'and', 'as', 'break', 'case', 'count', 'declarations', 'do',
  398. 'dynamic', 'elif', 'else', 'end-', 'end', 'evaluation', 'false',
  399. 'forall', 'forward', 'from', 'function', 'hashmap', 'if',
  400. 'imports', 'include', 'initialisations', 'initializations', 'inter',
  401. 'max', 'min', 'model', 'namespace', 'next', 'not', 'nsgroup',
  402. 'nssearch', 'of', 'options', 'or', 'package', 'parameters',
  403. 'procedure', 'public', 'prod', 'record', 'repeat', 'requirements',
  404. 'return', 'sum', 'then', 'to', 'true', 'union', 'until', 'uses',
  405. 'version', 'while', 'with'), prefix=r'\b', suffix=r'\b'),
  406. Keyword.Builtin),
  407. (words((
  408. 'range', 'array', 'set', 'list', 'mpvar', 'mpproblem', 'linctr',
  409. 'nlctr', 'integer', 'string', 'real', 'boolean', 'text', 'time',
  410. 'date', 'datetime', 'returned', 'Model', 'Mosel', 'counter',
  411. 'xmldoc', 'is_sos1', 'is_sos2', 'is_integer', 'is_binary',
  412. 'is_continuous', 'is_free', 'is_semcont', 'is_semint',
  413. 'is_partint'), prefix=r'\b', suffix=r'\b'),
  414. Keyword.Type),
  415. (r'(\+|\-|\*|/|=|<=|>=|\||\^|<|>|<>|\.\.|\.|:=|::|:|in|mod|div)',
  416. Operator),
  417. (r'[()\[\]{},;]+', Punctuation),
  418. (words(FUNCTIONS, prefix=r'\b', suffix=r'\b'), Name.Function),
  419. (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float),
  420. (r'\d+([eE][+-]?\d+)?', Number.Integer),
  421. (r'[+-]?Infinity', Number.Integer),
  422. (r'0[xX][0-9a-fA-F]+', Number),
  423. (r'"', String.Double, 'double_quote'),
  424. (r'\'', String.Single, 'single_quote'),
  425. (r'(\w+|(\.(?!\.)))', Text),
  426. ],
  427. 'single_quote': [
  428. (r'\'', String.Single, '#pop'),
  429. (r'[^\']+', String.Single),
  430. ],
  431. 'double_quote': [
  432. (r'(\\"|\\[0-7]{1,3}\D|\\[abfnrtv]|\\\\)', String.Escape),
  433. (r'\"', String.Double, '#pop'),
  434. (r'[^"\\]+', String.Double),
  435. ],
  436. }