pmacs3/mode/lily.py

91 lines
3.5 KiB
Python
Raw Normal View History

2009-02-17 16:45:23 -05:00
import color, mode
from lex import Grammar, PatternRule, RegionRule, PatternGroupRule
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
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'%\}'),
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-])"),
2009-02-17 19:37:11 -05:00
PatternRule(r'measure', r'(?:[0-9]+\.)?[0-9]+\\(?:mm|cm|in)'),
2009-02-17 16:45:23 -05:00
RegionRule(r'scheme', r'#\(', SchemeGrammar, '\)'),
2009-02-17 19:37:11 -05:00
PatternRule(r'bareword', r'[a-zA-Z][a-zA-Z_0-9-]*[a-zA-Z0-9]'),
2009-02-17 16:45:23 -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):
name = 'lily'
2009-02-17 16:45:23 -05:00
extensions = ['.ly']
tabwidth = 2
tabbercls = LilyTabber
2009-02-17 16:45:23 -05:00
grammar = LilyGrammar
commentc = '%'
2009-02-17 19:37:11 -05:00
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'),
2009-02-17 19:37:11 -05:00
'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'),
2009-02-17 19:37:11 -05:00
}
2009-02-17 16:45:23 -05:00
opentokens = ('delimiter',)
opentags = {'<<': '>>', '{': '}'}
2009-02-17 16:45:23 -05:00
closetokens = ('delimiter',)
closetags = {'>>': '<<', '}': '{'}
_bindings = {
'close-brace': ('}',),
}
2009-02-17 16:45:23 -05:00
install = Lily.install