preliminary lilypond support

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-18 06:20:43 +00:00
parent f5e5250b9e
commit 5124367014
1 changed files with 61 additions and 15 deletions

View File

@ -1,7 +1,12 @@
import color, mode
from lex import Grammar, PatternRule, RegionRule
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'(?:[^%]|%[^}])+')]
@ -10,35 +15,76 @@ class LilyGrammar(Grammar):
rules = [
PatternRule(r'comment', r'%.*$'),
RegionRule(r'comment', r'%\{', CommentGrammar, r'%\}'),
RegionRule(r'string', r'"', StringGrammar2, r'"'),
PatternRule(r'delimiter', r'(?:[=(){}\[\];:,.])'),
PatternRule(r'note', r"[a-g][sf]?[',]*(?![a-z-])"),
PatternRule(r'measure', r'(?:[0-9]+\.)?[0-9]+\\(?:mm|cm|in)'),
RegionRule(r'scheme', r'#\(', SchemeGrammar, '\)'),
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):
modename = 'lily'
extensions = ['.ly']
tabwidth = 2
tabbercls = LilyTabber
grammar = LilyGrammar
commentc = '%'
colors = {
'note': ('yellow', 'default'),
'directive': ('cyan', 'default'),
'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 = {'(': ')', '[': ']', '{': '}'}
opentags = {'<<': '>>', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
closetags = {'>>': '<<', '}': '{'}
_bindings = {
'close-brace': ('}',),
}
install = Lily.install