This repository has been archived on 2022-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/textadept/.textadept/lexers/uxntal.lua

45 lines
1.1 KiB
Lua

-- uxntal LPeg lexer.
local lexer = require('lexer')
local token, word_match = lexer.token, lexer.word_match
local P, S = lpeg.P, lpeg.S
local lex = lexer.new('uxntal')
-- opcodes
local words =
P("BRK") + P("LIT") + P("INC") + P("POP") +
P("DUP") + P("NIP") + P("SWP") + P("OVR") +
P("ROT") + P("EQU") + P("NEQ") + P("GTH") +
P("LTH") + P("JMP") + P("JCN") + P("JSR") +
P("STH") + P("LDZ") + P("STZ") + P("LDR") +
P("STR") + P("LDA") + P("STA") + P("DEI") +
P("DEO") + P("ADD") + P("SUB") + P("MUL") +
P("DIV") + P("AND") + P("ORA") + P("EOR") +
P("SFT")
lex:add_rule('keyword', token(lexer.KEYWORD, words * S(" rk2")^-3))
-- numbers
lex:add_rule('number', token(lexer.NUMBER, S("$#") * lexer.xdigit^1))
-- comments
local comment = token(lexer.COMMENT, lexer.range('( ', ' )'))
lex:add_rule('comment', comment)
-- address references
local ref = token(lexer.IDENTIFIER, S(";.,") * (lexer.word + S('&/-_'))^1)
lex:add_rule('reference', ref)
-- labels
local label = token(lexer.LABEL, S("@&") * (lexer.word + S('&/-_'))^1)
lex:add_rule('label', label)
return lex