From 108699247848e254f996236bca44d8ff46cabb14 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Mon, 15 Aug 2011 19:58:58 +0200 Subject: [PATCH] Issue 905: Gracefully ignore UTF-8 BOM in the middle of a file --- input/regression/bom-mark.ly | 11 +++++++++++ lily/include/lily-lexer.hh | 1 + lily/lexer.ll | 4 ++-- lily/lily-lexer.cc | 14 +++++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 input/regression/bom-mark.ly diff --git a/input/regression/bom-mark.ly b/input/regression/bom-mark.ly new file mode 100644 index 0000000000..19895a5af8 --- /dev/null +++ b/input/regression/bom-mark.ly @@ -0,0 +1,11 @@ + \version "2.15.9" + +#(ly:set-option 'warning-as-error #f) + +\header { + texidoc = "This input file contains a UTF-8 BOM not at the very beginning, + but on the first line after the first byte. LilyPond should gracefully + ignore this BOM as specified in RFC 3629, but print a warning." +} + +{ c } diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index b87188b401..f4f6e14d3e 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -111,6 +111,7 @@ public: void push_note_state (SCM tab); void pop_state (); void LexerError (char const *); + void LexerWarning (char const *); void set_identifier (SCM path, SCM val); int get_state () const; bool is_note_state () const; diff --git a/lily/lexer.ll b/lily/lexer.ll index a9b1d3980e..7088252793 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -199,8 +199,8 @@ BOM_UTF8 \357\273\277 {BOM_UTF8}/.* { if (this->lexloc_->line_number () != 1 || this->lexloc_->column_number () != 0) { - LexerError (_ ("stray UTF-8 BOM encountered").c_str ()); - exit (1); + LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ()); + // exit (1); } debug_output (_ ("Skipping UTF-8 BOM")); } diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 5d87c83872..ba6429c3ea 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -310,7 +310,7 @@ void Lily_lexer::LexerError (char const *s) { if (include_stack_.empty ()) - message (_f ("error at EOF: %s", s) + "\n"); + non_fatal_error (s, _f ("%s:EOF", s)); else { error_level_ |= 1; @@ -319,6 +319,18 @@ Lily_lexer::LexerError (char const *s) } } +void +Lily_lexer::LexerWarning (char const *s) +{ + if (include_stack_.empty ()) + warning (s, _f ("%s:EOF", s)); + else + { + Input spot (*lexloc_); + spot.warning (s); + } +} + char Lily_lexer::escaped_char (char c) const { -- 2.39.5