Compare commits

..

10 Commits

Author SHA1 Message Date
~d6 225a6ab3e2 merge
--HG--
branch : pmacs2
2022-03-24 22:41:46 -04:00
~d6 891535fa99 syntax check
--HG--
branch : pmacs2
2022-03-24 22:41:26 -04:00
Erik Osheim 2ff9e017e4 merge
--HG--
branch : pmacs2
2022-03-07 21:33:58 -05:00
Erik Osheim 5ebd314164 fix SFT docs
--HG--
branch : pmacs2
2022-03-07 21:33:47 -05:00
~d6 864c1f4e9d asm command
--HG--
branch : pmacs2
2022-01-27 21:55:10 -05:00
~d6 0cfae9cb2a highlight strings in conf
--HG--
branch : pmacs2
2021-12-28 22:47:37 -05:00
~d6 fe83426f8e nested uxntal comments
--HG--
branch : pmacs2
2021-12-28 22:47:24 -05:00
~d6 8ef03ac77a improve syntax, fix highlighting
--HG--
branch : pmacs2
2021-12-23 00:44:45 -05:00
~d6 997be878f2 fix token matching for tal mode
--HG--
branch : pmacs2
2021-12-22 22:01:33 -05:00
~d6 8ae2a8f0b0 update years in about buffer
--HG--
branch : pmacs2
2021-12-21 01:30:34 -05:00
3 changed files with 57 additions and 10 deletions

View File

@ -12,7 +12,7 @@ _data = '''
[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:*]*****
[y:d:*]***** [d:d]to view available commands use [c:d:*]C-c M-h [b:d:*](show-bindings-buffer)

View File

@ -6,8 +6,8 @@ class ConfGrammar(Grammar):
rules = [
PatternRule('conf.comment', '#.*$'),
PatternRule('conf.comment', '//.*$'),
#RegionRule('conf.string', "'", StringGrammar1, "'"),
#RegionRule('conf.string', '"', StringGrammar2, '"'),
RegionRule('conf.string', "'", StringGrammar1, "'"),
RegionRule('conf.string', '"', StringGrammar2, '"'),
PatternRule('conf.data', r'(?:[^\'"#/]|/(?!/))+'),
]

View File

@ -1,14 +1,24 @@
from method import Argument, Method
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule
from lex import Grammar, PatternRule, PatternMatchRule, RegionRule
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):
rules = [
PatternRule('spaces', '[ \t]+'),
RegionRule('comment', r'\((?:[ \t]|$)', Grammar, '(?:^|[ \t])\)'),
comment_rule,
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.pad', r'\|[^ \t\n]+'), # pad (absolute)
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 char
PatternRule('tal.addr', r'\"[^/ \t\n]+'), # raw word
PatternMatchRule('x', r'(~)(.+)$', 'tal.include', 'tal.filename'),
PatternRule('tal.word', r'[^ \t\n]+'),
PatternRule('eol', '\n'),
]
@ -57,6 +68,31 @@ hi_cyan = ('cyan155', 'default')
lo_blue = ('blue113', '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):
'''View documentation'''
ops = {
@ -98,7 +134,7 @@ class Taldoc(Method):
'AND': ['And', [['a', 'b'], ['a&b']], None, 'bitwise-and (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)'],
'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?)$')
addr_dict = {
@ -161,7 +197,10 @@ class Taldoc(Method):
if '2' in suffix:
glyph = '*'
if 'k' in suffix:
ds = [ds[0], ds[0] + ds[1]]
if ds is not None:
ds = [ds[0], ds[0] + ds[1]]
if rs is not None:
rs = [rs[0], rs[0] + rs[1]]
def mark(x):
if x.endswith('^') or x.endswith('*'):
return x
@ -172,7 +211,7 @@ class Taldoc(Method):
if rs is None:
msg = '%s (%s) %s: %s' % (word, stk(ds), name, desc)
elif ds is None:
msg = '%s {%s} %: %s' % (word, stk(rs), name, desc)
msg = '%s {%s} %s: %s' % (word, stk(rs), name, desc)
else:
msg = '%s (%s) {%s} %s: %s' % (word, stk(ds), stk(rs), name, desc)
w.set_error(msg)
@ -206,7 +245,7 @@ class Tal(Fundamental):
name = 'tal'
extensions = ['.tal']
grammar = TalGrammar
actions = [Taldoc]
actions = [Taldoc, Talasm, TalCheck]
colors = {
'tal.addr': hi_cyan,
'tal.defmacro': hi_blue,
@ -217,8 +256,16 @@ class Tal(Fundamental):
'tal.number': hi_green,
'tal.pad': hi_orange,
'tal.spacer': hi_orange,
'tal.include': lo_cyan,
'tal.filename': hi_cyan,
}
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
_bindings = {
'talasm': ('C-c c', 'C-c C-c',),
'tal-check': ('C-c s',),
'taldoc': ('C-c p',),
'close-paren': (')',),
'close-brace': ('}',),