Commits

Anonymous committed f2c3954

[svn] added MuPAD lexer

Comments (0)

Files changed (4)

 - Tiberius Teng
 - Adam Blinkinsop <blinks@acm.org>
 - Kirk McDonald
+- Christopher Creutzig <christopher@creutzig.de>

pygments/lexers/_mapping.py

     'MakoLexer': ('pygments.lexers.templates', 'Mako', ('mako',), ('*.mao',), ('application/x-mako',)),
     'MakoXmlLexer': ('pygments.lexers.templates', 'XML+Mako', ('xml+mako',), (), ('application/xml+mako',)),
     'MoinWikiLexer': ('pygments.lexers.text', 'MoinMoin/Trac Wiki markup', ('trac-wiki', 'moin'), (), ('text/x-trac-wiki',)),
+    'MuPADLexer': ('pygments.lexers.math', 'MuPAD', ('mupad',), ('*.mu',), ()),
     'MyghtyCssLexer': ('pygments.lexers.templates', 'CSS+Myghty', ('css+myghty',), (), ('text/css+myghty',)),
     'MyghtyHtmlLexer': ('pygments.lexers.templates', 'HTML+Myghty', ('html+myghty',), (), ('text/html+myghty',)),
     'MyghtyJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Myghty', ('js+myghty', 'javascript+myghty'), (), ('application/x-javascript+myghty', 'text/x-javascript+myghty', 'text/javascript+mygthy')),

pygments/lexers/math.py

+# -*- coding: utf-8 -*-
+"""
+    pygments.lexers.math
+    ~~~~~~~~~~~~~~~~~~~~~
+
+    Lexers for math languages.
+
+    :copyright: 2007 by Christopher Creutzig.
+    :license: BSD, see LICENSE for more details.
+"""
+
+from pygments.lexer import RegexLexer, bygroups
+from pygments.token import *
+
+__all__ = ['MuPADLexer']
+
+class MuPADLexer(RegexLexer):
+    """
+    A MuPAD lexer.
+    Contributed by Christopher Creutzig <christopher@creutzig.de>.
+
+    *New in Pygments 0.8*
+    """
+    name = 'MuPAD'
+    aliases = ['mupad']
+    filenames = ['*.mu']
+
+    tokens = {
+      'root' : [
+        (r'//.*?$', Comment.Single),
+        (r'/\*', Comment.Multiline, 'comment'),
+        (r'"(?:[^"\\]+|\\.)*"', String),
+        (r'\(|\)|\[|\]|\{|\}', Punctuation),
+        (r'''(?x)\b(?:
+            next|break|end|
+            axiom|end_axiom|category|end_category|domain|end_domain|inherits|
+            if|%if|then|elif|else|end_if|
+            case|of|do|otherwise|end_case|
+            while|end_while|
+            repeat|until|end_repeat|
+            for|from|to|downto|step|end_for|
+            proc|local|option|save|begin|end_proc|
+            delete|frame
+          )\b''', Keyword),
+        (r'''(?x)\b(?:
+            DOM_ARRAY|DOM_BOOL|DOM_COMPLEX|DOM_DOMAIN|DOM_EXEC|DOM_EXPR|
+            DOM_FAIL|DOM_FLOAT|DOM_FRAME|DOM_FUNC_ENV|DOM_HFARRAY|DOM_IDENT|
+            DOM_INT|DOM_INTERVAL|DOM_LIST|DOM_NIL|DOM_NULL|DOM_POLY|DOM_PROC|
+            DOM_PROC_ENV|DOM_RAT|DOM_SET|DOM_STRING|DOM_TABLE|DOM_VAR
+          )\b''', Name.Class),
+        (r'''(?x)\b(?:
+            PI|EULER|E|CATALAN|
+            NIL|FAIL|undefined|infinity|
+            TRUE|FALSE|UNKNOWN
+          )\b''',
+          Name.Constant),
+        (r'\b(?:dom|procname)\b', Name.Builtin.Pseudo),
+        (r'\.|,|:|;|=|\+|-|\*|/|\^|@|>|<|\$|\||!|\'|%|~=', Operator),
+        (r'''(?x)\b(?:
+            and|or|not|xor|
+            assuming|
+            div|mod|
+            union|minus|intersect|in|subset
+          )\b''',
+          Operator.Word),
+        (r'\b(?:I|RDN_INF|RD_NINF|RD_NAN)\b', Number),
+        #(r'\b(?:adt|linalg|newDomain|hold)\b', Name.Builtin),
+        (r'''(?x)
+          ((?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
+          (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*)\s*([(])''',
+          bygroups(Name.Function, Punctuation)),
+        (r'''(?x)
+          (?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
+          (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*''', Name.Variable),
+        (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number),
+        (r'\.[0-9]+(?:e[0-9]+)?', Number),
+        (r'.', Text)
+      ],
+      'comment' : [
+        (r'[^*/]', Comment.Multiline),
+        (r'/\*', Comment.Multiline, '#push'),
+        (r'\*/', Comment.Multiline, '#pop'),
+        (r'[*/]', Comment.Multiline)
+      ]
+    }

