From 86ed23234875bc32c6dab9b8f4c26f370e881538 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 28 Jun 2015 12:35:06 -0400 Subject: [PATCH] Lexer: Added ::wasQuoted to determine original quote state --- src/Lexer.cpp | 9 +++++++++ src/Lexer.h | 25 +++++++++++++------------ test/lexer.t.cpp | 10 ++++++++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 2642d56c9..856218ecc 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -324,6 +324,15 @@ void Lexer::dequote (std::string& input) } } +//////////////////////////////////////////////////////////////////////////////// +bool Lexer::wasQuoted (const std::string& input) +{ + if (input.find_first_of (" \t()") != std::string::npos) + return true; + + return false; +} + //////////////////////////////////////////////////////////////////////////////// bool Lexer::isEOS () const { diff --git a/src/Lexer.h b/src/Lexer.h index 2bacdd727..bb83f461b 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -63,18 +63,19 @@ public: // Static helpers. static const std::string typeName (const Lexer::Type&); - static bool isWhitespace (int); - static bool isAlpha (int); - static bool isDigit (int); - static bool isHexDigit (int); - static bool isIdentifierStart (int); - static bool isIdentifierNext (int); - static bool isSingleCharOperator (int); - static bool isDoubleCharOperator (int, int, int); - static bool isTripleCharOperator (int, int, int, int); - static bool isBoundary (int, int); - static bool isPunctuation (int); - static void dequote (std::string&); + static bool isWhitespace (int); + static bool isAlpha (int); + static bool isDigit (int); + static bool isHexDigit (int); + static bool isIdentifierStart (int); + static bool isIdentifierNext (int); + static bool isSingleCharOperator (int); + static bool isDoubleCharOperator (int, int, int); + static bool isTripleCharOperator (int, int, int, int); + static bool isBoundary (int, int); + static bool isPunctuation (int); + static void dequote (std::string&); + static bool wasQuoted (const std::string&); // Helpers. bool isEOS () const; diff --git a/test/lexer.t.cpp b/test/lexer.t.cpp index 0e873c7f8..698cb5840 100644 --- a/test/lexer.t.cpp +++ b/test/lexer.t.cpp @@ -36,7 +36,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (795); + UnitTest t (799); std::vector > tokens; std::string token; @@ -71,7 +71,7 @@ int main (int argc, char** argv) t.ok (Lexer::isWhitespace (0x205F), "U+205F isWhitespace"); t.ok (Lexer::isWhitespace (0x3000), "U+3000 isWhitespace"); - // static bool Lexer::isBoundary(int, int); + // static bool Lexer::isBoundary (int, int); t.ok (Lexer::isBoundary (' ', 'a'), "' ' --> 'a' = isBoundary"); t.ok (Lexer::isBoundary ('a', ' '), "'a' --> ' ' = isBoundary"); t.ok (Lexer::isBoundary (' ', '+'), "' ' --> '+' = isBoundary"); @@ -80,6 +80,12 @@ int main (int argc, char** argv) t.ok (Lexer::isBoundary ('(', '('), "'(' --> '(' = isBoundary"); t.notok (Lexer::isBoundary ('r', 'd'), "'r' --> 'd' = isBoundary"); + // static bool Lexer::wasQuoted (const std::string&); + t.notok (Lexer::wasQuoted (""), "'' --> !wasQuoted"); + t.notok (Lexer::wasQuoted ("foo"), "'foo' --> !wasQuoted"); + t.ok (Lexer::wasQuoted ("a b"), "'a b' --> wasQuoted"); + t.ok (Lexer::wasQuoted ("(a)"), "'(a)' --> wasQuoted"); + // Should result in no tokens. Lexer l0 (""); t.notok (l0.token (token, type), "'' --> no tokens");