From b1ea96438c5d37fa608caf97329c9a5c8097e995 Mon Sep 17 00:00:00 2001 From: xoxorwr Date: Sun, 10 Aug 2025 08:12:16 +0200 Subject: [PATCH 1/2] Add support for the Odin programming language --- src/languages/odin.js | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/languages/odin.js diff --git a/src/languages/odin.js b/src/languages/odin.js new file mode 100644 index 0000000000..b33ab7b3b1 --- /dev/null +++ b/src/languages/odin.js @@ -0,0 +1,123 @@ +/* +Language: Odin +Author: xoxorwr +Source: https://odin-lang.org/ (overview) & package builtin (pkg.odin-lang.org) +*/ + +export default function(hljs) { + const LITERALS = [ + "true", + "false", + "nil" + ]; + + // Common built-in procedures / predeclared procs (pulled from package builtin) + const BUILT_INS = [ + "len", "cap", "size_of", "align_of", "offset_of", "offset_of_selector", "offset_of_member", "offset_of_by_string", + "type_of", "type_info_of", "typeid_of", + "raw_data", "copy", "copy_slice", "copy_from_string", + "make", "new", "new_clone", "make_slice", "make_dynamic_array", "make_map", + "append", "append_elems", "append_string", "append_elem", + "inject_at", "inject_at_elems", "assign_at", "assign_at_elems", + "pop", "pop_safe", "pop_front", "pop_front_safe", + "delete", "delete_dynamic_array", "delete_slice", "delete_map", + "reserve", "reserve_map", "shrink_map", "resize_dynamic_array", + "unordered_remove", "ordered_remove", "remove_range", + "map_insert", "map_upsert", "map_entry", + "soa_zip", "soa_unzip", "raw_soa_footer_slice", "raw_soa_footer_dynamic_array", + "min", "max", "abs", "clamp", "assert", "ensure", "panic", "unimplemented", + "swizzle", "complex", "quaternion", "real", "imag", "conj" + ]; + + // Predeclared type names (from package builtin). Also include 'matrix' which is a built-in type constructor. + const TYPES = [ + "byte","bool","b8","b16","b32","b64", + "i8","u8","i16","u16","i32","u32","i64","u64", + "i128","u128","rune", + "f16","f32","f64", + "complex32","complex64","complex128", + "quaternion64","quaternion128","quaternion256", + "int","uint","uintptr","rawptr","string","cstring","typeid","any", + "i16le","u16le","i32le","u32le","i64le","u64le","i128le","u128le", + "i16be","u16be","i32be","u32be","i64be","u64be","i128be","u128be", + "f16le","f32le","f64le","f16be","f32be","f64be", + "Maybe","Objc_Block", + "matrix" + ]; + + const KWS = [ + "package","import","foreign","proc","struct","enum","union","map","matrix","matrix", + "matrix","matrix","type","package","return","if","else","for","do","when","where", + "asm","context","dynamic","or_else","or_return","not_in","in","using","break","continue", + "defer","fallthrough","switch","case","transmute","cast","auto_cast","distinct","using" + ]; + + const KEYWORDS = { + keyword: KWS, + type: TYPES, + literal: LITERALS, + built_in: BUILT_INS + }; + + return { + name: 'Odin', + aliases: ['odin'], + keywords: KEYWORDS, + illegal: ' Date: Sun, 10 Aug 2025 08:20:30 +0200 Subject: [PATCH 2/2] Add test case --- test/detect/odin/default.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/detect/odin/default.txt diff --git a/test/detect/odin/default.txt b/test/detect/odin/default.txt new file mode 100644 index 0000000000..859774f48f --- /dev/null +++ b/test/detect/odin/default.txt @@ -0,0 +1,22 @@ +package main + +import "core:fmt" + +main :: proc() { + program := "+ + * 😃 - /" + accumulator := 0 + + for token in program { + switch token { + case '+': accumulator += 1 + case '-': accumulator -= 1 + case '*': accumulator *= 2 + case '/': accumulator /= 2 + case '😃': accumulator *= accumulator + case: // Ignore everything else + } + } + + fmt.printf("The program \"%s\" calculates the value %d\n", + program, accumulator) +}