tests/examplefiles/AlternatingGroup.mu

+/*++ $Id: AlternatingGroup.mu,v 1.4 2003/09/08 15:00:47 nthiery Exp $
+
+Dom::AlternatingGroup(n) -- the Alternating Group of {1..n}
+
+n	   - integer >= 1
+
+Elements are represented as in Dom::PermutationGroup(n)
+
+Author:	     Nicolas M. Thi�ry <nthiery@users.sourceforge.net>
+License:     LGPL
+Created:     August 8th, 1999
+Last update: $Date: 2003/09/08 15:00:47 $
+++*/
+
+domain Dom::AlternatingGroup(n: Type::PosInt)
+    inherits Dom::PermutationGroup(n,toBeDefined);
+    category Cat::PermutationGroup;
+    axiom Ax::canonicalRep;
+
+/*--
+    size
+
+    Size of the group.
+--*/
+
+    size := fact(n)/2;
+
+/*--
+    generators
+
+    A list of generators of the group
+
+    The first 3-cycle (1,2,3), and a maximal even cycle (1,...,n) or
+    (2,...,n) depending on the parity of n
+
+--*/
+
+    generators :=
+    if	 n<=2	     then generators:=[dom([[1]])];
+    elif n=3	     then generators:=[dom([[1,2,3]])];
+    elif n mod 2=0   then generators:=[dom([[1,2,3]]), dom([[$2..n]])];
+    else		  generators:=[dom([[1,2,3]]), dom([[$1..n]])];
+    end_if;
+    
+/*--
+    allElements
+
+    List of all the elements of the group
+--*/
+
+    allElements :=
+    proc()
+	option remember;
+	local p;
+    begin
+	[new(dom,p) $ p in select(combinat::permutations(n),
+				  p->bool(combinat::permutations::sign(p)=1))];
+    end_proc;
+
+/*--
+    cycleTypes:
+
+    Count the elements of the group by cycle type.
+    (Cf Cat::PermutationGroupModule).
+
+    Same algorithm as for Dom::SymmetricGroup, but only even permutations
+    are considered. This is done by disregarding partitions p such
+    that n-length(p) is odd.
+--*/
+
+    cycleTypes :=
+    proc()
+	option remember;
+	local t, p, gen;
+    begin
+	userinfo(3, "cycleTypes: starting computation");
+	t:=table();
+
+	gen := combinat::partitions::generator(n);
+	while (p:=gen()) <> FAIL do
+	    userinfo(5, "working on partition", p);
+	    if(n-nops(p) mod 2=0) then
+		// Compute the size of the conjugacy class of Sn indexed by p
+		// and the cycle type of a permutation in this conjugacy class
+                t[combinat::partitions::toExp(p,n)]
+                  := combinat::partitions::conjugacyClassSize(p);
+	    end_if;
+        end_while;
+	t;
+    end_proc;
+
+begin
+    if testargs() then
+	if args(0) <> 1 then error("wrong no of args"); end_if;
+	if not testtype(n,DOM_INT) then
+	    error("argument must be integer")
+	end_if;
+	if n < 1 then
+	    error("argument must be positive")
+	end_if;
+    end_if;
+end_domain: