Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 05:17, 20 February 2026 by TK421 (talk | contribs) (Trying to get syntax highlighting working)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

-- List of IC10 opcodes (all strings) local opcodes = {

   "add","sub","mul","div",
   "and","or","xor","not",
   "beq","bne","j","jal",
   "move","slt","sgt"

}

-- Build lookup table local opcode_lookup = {} for _, op in ipairs(opcodes) do

   opcode_lookup[op] = true

end

local function highlight_line(line)

   line = mw.text.nowiki(line)
   -- comments
   line = mw.text.gsub(line, "(#.*)",
       '%1')
   -- labels
   line = mw.text.gsub(line, "^(%w+:)",
       '%1')
   -- registers r0–r15
   line = mw.text.gsub(line, "%f[%w](r1?[0-5])%f[%W]",
       '%1')
   -- numbers hex
   line = mw.text.gsub(line, "%f[%w](%-?0x%x+)%f[%W]",
       '%1')
   -- numbers decimal
   line = mw.text.gsub(line, "%f[%w](%-?%d+)%f[%W]",
       '%1')
   -- opcodes
   for op,_ in pairs(opcode_lookup) do
       line = mw.text.gsub(line,
           "%f[%w]("..op..")%f[%W]",
           '%1')
   end
   return line

end

function p.highlight(frame)

   local text = frame.args[1] or ""
   local lines = mw.text.split(text, "\n")
   for i,line in ipairs(lines) do
       lines[i] = highlight_line(line)
   end

return '

'
        .. table.concat(lines, "\n") ..
        '

'

end

return p