nested uxntal comments

--HG--
branch : pmacs2
This commit is contained in:
~d6 2021-12-28 22:47:24 -05:00
parent 8ef03ac77a
commit fe83426f8e
1 changed files with 15 additions and 2 deletions

View File

@ -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 = {'(': ')', '[': ']', '{': '}'}