Skip to content

Commit fd5ce1a

Browse files
sebastiaanspeckkrn-sebastiaan
authored andcommitted
Apply fixes for Magik language
1 parent 29e1beb commit fd5ce1a

13 files changed

Lines changed: 75 additions & 83 deletions

src/languages/magik.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,18 @@ export default {
2222
greedy: true
2323
},
2424

25-
'declaration': [
26-
{ pattern: /(\b_package\s+).*/i, lookbehind: true },
27-
{ pattern: /(\b_global\s+)(?!_)\w+/i, lookbehind: true },
28-
{ pattern: /(\b_constant\s+)[a-z_]+/i, lookbehind: true }
29-
],
30-
3125
'pragma': {
3226
pattern: /_pragma.*/,
33-
alias: 'prolog',
34-
inside: {
35-
'modifier': /classify_level|topic|usage/,
36-
'pragma-punctuation': { pattern: /[={},]/ }
37-
}
27+
alias: 'prolog'
3828
},
3929

40-
'number': /\b\d+(?:\.\d+)?(?:[e&][+-]?\d+)?\b|\b(?:[2-9]|[12]\d|3[0-6])r[a-z0-9]+\b/i,
41-
4230
'symbol': {
4331
pattern: /(^|\W):(?:\|[^|]*\||\\.|[\w?!])+/,
4432
lookbehind: true
4533
},
4634

