Skip to content

Commit 6e85ff4

Browse files
authored
Merge pull request #1 from RunDevelopment/impr-3204
Address review comments
2 parents cd99873 + 9f52675 commit 6e85ff4

File tree

7 files changed

+42
-100
lines changed

7 files changed

+42
-100
lines changed

components/prism-odin.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
(function (Prism) {
2-
var escapes = /\\(?:["'\\abefnrtv]|0[0-7]{2}|U[\dA-Fa-f]{6}|u[\dA-Fa-f]{4}|x[\dA-Fa-f]{2})/.source;
3-
4-
function withEscapes(pattern, flags) {
5-
return RegExp(pattern.replace(/<escapes>/g, escapes), flags);
6-
}
2+
var escapes = /\\(?:["'\\abefnrtv]|0[0-7]{2}|U[\dA-Fa-f]{6}|u[\dA-Fa-f]{4}|x[\dA-Fa-f]{2})/;
73

84
Prism.languages.odin = {
95
/**
@@ -31,10 +27,10 @@
3127
* Should be found before strings because of '"'"- and '`'`-like sequences.
3228
*/
3329
'char': {
34-
pattern: withEscapes(/'(?:<escapes>|[^\n\r'\\])'/.source),
30+
pattern: /'(?:\\(?:.|[0Uux][0-9A-Fa-f]{1,6})|[^\n\r'\\])'/,
3531
greedy: true,
3632
inside: {
37-
'symbol': withEscapes(/<escapes>/.source)
33+
'symbol': escapes
3834
}
3935
},
4036

@@ -44,10 +40,10 @@
4440
greedy: true
4541
},
4642
{
47-
pattern: withEscapes(/"(?:<escapes>|[^\n\r"\\])*"/.source),
43+
pattern: /"(?:\\.|[^\n\r"\\])*"/,
4844
greedy: true,
4945
inside: {
50-
'symbol': withEscapes(/<escapes>/.source)
46+
'symbol': escapes
5147
}
5248
}
5349
],
@@ -57,35 +53,26 @@
5753
alias: 'property'
5854
},
5955

60-
'number': /(?:\b0(?:b[01_]+|d[\d_]+|h_*(?:(?:(?:[\dA-Fa-f]_*){8}){1,2}|(?:[\dA-Fa-f]_*){4})|o[0-7_]+|x[\dA-F_a-f]+|z[\dAB_ab]+)\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][+-]?\d*)?[ijk]?)/,
56+
'number': /\b0(?:b[01_]+|d[\d_]+|h_*(?:(?:(?:[\dA-Fa-f]_*){8}){1,2}|(?:[\dA-Fa-f]_*){4})|o[0-7_]+|x[\dA-F_a-f]+|z[\dAB_ab]+)\b|(?:\b\d+(?:\.(?!\.)\d*)?|\B\.\d+)(?:[Ee][+-]?\d*)?[ijk]?(?!\w)/,
6157

6258
'discard': {
6359
pattern: /\b_\b/,
6460
alias: 'keyword'
6561
},
6662

67-
/**
68-
* proc is defined below.
69-
*/
70-
'keyword': /\b(?:asm|auto_cast|bit_set|break|case|cast|context|continue|defer|distinct|do|dynamic|else|enum|fallthrough|for|foreign|if|import|in|map|matrix|not_in|or_else|or_return|package|return|struct|switch|transmute|typeid|union|using|when|where)\b/,
63+
'procedure-definition': {
64+
pattern: /\b\w+(?=[ \t]*(?::\s*){2}proc\b)/,
65+
alias: 'function'
66+
},
67+
68+
'keyword': /\b(?:asm|auto_cast|bit_set|break|case|cast|context|continue|defer|distinct|do|dynamic|else|enum|fallthrough|for|foreign|if|import|in|map|matrix|not_in|or_else|or_return|package|proc|return|struct|switch|transmute|typeid|union|using|when|where)\b/,
7169

