import color, mode from lex import Grammar, PatternRule, RegionRule, PatternGroupRule from mode.scheme import SchemeGrammar from mode.python import StringGrammar1, StringGrammar2 import regex import tab class MarkupGrammar(Grammar): rules = [PatternRule(r'data', r'[^}]+')] class CommentGrammar(Grammar): rules = [PatternRule(r'data', r'(?:[^%]|%[^}])+')] class LilyGrammar(Grammar): rules = [ PatternRule(r'comment', r'%.*$'), RegionRule(r'comment', r'%\{', CommentGrammar, r'%\}'), RegionRule(r'string', r'#?"', StringGrammar2, r'"'), PatternRule(r'boolean', r'#?#[tf]'), PatternGroupRule(r'd1', r'directive', r'\\new', r'spaces', r' +', r'lily_class', r'[a-zA-Z_]+'), PatternGroupRule(r'd2', r'directive', r'\\set', r'spaces', r' +', r'lily_var', r'[a-zA-Z_]+'), PatternGroupRule(r'd3', r'directive', r'\\override', r'spaces', r' +', r'lily_var', r'[a-zA-Z_]+'), PatternRule(r'tie', r'~'), PatternRule(r'augmentation', r'\.+'), PatternRule(r'directive', r'\\[a-zA-Z_][a-zA-Z_0-9]*'), #PatternRule(r'dynamics', r'\\[a-z]+'), PatternRule(r'delimiter', r'(?:[={}]|<<|>>)'), RegionRule(r'text', r'^"', StringGrammar2, r'"'), RegionRule(r'markup', r'(?<=\\markup) *{', MarkupGrammar, '}'), PatternRule(r'huh', r'\\!'), PatternRule(r'spaces', ' +'), PatternRule(r'eol', '\n'), PatternRule(r'chord', r'[<>]'), PatternRule(r'beam', r'[\[\]]'), PatternRule(r'slur', r'[()]'), PatternRule(r'pslur', r'\\[()]'), PatternRule(r'articulation', r'[-_+][-.>^+_]'), PatternRule(r'fingering', r'[-_+][0-9]+'), PatternRule(r'time', r'[0-9]+/[0-9]+'), PatternRule(r'note', r"[a-g][sf]?[,']*[0-9]*(?![a-z-])"), PatternRule(r'rest', r"r[0-9]*(?![a-z-])"), PatternRule(r'srest', r"s[0-9]*(?![a-z-])"), PatternRule(r'measure', r'(?:[0-9]+\.)?[0-9]+\\(?:mm|cm|in)'), RegionRule(r'scheme', r'#\(', SchemeGrammar, '\)'), PatternRule(r'bareword', r'[a-zA-Z][a-zA-Z_0-9-]*[a-zA-Z0-9]'), ] class LilyTabber(tab.StackTabber): wsre = regex.whitespace wst = ('spaces', 'null', 'eol',) sre = regex.space st = ('spaces', 'null',) class Lily(mode.Fundamental): name = 'lily' extensions = ['.ly'] tabwidth = 2 tabbercls = LilyTabber grammar = LilyGrammar commentc = '%' colors = { 'boolean': ('magenta', 'default', 'bold'), 'lily_class': ('magenta', 'default', 'bold'), 'lily_var': ('cyan', 'default', 'bold'), 'directive': ('blue', 'default', 'bold'), 'markup.start': ('cyan', 'default'), 'markup.data': ('cyan', 'default'), 'markup.end': ('cyan', 'default'), 'time': ('yellow', 'default'), 'note': ('yellow', 'default', 'bold'), 'rest': ('yellow', 'default'), 'srest': ('yellow', 'default'), 'scheme.start': ('magenta', 'default'), 'scheme.end': ('magenta', 'default'), 'measure': ('green', 'default'), 'beam': ('red', 'default'), 'slur': ('red', 'default'), 'plur': ('red', 'default'), 'tie': ('red', 'default'), 'huh': ('red', 'default'), } opentokens = ('delimiter',) opentags = {'<<': '>>', '{': '}'} closetokens = ('delimiter',) closetags = {'>>': '<<', '}': '{'} _bindings = { 'close-brace': ('}',), } install = Lily.install