35+
'number': /\b\d+(?:\.\d+)?(?:[e&][+-]?\d+)?\b|\b(?:[2-9]|[12]\d|3[0-6])r[a-z0-9]+\b/i,
36+
4737
'operator': [
4838
/_(?:and|andif|or|orif|xor)<</i, /(?:\*\*\^?|\*\^?|\/\^?|_mod\^?|_div\^?|-\^?|\+\^?)<</i, /\^?<</, // assignment operators
4939
/<>/, />=/, /<=/, /</, /~=/, /=/, // relational operators
@@ -56,8 +46,18 @@ export default {
5646
{ pattern: /\b_(?:div|mod)\b/i, alias: 'keyword' } // math
5747
],
5848

49+
'declaration': [
50+
{ pattern: /(\b_package\s+).*/i, lookbehind: true },
51+
{ pattern: /(\b_global\s+)(?!_)\w+/i, lookbehind: true },
52+
{ pattern: /(\b_constant\s+)(?!_)\w+/i, lookbehind: true }
53+
],
54+
55+
'keyword-variable': {
56+
pattern: /\b_(?:class|dynamic|global|import|local)\b/i,
57+
alias: 'keyword'
58+
},
59+
5960
'keyword': [
60-
/\b_(?:class|dynamic|global|import|local)\b/i, // variables
6161
/\b_(?:block|endblock)\b/i, // block
6262
/\b_(?:elif|else|endif|if|then)\b/i, // if
6363
/\b_(?:and|andif|not|or|orif|xor)\b/i, // logical operators
@@ -75,7 +75,7 @@ export default {
7575
],
7676

7777
'slot': {
78-
pattern: /(^|[\s({])\.\s*[a-z_]+/i,
78+
pattern: /(^|[\s({])\.\s*[a-z][\w?!]+/i,
7979
lookbehind: true
8080
},
8181

@@ -111,8 +111,8 @@ export default {
111111
'function': [
112112
/\b_(?:abstract|endmethod|iter|method|private)\b/i, // method keywords
113113
/\b_(?:endproc|proc)\b/i, // procedure
114-
{ pattern: /(\.)\s*\|[a-z_]\w*[!?]?\|/, lookbehind: true }, // encased |methodNames|
115-
{ pattern: /(\.)\s*[a-z_]\w*[!?]?/, lookbehind: true }, // methods
114+
{ pattern: /(\.)\s*\|[a-z][\w?!]*\|/, lookbehind: true }, // encased |methodNames|
115+
{ pattern: /(\.)\s*[a-z][\w?!]*/, lookbehind: true }, // methods
116116
],
117117

118118
'variable': [

tests/languages/magik/constant_feature.test

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
_constant something
2-
_global _constant something
3-
_global _constant gis_program_manager << _unset
1+
_block
2+
_constant something << _unset
3+
_constant max_size << 1
4+
_constant _local max_size << 1
5+
_local _constant max_size << 1
6+
_endblock
47
_global _constant !current_view! << _unset
5-
_constant max_size << 1
6-
_constant _local max_size << 1
7-
_local _constant max_size << 1
8+
_global _constant gis_program_manager << _unset
89

910
----------------------------------------------------
1011

1112
[
12-
["constant", "_constant"], ["declaration", "something"],
13-
["keyword", "_global"], ["constant", "_constant"], ["declaration", "something"],
14-
["keyword", "_global"], ["constant", "_constant"], ["declaration", "gis_program_manager"], ["operator", "<<"], ["unset", "_unset"],
15-
["keyword", "_global"], ["constant", "_constant"], ["variable", "!current_view!"], ["operator", "<<"], ["unset", "_unset"],
16-
["constant", "_constant"], ["declaration", "max_size"], ["operator", "<<"], ["number", "1"],
17-
["constant", "_constant"], ["declaration", "_local"], ["variable", "max_size"], ["operator", "<<"], ["number", "1"],
18-
["keyword", "_local"], ["constant", "_constant"], ["declaration", "max_size"], ["operator", "<<"], ["number", "1"]
13+
["keyword", "_block"],
14+
["constant", "_constant"], ["declaration", "something"], ["operator", "<<"], ["unset", "_unset"],
15+
["constant", "_constant"], ["declaration", "max_size"], ["operator", "<<"], ["number", "1"],
16+
["constant", "_constant"], ["keyword-variable", "_local"], ["variable", "max_size"], ["operator", "<<"], ["number", "1"],
17+
["keyword-variable", "_local"], ["constant", "_constant"], ["declaration", "max_size"], ["operator", "<<"], ["number", "1"],
18+
["keyword", "_endblock"],
19+
["keyword-variable", "_global"], ["constant", "_constant"], ["variable", "!current_view!"], ["operator", "<<"], ["unset", "_unset"],
20+
["keyword-variable", "_global"], ["constant", "_constant"], ["declaration", "gis_program_manager"], ["operator", "<<"], ["unset", "_unset"]
1921
]
2022

2123
----------------------------------------------------

tests/languages/magik/declaration_feature.test

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_package user
2+
_global some_var
23
_global some_var; some_var << 1
34
_constant yippie << 2
45
_global _constant !done_meas_follow_nodes! << _unset
@@ -7,9 +8,10 @@ _global _constant !done_meas_follow_nodes! << _unset
78

89
[
910
["builtin", "_package"], ["declaration", "user"],
10-
["keyword", "_global"], ["declaration", "some_var"], ["punctuation", ";"], ["variable", "some_var"], ["operator", "<<"], ["number", "1"],
11-
["constant", "_constant"], ["declaration", "yippie"], ["operator", "<<"], ["number", "2"],
12-
["keyword", "_global"], ["constant", "_constant"], ["variable", "!done_meas_follow_nodes!"], ["operator", "<<"], ["unset", "_unset"]
11+
["keyword-variable", "_global"], ["declaration", "some_var"],
12+
["keyword-variable", "_global"], ["declaration", "some_var"], ["punctuation", ";"], ["variable", "some_var"], ["operator", "<<"], ["number", "1"],
13+
["constant", "_constant"], ["declaration", "yippie"], ["operator", "<<"], ["number", "2"],
14+
["keyword-variable", "_global"], ["constant", "_constant"], ["variable", "!done_meas_follow_nodes!"], ["operator", "<<"], ["unset", "_unset"]
1315
]
1416

1517
----------------------------------------------------

tests/languages/magik/function_feature.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ variable.method_name?
66
variable.method_name()
77
variable.|methodName|()
88
object.method
9+
object.int!method
910
object.getName
1011
object.|getName|
1112
object.method<< _unset
@@ -26,6 +27,7 @@ _clone.init()
2627
["variable", "variable"], ".", ["function", "method_name"], ["punctuation", "("], ["punctuation", ")"],
2728
["variable", "variable"], ".", ["function", "|methodName|"], ["punctuation", "("], ["punctuation", ")"],
2829
["variable", "object"], ".", ["function", "method"],
30+
["variable", "object"], ".", ["function", "int!method"],
2931
["variable", "object"], ".", ["function", "getName"],
3032
["variable", "object"], ".", ["function", "|getName|"],
3133
["variable", "object"], ".", ["function", "method"], ["operator", "<<"], ["unset", "_unset"],

tests/languages/magik/global-reference_feature.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
[
99
["global-reference", "@gis_program_manager"],
10-
["punctuation", "("], ["global-reference", "@gis_program_manager"], ["punctuation", ")"],
11-
["punctuation", "{"], ["global-reference", "@gis_program_manager"], ["punctuation", "}"],
12-
["punctuation", ","], ["global-reference", "@gis_program_manager"]
10+
["punctuation", "("], ["global-reference", "@gis_program_manager"], ["punctuation", ")"],
11+
["punctuation", "{"], ["global-reference", "@gis_program_manager"], ["punctuation", "}"],
12+
["punctuation", ","], ["global-reference", "@gis_program_manager"]
1313
]
1414

1515
----------------------------------------------------
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
_class _dynamic _global _import _local
2+
3+
----------------------------------------------------
4+
5+
[
6+
["keyword-variable", "_class"], ["keyword-variable", "_dynamic"], ["keyword-variable", "_global"], ["keyword-variable", "_import"], ["keyword-variable", "_local"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks for keyword variables.

tests/languages/magik/keyword_feature.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
_class _dynamic _global _import _local
21
_block _endblock
32
_elif _else _endif _if _then
43
_and _andif _not _or _orif _xor
@@ -17,7 +16,6 @@ _allresults _gather _optional _scatter
1716
----------------------------------------------------
1817

1918
[
20-
["keyword", "_class"], ["keyword", "_dynamic"], ["keyword", "_global"], ["keyword", "_import"], ["keyword", "_local"],
2119
["keyword", "_block"], ["keyword", "_endblock"],
2220
["keyword", "_elif"], ["keyword", "_else"], ["keyword", "_endif"], ["keyword", "_if"], ["keyword", "_then"],
2321
["keyword", "_and"], ["keyword", "_andif"], ["keyword", "_not"], ["keyword", "_or"], ["keyword", "_orif"], ["keyword", "_xor"],

tests/languages/magik/pragma.test

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
_pragma(classify_level=basic, usage=restricted, topic=prism)
2+
_pragma(classify_level=advanced, usage=unrestricted, topic=different_prism)
3+
4+
----------------------------------------------------
5+
6+
[
7+
["pragma", "_pragma(classify_level=basic, usage=restricted, topic=prism)"],
8+
["pragma", "_pragma(classify_level=advanced, usage=unrestricted, topic=different_prism)"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for pragmas.

tests/languages/magik/slot_feature.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.slot_name
2+
.embedded?
23
some_class.some_method(.slot_name)
34
some_class.some_method(_optional .slot_name, .another_slot_name)
45
{.slot_name, some_other_variable, .another_slot_name}
@@ -8,11 +9,11 @@ _global some_variable; some_variable << .slot_name
89

910
[
1011
["slot", ".slot_name"],
12+
["slot", ".embedded?"],
1113
["variable", "some_class"], ".", ["function", "some_method"], ["punctuation", "("], ["slot", ".slot_name"], ["punctuation", ")"],
1214
["variable", "some_class"], ".", ["function", "some_method"], ["punctuation", "("], ["keyword", "_optional"], ["slot", ".slot_name"], ["punctuation", ","], ["slot", ".another_slot_name"], ["punctuation", ")"],
1315
["punctuation", "{"], ["slot", ".slot_name"], ["punctuation", ","], ["variable", "some_other_variable"], ["punctuation", ","], ["slot", ".another_slot_name"], ["punctuation", "}"],
14-
["keyword", "_global"], ["declaration", "some_variable"], ["punctuation", ";"], ["variable", "some_variable"], ["operator", "<<"], ["slot", ".slot_name"]
15-
16+
["keyword-variable", "_global"], ["declaration", "some_variable"], ["punctuation", ";"], ["variable", "some_variable"], ["operator", "<<"], ["slot", ".slot_name"]
1617
]
1718

1819
----------------------------------------------------

0 commit comments

Comments
 (0)