Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
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 @@ -919,6 +919,10 @@
"title": "OCaml",
"owner": "Golmote"
},
"odin": {
"title": "Odin",
"owner": "edukisto"
},
"opencl": {
"title": "OpenCL",
"require": "c",
Expand Down
61 changes: 61 additions & 0 deletions components/prism-odin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
(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);
}

Prism.languages.odin = {
/**
* The current implementation of multiline comments doesn't support nesting.
*/
'comment': [
{
pattern: /\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
{
pattern: /#![^\n\r]*/,
greedy: true
},
{
pattern: /\/\/[^\n\r]*/,
greedy: true
}
],

/**
* Should be found before strings because of '"'"- and '`'`-like sequences.
*/
'char': {
pattern: withEscapes(/'(?:<escapes>|[^\n\r'\\])'/.source),
inside: {
'symbol': withEscapes(/<escapes>/.source)
}
},

'string': [
{
pattern: /`[^`]*`/,
greedy: true
},
{
pattern: withEscapes(/"(?:<escapes>|[^\n\r"\\])*"/.source),
greedy: true,
inside: {
'symbol': withEscapes(/<escapes>/.source)
}
}
],

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

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

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

'function': /\b\w+(?=\()/,

'operator': /\+\+|---?|->|\.\.[<=]?|(?:&~|[-!*+/=~]|[%&<>|]{1,2})=?|[#$(),.:;?@\[\]^{}]/
};
}(Prism));
1 change: 1 addition & 0 deletions components/prism-odin.min.js

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

12 changes: 12 additions & 0 deletions examples/prism-odin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h2>Example</h2>

<pre><code>package main

import "core:fmt"

main :: proc() {
i: int
for i := 0; i &lt; 100; i += 1 {
fmt.println(i, " bottles of beer on the wall.\n")
}
}</code></pre>
13 changes: 13 additions & 0 deletions tests/languages/odin/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
_
false
nil
true

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

[
["boolean", "_"],
["boolean", "false"],
["boolean", "nil"],
["boolean", "true"]
]
147 changes: 147 additions & 0 deletions tests/languages/odin/character_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
' '
'!'
'"'
'0'
'\"'
'\''
'\000'
'\077'
'\U000000'
'\UFFFFFF'
'\Uffffff'
'\\'
'\a'
'\b'
'\e'
'\f'
'\n'
'\r'
'\t'
'\u0000'
'\uFFFF'
'\uffff'
'\v'
'\x00'
'\xFF'
'\xff'
'a'

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

[
["char", ["' '"]],
["char", ["'!'"]],
["char", ["'\"'"]],
["char", ["'0'"]],
["char", [
"'",
["symbol", "\\\""],
"'"
]],
["char", [
"'",
["symbol", "\\'"],
"'"
]],
["char", [
"'",
["symbol", "\\000"],
"'"
]],
["char", [
"'",
["symbol", "\\077"],
"'"
]],
["char", [
"'",
["symbol", "\\U000000"],
"'"
]],
["char", [
"'",
["symbol", "\\UFFFFFF"],
"'"
]],
["char", [
"'",
["symbol", "\\Uffffff"],
"'"
]],
["char", [
"'",
["symbol", "\\\\"],
"'"
]],
["char", [
"'",
["symbol", "\\a"],
"'"
]],
["char", [
"'",
["symbol", "\\b"],
"'"
]],
["char", [
"'",
["symbol", "\\e"],
"'"
]],
["char", [
"'",
["symbol", "\\f"],
"'"
]],
["char", [
"'",
["symbol", "\\n"],
"'"
]],
["char", [
"'",
["symbol", "\\r"],
"'"
]],
["char", [
"'",
["symbol", "\\t"],
"'"
]],
["char", [
"'",
["symbol", "\\u0000"],
"'"
]],
["char", [
"'",
["symbol", "\\uFFFF"],
"'"
]],
["char", [
"'",
["symbol", "\\uffff"],
"'"
]],
["char", [
"'",
["symbol", "\\v"],
"'"
]],
["char", [
"'",
["symbol", "\\x00"],
"'"
]],
["char", [
"'",
["symbol", "\\xFF"],
"'"
]],
["char", [
"'",
["symbol", "\\xff"],
"'"
]],
["char", ["'a'"]]
]
90 changes: 90 additions & 0 deletions tests/languages/odin/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
*/
/* A comment */
/*!*/
/*""*/
/*"\a"*/
/*#!*/
/*' '*/
/*'\a'*/
/**/
/*//*/
/*0*/
/*``*/
/*`\a`*/
/*false*/
/*if*/
Not a comment /* A comment */
#!
#! A comment
#!!
#!""
#!#!
#!' '
#!/**/
#!//
#!0
#!``
#!false
#!if
Not a comment #! A comment
//
// A comment
//!
//""
//#!
//' '
///**/
////
//0
//``
//false
//if
Not a comment // A comment

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

[
["comment", "/*\r\n*/"],
["comment", "/* A comment */"],
["comment", "/*!*/"],
["comment", "/*\"\"*/"],
["comment", "/*\"\\a\"*/"],
["comment", "/*#!*/"],
["comment", "/*' '*/"],
["comment", "/*'\\a'*/"],
["comment", "/**/"],
["comment", "/*//*/"],
["comment", "/*0*/"],
["comment", "/*``*/"],
["comment", "/*`\\a`*/"],
["comment", "/*false*/"],
["comment", "/*if*/"],
"\r\nNot a comment ", ["comment", "/* A comment */"],
["comment", "#!"],
["comment", "#! A comment"],
["comment", "#!!"],
["comment", "#!\"\""],
["comment", "#!#!"],
["comment", "#!' '"],
["comment", "#!/**/"],
["comment", "#!//"],
["comment", "#!0"],
["comment", "#!``"],
["comment", "#!false"],
["comment", "#!if"],
"\r\nNot a comment ", ["comment", "#! A comment"],
["comment", "//"],
["comment", "// A comment"],
["comment", "//!"],
["comment", "//\"\""],
["comment", "//#!"],
["comment", "//' '"],
["comment", "///**/"],
["comment", "////"],
["comment", "//0"],
["comment", "//``"],
["comment", "//false"],
["comment", "//if"],
"\r\nNot a comment ", ["comment", "// A comment"]
]
9 changes: 9 additions & 0 deletions tests/languages/odin/failed_multiline_comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*/**/*/

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

[
["comment", "/*/**/"],
["operator", "*"],
["operator", "/"]
]
Loading