80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
|
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
|