codekingpro/portable-devtools
114k
1"""2 pygments.lexers.ampl3 ~~~~~~~~~~~~~~~~~~~~4 5 Lexers for the AMPL language.6 7 :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8 :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups, using, this, words12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \13 Number, Punctuation, Whitespace14 15__all__ = ['AmplLexer']16 17 18class AmplLexer(RegexLexer):19 """20 For AMPL source code.21 """22 name = 'Ampl'23 url = 'http://ampl.com/'24 aliases = ['ampl']25 filenames = ['*.run']26 version_added = '2.2'27 28 tokens = {29 'root': [30 (r'\n', Text),31 (r'\s+', Whitespace),32 (r'#.*?\n', Comment.Single),33 (r'/[*](.|\n)*?[*]/', Comment.Multiline),34 (words((35 'call', 'cd', 'close', 'commands', 'data', 'delete', 'display',36 'drop', 'end', 'environ', 'exit', 'expand', 'include', 'load',37 'model', 'objective', 'option', 'problem', 'purge', 'quit',38 'redeclare', 'reload', 'remove', 'reset', 'restore', 'shell',39 'show', 'solexpand', 'solution', 'solve', 'update', 'unload',40 'xref', 'coeff', 'coef', 'cover', 'obj', 'interval', 'default',41 'from', 'to', 'to_come', 'net_in', 'net_out', 'dimen',42 'dimension', 'check', 'complements', 'write', 'function',43 'pipe', 'format', 'if', 'then', 'else', 'in', 'while', 'repeat',44 'for'), suffix=r'\b'), Keyword.Reserved),45 (r'(integer|binary|symbolic|ordered|circular|reversed|INOUT|IN|OUT|LOCAL)',46 Keyword.Type),47 (r'\".*?\"', String.Double),48 (r'\'.*?\'', String.Single),49 (r'[()\[\]{},;:]+', Punctuation),50 (r'\b(\w+)(\.)(astatus|init0|init|lb0|lb1|lb2|lb|lrc|'51 r'lslack|rc|relax|slack|sstatus|status|ub0|ub1|ub2|'52 r'ub|urc|uslack|val)',53 bygroups(Name.Variable, Punctuation, Keyword.Reserved)),54 (r'(set|param|var|arc|minimize|maximize|subject to|s\.t\.|subj to|'55 r'node|table|suffix|read table|write table)(\s+)(\w+)',56 bygroups(Keyword.Declaration, Whitespace, Name.Variable)),57 (r'(param)(\s*)(:)(\s*)(\w+)(\s*)(:)(\s*)((\w|\s)+)',58 bygroups(Keyword.Declaration, Whitespace, Punctuation, Whitespace,59 Name.Variable, Whitespace, Punctuation, Whitespace, Name.Variable)),60 (r'(let|fix|unfix)(\s*)((?:\{.*\})?)(\s*)(\w+)',61 bygroups(Keyword.Declaration, Whitespace, using(this), Whitespace,62 Name.Variable)),63 (words((64 'abs', 'acos', 'acosh', 'alias', 'asin', 'asinh', 'atan', 'atan2',65 'atanh', 'ceil', 'ctime', 'cos', 'exp', 'floor', 'log', 'log10',66 'max', 'min', 'precision', 'round', 'sin', 'sinh', 'sqrt', 'tan',67 'tanh', 'time', 'trunc', 'Beta', 'Cauchy', 'Exponential', 'Gamma',68 'Irand224', 'Normal', 'Normal01', 'Poisson', 'Uniform', 'Uniform01',69 'num', 'num0', 'ichar', 'char', 'length', 'substr', 'sprintf',70 'match', 'sub', 'gsub', 'print', 'printf', 'next', 'nextw', 'prev',71 'prevw', 'first', 'last', 'ord', 'ord0', 'card', 'arity',72 'indexarity'), prefix=r'\b', suffix=r'\b'), Name.Builtin),73 (r'(\+|\-|\*|/|\*\*|=|<=|>=|==|\||\^|<|>|\!|\.\.|:=|\&|\!=|<<|>>)',74 Operator),75 (words((76 'or', 'exists', 'forall', 'and', 'in', 'not', 'within', 'union',77 'diff', 'difference', 'symdiff', 'inter', 'intersect',78 'intersection', 'cross', 'setof', 'by', 'less', 'sum', 'prod',79 'product', 'div', 'mod'), suffix=r'\b'),80 Keyword.Reserved), # Operator.Name but not enough emphasized with that81 (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float),82 (r'\d+([eE][+-]?\d+)?', Number.Integer),83 (r'[+-]?Infinity', Number.Integer),84 (r'(\w+|(\.(?!\.)))', Text)85 ]86 87 }88 