Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@
"title": "Lua",
"owner": "Golmote"
},
"magik": {
"title": "Magik",
"owner": "sebastiaanspeck"
},
"magma": {
"title": "Magma (CAS)",
"owner": "RunDevelopment"
Expand Down
82 changes: 82 additions & 0 deletions src/languages/magik.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/** @type {import('../types.d.ts').LanguageProto<'magik'>} */
export default {
id: 'magik',
grammar: {
'comment': [
{ pattern: /##.*/, greedy: true }, // documentation
{ pattern: /#.*/, greedy: true } // comment
],

'keyword': [
/\b_(?:class|constant|dynamic|global|import|local)\b/, // variables,
/\b_(?:abstract|endmethod|iter|method|private)\b/, // method
/\b_(?:endproc|proc)\b/, // procedure
/\b_(?:block|endblock)\b/, // block
/\b_(?:elif|else|endif|if|then)\b/, // if
/\b_(?:continue|endloop|finally|for|leave|loop|loopbody|over|while)\b/, // loop
/\b_(?:default|handling)\b/, // handling
/\b_(?:catch|endcatch)\b/, // catch
/\b_throw\b/, // throw
/\b_primitive\b/, // primitive
/\b_(?:endtry|try|when)\b/, // try
/\b_(?:endprotect|locking|protect|protection)\b/, // protect
/\b_(?:endlock|lock)\b/, // lock
/\b_with\b/ // standalone since _finally, _handling, _throw, _try, _leave and _continue all can have this
],

'builtin': [
/\b_(?:clone|package|self|super|thisthread|unset)\b/
],

'boolean': /\b_(?:false|maybe|true)\b/,

'char': {
pattern: /%(?:[a-z][\w?!]*|.)/i,
greedy: true
},

'variable': [
/\|![\w?!]+!\|/, /\|![\w?!]+\|!/, /!\|[\w?!]+\|!/, /!\|\|!/, /![a-z][\w?!]*!/i, // dynamic variable
/[a-z_]\w*:[a-z_]\w*/i, // global variable
/@(?:[a-z_]\w*:)?[a-z_]\w*/i, // global reference
],

'symbol': /:(?:\|[^|]*\||[\w?!])+/,

'number': {
pattern: /\b\d+(?:\.\d+)?(?:[e&][+-]?\d+)?\b|\b(?:[2-9]|[12]\d|3[0-6])r[a-z0-9]+\b/i,
greedy: true
},

'string': {
pattern: /"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'/,
greedy: true
},

'regex': {
pattern: /\/(?:\/|(?:\\.|[^\\/\r\n])+\/[qisdlmuCX]*)/,
greedy: true
},

'operator': [
/\^<</, /<</, { pattern: /_(?:and|andif|or|orif|xor)<</, greedy: true }, { pattern: /(?:\*\*\^?|\*\^?|\/\^?|_mod\^?|_div\^?|-\^?|\+\^?)<</, greedy: true }, // assignment operators
/>>/, /\b_return\b/, // return operators
/\b_(?:cf|is|isnt)\b/, /<>/, />=/, /<=/, /</, />/, /~=/, /=/, // relational operators
/\b_(?:and|andif|or|orif|xor)\b/, // logical operators
/\*\*/, /\*/, /\//, /\b_(?:div|mod)\b/, // arithmetic operators
/\+/, /-/, /\b_not\b/, /~/, // unary operators
],

'property': {
pattern: /_pragma.*/,
greedy: true,
inside: {
'modifier': /classify_level|topic|usage/,
'punctuation': /[={},]/
}
},

'punctuation': /[[\](){},;]/

}
};
15 changes: 15 additions & 0 deletions tests/languages/magik/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
_false
_maybe
_true

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

[
["boolean", "_false"],
["boolean", "_maybe"],
["boolean", "_true"]
]

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

Checks for booleans.
17 changes: 17 additions & 0 deletions tests/languages/magik/builtin_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_clone
_package
_self
_super

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

[
["builtin", "_clone"],
["builtin", "_package"],
["builtin", "_self"],
["builtin", "_super"]
]

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

Checks for builtins.
31 changes: 31 additions & 0 deletions tests/languages/magik/char_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%a
%.
%,
%-
%?
%/
%|
%1
%space
%newline
%tab

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

[
["char", "%a"],
["char", "%."],
["char", "%,"],
["char", "%-"],
["char", "%?"],
["char", "%/"],
["char", "%|"],
["char", "%1"],
["char", "%space"],
["char", "%newline"],
["char", "%tab"]
]

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

Checks for char tokens.
41 changes: 41 additions & 0 deletions tests/languages/magik/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Single line 'comment'

# Multi
# Line
# Comment

_block
1 _and # comment
2
_endblock

## documentation

## multi
## line
## documentation

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

[
["comment", "# Single line 'comment'"],

["comment", "# Multi"],
["comment", "# Line"],
["comment", "# Comment"],

["keyword", "_block"],
["number", "1"], ["operator", "_and"], ["comment", "# comment"],
["number", "2"],
["keyword", "_endblock"],

["comment", "## documentation"],

["comment", "## multi"],
["comment", "## line"],
["comment", "## documentation"]
]

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

Checks for comments.
77 changes: 77 additions & 0 deletions tests/languages/magik/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
_class _constant _dynamic _global _import _local
_abstract _private _iter _method _endmethod
_proc _endproc
_block _endblock
_if _elif _then _else _endif
_for _over _loop _endloop _continue _finally _leave _loopbody _while
_default _handling
_catch _endcatch
_throw
_primitive
_try _when _endtry
_protect _locking _protection _endprotect
_lock _endlock
_with

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

[
["keyword", "_class"],
["keyword", "_constant"],
["keyword", "_dynamic"],
["keyword", "_global"],
["keyword", "_import"],
["keyword", "_local"],

["keyword", "_abstract"],
["keyword", "_private"],
["keyword", "_iter"],
["keyword", "_method"],
["keyword", "_endmethod"],

["keyword", "_proc"],
["keyword", "_endproc"],

["keyword", "_block"],
["keyword", "_endblock"],

["keyword", "_if"],
["keyword", "_elif"],
["keyword", "_then"],
["keyword", "_else"],
["keyword", "_endif"],

["keyword", "_for"],
["keyword", "_over"],
["keyword", "_loop"],
["keyword", "_endloop"],
["keyword", "_continue"],
["keyword", "_finally"],
["keyword", "_leave"],
["keyword", "_loopbody"],
["keyword", "_while"],

["keyword", "_default"],
["keyword", "_handling"],

["keyword", "_catch"],
["keyword", "_endcatch"],

["keyword", "_throw"],

["keyword", "_primitive"],

["keyword", "_try"],
["keyword", "_when"],
["keyword", "_endtry"],

["keyword", "_protect"],
["keyword", "_locking"],
["keyword", "_protection"],
["keyword", "_endprotect"],

["keyword", "_lock"],
["keyword", "_endlock"],

["keyword", "_with"]
]
17 changes: 17 additions & 0 deletions tests/languages/magik/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
123
3.14
1e10
16r1A2B

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

[
["number", "123"],
["number", "3.14"],
["number", "1e10"],
["number", "16r1A2B"]
]

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

Checks for numbers.
Loading