123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- """
- pygments.lexers.maple
- ~~~~~~~~~~~~~~~~~~~~~
- Lexers for Maple.
- :copyright: Copyright 2006-2025 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, 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 = '2.19'
- 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'\s+', Whitespace),
- ],
- 'comment': [
- (r'.*\(\*', Comment.Multiline, '#push'),
- (r'.*\*\)', Comment.Multiline, '#pop'),
- (r'.*\n', Comment.Multiline),
- ]
- }
- def analyse_text(text):
- if ':=' in text:
- return 0.1
|