7270
/**
7371
* false, nil, true can be used as procedure names. "_" and keywords can't.
7472
*/
75-
'procedure-name': [
76-
{
77-
pattern: /\b\w+(?=[ \t]*(?::[ \n\r\t]*){2}proc\b)/,
78-
alias: 'function'
79-
},
80-
{
81-
pattern: /\b\w+(?=[ \t]*\()/,
82-
alias: 'function'
83-
}
84-
],
85-
86-
'procedure': {
87-
pattern: /\bproc\b/,
88-
alias: 'keyword'
73+
'procedure-name': {
74+
pattern: /\b\w+(?=[ \t]*\()/,
75+
alias: 'function'
8976
},
9077

9178
'boolean': /\b(?:false|nil|true)\b/,

components/prism-odin.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.

tests/languages/odin/keyword_feature.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464
["keyword", "or_else"],
6565
["keyword", "or_return"],
6666
["keyword", "package"],
67-
["procedure", "proc"],
67+
["keyword", "proc"],
6868
["keyword", "return"],
6969
["keyword", "struct"],
7070
["keyword", "switch"],

tests/languages/odin/not_a_character_feature.test

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/languages/odin/not_a_number_feature.test

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,5 @@
2727
----------------------------------------------------
2828

2929
[
30-
["number", "0"], "B0\r\n",
31-
["number", "0"], "D0\r\n",
32-
["number", "0"], "I\r\n",
33-
["number", "0"], "O0\r\n",
34-
["number", "0"], "Z0\r\n",
35-
["number", "0"], "b\r\n",
36-
["number", "0"], "b2\r\n",
37-
["number", "0"], "d\r\n",
38-
["number", "0"], "h\r\n",
39-
["number", "0"], "h0\r\n",
40-
["number", "0"], "h00\r\n",
41-
["number", "0"], "h000\r\n",
42-
["number", "0"], "h00000\r\n",
43-
["number", "0"], "h0000000\r\n",
44-
["number", "0"], "h000000000\r\n",
45-
["number", "0"], "h000000000000000\r\n",
46-
["number", "0"], "h00000000000000000\r\n",
47-
["number", "0"], "h_\r\n",
48-
["number", "0"], "o\r\n",
49-
["number", "0"], "o8\r\n",
50-
["number", "0"], "x\r\n",
51-
["number", "0"], "X0\r\n",
52-
["number", "0"], "xG\r\n",
53-
["number", "0"], "z\r\n",
54-
["number", "0"], "zC"
30+
"0B0\r\n0D0\r\n0I\r\n0O0\r\n0Z0\r\n0b\r\n0b2\r\n0d\r\n0h\r\n0h0\r\n0h00\r\n0h000\r\n0h00000\r\n0h0000000\r\n0h000000000\r\n0h000000000000000\r\n0h00000000000000000\r\n0h_\r\n0o\r\n0o8\r\n0x\r\n0X0\r\n0xG\r\n0z\r\n0zC"
5531
]

tests/languages/odin/operator_feature.test

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
~
4343
~=
4444

45+
// ranges
46+
0..<10
47+
4548
----------------------------------------------------
4649

4750
[
@@ -87,5 +90,8 @@
8790
["operator", "||"],
8891
["operator", "||="],
8992
["operator", "~"],
90-
["operator", "~="]
93+
["operator", "~="],
94+
95+
["comment", "// ranges"],
96+
["number", "0"], ["operator", "..<"], ["number", "10"]
9197
]

tests/languages/odin/procedure_feature.test

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@ do_math()
22
fibonacci()
33
log10()
44

5+
cross :: proc(a, b: Vector3) -> Vector3
6+
57
----------------------------------------------------
68

79
[
810
["procedure-name", "do_math"], ["punctuation", "("], ["punctuation", ")"],
911
["procedure-name", "fibonacci"], ["punctuation", "("], ["punctuation", ")"],
10-
["procedure-name", "log10"], ["punctuation", "("], ["punctuation", ")"]
12+
["procedure-name", "log10"], ["punctuation", "("], ["punctuation", ")"],
13+
14+
["procedure-definition", "cross"],
15+
["punctuation", ":"],
16+
["punctuation", ":"],
17+
["keyword", "proc"],
18+
["punctuation", "("],
19+
"a",
20+
["punctuation", ","],
21+
" b",
22+
["punctuation", ":"],
23+
" Vector3",
24+
["punctuation", ")"],
25+
["arrow", "->"],
26+
" Vector3"
1127
]

0 commit comments

Comments
 (0)