Skip to content

Commit

Permalink
Merge pull request #2763 from Randl/master
Browse files Browse the repository at this point in the history
Maple lexer
  • Loading branch information
Anteru authored Jan 5, 2025
2 parents 69216f7 + 4a7142d commit a522163
Show file tree
Hide file tree
Showing 7 changed files with 11,860 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ Other contributors, listed alphabetically, are:
* Enrique Zamudio -- Ceylon lexer
* Alex Zimin -- Nemerle lexer
* Rob Zimmerman -- Kal lexer
* Evgenii Zheltonozhskii -- Maple lexer
* Vincent Zurczak -- Roboconf lexer
* Hubert Gruniaux -- C and C++ lexer improvements
* Thomas Symalla -- AMDGPU Lexer
Expand Down
1 change: 1 addition & 0 deletions pygments/lexers/_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
'MakoJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Mako', ('javascript+mako', 'js+mako'), (), ('application/x-javascript+mako', 'text/x-javascript+mako', 'text/javascript+mako')),
'MakoLexer': ('pygments.lexers.templates', 'Mako', ('mako',), ('*.mao',), ('application/x-mako',)),
'MakoXmlLexer': ('pygments.lexers.templates', 'XML+Mako', ('xml+mako',), (), ('application/xml+mako',)),
'MapleLexer': ('pygments.lexers.maple', 'Maple', ('maple',), ('*.mpl', '*.mi', '*.mm'), ('text/x-maple',)),
'MaqlLexer': ('pygments.lexers.business', 'MAQL', ('maql',), ('*.maql',), ('text/x-gooddata-maql', 'application/x-gooddata-maql')),
'MarkdownLexer': ('pygments.lexers.markup', 'Markdown', ('markdown', 'md'), ('*.md', '*.markdown'), ('text/x-markdown',)),
'MaskLexer': ('pygments.lexers.javascript', 'Mask', ('mask',), ('*.mask',), ('text/x-mask',)),
Expand Down
294 changes: 294 additions & 0 deletions pygments/lexers/maple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
"""
pygments.lexers.maple
~~~~~~~~~~~~~~~~~~~~~
Lexers for Maple.
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""

from pygments.lexer import words, bygroups, ExtendedRegexLexer
from pygments.token import Comment, Name, String, Whitespace, Operator, Punctuation, Number, Text, Keyword

__all__ = ['MapleLexer']


class MapleLexer(ExtendedRegexLexer):
"""
Lexer for Maple.
"""

name = 'Maple'
aliases = ['maple']
filenames = ['*.mpl', '*.mi', '*.mm']
mimetypes = ['text/x-maple']
url = 'https://www.maplesoft.com/products/Maple/'
version_added = ''

keywords = ('and',
'assuming',
'break',
'by',
'catch',
'description',
'do',
'done',
'elif',
'else',
'end',
'error',
'export',
'fi',
'finally',
'for',
'from',
'global',
'if',
'implies',
'in',
'intersect',
'local',
'minus',
'mod',
'module',
'next',
'not',
'od',
'option',
'options',
'or',
'proc',
'quit',
'read',
'return',
'save',
'stop',
'subset',
'then',
'to',
'try',
'union',
'use',
'uses',
'while',
'xor')

builtins = ('abs',
'add',
'addressof',
'anames',
'and',
'andmap',
'andseq',
'appendto',
'Array',
'array',
'ArrayOptions',
'assemble',
'ASSERT',
'assign',
'assigned',
'attributes',
'cat',
'ceil',
'coeff',
'coeffs',
'conjugate',
'convert',
'CopySign',
'DEBUG',
'debugopts',
'Default0',
'DefaultOverflow',
'DefaultUnderflow',
'degree',
'denom',
'diff',
'disassemble',
'divide',
'done',
'entries',
'EqualEntries',
'eval',
'evalb',
'evalf',
'evalhf',
'evalindets',
'evaln',
'expand',
'exports',
'factorial',
'floor',
'frac',
'frem',
'FromInert',
'frontend',
'gc',
'genpoly',
'has',
'hastype',
'hfarray',
'icontent',
'igcd',
'ilcm',
'ilog10',
'Im',
'implies',
'indets',
'indices',
'intersect',
'iolib',
'iquo',
'irem',
'iroot',
'iroot',
'isqrt',
'kernelopts',
'lcoeff',
'ldegree',
'length',
'lexorder',
'lhs',
'lowerbound',
'lprint',
'macro',
'map',
'max',
'maxnorm',
'member',
'membertype',
'min',
'minus',
'mod',
'modp',
'modp1',
'modp2',
'mods',
'mul',
'NextAfter',
'nops',
'normal',
'not',
'numboccur',
'numelems',
'numer',
'NumericClass',
'NumericEvent',
'NumericEventHandler',
'NumericStatus',
'op',
'or',
'order',
'OrderedNE',
'ormap',
'orseq',
'parse',
'piecewise',
'pointto',
'print',
'quit',
'Re',
'readlib',
'Record',
'remove',
'rhs',
'round',
'rtable',
'rtable_elems',
'rtable_eval',
'rtable_indfns',
'rtable_num_elems',
'rtable_options',
'rtable_redim',
'rtable_scanblock',
'rtable_set_indfn',
'rtable_split_unit',
'savelib',
'Scale10',
'Scale2',
'SDMPolynom',
'searchtext',
'SearchText',
'select',
'selectremove',
'seq',
'series',
'setattribute',
'SFloatExponent',
'SFloatMantissa',
'sign',
'sort',
'ssystem',
'stop',
'String',
'subs',
'subset',
'subsindets',
'subsop',
'substring',
'system',
'table',
'taylor',
'tcoeff',
'time',
'timelimit',
'ToInert',
'traperror',
'trunc',
'type',
'typematch',
'unames',
'unassign',
'union',
'Unordered',
'upperbound',
'userinfo',
'writeto',
'xor',
'xormap',
'xorseq')

def delayed_callback(self, match, ctx):
yield match.start(1), Punctuation, match.group(1) # quote

ctx.pos = match.start(2)
orig_end = ctx.end
ctx.end = match.end(2)

yield from self.get_tokens_unprocessed(context=ctx)
yield match.end(2), Punctuation, match.group(1) # quote

ctx.pos = match.end()
ctx.end = orig_end

tokens = {
'root': [
(r'#.*\n', Comment.Single),
(r'\(\*', Comment.Multiline, 'comment'),
(r'"(\\.|.|\s)*?"', String),
(r"('+)((.|\n)*?)\1", delayed_callback),
(r'`(\\`|.)*?`', Name),
(words(keywords, prefix=r'\b', suffix=r'\b'), Keyword),
(words(builtins, prefix=r'\b', suffix=r'\b'), Name.Builtin),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'(:=|\*\*|@@|<=|>=|<>|->|::|\.\.|&\+|[\+\-\*\.\^\$/@&,:=<>%~])', Operator),
(r'[;^!@$\(\)\[\]{}|_\\#?]', Punctuation),
(r'(\d+)(\.\.)', bygroups(Number.Integer, Punctuation)),
(r'(\d*\.\d+|\d+\.\d*)([eE][+-]?\d+)?', Number.Float),
(r'\d+', Number.Integer),
(r'\n', Whitespace),
(r'[^\S\n]+', Whitespace),
(r'\s+', Text),

],
'comment': [
(r'.*\(\*', Comment.Multiline, '#push'),
(r'.*\*\)', Comment.Multiline, '#pop'),
(r'.*\n', Comment.Multiline),
]
}

def analyse_text(text):
if ':=' in text:
return 0.1
Loading

0 comments on commit a522163

Please sign in to comment.