Skip to content

Commit

Permalink
Merge pull request #1 from RunDevelopment/impr-3204
Browse files Browse the repository at this point in the history
Address review comments
  • Loading branch information
edukisto committed Mar 28, 2022
2 parents cd99873 + 9f52675 commit 6e85ff4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 100 deletions.
43 changes: 15 additions & 28 deletions components/prism-odin.js
@@ -1,9 +1,5 @@
(function (Prism) {
var escapes = /\\(?:["'\\abefnrtv]|0[0-7]{2}|U[\dA-Fa-f]{6}|u[\dA-Fa-f]{4}|x[\dA-Fa-f]{2})/.source;

function withEscapes(pattern, flags) {
return RegExp(pattern.replace(/<escapes>/g, escapes), flags);
}
var escapes = /\\(?:["'\\abefnrtv]|0[0-7]{2}|U[\dA-Fa-f]{6}|u[\dA-Fa-f]{4}|x[\dA-Fa-f]{2})/;

Prism.languages.odin = {
/**
Expand Down Expand Up @@ -31,10 +27,10 @@
* Should be found before strings because of '"'"- and '`'`-like sequences.
*/
'char': {
pattern: withEscapes(/'(?:<escapes>|[^\n\r'\\])'/.source),
pattern: /'(?:\\(?:.|[0Uux][0-9A-Fa-f]{1,6})|[^\n\r'\\])'/,
greedy: true,
inside: {
'symbol': withEscapes(/<escapes>/.source)
'symbol': escapes
}
},

Expand All @@ -44,10 +40,10 @@
greedy: true
},
{
pattern: withEscapes(/"(?:<escapes>|[^\n\r"\\])*"/.source),
pattern: /"(?:\\.|[^\n\r"\\])*"/,
greedy: true,
inside: {
'symbol': withEscapes(/<escapes>/.source)
'symbol': escapes
}
}
],
Expand All @@ -57,35 +53,26 @@
alias: 'property'
},

'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]?)/,
'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)/,

'discard': {
pattern: /\b_\b/,
alias: 'keyword'
},

/**
* proc is defined below.
*/
'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/,
'procedure-definition': {
pattern: /\b\w+(?=[ \t]*(?::\s*){2}proc\b)/,
alias: 'function'
},

'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/,

/**
* false, nil, true can be used as procedure names. "_" and keywords can't.
*/
'procedure-name': [
{
pattern: /\b\w+(?=[ \t]*(?::[ \n\r\t]*){2}proc\b)/,
alias: 'function'
},
{
pattern: /\b\w+(?=[ \t]*\()/,
alias: 'function'
}
],

'procedure': {
pattern: /\bproc\b/,
alias: 'keyword'
'procedure-name': {
pattern: /\b\w+(?=[ \t]*\()/,
alias: 'function'
},

'boolean': /\b(?:false|nil|true)\b/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-odin.min.js

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

2 changes: 1 addition & 1 deletion tests/languages/odin/keyword_feature.test
Expand Up @@ -64,7 +64,7 @@ where
["keyword", "or_else"],
["keyword", "or_return"],
["keyword", "package"],
["procedure", "proc"],
["keyword", "proc"],
["keyword", "return"],
["keyword", "struct"],
["keyword", "switch"],
Expand Down
43 changes: 0 additions & 43 deletions tests/languages/odin/not_a_character_feature.test

This file was deleted.

26 changes: 1 addition & 25 deletions tests/languages/odin/not_a_number_feature.test
Expand Up @@ -27,29 +27,5 @@
----------------------------------------------------

[
["number", "0"], "B0\r\n",
["number", "0"], "D0\r\n",
["number", "0"], "I\r\n",
["number", "0"], "O0\r\n",
["number", "0"], "Z0\r\n",
["number", "0"], "b\r\n",
["number", "0"], "b2\r\n",
["number", "0"], "d\r\n",
["number", "0"], "h\r\n",
["number", "0"], "h0\r\n",
["number", "0"], "h00\r\n",
["number", "0"], "h000\r\n",
["number", "0"], "h00000\r\n",
["number", "0"], "h0000000\r\n",
["number", "0"], "h000000000\r\n",
["number", "0"], "h000000000000000\r\n",
["number", "0"], "h00000000000000000\r\n",
["number", "0"], "h_\r\n",
["number", "0"], "o\r\n",
["number", "0"], "o8\r\n",
["number", "0"], "x\r\n",
["number", "0"], "X0\r\n",
["number", "0"], "xG\r\n",
["number", "0"], "z\r\n",
["number", "0"], "zC"
"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"
]
8 changes: 7 additions & 1 deletion tests/languages/odin/operator_feature.test
Expand Up @@ -42,6 +42,9 @@
~
~=

// ranges
0..<10

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

[
Expand Down Expand Up @@ -87,5 +90,8 @@
["operator", "||"],
["operator", "||="],
["operator", "~"],
["operator", "~="]
["operator", "~="],

["comment", "// ranges"],
["number", "0"], ["operator", "..<"], ["number", "10"]
]
18 changes: 17 additions & 1 deletion tests/languages/odin/procedure_feature.test
Expand Up @@ -2,10 +2,26 @@ do_math()
fibonacci()
log10()

cross :: proc(a, b: Vector3) -> Vector3

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

[
["procedure-name", "do_math"], ["punctuation", "("], ["punctuation", ")"],
["procedure-name", "fibonacci"], ["punctuation", "("], ["punctuation", ")"],
["procedure-name", "log10"], ["punctuation", "("], ["punctuation", ")"]
["procedure-name", "log10"], ["punctuation", "("], ["punctuation", ")"],

["procedure-definition", "cross"],
["punctuation", ":"],
["punctuation", ":"],
["keyword", "proc"],
["punctuation", "("],
"a",
["punctuation", ","],
" b",
["punctuation", ":"],
" Vector3",
["punctuation", ")"],
["arrow", "->"],
" Vector3"
]

0 comments on commit 6e85ff4

Please sign in to comment.