diff --git a/application.py b/application.py index 827f609..9139853 100755 --- a/application.py +++ b/application.py @@ -179,7 +179,7 @@ class Application(object): 'awk', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', 'mbox', 'error', 'lua', 'lily', 'forth', 'ebnf', 'colortest', 'go', 'inform6', 'scala', 'markdown', 'roy', 'twine', 'idris', 'rust', - 'bosatsu', 'tal', + 'bosatsu', 'tal', 'modal', ) for name in names: exec("import mode.%s; mode.%s.install(self)" % (name, name)) diff --git a/mode/modal.py b/mode/modal.py new file mode 100644 index 0000000..7396fea --- /dev/null +++ b/mode/modal.py @@ -0,0 +1,43 @@ +from mode import Fundamental +from lex import Grammar, PatternRule, RegionRule + +class DataGrammar(Grammar): + pass + +DataGrammar.rules = [ + PatternRule('spaces', ' +'), + RegionRule('sequence', r'\(', DataGrammar, r'\)|$'), + PatternRule('register', r'\?[a-z]'), + PatternRule('word', r'[^() \n]+'), +] + +class RuleGrammar(Grammar): + rules = [ + PatternRule('spaces', ' +'), + RegionRule('group', r'\(', DataGrammar, r'\)|$'), + PatternRule('register', r'\?[a-z]'), + PatternRule('word', r'[^() \n]+'), + ] + +class ModalGrammar(Grammar): + rules = [ + PatternRule('spaces', ' +'), + PatternRule('eol', r'\n'), + RegionRule('modal.rule', '<>', RuleGrammar, '\n|$'), + PatternRule('modal.lit', r'[^\n]+'), + ] + +class Modal(Fundamental): + name = 'Modal' + extensions = ['.modal'] + grammar = ModalGrammar + colors = { + 'modal.lit': ('cyan', 'default'), + 'modal.rule.start': ('magenta', 'default'), + 'register': ('yellow', 'default'), + 'modal.rule.group.start': ('blue', 'default'), + 'modal.rule.group.end': ('blue', 'default'), + } + +def install(*args): + Modal.install(*args)