(function (hiril) { // // hiril - Radiance IL Syntax Highlighter // // Copyright (c) 2020-2025 Alexis Sellier // const selector = hiril || '.language-ril'; const keywords = ['fn', 'data', 'extern', 'mut', 'align']; const instrs = [ 'reserve', 'load', 'sload', 'store', 'blit', 'copy', 'add', 'sub', 'mul', 'sdiv', 'udiv', 'srem', 'urem', 'neg', 'eq', 'ne', 'slt', 'sge', 'ult', 'uge', 'and', 'or', 'xor', 'shl', 'sshr', 'ushr', 'not', 'zext', 'sext', 'call', 'ret', 'jmp', 'switch', 'unreachable', 'ecall', 'ebreak' ]; const branchOps = ['br.eq', 'br.ne', 'br.slt', 'br.ult']; const dataItems = ['str', 'sym', 'undef']; const types = ['w8', 'w16', 'w32', 'w64']; // Syntax definition. // // The key becomes the class name of the span around the matched block of code. const syntax = [ ['comment', /(\/\/[^\n]*)/g], ['string' , /("[^"]*")/g], ['reg' , /(%[0-9]+)/g], ['label' , /(@[A-Za-z_][A-Za-z#0-9_]*)/g], ['symbol' , /(\$[A-Za-z_][A-Za-z0-9_]*)/g], ['number' , /\b(-?[0-9]+|0x[a-fA-F0-9]+)\b/g], ['delim' , /([{}();:,])/g], ['keyword', new RegExp('\\b(' + keywords.join('|') + ')\\b', 'g')], ['instr' , new RegExp('\\b(' + branchOps.join('|').replace(/\./g, '\\.') + ')\\b', 'g')], ['instr' , new RegExp('\\b(' + instrs.join('|') + ')\\b', 'g')], ['type' , new RegExp('\\b(' + dataItems.join('|') + ')\\b', 'g')], ['type' , new RegExp('\\b(' + types.join('|') + ')\\b', 'g')], ]; const table = {}; // Encode ASCII characters to Braille to avoid conflicts between patterns. const encode = (str) => { const encoded = [...str].map(c => c.charCodeAt(0) <= 127 ? String.fromCharCode(c.charCodeAt(0) + 0x2800) : c ).join(''); table[encoded] = str; return encoded; }; // Decode Braille back to ASCII. const decode = (str) => table[str] || [...str].map(c => { const code = c.charCodeAt(0) - 0x2800; return code >= 0 && code <= 127 ? String.fromCharCode(code) : c; }).join(''); // Escape HTML special characters. const escape = (str) => str.replace(//g, '>'); // Highlight all matching elements. for (const node of document.querySelectorAll(selector)) { for (const child of node.childNodes) { if (child.nodeType !== Node.TEXT_NODE) continue; if (/^\$\s/.test(child.nodeValue.trim())) continue; // Skip shell snippets. for (const [cls, re] of syntax) { child.nodeValue = child.nodeValue.replace(re, (_, m) => '\u00ab' + encode(cls) + '\u00b7' + encode(m) + '\u00b7' + encode(cls) + '\u00bb' ); } } node.innerHTML = node.innerHTML.replace( /\u00ab(.+?)\u00b7(.+?)\u00b7\1\u00bb/g, (_, name, value) => { value = value.replace(/\u00ab[^\u00b7]+\u00b7|\u00b7[^\u00bb]+\u00bb/g, ''); return '' + escape(decode(value)) + ''; } ); } })(window.hiril);