From: Braden M. <br...@us...> - 2006-11-18 20:48:48
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv6457/src/libopenvrml/openvrml Modified Files: Tag: OpenVRML-0_16-BRANCH Vrml97Parser.g X3DVrmlParser.g Log Message: Report accurate line and column number information in parser error messages. Index: X3DVrmlParser.g =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/X3DVrmlParser.g,v retrieving revision 1.21.2.1 retrieving revision 1.21.2.2 diff -C2 -d -r1.21.2.1 -r1.21.2.2 *** X3DVrmlParser.g 17 Nov 2006 06:47:06 -0000 1.21.2.1 --- X3DVrmlParser.g 18 Nov 2006 20:48:46 -0000 1.21.2.2 *************** *** 226,245 **** } virtual void reportError(const antlr::RecognitionException & ex) { ! this->browser_->err(this->getFilename() + ": " + ex.toString()); } virtual void reportError(const std::string & s) { ! this->browser_->err(this->getFilename() + ": error: " + s); } virtual void reportWarning(const std::string & s) { ! this->browser_->err(this->getFilename() + ": warning: " + s); } private: openvrml::browser * browser_; } --- 226,261 ---- } + virtual void consume() + { + this->last_token_ = this->LT(1); + this->LLkParser::consume(); + } + virtual void reportError(const antlr::RecognitionException & ex) { ! std::ostringstream out; ! out << ex.getFilename() << ':' << ex.getLine() << ':' << ex.getColumn() ! << ": error: " << ex.getMessage(); ! this->browser_->err(out.str()); } virtual void reportError(const std::string & s) { ! std::ostringstream out; ! out << this->getFilename() << ':' << this->last_token_->getLine() ! << ':' << this->last_token_->getColumn() << ": error: " << s; ! this->browser_->err(out.str()); } virtual void reportWarning(const std::string & s) { ! std::ostringstream out; ! out << this->getFilename() << ':' << this->last_token_->getLine() ! << ':' << this->last_token_->getColumn() << ": warning: " << s; ! this->browser_->err(out.str()); } private: + antlr::RefToken last_token_; openvrml::browser * browser_; } Index: Vrml97Parser.g =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/Vrml97Parser.g,v retrieving revision 1.68.2.1 retrieving revision 1.68.2.2 diff -C2 -d -r1.68.2.1 -r1.68.2.2 *** Vrml97Parser.g 17 Nov 2006 06:47:06 -0000 1.68.2.1 --- Vrml97Parser.g 18 Nov 2006 20:48:46 -0000 1.68.2.2 *************** *** 108,112 **** std::istream & in_; size_t line_; ! size_t col_; int c_; int prev_char_; --- 108,112 ---- std::istream & in_; size_t line_; ! int col_; int c_; int prev_char_; *************** *** 195,199 **** in_(in), line_(1), ! col_(0), c_(' '), prev_char_('\0'), --- 195,199 ---- in_(in), line_(1), ! col_(-1), c_(' '), prev_char_('\0'), *************** *** 231,234 **** --- 231,237 ---- } + token->setLine(int(this->line_)); + token->setColumn(int(this->col_)); + if (this->c_ == EOF) { token->setType(EOF_); *************** *** 435,440 **** } - token->setLine(int(this->line_)); - token->setColumn(int(this->col_)); this->prev_token_type_ = token->getType(); --- 438,441 ---- *************** *** 449,453 **** // ! // Increment the line count (and reset the column count to zero) if the // current character is a newline character EXCEPT if the current character // is a linefeed AND the previous character is a carriage return. --- 450,454 ---- // ! // Increment the line count (and reset the column count to -1) if the // current character is a newline character EXCEPT if the current character // is a linefeed AND the previous character is a carriage return. *************** *** 456,460 **** if (!((this->c_ == 0x0a) && (this->prev_char_ == 0x0d))) { ++this->line_; ! this->col_ = 0; } } --- 457,461 ---- if (!((this->c_ == 0x0a) && (this->prev_char_ == 0x0d))) { ++this->line_; ! this->col_ = -1; } } *************** *** 620,639 **** } virtual void reportError(const antlr::RecognitionException & ex) { ! this->browser_->err(this->getFilename() + ": " + ex.toString()); } virtual void reportError(const std::string & s) { ! this->browser_->err(this->getFilename() + ": error: " + s); } virtual void reportWarning(const std::string & s) { ! this->browser_->err(this->getFilename() + ": warning: " + s); } private: openvrml::browser * browser_; } --- 621,656 ---- } + virtual void consume() + { + this->last_token_ = this->LT(1); + this->LLkParser::consume(); + } + virtual void reportError(const antlr::RecognitionException & ex) { ! std::ostringstream out; ! out << ex.getFilename() << ':' << ex.getLine() << ':' << ex.getColumn() ! << ": error: " << ex.getMessage(); ! this->browser_->err(out.str()); } virtual void reportError(const std::string & s) { ! std::ostringstream out; ! out << this->getFilename() << ':' << this->last_token_->getLine() ! << ':' << this->last_token_->getColumn() << ": error: " << s; ! this->browser_->err(out.str()); } virtual void reportWarning(const std::string & s) { ! std::ostringstream out; ! out << this->getFilename() << ':' << this->last_token_->getLine() ! << ':' << this->last_token_->getColumn() << ": warning: " << s; ! this->browser_->err(out.str()); } private: + antlr::RefToken last_token_; openvrml::browser * browser_; } |