3 pygments.lexers.algebra |
3 pygments.lexers.algebra |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for computer algebra systems. |
6 Lexers for computer algebra systems. |
7 |
7 |
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
14 from pygments.lexer import RegexLexer, bygroups, words |
14 from pygments.lexer import RegexLexer, bygroups, words |
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
16 Number, Punctuation |
16 Number, Punctuation |
17 |
17 |
18 __all__ = ['GAPLexer', 'MathematicaLexer', 'MuPADLexer'] |
18 __all__ = ['GAPLexer', 'MathematicaLexer', 'MuPADLexer', 'BCLexer'] |
19 |
19 |
20 |
20 |
21 class GAPLexer(RegexLexer): |
21 class GAPLexer(RegexLexer): |
22 """ |
22 """ |
23 For `GAP <http://www.gap-system.org>`_ source code. |
23 For `GAP <http://www.gap-system.org>`_ source code. |
63 (?:\w+|`[^`]*`) |
63 (?:\w+|`[^`]*`) |
64 (?:::\w+|`[^`]*`)*''', Name.Variable), |
64 (?:::\w+|`[^`]*`)*''', Name.Variable), |
65 (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number), |
65 (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number), |
66 (r'\.[0-9]+(?:e[0-9]+)?', Number), |
66 (r'\.[0-9]+(?:e[0-9]+)?', Number), |
67 (r'.', Text) |
67 (r'.', Text) |
68 ] |
68 ], |
69 } |
69 } |
70 |
70 |
71 |
71 |
72 class MathematicaLexer(RegexLexer): |
72 class MathematicaLexer(RegexLexer): |
73 """ |
73 """ |
181 'comment': [ |
181 'comment': [ |
182 (r'[^*/]', Comment.Multiline), |
182 (r'[^*/]', Comment.Multiline), |
183 (r'/\*', Comment.Multiline, '#push'), |
183 (r'/\*', Comment.Multiline, '#push'), |
184 (r'\*/', Comment.Multiline, '#pop'), |
184 (r'\*/', Comment.Multiline, '#pop'), |
185 (r'[*/]', Comment.Multiline) |
185 (r'[*/]', Comment.Multiline) |
186 ] |
186 ], |
187 } |
187 } |
|
188 |
|
189 |
|
190 class BCLexer(RegexLexer): |
|
191 """ |
|
192 A `BC <https://www.gnu.org/software/bc/>`_ lexer. |
|
193 |
|
194 .. versionadded:: 2.1 |
|
195 """ |
|
196 name = 'BC' |
|
197 aliases = ['bc'] |
|
198 filenames = ['*.bc'] |
|
199 |
|
200 tokens = { |
|
201 'root': [ |
|
202 (r'/\*', Comment.Multiline, 'comment'), |
|
203 (r'"(?:[^"\\]|\\.)*"', String), |
|
204 (r'[{}();,]', Punctuation), |
|
205 (words(('if', 'else', 'while', 'for', 'break', 'continue', |
|
206 'halt', 'return', 'define', 'auto', 'print', 'read', |
|
207 'length', 'scale', 'sqrt', 'limits', 'quit', |
|
208 'warranty'), suffix=r'\b'), Keyword), |
|
209 (r'\+\+|--|\|\||&&|' |
|
210 r'([-<>+*%\^/!=])=?', Operator), |
|
211 # bc doesn't support exponential |
|
212 (r'[0-9]+(\.[0-9]*)?', Number), |
|
213 (r'\.[0-9]+', Number), |
|
214 (r'.', Text) |
|
215 ], |
|
216 'comment': [ |
|
217 (r'[^*/]+', Comment.Multiline), |
|
218 (r'\*/', Comment.Multiline, '#pop'), |
|
219 (r'[*/]', Comment.Multiline) |
|
220 ], |
|
221 } |