Skip to content

Commit a1b67ce

Browse files
Added support for Magma (CAS) (#3055)
1 parent 23cd9b6 commit a1b67ce

15 files changed

+387
-2
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,10 @@
783783
"title": "Lua",
784784
"owner": "Golmote"
785785
},
786+
"magma": {
787+
"title": "Magma (CAS)",
788+
"owner": "RunDevelopment"
789+
},
786790
"makefile": {
787791
"title": "Makefile",
788792
"owner": "Golmote"

components/prism-magma.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Prism.languages.magma = {
2+
'output': {
3+
pattern: /^(>.*(?:\r(?:\n|(?!\n))|\n))(?!>)(?:.+|(?:\r(?:\n|(?!\n))|\n)(?!>).*)(?:(?:\r(?:\n|(?!\n))|\n)(?!>).*)*/m,
4+
lookbehind: true,
5+
greedy: true
6+
},
7+
8+
'comment': {
9+
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
10+
greedy: true
11+
},
12+
'string': {
13+
pattern: /(^|[^\\"])"(?:[^\r\n\\"]|\\.)*"/,
14+
lookbehind: true,
15+
greedy: true
16+
},
17+
18+
// http://magma.maths.usyd.edu.au/magma/handbook/text/82
19+
'keyword': /\b(?:_|adj|and|assert|assert2|assert3|assigned|break|by|case|cat|catch|clear|cmpeq|cmpne|continue|declare|default|delete|diff|div|do|elif|else|end|eq|error|eval|exists|exit|for|forall|forward|fprintf|freeze|function|ge|gt|if|iload|import|in|intrinsic|is|join|le|load|local|lt|meet|mod|ne|not|notadj|notin|notsubset|or|print|printf|procedure|quit|random|read|readi|repeat|require|requirege|requirerange|restore|return|save|sdiff|select|subset|then|time|to|try|until|vprint|vprintf|vtime|when|where|while|xor)\b/,
20+
'boolean': /\b(?:false|true)\b/,
21+
22+
'generator': {
23+
pattern: /\b[a-z_]\w*(?=\s*<)/i,
24+
alias: 'class-name'
25+
},
26+
'function': /\b[a-z_]\w*(?=\s*\()/i,
27+
28+
'number': {
29+
pattern: /(^|[^\w.]|\.\.)(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?:_[a-z]?)?(?=$|[^\w.]|\.\.)/,
30+
lookbehind: true
31+
},
32+
33+
'operator': /->|[-+*/^~!|#=]|:=|\.\./,
34+
'punctuation': /[()[\]{}<>,;.:]/
35+
};

components/prism-magma.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-magma.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h2>Full example</h2>
2+
<pre><code>// Source: http://magma.maths.usyd.edu.au/magma/handbook/text/115#963
3+
> D := Denominator;
4+
> N := Numerator;
5+
> farey := function(n)
6+
> f := [ RationalField() | 0, 1/n ];
7+
> p := 0;
8+
> q := 1;
9+
> while p/q lt 1 do
10+
> p := ( D(f[#f-1]) + n) div D(f[#f]) * N(f[#f]) - N(f[#f-1]);
11+
> q := ( D(f[#f-1]) + n) div D(f[#f]) * D(f[#f]) - D(f[#f-1]);
12+
> Append(~f, p/q);
13+
> end while;
14+
> return f;
15+
> end function;
16+
> function farey(n)
17+
> if n eq 1 then
18+
> return [RationalField() | 0, 1 ];
19+
> else
20+
> f := farey(n-1);
21+
> i := 0;
22+
> while i lt #f-1 do
23+
> i +:= 1;
24+
> if D(f[i]) + D(f[i+1]) eq n then
25+
> Insert( ~f, i+1, (N(f[i]) + N(f[i+1]))/(D(f[i]) + D(f[i+1])));
26+
> end if;
27+
> end while;
28+
> return f;
29+
> end if;
30+
> end function;
31+
> farey := func&lt; n |
32+
> Sort(Setseq({ a/b : a in { 0..n }, b in { 1..n } | a le b }))>;
33+
> farey(6);
34+
[ 0, 1/6, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 5/6, 1 ]</code></pre>

plugins/show-language/prism-show-language.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"llvm": "LLVM IR",
138138
"log": "Log file",
139139
"lolcode": "LOLCODE",
140+
"magma": "Magma (CAS)",
140141
"md": "Markdown",
141142
"markup-templating": "Markup templating",
142143
"matlab": "MATLAB",

plugins/show-language/prism-show-language.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// comment
2+
3+
/*
4+
comment
5+
*/
6+
7+
----------------------------------------------------
8+
9+
[
10+
["comment", "// comment"],
11+
12+
["comment", "/*\r\n comment\r\n */"]
13+
]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
G<a, b> := Group<a, b | a^2 = b^3 = a^b*b^2>;
2+
3+
----------------------------------------------------
4+
5+
[
6+
["generator", "G"],
7+
["punctuation", "<"],
8+
"a",
9+
["punctuation", ","],
10+
" b",
11+
["punctuation", ">"],
12+
["operator", ":="],
13+
["generator", "Group"],
14+
["punctuation", "<"],
15+
"a",
16+
["punctuation", ","],
17+
" b ",
18+
["operator", "|"],
19+
" a",
20+
["operator", "^"],
21+
["number", "2"],
22+
["operator", "="],
23+
" b",
24+
["operator", "^"],
25+
["number", "3"],
26+
["operator", "="],
27+
" a",
28+
["operator", "^"],
29+
"b",
30+
["operator", "*"],
31+
"b",
32+
["operator", "^"],
33+
["number", "2"],
34+
["punctuation", ">"],
35+
["punctuation", ";"]
36+
]
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
_;
2+
adj;
3+
and;
4+
assert;
5+
assert2;
6+
assert3;
7+
assigned;
8+
break;
9+
by;
10+
case;
11+
cat;
12+
catch;
13+
clear;
14+
cmpeq;
15+
cmpne;
16+
continue;
17+
declare;
18+
default;
19+
delete;
20+
diff;
21+
div;
22+
do;
23+
elif;
24+
else;
25+
end;
26+
eq;
27+
error;
28+
eval;
29+
exists;
30+
exit;
31+
for;
32+
forall;
33+
forward;
34+
fprintf;
35+
freeze;
36+
function;
37+
ge;
38+
gt;
39+
if;
40+
iload;
41+
import;
42+
in;
43+
intrinsic;
44+
is;
45+
join;
46+
le;
47+
load;
48+
local;
49+
lt;
50+
meet;
51+
mod;
52+
ne;
53+
not;
54+
notadj;
55+
notin;
56+
notsubset;
57+
or;
58+
print;
59+
printf;
60+
procedure;
61+
quit;
62+
random;
63+
read;
64+
readi;
65+
repeat;
66+
require;
67+
requirege;
68+
requirerange;
69+
restore;
70+
return;
71+
save;
72+
sdiff;
73+
select;
74+
subset;
75+
then;
76+
time;
77+
to;
78+
try;
79+
until;
80+
vprint;
81+
vprintf;
82+
vtime;
83+
when;
84+
where;
85+
while;
86+
xor;
87+
88+
----------------------------------------------------
89+
90+
[
91+
["keyword", "_"], ["punctuation", ";"],
92+
["keyword", "adj"], ["punctuation", ";"],
93+
["keyword", "and"], ["punctuation", ";"],
94+
["keyword", "assert"], ["punctuation", ";"],
95+
["keyword", "assert2"], ["punctuation", ";"],
96+
["keyword", "assert3"], ["punctuation", ";"],
97+
["keyword", "assigned"], ["punctuation", ";"],
98+
["keyword", "break"], ["punctuation", ";"],
99+
["keyword", "by"], ["punctuation", ";"],
100+
["keyword", "case"], ["punctuation", ";"],
101+
["keyword", "cat"], ["punctuation", ";"],
102+
["keyword", "catch"], ["punctuation", ";"],
103+
["keyword", "clear"], ["punctuation", ";"],
104+
["keyword", "cmpeq"], ["punctuation", ";"],
105+
["keyword", "cmpne"], ["punctuation", ";"],
106+
["keyword", "continue"], ["punctuation", ";"],
107+
["keyword", "declare"], ["punctuation", ";"],
108+
["keyword", "default"], ["punctuation", ";"],
109+
["keyword", "delete"], ["punctuation", ";"],
110+
["keyword", "diff"], ["punctuation", ";"],
111+
["keyword", "div"], ["punctuation", ";"],
112+
["keyword", "do"], ["punctuation", ";"],
113+
["keyword", "elif"], ["punctuation", ";"],
114+
["keyword", "else"], ["punctuation", ";"],
115+
["keyword", "end"], ["punctuation", ";"],
116+
["keyword", "eq"], ["punctuation", ";"],
117+
["keyword", "error"], ["punctuation", ";"],
118+
["keyword", "eval"], ["punctuation", ";"],
119+
["keyword", "exists"], ["punctuation", ";"],
120+
["keyword", "exit"], ["punctuation", ";"],
121+
["keyword", "for"], ["punctuation", ";"],
122+
["keyword", "forall"], ["punctuation", ";"],
123+
["keyword", "forward"], ["punctuation", ";"],
124+
["keyword", "fprintf"], ["punctuation", ";"],
125+
["keyword", "freeze"], ["punctuation", ";"],
126+
["keyword", "function"], ["punctuation", ";"],
127+
["keyword", "ge"], ["punctuation", ";"],
128+
["keyword", "gt"], ["punctuation", ";"],
129+
["keyword", "if"], ["punctuation", ";"],
130+
["keyword", "iload"], ["punctuation", ";"],
131+
["keyword", "import"], ["punctuation", ";"],
132+
["keyword", "in"], ["punctuation", ";"],
133+
["keyword", "intrinsic"], ["punctuation", ";"],
134+
["keyword", "is"], ["punctuation", ";"],
135+
["keyword", "join"], ["punctuation", ";"],
136+
["keyword", "le"], ["punctuation", ";"],
137+
["keyword", "load"], ["punctuation", ";"],
138+
["keyword", "local"], ["punctuation", ";"],
139+
["keyword", "lt"], ["punctuation", ";"],
140+
["keyword", "meet"], ["punctuation", ";"],
141+
["keyword", "mod"], ["punctuation", ";"],
142+
["keyword", "ne"], ["punctuation", ";"],
143+
["keyword", "not"], ["punctuation", ";"],
144+
["keyword", "notadj"], ["punctuation", ";"],
145+
["keyword", "notin"], ["punctuation", ";"],
146+
["keyword", "notsubset"], ["punctuation", ";"],
147+
["keyword", "or"], ["punctuation", ";"],
148+
["keyword", "print"], ["punctuation", ";"],
149+
["keyword", "printf"], ["punctuation", ";"],
150+
["keyword", "procedure"], ["punctuation", ";"],
151+
["keyword", "quit"], ["punctuation", ";"],
152+
["keyword", "random"], ["punctuation", ";"],
153+
["keyword", "read"], ["punctuation", ";"],
154+
["keyword", "readi"], ["punctuation", ";"],
155+
["keyword", "repeat"], ["punctuation", ";"],
156+
["keyword", "require"], ["punctuation", ";"],
157+
["keyword", "requirege"], ["punctuation", ";"],
158+
["keyword", "requirerange"], ["punctuation", ";"],
159+
["keyword", "restore"], ["punctuation", ";"],
160+
["keyword", "return"], ["punctuation", ";"],
161+
["keyword", "save"], ["punctuation", ";"],
162+
["keyword", "sdiff"], ["punctuation", ";"],
163+
["keyword", "select"], ["punctuation", ";"],
164+
["keyword", "subset"], ["punctuation", ";"],
165+
["keyword", "then"], ["punctuation", ";"],
166+
["keyword", "time"], ["punctuation", ";"],
167+
["keyword", "to"], ["punctuation", ";"],
168+
["keyword", "try"], ["punctuation", ";"],
169+
["keyword", "until"], ["punctuation", ";"],
170+
["keyword", "vprint"], ["punctuation", ";"],
171+
["keyword", "vprintf"], ["punctuation", ";"],
172+
["keyword", "vtime"], ["punctuation", ";"],
173+
["keyword", "when"], ["punctuation", ";"],
174+
["keyword", "where"], ["punctuation", ";"],
175+
["keyword", "while"], ["punctuation", ";"],
176+
["keyword", "xor"], ["punctuation", ";"]
177+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
123
2+
-123
3+
4+
1.234
5+
6+
0..100
7+
8+
----------------------------------------------------
9+
10+
[
11+
["number", "123"],
12+
["operator", "-"], ["number", "123"],
13+
14+
["number", "1.234"],
15+
16+
["number", "0"], ["operator", ".."], ["number", "100"]
17+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
+ - * / ^ ~ !
2+
=
3+
:= -> ..
4+
| #
5+
6+
----------------------------------------------------
7+
8+
[
9+
["operator", "+"],
10+
["operator", "-"],
11+
["operator", "*"],
12+
["operator", "/"],
13+
["operator", "^"],
14+
["operator", "~"],
15+
["operator", "!"],
16+
17+
["operator", "="],
18+
19+
["operator", ":="],
20+
["operator", "->"],
21+
["operator", ".."],
22+
23+
["operator", "|"],
24+
["operator", "#"]
25+
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy