| 1 | /* ANTLR Translator Generator | 
| 2 | * Project led by Terence Parr at http://www.jGuru.com | 
| 3 | * Software rights: http://www.antlr.org/license.html | 
| 4 | * | 
| 5 | * $Id: RecognitionException.cpp,v 1.1 2005-12-02 15:38:02 tim Exp $ | 
| 6 | */ | 
| 7 |  | 
| 8 | #include "antlr/RecognitionException.hpp" | 
| 9 | #include "antlr/String.hpp" | 
| 10 |  | 
| 11 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE | 
| 12 | namespace antlr { | 
| 13 | #endif | 
| 14 |  | 
| 15 | RecognitionException::RecognitionException() | 
| 16 | : ANTLRException("parsing error") | 
| 17 | , line(-1) | 
| 18 | , column(-1) | 
| 19 | { | 
| 20 | } | 
| 21 |  | 
| 22 | RecognitionException::RecognitionException(const ANTLR_USE_NAMESPACE(std)string& s) | 
| 23 | : ANTLRException(s) | 
| 24 | , line(-1) | 
| 25 | , column(-1) | 
| 26 | { | 
| 27 | } | 
| 28 |  | 
| 29 | RecognitionException::RecognitionException(const ANTLR_USE_NAMESPACE(std)string& s, | 
| 30 | const ANTLR_USE_NAMESPACE(std)string& fileName_, | 
| 31 | int line_,int column_) | 
| 32 | : ANTLRException(s) | 
| 33 | , fileName(fileName_) | 
| 34 | , line(line_) | 
| 35 | , column(column_) | 
| 36 | { | 
| 37 | } | 
| 38 |  | 
| 39 | ANTLR_USE_NAMESPACE(std)string RecognitionException::getFileLineColumnString() const | 
| 40 | { | 
| 41 | ANTLR_USE_NAMESPACE(std)string fileLineColumnString; | 
| 42 |  | 
| 43 | if ( fileName.length() > 0 ) | 
| 44 | fileLineColumnString = fileName + ":"; | 
| 45 |  | 
| 46 | if ( line != -1 ) | 
| 47 | { | 
| 48 | if ( fileName.length() == 0 ) | 
| 49 | fileLineColumnString = fileLineColumnString + "line "; | 
| 50 |  | 
| 51 | fileLineColumnString = fileLineColumnString + line; | 
| 52 |  | 
| 53 | if ( column != -1 ) | 
| 54 | fileLineColumnString = fileLineColumnString + ":" + column; | 
| 55 |  | 
| 56 | fileLineColumnString = fileLineColumnString + ":"; | 
| 57 | } | 
| 58 |  | 
| 59 | fileLineColumnString = fileLineColumnString + " "; | 
| 60 |  | 
| 61 | return fileLineColumnString; | 
| 62 | } | 
| 63 |  | 
| 64 | ANTLR_USE_NAMESPACE(std)string RecognitionException::toString() const | 
| 65 | { | 
| 66 | return getFileLineColumnString()+getMessage(); | 
| 67 | } | 
| 68 |  | 
| 69 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE | 
| 70 | } | 
| 71 | #endif |