]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 905: Gracefully ignore UTF-8 BOM in the middle of a file
authorReinhold Kainhofer <reinhold@kainhofer.com>
Mon, 15 Aug 2011 17:58:58 +0000 (19:58 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Tue, 30 Aug 2011 16:56:50 +0000 (18:56 +0200)
input/regression/bom-mark.ly [new file with mode: 0644]
lily/include/lily-lexer.hh
lily/lexer.ll
lily/lily-lexer.cc

diff --git a/input/regression/bom-mark.ly b/input/regression/bom-mark.ly
new file mode 100644 (file)
index 0000000..19895a5
--- /dev/null
@@ -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 }
index b87188b4017630239fb923ee9a4e59e5de63d8da..f4f6e14d3e020a14b21df5bc4b46f6e39170e636 100644 (file)
@@ -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;
index a9b1d3980ebb4866967996a8c7ec108614aa45b7..708825279384502b81c47e8b56f092a820762692 100644 (file)
@@ -199,8 +199,8 @@ BOM_UTF8    \357\273\277
 <INITIAL,chords,lyrics,figures,notes>{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"));
 }
index 5d87c83872d25052496f800de539760a71264c69..ba6429c3ea2798344702178363f200071c0f73cc 100644 (file)
@@ -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
 {