summaryrefslogtreecommitdiffstats
path: root/lib/antlr/src/MismatchedCharException.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /lib/antlr/src/MismatchedCharException.cpp
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/antlr/src/MismatchedCharException.cpp')
-rw-r--r--lib/antlr/src/MismatchedCharException.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/lib/antlr/src/MismatchedCharException.cpp b/lib/antlr/src/MismatchedCharException.cpp
new file mode 100644
index 00000000..e73dbf36
--- /dev/null
+++ b/lib/antlr/src/MismatchedCharException.cpp
@@ -0,0 +1,120 @@
+/* ANTLR Translator Generator
+ * Project led by Terence Parr at http://www.jGuru.com
+ * Software rights: http://www.antlr.org/license.html
+ *
+ * $Id$
+ */
+
+#include "antlr/CharScanner.hpp"
+#include "antlr/MismatchedCharException.hpp"
+#include "antlr/String.hpp"
+
+#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
+namespace antlr {
+#endif
+
+MismatchedCharException::MismatchedCharException()
+ : RecognitionException("Mismatched char")
+{}
+
+// Expected range / not range
+MismatchedCharException::MismatchedCharException(
+ int c,
+ int lower,
+ int upper_,
+ bool matchNot,
+ CharScanner* scanner_
+) : RecognitionException("Mismatched char",
+ scanner_->getFilename(),
+ scanner_->getLine(), scanner_->getColumn())
+ , mismatchType(matchNot ? NOT_RANGE : RANGE)
+ , foundChar(c)
+ , expecting(lower)
+ , upper(upper_)
+ , scanner(scanner_)
+{
+}
+
+// Expected token / not token
+MismatchedCharException::MismatchedCharException(
+ int c,
+ int expecting_,
+ bool matchNot,
+ CharScanner* scanner_
+) : RecognitionException("Mismatched char",
+ scanner_->getFilename(),
+ scanner_->getLine(), scanner_->getColumn())
+ , mismatchType(matchNot ? NOT_CHAR : CHAR)
+ , foundChar(c)
+ , expecting(expecting_)
+ , scanner(scanner_)
+{
+}
+
+// Expected BitSet / not BitSet
+MismatchedCharException::MismatchedCharException(
+ int c,
+ BitSet set_,
+ bool matchNot,
+ CharScanner* scanner_
+) : RecognitionException("Mismatched char",
+ scanner_->getFilename(),
+ scanner_->getLine(), scanner_->getColumn())
+ , mismatchType(matchNot ? NOT_SET : SET)
+ , foundChar(c)
+ , set(set_)
+ , scanner(scanner_)
+{
+}
+
+ANTLR_USE_NAMESPACE(std)string MismatchedCharException::getMessage() const
+{
+ ANTLR_USE_NAMESPACE(std)string s;
+
+ switch (mismatchType) {
+ case CHAR :
+ s += "expecting '" + charName(expecting) + "', found '" + charName(foundChar) + "'";
+ break;
+ case NOT_CHAR :
+ s += "expecting anything but '" + charName(expecting) + "'; got it anyway";
+ break;
+ case RANGE :
+ s += "expecting token in range: '" + charName(expecting) + "'..'" + charName(upper) + "', found '" + charName(foundChar) + "'";
+ break;
+ case NOT_RANGE :
+ s += "expecting token NOT in range: " + charName(expecting) + "'..'" + charName(upper) + "', found '" + charName(foundChar) + "'";
+ break;
+ case SET :
+ case NOT_SET :
+ {
+ s += ANTLR_USE_NAMESPACE(std)string("expecting ") + (mismatchType == NOT_SET ? "NOT " : "") + "one of (";
+ ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray();
+ for ( unsigned int i = 0; i < elems.size(); i++ )
+ {
+ s += " '";
+ s += charName(elems[i]);
+ s += "'";
+ }
+ s += "), found '" + charName(foundChar) + "'";
+ }
+ break;
+ default :
+ s += RecognitionException::getMessage();
+ break;
+ }
+
+ return s;
+}
+
+#ifndef NO_STATIC_CONSTS
+const int MismatchedCharException::CHAR;
+const int MismatchedCharException::NOT_CHAR;
+const int MismatchedCharException::RANGE;
+const int MismatchedCharException::NOT_RANGE;
+const int MismatchedCharException::SET;
+const int MismatchedCharException::NOT_SET;
+#endif
+
+#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
+}
+#endif