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+
]

0 commit comments

Comments
 (0)