Skip to content

Commit a522163

Browse files
authored
Merge pull request #2763 from Randl/master
Maple lexer
2 parents 69216f7 + 4a7142d commit a522163

File tree

7 files changed

+11860
-0
lines changed

7 files changed

+11860
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ Other contributors, listed alphabetically, are:
269269
* Enrique Zamudio -- Ceylon lexer
270270
* Alex Zimin -- Nemerle lexer
271271
* Rob Zimmerman -- Kal lexer
272+
* Evgenii Zheltonozhskii -- Maple lexer
272273
* Vincent Zurczak -- Roboconf lexer
273274
* Hubert Gruniaux -- C and C++ lexer improvements
274275
* Thomas Symalla -- AMDGPU Lexer

pygments/lexers/_mapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
'MakoJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Mako', ('javascript+mako', 'js+mako'), (), ('application/x-javascript+mako', 'text/x-javascript+mako', 'text/javascript+mako')),
310310
'MakoLexer': ('pygments.lexers.templates', 'Mako', ('mako',), ('*.mao',), ('application/x-mako',)),
311311
'MakoXmlLexer': ('pygments.lexers.templates', 'XML+Mako', ('xml+mako',), (), ('application/xml+mako',)),
312+
'MapleLexer': ('pygments.lexers.maple', 'Maple', ('maple',), ('*.mpl', '*.mi', '*.mm'), ('text/x-maple',)),
312313
'MaqlLexer': ('pygments.lexers.business', 'MAQL', ('maql',), ('*.maql',), ('text/x-gooddata-maql', 'application/x-gooddata-maql')),
313314
'MarkdownLexer': ('pygments.lexers.markup', 'Markdown', ('markdown', 'md'), ('*.md', '*.markdown'), ('text/x-markdown',)),
314315
'MaskLexer': ('pygments.lexers.javascript', 'Mask', ('mask',), ('*.mask',), ('text/x-mask',)),

pygments/lexers/maple.py

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
"""
2+
pygments.lexers.maple
3+
~~~~~~~~~~~~~~~~~~~~~
4+
5+
Lexers for Maple.
6+
7+
:copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.
8+
:license: BSD, see LICENSE for details.
9+
"""
10+
11+
from pygments.lexer import words, bygroups, ExtendedRegexLexer
12+
from pygments.token import Comment, Name, String, Whitespace, Operator, Punctuation, Number, Text, Keyword
13+
14+
__all__ = ['MapleLexer']
15+
16+
17+
class MapleLexer(ExtendedRegexLexer):
18+
"""
19+
Lexer for Maple.
20+
"""
21+
22+
name = 'Maple'
23+
aliases = ['maple']
24+
filenames = ['*.mpl', '*.mi', '*.mm']
25+
mimetypes = ['text/x-maple']
26+
url = 'https://www.maplesoft.com/products/Maple/'
27+
version_added = ''
28+
29+
keywords = ('and',
30+
'assuming',
31+
'break',
32+
'by',
33+
'catch',
34+
'description',
35+
'do',
36+
'done',
37+
'elif',
38+
'else',
39+
'end',
40+
'error',
41+
'export',
42+
'fi',
43+
'finally',
44+
'for',
45+
'from',
46+
'global',
47+
'if',
48+
'implies',
49+
'in',
50+
'intersect',
51+
'local',
52+
'minus',
53+
'mod',
54+
'module',
55+
'next',
56+
'not',
57+
'od',
58+
'option',
59+
'options',
60+
'or',
61+
'proc',
62+
'quit',
63+
'read',
64+
'return',
65+
'save',
66+
'stop',
67+
'subset',
68+
'then',
69+
'to',
70+
'try',
71+
'union',
72+
'use',
73+
'uses',
74+
'while',
75+
'xor')
76+
77+
builtins = ('abs',
78+
'add',
79+
'addressof',
80+
'anames',
81+
'and',
82+
'andmap',
83+
'andseq',
84+
'appendto',
85+
'Array',
86+
'array',
87+
'ArrayOptions',
88+
'assemble',
89+
'ASSERT',
90+
'assign',
91+
'assigned',
92+
'attributes',
93+
'cat',
94+
'ceil',
95+
'coeff',
96+
'coeffs',
97+
'conjugate',
98+
'convert',
99+
'CopySign',
100+
'DEBUG',
101+
'debugopts',
102+
'Default0',
103+
'DefaultOverflow',
104+
'DefaultUnderflow',
105+
'degree',
106+
'denom',
107+
'diff',
108+
'disassemble',
109+
'divide',
110+
'done',
111+
'entries',
112+
'EqualEntries',
113+
'eval',
114+
'evalb',
115+
'evalf',
116+
'evalhf',
117+
'evalindets',
118+
'evaln',
119+
'expand',
120+
'exports',
121+
'factorial',
122+
'floor',
123+
'frac',
124+
'frem',
125+
'FromInert',
126+
'frontend',
127+
'gc',
128+
'genpoly',
129+
'has',
130+
'hastype',
131+
'hfarray',
132+
'icontent',
133+
'igcd',
134+
'ilcm',
135+
'ilog10',
136+
'Im',
137+
'implies',
138+
'indets',
139+
'indices',
140+
'intersect',
141+
'iolib',
142+
'iquo',
143+
'irem',
144+
'iroot',
145+
'iroot',
146+
'isqrt',
147+
'kernelopts',
148+
'lcoeff',
149+
'ldegree',
150+
'length',
151+
'lexorder',
152+
'lhs',
153+
'lowerbound',
154+
'lprint',
155+
'macro',
156+
'map',
157+
'max',
158+
'maxnorm',
159+
'member',
160+
'membertype',
161+
'min',
162+
'minus',
163+
'mod',
164+
'modp',
165+
'modp1',
166+
'modp2',
167+
'mods',
168+
'mul',
169+
'NextAfter',
170+
'nops',
171+
'normal',
172+
'not',
173+
'numboccur',
174+
'numelems',
175+
'numer',
176+
'NumericClass',
177+
'NumericEvent',
178+
'NumericEventHandler',
179+
'NumericStatus',
180+
'op',
181+
'or',
182+
'order',
183+
'OrderedNE',
184+
'ormap',
185+
'orseq',
186+
'parse',
187+
'piecewise',
188+
'pointto',
189+
'print',
190+
'quit',
191+
'Re',
192+
'readlib',
193+
'Record',
194+
'remove',
195+
'rhs',
196+
'round',
197+
'rtable',
198+
'rtable_elems',
199+
'rtable_eval',
200+
'rtable_indfns',
201+
'rtable_num_elems',
202+
'rtable_options',
203+
'rtable_redim',
204+
'rtable_scanblock',
205+
'rtable_set_indfn',
206+
'rtable_split_unit',
207+
'savelib',
208+
'Scale10',
209+
'Scale2',
210+
'SDMPolynom',
211+
'searchtext',
212+
'SearchText',
213+
'select',
214+
'selectremove',
215+
'seq',
216+
'series',
217+
'setattribute',
218+
'SFloatExponent',
219+
'SFloatMantissa',
220+
'sign',
221+
'sort',
222+
'ssystem',
223+
'stop',
224+
'String',
225+
'subs',
226+
'subset',
227+
'subsindets',
228+
'subsop',
229+
'substring',
230+
'system',
231+
'table',
232+
'taylor',
233+
'tcoeff',
234+
'time',
235+
'timelimit',
236+
'ToInert',
237+
'traperror',
238+
'trunc',
239+
'type',
240+
'typematch',
241+
'unames',
242+
'unassign',
243+
'union',
244+
'Unordered',
245+
'upperbound',
246+
'userinfo',
247+
'writeto',
248+
'xor',
249+
'xormap',
250+
'xorseq')
251+
252+
def delayed_callback(self, match, ctx):
253+
yield match.start(1), Punctuation, match.group(1) # quote
254+
255+
ctx.pos = match.start(2)
256+
orig_end = ctx.end
257+
ctx.end = match.end(2)
258+
259+
yield from self.get_tokens_unprocessed(context=ctx)
260+
yield match.end(2), Punctuation, match.group(1) # quote
261+
262+
ctx.pos = match.end()
263+
ctx.end = orig_end
264+
265+
tokens = {
266+
'root': [
267+
(r'#.*\n', Comment.Single),
268+
(r'\(\*', Comment.Multiline, 'comment'),
269+
(r'"(\\.|.|\s)*?"', String),
270+
(r"('+)((.|\n)*?)\1", delayed_callback),
271+
(r'`(\\`|.)*?`', Name),
272+
(words(keywords, prefix=r'\b', suffix=r'\b'), Keyword),
273+
(words(builtins, prefix=r'\b', suffix=r'\b'), Name.Builtin),
274+
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
275+
(r'(:=|\*\*|@@|<=|>=|<>|->|::|\.\.|&\+|[\+\-\*\.\^\$/@&,:=<>%~])', Operator),
276+
(r'[;^!@$\(\)\[\]{}|_\\#?]', Punctuation),
277+
(r'(\d+)(\.\.)', bygroups(Number.Integer, Punctuation)),
278+
(r'(\d*\.\d+|\d+\.\d*)([eE][+-]?\d+)?', Number.Float),
279+
(r'\d+', Number.Integer),
280+
(r'\n', Whitespace),
281+
(r'[^\S\n]+', Whitespace),
282+
(r'\s+', Text),
283+
284+
],
285+
'comment': [
286+
(r'.*\(\*', Comment.Multiline, '#push'),
287+
(r'.*\*\)', Comment.Multiline, '#pop'),
288+
(r'.*\n', Comment.Multiline),
289+
]
290+
}
291+
292+
def analyse_text(text):
293+
if ':=' in text:
294+
return 0.1

0 commit comments

Comments
 (0)