Correction in the line numbering method
authordeba
Thu, 26 Jul 2007 12:18:02 +0000
changeset 24603c347c306703
parent 2459 ea943997a8fe
child 2461 1dd4d6ff9bac
Correction in the line numbering method
lemon/lemon_reader.h
     1.1 --- a/lemon/lemon_reader.h	Thu Jul 05 16:39:42 2007 +0000
     1.2 +++ b/lemon/lemon_reader.h	Thu Jul 26 12:18:02 2007 +0000
     1.3 @@ -616,6 +616,17 @@
     1.4        virtual int_type sync() {
     1.5  	return EOF;
     1.6        }
     1.7 +
     1.8 +    public:
     1.9 +
    1.10 +      int line_num() const {
    1.11 +	int r = _num;
    1.12 +	for (char_type* p = gptr(); p != egptr(); ++p) {
    1.13 +	  if (*p == '\n') --r;
    1.14 +	}
    1.15 +	return r;
    1.16 +      }
    1.17 +
    1.18      };
    1.19  
    1.20    public:
    1.21 @@ -700,30 +711,37 @@
    1.22      void run() {
    1.23        int line_num = 0;
    1.24        std::string line;
    1.25 -      try {
    1.26 -        SectionReaders::iterator it;
    1.27 -	while ((++line_num, getline(*is, line)) && line.find("@end") != 0) {
    1.28 -	  for (it = readers.begin(); it != readers.end(); ++it) {
    1.29 -	    if (it->first->header(line)) {
    1.30 -              it->second = true;
    1.31 -	      char buf[2048];
    1.32 -	      FilterStreamBuf buffer(*is, line_num);
    1.33 +      
    1.34 +      SectionReaders::iterator it;
    1.35 +      while ((++line_num, getline(*is, line)) && line.find("@end") != 0) {
    1.36 +	for (it = readers.begin(); it != readers.end(); ++it) {
    1.37 +	  if (it->first->header(line)) {
    1.38 +	    it->second = true;
    1.39 +	    char buf[2048];
    1.40 +	    FilterStreamBuf buffer(*is, line_num);
    1.41 +
    1.42 +	    try {
    1.43  	      buffer.pubsetbuf(buf, sizeof(buf));
    1.44  	      std::istream ss(&buffer);
    1.45  	      it->first->read(ss);
    1.46  	      break;
    1.47 -	    }
    1.48 +	    } catch (DataFormatError& error) {
    1.49 +	      error.line(buffer.line_num());
    1.50 +	      throw;
    1.51 +	    }	
    1.52  	  }
    1.53  	}
    1.54 -        for (it = readers.begin(); it != readers.end(); ++it) {
    1.55 -          if (!it->second) {
    1.56 -            it->first->missing();
    1.57 -          }
    1.58 -        }
    1.59 -      } catch (DataFormatError& error) {
    1.60 -	error.line(line_num);
    1.61 -	throw;
    1.62 -      }	
    1.63 +      }
    1.64 +      for (it = readers.begin(); it != readers.end(); ++it) {
    1.65 +	if (!it->second) {
    1.66 +	  try {
    1.67 +	    it->first->missing();
    1.68 +	  } catch (DataFormatError& error) {
    1.69 +	    error.line(line_num);
    1.70 +	    throw;
    1.71 +	  }	
    1.72 +	}
    1.73 +      }
    1.74      }
    1.75  
    1.76