Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Odin #3280

Closed
wants to merge 17 commits into from
Closed
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
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
99 changes: 99 additions & 0 deletions components/prism-odin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
(function (Prism) {
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 = {
/**
* The current implementation supports only 1 level of nesting.
*
* @author Michael Schmidt
* @author edukisto
*/
'comment': [
{
pattern: /\/\*(?:[^/*]|\/(?!\*)|\*(?!\/)|\/\*(?:\*(?!\/)|[^*])*(?:\*\/|$))*(?:\*\/|$)/,
greedy: true
},
{
pattern: /#![^\n\r]*/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true
},
{
pattern: /\/\/[^\n\r]*/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
greedy: true
}
],

/**
* Should be found before strings because of '"'"- and '`'`-like sequences.
*/
'char': {
pattern: /'(?:\\(?:.|[0Uux][0-9A-Fa-f]{1,6})|[^\n\r'\\])'/,
greedy: true,
inside: {
'symbol': escapes
}
},

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

'directive': {
pattern: /#\w+/,
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]?(?!\w)/,

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

'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]*\()/,
alias: 'function'
},

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

'constant-parameter-sign': {
pattern: /\$/,
alias: 'important'
},

'undefined': {
pattern: /---/,
alias: 'operator'
},

'arrow': {
pattern: /->/,
alias: 'punctuation'
},

'operator': /\+\+|--|\.\.[<=]?|(?:&~|[-!*+/=~]|[%&<>|]{1,2})=?|[?^]/,

'punctuation': /[(),.:;@\[\]{}]/
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
};
}(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>
11 changes: 11 additions & 0 deletions tests/languages/odin/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
false
nil
true

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

[
["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'"]]
]
92 changes: 92 additions & 0 deletions tests/languages/odin/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!
#! A comment
#!!
#!""
#!#!
#!' '
#!/**/
#!//
#!0
#!``
#!false
#!if
/*
*/
/* 1 /* 2 */ 1 */
/* A comment */
/*!*/
/*""*/
/*"\a"*/
/*#!*/
/*' '*/
/*'\a'*/
/**/
/*/**/*/
/*0*/
/*`\a`*/
/*``*/
/*false*/
/*if*/
//
// A comment
//!
//""
//#!
//' '
///**/
////
//0
//``
//false
//if
Not a comment #! A comment
Not a comment /* A comment */
Not a comment // A comment
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

[
["constant-parameter-sign", "$"]
]
9 changes: 9 additions & 0 deletions tests/languages/odin/directive_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#assert
#no_bounds_check

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

[
["directive", "#assert"],
["directive", "#no_bounds_check"]
]
Loading