|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.ampl |
|
4 ~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for the ampl language. <http://ampl.com/> |
|
7 |
|
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 from pygments.lexer import RegexLexer, bygroups, using, this, words |
|
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
14 Number, Punctuation |
|
15 |
|
16 __all__ = ['AmplLexer'] |
|
17 |
|
18 |
|
19 class AmplLexer(RegexLexer): |
|
20 """ |
|
21 For AMPL source code. |
|
22 |
|
23 .. versionadded:: 2.2 |
|
24 """ |
|
25 name = 'Ampl' |
|
26 aliases = ['ampl'] |
|
27 filenames = ['*.run'] |
|
28 |
|
29 tokens = { |
|
30 'root': [ |
|
31 (r'\n', Text), |
|
32 (r'\s+', Text.Whitespace), |
|
33 (r'#.*?\n', Comment.Single), |
|
34 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
35 (words(( |
|
36 'call', 'cd', 'close', 'commands', 'data', 'delete', 'display', |
|
37 'drop', 'end', 'environ', 'exit', 'expand', 'include', 'load', |
|
38 'model', 'objective', 'option', 'problem', 'purge', 'quit', |
|
39 'redeclare', 'reload', 'remove', 'reset', 'restore', 'shell', |
|
40 'show', 'solexpand', 'solution', 'solve', 'update', 'unload', |
|
41 'xref', 'coeff', 'coef', 'cover', 'obj', 'interval', 'default', |
|
42 'from', 'to', 'to_come', 'net_in', 'net_out', 'dimen', |
|
43 'dimension', 'check', 'complements', 'write', 'function', |
|
44 'pipe', 'format', 'if', 'then', 'else', 'in', 'while', 'repeat', |
|
45 'for'), suffix=r'\b'), Keyword.Reserved), |
|
46 (r'(integer|binary|symbolic|ordered|circular|reversed|INOUT|IN|OUT|LOCAL)', |
|
47 Keyword.Type), |
|
48 (r'\".*?\"', String.Double), |
|
49 (r'\'.*?\'', String.Single), |
|
50 (r'[()\[\]{},;:]+', Punctuation), |
|
51 (r'\b(\w+)(\.)(astatus|init0|init|lb0|lb1|lb2|lb|lrc|' |
|
52 r'lslack|rc|relax|slack|sstatus|status|ub0|ub1|ub2|' |
|
53 r'ub|urc|uslack|val)', |
|
54 bygroups(Name.Variable, Punctuation, Keyword.Reserved)), |
|
55 (r'(set|param|var|arc|minimize|maximize|subject to|s\.t\.|subj to|' |
|
56 r'node|table|suffix|read table|write table)(\s+)(\w+)', |
|
57 bygroups(Keyword.Declaration, Text, Name.Variable)), |
|
58 (r'(param)(\s*)(:)(\s*)(\w+)(\s*)(:)(\s*)((\w|\s)+)', |
|
59 bygroups(Keyword.Declaration, Text, Punctuation, Text, |
|
60 Name.Variable, Text, Punctuation, Text, Name.Variable)), |
|
61 (r'(let|fix|unfix)(\s*)((?:\{.*\})?)(\s*)(\w+)', |
|
62 bygroups(Keyword.Declaration, Text, using(this), Text, 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 that |
|
81 (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 } |