summaryrefslogtreecommitdiff
path: root/pygments/lexers/math.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-01-09 16:32:39 +0100
committerGeorg Brandl <georg@python.org>2014-01-09 16:32:39 +0100
commit077618ac2b6e71689ced7ca0f41ebf8ac0de4dcc (patch)
treebc28d01dbf807dfd807c48d3a79bf386a0467951 /pygments/lexers/math.py
parentbca6dbc6f061c3fe289a6a201363f72247ca949b (diff)
parentd5db9bdc770a09cf41976fe39a9f982bd79636af (diff)
downloadpygments-077618ac2b6e71689ced7ca0f41ebf8ac0de4dcc.tar.gz
Merged in adereth/pygments-main (pull request #245)
MathematicaLexer
Diffstat (limited to 'pygments/lexers/math.py')
-rw-r--r--pygments/lexers/math.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py
index 1cdcfb43..aa37c0b6 100644
--- a/pygments/lexers/math.py
+++ b/pygments/lexers/math.py
@@ -24,7 +24,7 @@ from pygments.lexers import _stan_builtins
__all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
- 'IDLLexer', 'RdLexer', 'IgorLexer']
+ 'IDLLexer', 'RdLexer', 'IgorLexer', 'MathematicaLexer']
class JuliaLexer(RegexLexer):
@@ -1916,3 +1916,49 @@ class IgorLexer(RegexLexer):
(r'.', Text),
],
}
+
+class MathematicaLexer(RegexLexer):
+ """
+ Lexer for `Mathematica <http://www.wolfram.com/mathematica/>`_ source code.
+
+ *New in Pygments 1.7.*
+ """
+ name = 'Mathematica'
+ aliases = ['mathematica', 'mma', 'nb']
+ filenames = ['*.nb', '*.cdf', '*.nbp', "*.ma"]
+ mimetypes = ['application/mathematica',
+ 'application/vnd.wolfram.mathematica',
+ 'application/vnd.wolfram.mathematica.package',
+ 'application/vnd.wolfram.cdf']
+
+ # http://reference.wolfram.com/mathematica/guide/Syntax.html
+ operators = [
+ ";;", "=", "=.", "!=" "==", ":=", "->", ":>", "/.", "+", "-", "*", "/",
+ "^", "&&", "||", "!", "<>", "|", "/;", "?", "@", "//", "/@", "@@",
+ "@@@", "~~", "===", "&"]
+ operators.sort(reverse=True)
+
+ punctuation = [",", ";", "(", ")", "[", "]", "{", "}"]
+
+ def _multi_escape(entries):
+ return '(%s)' % ('|'.join(re.escape(entry) for entry in entries))
+
+ tokens = {
+ 'root': [
+ (r'\(\*.*\*\)', Comment),
+
+ (r'([a-zA-Z]+[A-Za-z0-9]*`)', Name.Namespace),
+ (r'([A-Za-z0-9]*_+[A-Za-z0-9]*)', Name.Variable),
+ (r'#\d*', Name.Variable),
+ (r'([a-zA-Z]+[a-zA-Z0-9]*)', Name),
+
+ (r'-?[0-9]+\.[0-9]*', Number.Float),
+ (r'-?[0-9]*\.[0-9]+', Number.Float),
+ (r'-?[0-9]+', Number.Integer),
+
+ (_multi_escape(operators), Operator),
+ (_multi_escape(punctuation), Punctuation),
+ (r'(".*")', String),
+ (r'\s+', Text.Whitespace),
+ ],
+ }