Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/maxima.py: 71%
21 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.maxima
3 ~~~~~~~~~~~~~~~~~~~~~~
5 Lexer for the computer algebra system Maxima.
7 Derived from pygments/lexers/algebra.py.
9 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
10 :license: BSD, see LICENSE for details.
11"""
13import re
15from pygments.lexer import RegexLexer, bygroups, words
16from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
17 Number, Punctuation
19__all__ = ['MaximaLexer']
21class MaximaLexer(RegexLexer):
22 """
23 A Maxima lexer.
24 Derived from pygments.lexers.MuPADLexer.
26 .. versionadded:: 2.11
27 """
28 name = 'Maxima'
29 url = 'http://maxima.sourceforge.net'
30 aliases = ['maxima', 'macsyma']
31 filenames = ['*.mac', '*.max']
33 keywords = ('if', 'then', 'else', 'elseif',
34 'do', 'while', 'repeat', 'until',
35 'for', 'from', 'to', 'downto', 'step', 'thru')
37 constants = ('%pi', '%e', '%phi', '%gamma', '%i',
38 'und', 'ind', 'infinity', 'inf', 'minf',
39 'true', 'false', 'unknown', 'done')
41 operators = (r'.', r':', r'=', r'#',
42 r'+', r'-', r'*', r'/', r'^',
43 r'@', r'>', r'<', r'|', r'!', r"'")
45 operator_words = ('and', 'or', 'not')
47 tokens = {
48 'root': [
49 (r'/\*', Comment.Multiline, 'comment'),
50 (r'"(?:[^"\\]|\\.)*"', String),
51 (r'\(|\)|\[|\]|\{|\}', Punctuation),
52 (r'[,;$]', Punctuation),
53 (words (constants), Name.Constant),
54 (words (keywords), Keyword),
55 (words (operators), Operator),
56 (words (operator_words), Operator.Word),
57 (r'''(?x)
58 ((?:[a-zA-Z_#][\w#]*|`[^`]*`)
59 (?:::[a-zA-Z_#][\w#]*|`[^`]*`)*)(\s*)([(])''',
60 bygroups(Name.Function, Text.Whitespace, Punctuation)),
61 (r'''(?x)
62 (?:[a-zA-Z_#%][\w#%]*|`[^`]*`)
63 (?:::[a-zA-Z_#%][\w#%]*|`[^`]*`)*''', Name.Variable),
64 (r'[-+]?(\d*\.\d+([bdefls][-+]?\d+)?|\d+(\.\d*)?[bdefls][-+]?\d+)', Number.Float),
65 (r'[-+]?\d+', Number.Integer),
66 (r'\s+', Text.Whitespace),
67 (r'.', Text)
68 ],
69 'comment': [
70 (r'[^*/]+', Comment.Multiline),
71 (r'/\*', Comment.Multiline, '#push'),
72 (r'\*/', Comment.Multiline, '#pop'),
73 (r'[*/]', Comment.Multiline)
74 ]
75 }
77 def analyse_text (text):
78 strength = 0.0
79 # Input expression terminator.
80 if re.search (r'\$\s*$', text, re.MULTILINE):
81 strength += 0.05
82 # Function definition operator.
83 if ':=' in text:
84 strength += 0.02
85 return strength