[Lemon-commits] deba: r3299 - lemon/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Thu Jul 26 14:18:03 CEST 2007


Author: deba
Date: Thu Jul 26 14:18:02 2007
New Revision: 3299

Modified:
   lemon/trunk/lemon/lemon_reader.h

Log:
Correction in the line numbering method



Modified: lemon/trunk/lemon/lemon_reader.h
==============================================================================
--- lemon/trunk/lemon/lemon_reader.h	(original)
+++ lemon/trunk/lemon/lemon_reader.h	Thu Jul 26 14:18:02 2007
@@ -616,6 +616,17 @@
       virtual int_type sync() {
 	return EOF;
       }
+
+    public:
+
+      int line_num() const {
+	int r = _num;
+	for (char_type* p = gptr(); p != egptr(); ++p) {
+	  if (*p == '\n') --r;
+	}
+	return r;
+      }
+
     };
 
   public:
@@ -700,30 +711,37 @@
     void run() {
       int line_num = 0;
       std::string line;
-      try {
-        SectionReaders::iterator it;
-	while ((++line_num, getline(*is, line)) && line.find("@end") != 0) {
-	  for (it = readers.begin(); it != readers.end(); ++it) {
-	    if (it->first->header(line)) {
-              it->second = true;
-	      char buf[2048];
-	      FilterStreamBuf buffer(*is, line_num);
+      
+      SectionReaders::iterator it;
+      while ((++line_num, getline(*is, line)) && line.find("@end") != 0) {
+	for (it = readers.begin(); it != readers.end(); ++it) {
+	  if (it->first->header(line)) {
+	    it->second = true;
+	    char buf[2048];
+	    FilterStreamBuf buffer(*is, line_num);
+
+	    try {
 	      buffer.pubsetbuf(buf, sizeof(buf));
 	      std::istream ss(&buffer);
 	      it->first->read(ss);
 	      break;
-	    }
+	    } catch (DataFormatError& error) {
+	      error.line(buffer.line_num());
+	      throw;
+	    }	
 	  }
 	}
-        for (it = readers.begin(); it != readers.end(); ++it) {
-          if (!it->second) {
-            it->first->missing();
-          }
-        }
-      } catch (DataFormatError& error) {
-	error.line(line_num);
-	throw;
-      }	
+      }
+      for (it = readers.begin(); it != readers.end(); ++it) {
+	if (!it->second) {
+	  try {
+	    it->first->missing();
+	  } catch (DataFormatError& error) {
+	    error.line(line_num);
+	    throw;
+	  }	
+	}
+      }
     }
 
 



More information about the Lemon-commits mailing list