Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/ampl.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.ampl 

3 ~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for the AMPL language. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, bygroups, using, this, words 

12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

13 Number, Punctuation, Whitespace 

14 

15__all__ = ['AmplLexer'] 

16 

17 

18class AmplLexer(RegexLexer): 

19 """ 

20 For AMPL source code. 

21 

22 .. versionadded:: 2.2 

23 """ 

24 name = 'Ampl' 

25 url = 'http://ampl.com/' 

26 aliases = ['ampl'] 

27 filenames = ['*.run'] 

28 

29 tokens = { 

30 'root': [ 

31 (r'\n', Text), 

32 (r'\s+', 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, Whitespace, Name.Variable)), 

58 (r'(param)(\s*)(:)(\s*)(\w+)(\s*)(:)(\s*)((\w|\s)+)', 

59 bygroups(Keyword.Declaration, Whitespace, Punctuation, Whitespace, 

60 Name.Variable, Whitespace, Punctuation, Whitespace, Name.Variable)), 

61 (r'(let|fix|unfix)(\s*)((?:\{.*\})?)(\s*)(\w+)', 

62 bygroups(Keyword.Declaration, Whitespace, using(this), Whitespace, 

63 Name.Variable)), 

64 (words(( 

65 'abs', 'acos', 'acosh', 'alias', 'asin', 'asinh', 'atan', 'atan2', 

66 'atanh', 'ceil', 'ctime', 'cos', 'exp', 'floor', 'log', 'log10', 

67 'max', 'min', 'precision', 'round', 'sin', 'sinh', 'sqrt', 'tan', 

68 'tanh', 'time', 'trunc', 'Beta', 'Cauchy', 'Exponential', 'Gamma', 

69 'Irand224', 'Normal', 'Normal01', 'Poisson', 'Uniform', 'Uniform01', 

70 'num', 'num0', 'ichar', 'char', 'length', 'substr', 'sprintf', 

71 'match', 'sub', 'gsub', 'print', 'printf', 'next', 'nextw', 'prev', 

72 'prevw', 'first', 'last', 'ord', 'ord0', 'card', 'arity', 

73 'indexarity'), prefix=r'\b', suffix=r'\b'), Name.Builtin), 

74 (r'(\+|\-|\*|/|\*\*|=|<=|>=|==|\||\^|<|>|\!|\.\.|:=|\&|\!=|<<|>>)', 

75 Operator), 

76 (words(( 

77 'or', 'exists', 'forall', 'and', 'in', 'not', 'within', 'union', 

78 'diff', 'difference', 'symdiff', 'inter', 'intersect', 

79 'intersection', 'cross', 'setof', 'by', 'less', 'sum', 'prod', 

80 'product', 'div', 'mod'), suffix=r'\b'), 

81 Keyword.Reserved), # Operator.Name but not enough emphasized with that 

82 (r'(\d+\.(?!\.)\d*|\.(?!.)\d+)([eE][+-]?\d+)?', Number.Float), 

83 (r'\d+([eE][+-]?\d+)?', Number.Integer), 

84 (r'[+-]?Infinity', Number.Integer), 

85 (r'(\w+|(\.(?!\.)))', Text) 

86 ] 

87 

88 }