aboutsummaryrefslogtreecommitdiffstats
path: root/Scanner.cpp
diff options
context:
space:
mode:
authorLefteris Karapetsas <lefteris@refu.co>2014-12-01 06:25:42 +0800
committerLefteris Karapetsas <lefteris@refu.co>2014-12-01 06:25:42 +0800
commit21fdd84c09edd837fde1299c8e4f0b9545a8c1fa (patch)
treeee1f211fdb3582a4bb9ed124ca4d167b0460edc1 /Scanner.cpp
parenta59546473916fcccb2ddc444e7264a94c551c617 (diff)
downloaddexon-solidity-21fdd84c09edd837fde1299c8e4f0b9545a8c1fa.tar.gz
dexon-solidity-21fdd84c09edd837fde1299c8e4f0b9545a8c1fa.tar.zst
dexon-solidity-21fdd84c09edd837fde1299c8e4f0b9545a8c1fa.zip
Moving LiteralScope to Scanner.cpp
Diffstat (limited to 'Scanner.cpp')
-rw-r--r--Scanner.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/Scanner.cpp b/Scanner.cpp
index 3335e9df..6ef8a6c7 100644
--- a/Scanner.cpp
+++ b/Scanner.cpp
@@ -102,6 +102,47 @@ int hexValue(char c)
}
} // end anonymous namespace
+
+
+/// Scoped helper for literal recording. Automatically drops the literal
+/// if aborting the scanning before it's complete.
+enum LiteralType {
+ LITERAL_TYPE_STRING,
+ LITERAL_TYPE_NUMBER, // not really different from string type in behaviour
+ LITERAL_TYPE_COMMENT
+};
+
+class LiteralScope
+{
+public:
+ explicit LiteralScope(Scanner* _self, enum LiteralType _type): m_type(_type)
+ , m_scanner(_self)
+ , m_complete(false)
+ {
+ if (_type == LITERAL_TYPE_COMMENT)
+ m_scanner->m_nextSkippedComment.literal.clear();
+ else
+ m_scanner->m_nextToken.literal.clear();
+ }
+ ~LiteralScope()
+ {
+ if (!m_complete)
+ {
+ if (m_type == LITERAL_TYPE_COMMENT)
+ m_scanner->m_nextSkippedComment.literal.clear();
+ else
+ m_scanner->m_nextToken.literal.clear();
+ }
+ }
+ void complete() { m_complete = true; }
+
+private:
+ enum LiteralType m_type;
+ Scanner* m_scanner;
+ bool m_complete;
+}; // end of LiteralScope class
+
+
void Scanner::reset(CharStream const& _source)
{
m_source = _source;