From 315a590bd9186182a6f1897723ea76a8fe5ec94b Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 18 Feb 2009 00:37:11 +0000 Subject: [PATCH] lily support --HG-- branch : pmacs2 --- application.py | 2 +- code_examples/song.ly | 180 ++++++++++++++++++++++++++++++++++++++++++ mode/lily.py | 17 +++- 3 files changed, 195 insertions(+), 4 deletions(-) create mode 100644 code_examples/song.ly diff --git a/application.py b/application.py index 64daaff..99fbc1f 100755 --- a/application.py +++ b/application.py @@ -115,7 +115,7 @@ class Application(object): 'latex', 'insertmini', 'conf', 'haskell', 'erlang', 'iperl', 'iperlmini', 'ipython', 'ipythonmini', 'awk', 'shell', 'shellmini', 'fstab', 'yacc', 'pipe', - 'mbox', 'error', 'lua', + 'mbox', 'error', 'lua', 'lily' ) for name in names: exec("import mode.%s; mode.%s.install(self)" % (name, name)) diff --git a/code_examples/song.ly b/code_examples/song.ly new file mode 100644 index 0000000..73a236a --- /dev/null +++ b/code_examples/song.ly @@ -0,0 +1,180 @@ +%% Generated by lilypond-book.py +%% Options: [quote,alt=[image of music],indent=0\mm] +\include "lilypond-book-preamble.ly" + + +% **************************************************************** +% Start cut-&-pastable-section +% **************************************************************** + + + +\paper { + #(define dump-extents #t) + + line-width = 160\mm - 2.0 * 0.4\in + indent = 0\mm + force-assignment = #"" + line-width = #(- line-width (* mm 3.000000)) +} + +\layout { + +} + + + +% **************************************************************** +% ly snippet: +% **************************************************************** +\sourcefilename "pitches-headword.ly" +\sourcefileline 0 +\version "2.12.0" +\include "english.ly" +#(set-global-staff-size 15) +\paper{ + ragged-right=##t + line-width=17\cm + indent=0\cm +} + +\layout { + \context { \Score + \override PaperColumn #'keep-inside-line = ##t + \override NonMusicalPaperColumn #'keep-inside-line = ##t + } +} + +% NR 1.1 Pitches + +% L. v. Beethoven +% Piano sonata 21 - Dem Grafen von Waldstein Gewidmet +% chorale at measures 34 - 40+ + +\new PianoStaff << + + % RH Staff + \new Staff << + + % RH Voice 1 + \new Voice { + \set Score.currentBarNumber = #34 + \voiceOne + gs''2 ( ^ \markup \italic { dolce e molto ligato } + fs''4 + e''4 + | + ds''2 + cs''2 ) + | + ds''2 ( + e''4 + fs''4 + | + 2 + 2 ) + | + \oneVoice + \clef bass + 2 ( + 4 + 4 + | + 2 + 2 ) + | + \voiceOne + b2 %( + cs'4 + ds'4 + | + \clef treble + 4 %) + r4 r2 + } + + % RH Voice 2 + \new Voice { + \voiceTwo + \override Staff.DynamicLineSpanner #'staff-padding = #2.5 + 2 \p + 4 + 4 + | + 2 + e'2 + | + \once \override TextScript #'staff-padding = #2.5 + 2 _ \markup \italic { cresc. } + b'4 + 4 + | + b'2. ( \sf \> + a'4 ) + \clef bass + | \break + s1 \p + | + s1 + | + 4 ( + 2. ) + | + s4 + r4 r2 + } + + >> + + % LH Staff + \new Staff { + \override Staff.SustainPedalLineSpanner #'staff-padding = #5 + 2 ( \sustainOn + 4 \sustainOff + 4 + | + 2 + 2 ) \sustainOn + | + \clef bass + \slurDown + 2 ( \sustainOff + 4 + 4 \sustainOn + | + \clef treble + \voiceOne + << + { + 2 + 2 ) + } + \new Voice { + \voiceTwo + b1 \sustainOff + } + >> + \oneVoice + | + %\break + \clef bass + 2 ( + 4 + 4 + | + 2 + 2 ) \sustainOn + | + 1 ( \sustainOff + | + 4 ) + r4 r2 + } + +>> + + + +% **************************************************************** +% end ly snippet +% **************************************************************** diff --git a/mode/lily.py b/mode/lily.py index 22d5f88..043058b 100644 --- a/mode/lily.py +++ b/mode/lily.py @@ -1,6 +1,7 @@ import color, mode from lex import Grammar, PatternRule, RegionRule from mode.scheme import SchemeGrammar +from mode.python import StringGrammar1, StringGrammar2 class CommentGrammar(Grammar): rules = [PatternRule(r'data', r'(?:[^%]|%[^}])+')] @@ -10,13 +11,17 @@ class LilyGrammar(Grammar): 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'), + 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, '\)'), PatternRule(r'directive', r'\\[a-zA-Z_][a-zA-Z_0-9]*'), - PatternRule(r'bareword', r'[a-zA-Z_][a-zA-Z_0-9]*'), + PatternRule(r'bareword', r'[a-zA-Z][a-zA-Z_0-9-]*[a-zA-Z0-9]'), ] class Lily(mode.Fundamental): @@ -24,7 +29,13 @@ class Lily(mode.Fundamental): extensions = ['.ly'] grammar = LilyGrammar commentc = '%' - colors = {} + colors = { + 'note': ('yellow', 'default'), + 'directive': ('cyan', 'default'), + 'scheme.start': ('magenta', 'default'), + 'scheme.end': ('magenta', 'default'), + 'measure': ('green', 'default'), + } opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',)