diff options
author | welterde <devnull@localhost> | 2007-05-06 16:30:34 +0200 |
---|---|---|
committer | welterde <devnull@localhost> | 2007-05-06 16:30:34 +0200 |
commit | 0b6c1be09d077aba79d7b82f56a9e555f9afc3fe (patch) | |
tree | 5d8bcfcea5adbf121b5f10f5fb3260692c81d2d5 | |
parent | 77b258cea99b0d97d854aa636b84b07cc2511e7c (diff) | |
download | pygments-0b6c1be09d077aba79d7b82f56a9e555f9afc3fe.tar.gz |
[svn] added MuPAD lexer
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/math.py | 85 | ||||
-rw-r--r-- | tests/examplefiles/AlternatingGroup.mu | 102 |
4 files changed, 189 insertions, 0 deletions
@@ -13,3 +13,4 @@ Other contributors (as mentionend in :copyright:s) are: - Tiberius Teng - Adam Blinkinsop <blinks@acm.org> - Kirk McDonald +- Christopher Creutzig <christopher@creutzig.de> diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 11b35ee9..7f1b61e1 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -63,6 +63,7 @@ LEXERS = { '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')), diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py new file mode 100644 index 00000000..f93a6330 --- /dev/null +++ b/pygments/lexers/math.py @@ -0,0 +1,85 @@ +# -*- 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) + ] + } diff --git a/tests/examplefiles/AlternatingGroup.mu b/tests/examplefiles/AlternatingGroup.mu new file mode 100644 index 00000000..2cb19924 --- /dev/null +++ b/tests/examplefiles/AlternatingGroup.mu @@ -0,0 +1,102 @@ +/*++ $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: |