From 47a6f18874c1f99f76702534a36186a79e47fe0d Mon Sep 17 00:00:00 2001 From: Erik Sandberg Date: Mon, 7 Aug 2006 09:31:10 +0000 Subject: [PATCH] * lily/lexer.ll: Add \sourcefileline command * scripts/lilypond-book.py: insert \sourcefileline command in output, so lilypond error messages refer to the spot in the original .lytex / .itely sourcefile. --- ChangeLog | 28 +++++++++++++++++++++++++--- lily/include/source-file.hh | 4 ++++ lily/lexer.ll | 17 +++++++++++++++++ lily/source-file.cc | 13 ++++++++++++- scripts/lilypond-book.py | 14 +++++++------- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e400a8e1e..4e060b0131 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-08-07 Erik Sandberg + + * lily/lexer.ll, lily/source-file.cc: Add \sourcefileline command + + * scripts/lilypond-book.py: insert \sourcefileline command in + output, so lilypond error messages refer to the spot in the + original .lytex / .itely sourcefile. + 2006-08-04 Han-Wen Nienhuys * lily/spacing-loose-columns.cc (set_loose_columns): oops: use @@ -44,10 +52,24 @@ conversion of files older than 1.3.117. Fix escape error in the description for 2.9.6. -2006-08-02 Han-Wen Nienhuys +2006-08-02 Erik Sandberg + + * lily/*-engraver.cc: convert all try_music functions to listen_* + functions. - * lily/*-engraver.cc: convert all try_music functions in - *-engraver.cc. (Patch by Erik S.; please elaborate) + * lily/piano-pedal-engraver.cc: some additional cleanups: use + enums to represent pedal types, and calculate more data statically. + + * scm/part-combiner.scm (recording-group-emulate): create a + softcoded substitute for recording-group-engraver.cc. + + * lily/music.cc: make a common transpose function for events and + music + + * ly/declarations-init.ly: change melisma/melismaEnd. Eliminates + ManualMelismaEvent, and obsoletes Melisma_translator. + +2006-08-02 Han-Wen Nienhuys * input/test/instrument-name-align.ly: update version. diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index dd88a2c65a..33b4051c4c 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -39,6 +39,7 @@ public: bool contains (char const *pos_str0) const; int length () const; virtual int get_line (char const *pos_str0) const; + void set_line (char const *pos_str0, int i); string name_string () const; string file_line_column_string (char const *str0) const; @@ -66,6 +67,9 @@ public: SCM get_port () const; string name_; +protected: + int line_offset_; + private: vector newline_locations_; istream *istream_; diff --git a/lily/lexer.ll b/lily/lexer.ll index c6be4382d4..2fd018ff1b 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -112,6 +112,7 @@ SCM (* scm_parse_error_handler) (void *); %x markup %x notes %x quote +%x sourcefileline %x sourcefilename %x version @@ -191,6 +192,9 @@ BOM_UTF8 \357\273\277 \\sourcefilename{WHITE}* { yy_push_state (sourcefilename); } +\\sourcefileline{WHITE}* { + yy_push_state (sourcefileline); +} \"[^"]*\" { /* got the version number */ string s (YYText () + 1); s = s.substr (0, s.rfind ('\"')); @@ -218,6 +222,15 @@ BOM_UTF8 \357\273\277 scm_makfrom0str (s.c_str ())); } + +{INT} { + int i; + sscanf (YYText (), "%d", &i); + + yy_pop_state (); + this->here_input ().get_source_file ()->set_line (here_input ().start (), i); +} + . { LexerError (_ ("quoted string expected after \\version").c_str ()); yy_pop_state (); @@ -226,6 +239,10 @@ BOM_UTF8 \357\273\277 LexerError (_ ("quoted string expected after \\sourcefilename").c_str ()); yy_pop_state (); } +. { + LexerError (_ ("integer expected after \\sourcefileline").c_str ()); + yy_pop_state (); +} { [^\%]* { } diff --git a/lily/source-file.cc b/lily/source-file.cc index 902baa0e47..b44066f267 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -82,6 +82,7 @@ Source_file::Source_file (string filename, string data) { name_ = filename; istream_ = 0; + line_offset_ = 0; length_ = data.length (); contents_str0_ = string_copy (data); pos_str0_ = c_str (); @@ -96,6 +97,7 @@ Source_file::Source_file (string filename_string) { name_ = filename_string; istream_ = 0; + line_offset_ = 0; contents_str0_ = 0; if (filename_string == "-") @@ -329,7 +331,16 @@ Source_file::get_line (char const *pos_str0) const if (*pos_str0 == '\n') lo--; - return lo + 2; + return lo + 2 + line_offset_; +} + +void +Source_file::set_line (char const *pos_str0, int line) +{ + int current_line = get_line (pos_str0); + line_offset_ += line - current_line; + + assert (line == get_line (pos_str0)); } int diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 7861c524a5..c81e103177 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -827,7 +827,9 @@ class Lilypond_snippet (Snippet): self.do_options (os, self.type) def ly (self): - return self.substring ('code') + contents = self.substring ('code') + return ('\\sourcefileline %d\n%s' + % (self.line_number - 1, contents)) def full_ly (self): s = self.ly () @@ -1206,8 +1208,8 @@ class Lilypond_file_snippet (Lilypond_snippet): ## strip version string to make automated regtest comparisons ## across versions easier. contents = re.sub (r'\\version *"[^"]*"', '', contents) - - return ('\\sourcefilename \"%s\"\n%s' + + return ('\\sourcefilename \"%s\"\n\\sourcefileline 0\n%s' % (name, contents)) snippet_type_to_class = { @@ -1476,11 +1478,9 @@ def write_file_map (lys, name): #(ly:add-file-name-alist '( """) for ly in lys: - snippet_map.write ('("%s.ly" . "%s:%d (%s.ly)")\n' + snippet_map.write ('("%s.ly" . "%s")\n' % (ly.basename (), - name, - ly.line_number, - ly.basename ())) + name)) snippet_map.write ('))\n') -- 2.39.5