codekingpro/portable-devtools
114k
1"""2 pygments.lexers.maxima3 ~~~~~~~~~~~~~~~~~~~~~~4 5 Lexer for the computer algebra system Maxima.6 7 Derived from pygments/lexers/algebra.py.8 9 :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.10 :license: BSD, see LICENSE for details.11"""12 13import re14 15from pygments.lexer import RegexLexer, bygroups, words16from pygments.token import Text, Comment, Operator, Keyword, Name, String, \17 Number, Punctuation18 19__all__ = ['MaximaLexer']20 21class MaximaLexer(RegexLexer):22 """23 A Maxima lexer.24 Derived from pygments.lexers.MuPADLexer.25 """26 name = 'Maxima'27 url = 'http://maxima.sourceforge.net'28 aliases = ['maxima', 'macsyma']29 filenames = ['*.mac', '*.max']30 version_added = '2.11'31 32 keywords = ('if', 'then', 'else', 'elseif',33 'do', 'while', 'repeat', 'until',34 'for', 'from', 'to', 'downto', 'step', 'thru')35 36 constants = ('%pi', '%e', '%phi', '%gamma', '%i',37 'und', 'ind', 'infinity', 'inf', 'minf',38 'true', 'false', 'unknown', 'done')39 40 operators = (r'.', r':', r'=', r'#',41 r'+', r'-', r'*', r'/', r'^',42 r'@', r'>', r'<', r'|', r'!', r"'")43 44 operator_words = ('and', 'or', 'not')45 46 tokens = {47 'root': [48 (r'/\*', Comment.Multiline, 'comment'),49 (r'"(?:[^"\\]|\\.)*"', String),50 (r'\(|\)|\[|\]|\{|\}', Punctuation),51 (r'[,;$]', Punctuation),52 (words (constants), Name.Constant),53 (words (keywords), Keyword),54 (words (operators), Operator),55 (words (operator_words), Operator.Word),56 (r'''(?x)57 ((?:[a-zA-Z_#][\w#]*|`[^`]*`)58 (?:::[a-zA-Z_#][\w#]*|`[^`]*`)*)(\s*)([(])''',59 bygroups(Name.Function, Text.Whitespace, Punctuation)),60 (r'''(?x)61 (?:[a-zA-Z_#%][\w#%]*|`[^`]*`)62 (?:::[a-zA-Z_#%][\w#%]*|`[^`]*`)*''', Name.Variable),63 (r'[-+]?(\d*\.\d+([bdefls][-+]?\d+)?|\d+(\.\d*)?[bdefls][-+]?\d+)', Number.Float),64 (r'[-+]?\d+', Number.Integer),65 (r'\s+', Text.Whitespace),66 (r'.', Text)67 ],68 'comment': [69 (r'[^*/]+', Comment.Multiline),70 (r'/\*', Comment.Multiline, '#push'),71 (r'\*/', Comment.Multiline, '#pop'),72 (r'[*/]', Comment.Multiline)73 ]74 }75 76 def analyse_text (text):77 strength = 0.078 # Input expression terminator.79 if re.search (r'\$\s*$', text, re.MULTILINE):80 strength += 0.0581 # Function definition operator.82 if ':=' in text:83 strength += 0.0284 return strength85 