From fe83426f8ed2aa6b8e6c6010662d2d9982f27f03 Mon Sep 17 00:00:00 2001 From: d6 Date: Tue, 28 Dec 2021 22:47:24 -0500 Subject: [PATCH] nested uxntal comments --HG-- branch : pmacs2 --- mode/tal.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mode/tal.py b/mode/tal.py index c8be73f..1634909 100644 --- a/mode/tal.py +++ b/mode/tal.py @@ -1,12 +1,22 @@ 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, '\)'), + 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?(?![a-zA-z0-9_])'), # instructions PatternRule('tal.defmacro', r'%[^ \t\n]+'), # macro-define @@ -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'), ] @@ -220,6 +231,8 @@ 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 = {'(': ')', '[': ']', '{': '}'}