add uxn/tal mode

--HG--
branch : pmacs2
This commit is contained in:
~d6 2021-09-30 23:58:50 -04:00
parent 548c3fc17f
commit cf4a1ca9de
2 changed files with 81 additions and 2 deletions

View File

@ -1,4 +1,4 @@
#!/usr/local/bin/python3
#!/usr/bin/env python3
import curses
from getpass import getpass
@ -179,7 +179,7 @@ class Application(object):
'awk', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', 'mbox',
'error', 'lua', 'lily', 'forth', 'ebnf', 'colortest', 'go',
'inform6', 'scala', 'markdown', 'roy', 'twine', 'idris', 'rust',
'bosatsu',
'bosatsu', 'tal',
)
for name in names:
exec("import mode.%s; mode.%s.install(self)" % (name, name))

79
mode/tal.py Normal file
View File

@ -0,0 +1,79 @@
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule
class TalGrammar(Grammar):
rules = [
PatternRule('spaces', '[ \t]+'),
RegionRule('comment', r'\(', Grammar, '\)'),
PatternRule('delimiter', r'[\[\]{}]'),
PatternRule('tal.inst', r'(BRK|LIT|INC|POP|DUP|NIP|SWP|OVR|ROT|EQU|NEQ|GTH|LTH|JMP|JCN|JSR|STH|LDZ|STZ|LDR|STR|LDA|STA|DEI|DEO|ADD|SUB|MUL|DIV|AND|ORA|EOR|SFT)2?k?r?'), # instructions
PatternRule('tal.defmacro', r'%[^ ]+'), # macro-define
PatternRule('tal.pad', r'\|[^ ]+'), # pad (absolute)
PatternRule('tal.pad', r'\$[^ ]+'), # pad (relative)
PatternRule('tal.deflabel', r'@[^ ]+'), # label-define
PatternRule('tal.defsublabel', r'&[^ ]+'), # sublabel-define
PatternRule('tal.spacer', r'/[^ ]+'), # sublabel-spacer
PatternRule('tal.hex', r'#[0-9a-fA-F]+'), # literal hex
PatternRule('tal.addr', r'\.[^/ ]+'), # little addr (zero page)
PatternRule('tal.addr', r',[^/ ]+'), # little addr (relative)
PatternRule('tal.addr', r';[^/ ]+'), # little addr (absolute)
PatternRule('tal.addr', r':[^/ ]+'), # raw addr
PatternRule('tal.addr', r'\'[^/ ]+'), # raw char
PatternRule('tal.addr', r'\"[^/ ]+'), # raw word
PatternRule('tal.word', r'[^ ]+'),
PatternRule('eol', '\n'),
]
# white is for delimiters, operators, numbers
default = ('default', 'default')
# magenta is for keywords/builtins
lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta414', 'default')
# red is for comments
lo_red = ('red300', 'default')
hi_red = ('red511', 'default')
# orange is for macro definitions, headers and constants
hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default')
# yellow is for parts of macros
hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default')
# green is for strings and characters
lo_green = ('green030', 'default')
hi_green = ('green050', 'default')
# cyan is for types
lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default')
# blue is definitions, functions and some macros
lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default')
class Tal(Fundamental):
name = 'tal'
extensions = ['.tal']
grammar = TalGrammar
colors = {
'tal.addr': hi_cyan,
'tal.defmacro': hi_blue,
'tal.addr': hi_yellow,
'tal.inst': hi_magenta,
'tal.deflabel': hi_blue,
'tal.defsublabel': hi_cyan,
'tal.hex': hi_green,
'tal.pad': hi_orange,
'tal.spacer': hi_orange,
}
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Tal.install