Skip to content

Commit

Permalink
Added support for GAP (CAS) (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Sep 12, 2021
1 parent 8d0b74b commit 23cd9b6
Show file tree
Hide file tree
Showing 15 changed files with 502 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@
"require": "clike",
"owner": "LiarOnce"
},
"gap": {
"title": "GAP (CAS)",
"owner": "RunDevelopment"
},
"gcode": {
"title": "G-code",
"owner": "RunDevelopment"
Expand Down
54 changes: 54 additions & 0 deletions components/prism-gap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// https://www.gap-system.org/Manuals/doc/ref/chap4.html
// https://www.gap-system.org/Manuals/doc/ref/chap27.html

Prism.languages.gap = {
'shell': {
pattern: /^gap>[\s\S]*?(?=^gap>|$(?![\s\S]))/m,
greedy: true,
inside: {
'gap': {
pattern: /^(gap>).+(?:(?:\r(?:\n|(?!\n))|\n)>.*)*/,
lookbehind: true,
inside: null // see below
},
'punctuation': /^gap>/
}
},

'comment': {
pattern: /#.*/,
greedy: true
},
'string': {
pattern: /(^|[^\\'"])(?:'(?:[^\r\n\\']|\\.){1,10}'|"(?:[^\r\n\\"]|\\.)*"(?!")|"""[\s\S]*?""")/,
lookbehind: true,
greedy: true,
inside: {
'continuation': {
pattern: /([\r\n])>/,
lookbehind: true,
alias: 'punctuation'
}
}
},

'keyword': /\b(?:Assert|Info|IsBound|QUIT|TryNextMethod|Unbind|and|atomic|break|continue|do|elif|else|end|fi|for|function|if|in|local|mod|not|od|or|quit|readonly|readwrite|rec|repeat|return|then|until|while)\b/,
'boolean': /\b(?:false|true)\b/,

'function': /\b[a-z_]\w*(?=\s*\()/i,

'number': {
pattern: /(^|[^\w.]|\.\.)(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?(?:_[a-z]?)?(?=$|[^\w.]|\.\.)/,
lookbehind: true
},

'continuation': {
pattern: /([\r\n])>/,
lookbehind: true,
alias: 'punctuation'
},
'operator': /->|[-+*/^~=!]|<>|[<>]=?|:=|\.\./,
'punctuation': /[()[\]{},;.:]/
};

Prism.languages.gap.shell.inside.gap.inside = Prism.languages.gap;
1 change: 1 addition & 0 deletions components/prism-gap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/prism-gap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2>Full example</h2>
<pre><code># Source: https://www.gap-system.org/Manuals/doc/ref/chap4.html#X815F71EA7BC0EB6F
gap> fib := function ( n )
> local f1, f2, f3, i;
> f1 := 1; f2 := 1;
> for i in [3..n] do
> f3 := f1 + f2;
> f1 := f2;
> f2 := f3;
> od;
> return f2;
> end;;
gap> List( [1..10], fib );
[ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ]
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"ftl": "FreeMarker Template Language",
"gml": "GameMaker Language",
"gamemakerlanguage": "GameMaker Language",
"gap": "GAP (CAS)",
"gcode": "G-code",
"gdscript": "GDScript",
"gedcom": "GEDCOM",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/languages/gap/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
false
true

----------------------------------------------------

[
["boolean", "false"],
["boolean", "true"]
]
7 changes: 7 additions & 0 deletions tests/languages/gap/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# comment

----------------------------------------------------

[
["comment", "# comment"]
]
71 changes: 71 additions & 0 deletions tests/languages/gap/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Assert;
Info;
IsBound;
QUIT;
TryNextMethod;
Unbind;
and;
atomic;
break;
continue;
do;
elif;
else;
end;
fi;
for;
function;
if;
in;
local;
mod;
not;
od;
or;
quit;
readonly;
readwrite;
rec;
repeat;
return;
then;
until;
while;

----------------------------------------------------

[
["keyword", "Assert"], ["punctuation", ";"],
["keyword", "Info"], ["punctuation", ";"],
["keyword", "IsBound"], ["punctuation", ";"],
["keyword", "QUIT"], ["punctuation", ";"],
["keyword", "TryNextMethod"], ["punctuation", ";"],
["keyword", "Unbind"], ["punctuation", ";"],
["keyword", "and"], ["punctuation", ";"],
["keyword", "atomic"], ["punctuation", ";"],
["keyword", "break"], ["punctuation", ";"],
["keyword", "continue"], ["punctuation", ";"],
["keyword", "do"], ["punctuation", ";"],
["keyword", "elif"], ["punctuation", ";"],
["keyword", "else"], ["punctuation", ";"],
["keyword", "end"], ["punctuation", ";"],
["keyword", "fi"], ["punctuation", ";"],
["keyword", "for"], ["punctuation", ";"],
["keyword", "function"], ["punctuation", ";"],
["keyword", "if"], ["punctuation", ";"],
["keyword", "in"], ["punctuation", ";"],
["keyword", "local"], ["punctuation", ";"],
["keyword", "mod"], ["punctuation", ";"],
["keyword", "not"], ["punctuation", ";"],
["keyword", "od"], ["punctuation", ";"],
["keyword", "or"], ["punctuation", ";"],
["keyword", "quit"], ["punctuation", ";"],
["keyword", "readonly"], ["punctuation", ";"],
["keyword", "readwrite"], ["punctuation", ";"],
["keyword", "rec"], ["punctuation", ";"],
["keyword", "repeat"], ["punctuation", ";"],
["keyword", "return"], ["punctuation", ";"],
["keyword", "then"], ["punctuation", ";"],
["keyword", "until"], ["punctuation", ";"],
["keyword", "while"], ["punctuation", ";"]
]
43 changes: 43 additions & 0 deletions tests/languages/gap/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
0
123134523423423412345132123123432744839127384723987497
+123123
-245435

66/123
66/-123

3.14
6.62606896e-34
.1
.1e1
-.999
1._
1._l

[1..100]

----------------------------------------------------

[
["number", "0"],
["number", "123134523423423412345132123123432744839127384723987497"],
["operator", "+"], ["number", "123123"],
["operator", "-"], ["number", "245435"],

["number", "66"], ["operator", "/"], ["number", "123"],
["number", "66"], ["operator", "/"], ["operator", "-"], ["number", "123"],

["number", "3.14"],
["number", "6.62606896e-34"],
["number", ".1"],
["number", ".1e1"],
["operator", "-"], ["number", ".999"],
["number", "1._"],
["number", "1._l"],

["punctuation", "["],
["number", "1"],
["operator", ".."],
["number", "100"],
["punctuation", "]"]
]
34 changes: 34 additions & 0 deletions tests/languages/gap/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
+ - * / ^ ~
= <> < > <= >=
:= .. ->

!. ![ !{

----------------------------------------------------

[
["operator", "+"],
["operator", "-"],
["operator", "*"],
["operator", "/"],
["operator", "^"],
["operator", "~"],

["operator", "="],
["operator", "<>"],
["operator", "<"],
["operator", ">"],
["operator", "<="],
["operator", ">="],

["operator", ":="],
["operator", ".."],
["operator", "->"],

["operator", "!"],
["punctuation", "."],
["operator", "!"],
["punctuation", "["],
["operator", "!"],
["punctuation", "{"]
]
18 changes: 18 additions & 0 deletions tests/languages/gap/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
( ) [ ] { }
, ; . :

----------------------------------------------------

[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],

["punctuation", ","],
["punctuation", ";"],
["punctuation", "."],
["punctuation", ":"]
]
Loading

0 comments on commit 23cd9b6

Please sign in to comment.