Compare commits
10 Commits
480754b38e
...
225a6ab3e2
Author | SHA1 | Date |
---|---|---|
~d6 | 225a6ab3e2 | |
~d6 | 891535fa99 | |
Erik Osheim | 2ff9e017e4 | |
Erik Osheim | 5ebd314164 | |
~d6 | 864c1f4e9d | |
~d6 | 0cfae9cb2a | |
~d6 | fe83426f8e | |
~d6 | 8ef03ac77a | |
~d6 | 997be878f2 | |
~d6 | 8ae2a8f0b0 |
|
@ -12,7 +12,7 @@ _data = '''
|
||||||
[y:d:*] ************ ***** ***** **** ************* ********** **********
|
[y:d:*] ************ ***** ***** **** ************* ********** **********
|
||||||
[y:d:*] ********** ***** ***** **** ****** **** ******** ********
|
[y:d:*] ********** ***** ***** **** ****** **** ******** ********
|
||||||
[y:d:*] ***
|
[y:d:*] ***
|
||||||
[y:d:*] *** [c:d:*]pmacs[d:d] is a python-based text editor by [c:d:*]Erik Osheim[d:d], [b:d:*](c) 2005-2009
|
[y:d:*] *** [c:d:*]pmacs[d:d] is a python-based text editor by [c:d:*]Erik Osheim[d:d], [b:d:*](c) 2005-2021
|
||||||
[y:d:*] *** [c:d:*]pmacs[d:d] is available to you under the [c:d:*]GNU General Public License v2
|
[y:d:*] *** [c:d:*]pmacs[d:d] is available to you under the [c:d:*]GNU General Public License v2
|
||||||
[y:d:*]*****
|
[y:d:*]*****
|
||||||
[y:d:*]***** [d:d]to view available commands use [c:d:*]C-c M-h [b:d:*](show-bindings-buffer)
|
[y:d:*]***** [d:d]to view available commands use [c:d:*]C-c M-h [b:d:*](show-bindings-buffer)
|
||||||
|
|
|
@ -6,8 +6,8 @@ class ConfGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule('conf.comment', '#.*$'),
|
PatternRule('conf.comment', '#.*$'),
|
||||||
PatternRule('conf.comment', '//.*$'),
|
PatternRule('conf.comment', '//.*$'),
|
||||||
#RegionRule('conf.string', "'", StringGrammar1, "'"),
|
RegionRule('conf.string', "'", StringGrammar1, "'"),
|
||||||
#RegionRule('conf.string', '"', StringGrammar2, '"'),
|
RegionRule('conf.string', '"', StringGrammar2, '"'),
|
||||||
PatternRule('conf.data', r'(?:[^\'"#/]|/(?!/))+'),
|
PatternRule('conf.data', r'(?:[^\'"#/]|/(?!/))+'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
59
mode/tal.py
59
mode/tal.py
|
@ -1,14 +1,24 @@
|
||||||
from method import Argument, Method
|
from method import Argument, Method
|
||||||
from mode import Fundamental
|
from mode import Fundamental
|
||||||
from lex import Grammar, PatternRule, RegionRule
|
from lex import Grammar, PatternRule, PatternMatchRule, RegionRule
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
class CommentGrammar(Grammar): pass
|
||||||
|
|
||||||
|
comment_rule = RegionRule('comment', r'\((?:[ \t\n]|$)', CommentGrammar, r'\)(?:[ \t\n]|$)')
|
||||||
|
|
||||||
|
CommentGrammar.rules = [
|
||||||
|
comment_rule,
|
||||||
|
PatternRule('data', r'[^\(\) \t\n][^ \t\n]*|[\(\)][^ \t\n]+'),
|
||||||
|
PatternRule('spaces', r'[ \t]+'),
|
||||||
|
]
|
||||||
|
|
||||||
class TalGrammar(Grammar):
|
class TalGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule('spaces', '[ \t]+'),
|
PatternRule('spaces', '[ \t]+'),
|
||||||
RegionRule('comment', r'\((?:[ \t]|$)', Grammar, '(?:^|[ \t])\)'),
|
comment_rule,
|
||||||
PatternRule('delimiter', r'[\[\]{}]'),
|
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.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?(?![a-zA-z0-9_])'), # instructions
|
||||||
PatternRule('tal.defmacro', r'%[^ \t\n]+'), # macro-define
|
PatternRule('tal.defmacro', r'%[^ \t\n]+'), # macro-define
|
||||||
PatternRule('tal.pad', r'\|[^ \t\n]+'), # pad (absolute)
|
PatternRule('tal.pad', r'\|[^ \t\n]+'), # pad (absolute)
|
||||||
PatternRule('tal.pad', r'\$[^ \t\n]+'), # pad (relative)
|
PatternRule('tal.pad', r'\$[^ \t\n]+'), # pad (relative)
|
||||||
|
@ -22,6 +32,7 @@ class TalGrammar(Grammar):
|
||||||
PatternRule('tal.addr', r':[^/ \t\n]+'), # raw addr
|
PatternRule('tal.addr', r':[^/ \t\n]+'), # raw addr
|
||||||
PatternRule('tal.addr', r'\'[^/ \t\n]+'), # raw char
|
PatternRule('tal.addr', r'\'[^/ \t\n]+'), # raw char
|
||||||
PatternRule('tal.addr', r'\"[^/ \t\n]+'), # raw word
|
PatternRule('tal.addr', r'\"[^/ \t\n]+'), # raw word
|
||||||
|
PatternMatchRule('x', r'(~)(.+)$', 'tal.include', 'tal.filename'),
|
||||||
PatternRule('tal.word', r'[^ \t\n]+'),
|
PatternRule('tal.word', r'[^ \t\n]+'),
|
||||||
PatternRule('eol', '\n'),
|
PatternRule('eol', '\n'),
|
||||||
]
|
]
|
||||||
|
@ -57,6 +68,31 @@ hi_cyan = ('cyan155', 'default')
|
||||||
lo_blue = ('blue113', 'default')
|
lo_blue = ('blue113', 'default')
|
||||||
hi_blue = ('blue225', 'default')
|
hi_blue = ('blue225', 'default')
|
||||||
|
|
||||||
|
class Talasm(Method):
|
||||||
|
'''Assemble the given .tal file'''
|
||||||
|
bname = '*Talasm*'
|
||||||
|
def run_pipe(self, w, args, switch, mname=None):
|
||||||
|
return w.application.run_pipe(args, w.buffer, self.bname, switch, mname)
|
||||||
|
def get_dest(self, w):
|
||||||
|
path = w.buffer.path
|
||||||
|
if path.endswith('.tal'):
|
||||||
|
return path[:-4] + '.rom'
|
||||||
|
else:
|
||||||
|
raise Exception('invalid path: %s' % path)
|
||||||
|
def _execute(self, w, **vargs):
|
||||||
|
path = w.buffer.path
|
||||||
|
dest = self.get_dest(w)
|
||||||
|
args = ['uxnasm', path, dest]
|
||||||
|
r = self.run_pipe(w, args, lambda x: x != 0, 'error')
|
||||||
|
b = w.application.get_buffer_by_name(self.bname)
|
||||||
|
b.orig_path = w.buffer.path
|
||||||
|
if r == 0: w.set_error(b.lines[-2])
|
||||||
|
|
||||||
|
class TalCheck(Talasm):
|
||||||
|
'''Check the syntax of the current .tal file'''
|
||||||
|
def get_dest(self, w):
|
||||||
|
return '/dev/null'
|
||||||
|
|
||||||
class Taldoc(Method):
|
class Taldoc(Method):
|
||||||
'''View documentation'''
|
'''View documentation'''
|
||||||
ops = {
|
ops = {
|
||||||
|
@ -98,7 +134,7 @@ class Taldoc(Method):
|
||||||
'AND': ['And', [['a', 'b'], ['a&b']], None, 'bitwise-and (a & b)'],
|
'AND': ['And', [['a', 'b'], ['a&b']], None, 'bitwise-and (a & b)'],
|
||||||
'ORA': ['Or', [['a', 'b'], ['a|b']], None, 'bitwise-or (a | b)'],
|
'ORA': ['Or', [['a', 'b'], ['a|b']], None, 'bitwise-or (a | b)'],
|
||||||
'EOR': ['Exclusive Or', [['a', 'b'], ['a^b']], None, 'bitwise-xor (a ^ b)'],
|
'EOR': ['Exclusive Or', [['a', 'b'], ['a^b']], None, 'bitwise-xor (a ^ b)'],
|
||||||
'SFT': ['Shift', [['a', 'b^'], ['c']], None, 'bitshift left (b >> 4) then right (b & 0xf)'],
|
'SFT': ['Shift', [['a', 'b^'], ['c']], None, 'bitshift right (b & 0x0f) then left (b >> 4)'],
|
||||||
}
|
}
|
||||||
inst_re = re.compile(r'^([A-Z]{3})(2?k?r?)$')
|
inst_re = re.compile(r'^([A-Z]{3})(2?k?r?)$')
|
||||||
addr_dict = {
|
addr_dict = {
|
||||||
|
@ -161,7 +197,10 @@ class Taldoc(Method):
|
||||||
if '2' in suffix:
|
if '2' in suffix:
|
||||||
glyph = '*'
|
glyph = '*'
|
||||||
if 'k' in suffix:
|
if 'k' in suffix:
|
||||||
|
if ds is not None:
|
||||||
ds = [ds[0], ds[0] + ds[1]]
|
ds = [ds[0], ds[0] + ds[1]]
|
||||||
|
if rs is not None:
|
||||||
|
rs = [rs[0], rs[0] + rs[1]]
|
||||||
def mark(x):
|
def mark(x):
|
||||||
if x.endswith('^') or x.endswith('*'):
|
if x.endswith('^') or x.endswith('*'):
|
||||||
return x
|
return x
|
||||||
|
@ -172,7 +211,7 @@ class Taldoc(Method):
|
||||||
if rs is None:
|
if rs is None:
|
||||||
msg = '%s (%s) %s: %s' % (word, stk(ds), name, desc)
|
msg = '%s (%s) %s: %s' % (word, stk(ds), name, desc)
|
||||||
elif ds is None:
|
elif ds is None:
|
||||||
msg = '%s {%s} %: %s' % (word, stk(rs), name, desc)
|
msg = '%s {%s} %s: %s' % (word, stk(rs), name, desc)
|
||||||
else:
|
else:
|
||||||
msg = '%s (%s) {%s} %s: %s' % (word, stk(ds), stk(rs), name, desc)
|
msg = '%s (%s) {%s} %s: %s' % (word, stk(ds), stk(rs), name, desc)
|
||||||
w.set_error(msg)
|
w.set_error(msg)
|
||||||
|
@ -206,7 +245,7 @@ class Tal(Fundamental):
|
||||||
name = 'tal'
|
name = 'tal'
|
||||||
extensions = ['.tal']
|
extensions = ['.tal']
|
||||||
grammar = TalGrammar
|
grammar = TalGrammar
|
||||||
actions = [Taldoc]
|
actions = [Taldoc, Talasm, TalCheck]
|
||||||
colors = {
|
colors = {
|
||||||
'tal.addr': hi_cyan,
|
'tal.addr': hi_cyan,
|
||||||
'tal.defmacro': hi_blue,
|
'tal.defmacro': hi_blue,
|
||||||
|
@ -217,8 +256,16 @@ class Tal(Fundamental):
|
||||||
'tal.number': hi_green,
|
'tal.number': hi_green,
|
||||||
'tal.pad': hi_orange,
|
'tal.pad': hi_orange,
|
||||||
'tal.spacer': hi_orange,
|
'tal.spacer': hi_orange,
|
||||||
|
'tal.include': lo_cyan,
|
||||||
|
'tal.filename': hi_cyan,
|
||||||
}
|
}
|
||||||
|
opentokens = ('delimiter',)
|
||||||
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||||
|
closetokens = ('delimiter',)
|
||||||
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
_bindings = {
|
_bindings = {
|
||||||
|
'talasm': ('C-c c', 'C-c C-c',),
|
||||||
|
'tal-check': ('C-c s',),
|
||||||
'taldoc': ('C-c p',),
|
'taldoc': ('C-c p',),
|
||||||
'close-paren': (')',),
|
'close-paren': (')',),
|
||||||
'close-brace': ('}',),
|
'close-brace': ('}',),
|
||||||
|
|
Loading…
Reference in New Issue