2009-02-17 16:45:23 -05:00
|
|
|
import color, mode
|
2009-03-28 22:20:37 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
|
2009-02-17 16:45:23 -05:00
|
|
|
from mode.scheme import SchemeGrammar
|
2009-02-17 19:37:11 -05:00
|
|
|
from mode.python import StringGrammar1, StringGrammar2
|
2009-02-18 01:20:43 -05:00
|
|
|
import regex
|
|
|
|
import tab
|
|
|
|
|
|
|
|
class MarkupGrammar(Grammar):
|
|
|
|
rules = [PatternRule(r'data', r'[^}]+')]
|
2009-02-17 16:45:23 -05:00
|
|
|
|
|
|
|
class CommentGrammar(Grammar):
|
|
|
|
rules = [PatternRule(r'data', r'(?:[^%]|%[^}])+')]
|
|
|
|
|
|
|
|
class LilyGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'comment', r'%.*$'),
|
|
|
|
RegionRule(r'comment', r'%\{', CommentGrammar, r'%\}'),
|
2009-02-18 01:20:43 -05:00
|
|
|
RegionRule(r'string', r'#?"', StringGrammar2, r'"'),
|
|
|
|
PatternRule(r'boolean', r'#?#[tf]'),
|
2009-07-23 16:26:59 -04:00
|
|
|
PatternMatchRule(r'x', r'(\\new)( +)([a-zA-Z_]+)', r'lily.directive',
|
|
|
|
r'spaces', r'lily.class'),
|
|
|
|
PatternMatchRule(r'x', r'(\\set|\\override)( +)([a-zA-Z_]+)',
|
|
|
|
r'lily.directive', r'spaces', r'lily.var'),
|
|
|
|
PatternRule(r'lily.tie', r'~'),
|
|
|
|
PatternRule(r'lily.augmentation', r'\.+'),
|
|
|
|
PatternRule(r'lily.directive', r'\\[a-zA-Z_][a-zA-Z_0-9]*'),
|
2009-02-18 01:20:43 -05:00
|
|
|
PatternRule(r'delimiter', r'(?:[={}]|<<|>>)'),
|
2009-07-23 16:26:59 -04:00
|
|
|
RegionRule(r'lily.text', r'^"', StringGrammar2, r'"'),
|
|
|
|
RegionRule(r'lily.markup', r'(?<=\\markup) *{', MarkupGrammar, '}'),
|
|
|
|
PatternRule(r'lily.huh', r'\\!'),
|
2009-02-18 01:20:43 -05:00
|
|
|
PatternRule(r'spaces', ' +'),
|
|
|
|
PatternRule(r'eol', '\n'),
|
2009-07-23 16:26:59 -04:00
|
|
|
PatternRule(r'lily.chord', r'[<>]'),
|
|
|
|
PatternRule(r'lily.beam', r'[\[\]]'),
|
|
|
|
PatternRule(r'lily.slur', r'[()]'),
|
|
|
|
PatternRule(r'lily.pslur', r'\\[()]'),
|
|
|
|
PatternRule(r'lily.articulation', r'[-_+][-.>^+_]'),
|
|
|
|
PatternRule(r'lily.fingering', r'[-_+][0-9]+'),
|
|
|
|
PatternRule(r'lily.time', r'[0-9]+/[0-9]+'),
|
|
|
|
PatternRule(r'lily.note', r"[a-g][sf]?[,']*[0-9]*(?![a-z-])"),
|
|
|
|
PatternRule(r'lily.rest', r"r[0-9]*(?![a-z-])"),
|
|
|
|
PatternRule(r'lily.srest', r"s[0-9]*(?![a-z-])"),
|
|
|
|
PatternRule(r'lily.measure', r'(?:[0-9]+\.)?[0-9]+\\(?:mm|cm|in)'),
|
|
|
|
RegionRule(r'lily.scheme', r'#\(', SchemeGrammar, '\)'),
|
|
|
|
PatternRule(r'lily.bareword', r'[a-zA-Z][a-zA-Z_0-9-]*[a-zA-Z0-9]'),
|
2009-02-17 16:45:23 -05:00
|
|
|
]
|
|
|
|
|
2009-02-18 01:20:43 -05:00
|
|
|
class LilyTabber(tab.StackTabber):
|
|
|
|
wsre = regex.whitespace
|
|
|
|
wst = ('spaces', 'null', 'eol',)
|
|
|
|
sre = regex.space
|
|
|
|
st = ('spaces', 'null',)
|
|
|
|
|
2009-02-17 16:45:23 -05:00
|
|
|
class Lily(mode.Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'lily'
|
2009-02-17 16:45:23 -05:00
|
|
|
extensions = ['.ly']
|
2009-03-17 15:24:10 -04:00
|
|
|
tabwidth = 2
|
|
|
|
tabbercls = LilyTabber
|
2009-02-17 16:45:23 -05:00
|
|
|
grammar = LilyGrammar
|
|
|
|
commentc = '%'
|
2009-02-17 19:37:11 -05:00
|
|
|
colors = {
|
2009-07-23 16:26:59 -04:00
|
|
|
'lily.boolean': ('magenta', 'default', 'bold'),
|
|
|
|
'lily.class': ('magenta', 'default', 'bold'),
|
|
|
|
'lily.var': ('cyan', 'default', 'bold'),
|
|
|
|
'lily.directive': ('blue', 'default', 'bold'),
|
|
|
|
'lily.markup.start': ('cyan', 'default'),
|
|
|
|
'lily.markup.data': ('cyan', 'default'),
|
|
|
|
'lily.markup.end': ('cyan', 'default'),
|
|
|
|
'lily.time': ('yellow', 'default'),
|
|
|
|
'lily.note': ('yellow', 'default', 'bold'),
|
|
|
|
'lily.rest': ('yellow', 'default'),
|
|
|
|
'lily.srest': ('yellow', 'default'),
|
|
|
|
'lily.scheme.start': ('magenta', 'default'),
|
|
|
|
'lily.scheme.end': ('magenta', 'default'),
|
|
|
|
'lily.measure': ('green', 'default'),
|
|
|
|
'lily.beam': ('red', 'default'),
|
|
|
|
'lily.slur': ('red', 'default'),
|
|
|
|
'lily.plur': ('red', 'default'),
|
|
|
|
'lily.tie': ('red', 'default'),
|
|
|
|
'lily.huh': ('red', 'default'),
|
2009-02-17 19:37:11 -05:00
|
|
|
}
|
2009-02-17 16:45:23 -05:00
|
|
|
opentokens = ('delimiter',)
|
2009-02-18 01:20:43 -05:00
|
|
|
opentags = {'<<': '>>', '{': '}'}
|
2009-02-17 16:45:23 -05:00
|
|
|
closetokens = ('delimiter',)
|
2009-02-18 01:20:43 -05:00
|
|
|
closetags = {'>>': '<<', '}': '{'}
|
|
|
|
_bindings = {
|
|
|
|
'close-brace': ('}',),
|
|
|
|
}
|
2009-02-17 16:45:23 -05:00
|
|
|
|
|
|
|
install = Lily.install
|