From fed3b815a068ef56bf6503f5db89c042beca4de8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 17 Jul 2015 14:59:42 -0400 Subject: [PATCH] Lexer: Dead code removal --- src/Lexer.cpp | 53 --------------------------------------------------- src/Lexer.h | 3 --- src/lex.cpp | 8 +++++--- 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 9b862631c..3a48e04f9 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -97,22 +97,6 @@ bool Lexer::token (std::string& token, Lexer::Type& type) return false; } -//////////////////////////////////////////////////////////////////////////////// -// This static method tokenizes the input and provides a vector of token/type -// results from a high-level lex. -std::vector > Lexer::tokens ( - const std::string& text) -{ - std::vector > all; - std::string token; - Lexer::Type type; - Lexer l (text); - while (l.token (token, type)) - all.push_back (std::pair (token, type)); - - return all; -} - //////////////////////////////////////////////////////////////////////////////// // This static method tokenizes the input, but discards the type information. std::vector Lexer::split (const std::string& text) @@ -1093,30 +1077,6 @@ bool Lexer::isWord (std::string& token, Lexer::Type& type) return false; } -//////////////////////////////////////////////////////////////////////////////// -// Lexer::Type::word -// [^\s]+ -bool Lexer::isContiguous (std::string& token, Lexer::Type& type) -{ - std::size_t marker = _cursor; - - while (_text[marker] && - ! isWhitespace (_text[marker]) && - _text[marker] != '(' && - _text[marker] != ')') - utf8_next_char (_text, marker); - - if (marker > _cursor) - { - token = _text.substr (_cursor, marker - _cursor); - type = Lexer::Type::word; - _cursor = marker; - return true; - } - - return false; -} - //////////////////////////////////////////////////////////////////////////////// // Static std::string Lexer::typeToString (Lexer::Type type) @@ -1148,19 +1108,6 @@ bool Lexer::isAllDigits (const std::string& text) return text.find_first_not_of ("0123456789") == std::string::npos; } -//////////////////////////////////////////////////////////////////////////////// -// Not escape-proof. -bool Lexer::isOneWord (const std::string& text) -{ - std::string::size_type i = 0; - int character; - while ((character = utf8_next_char (text, i))) - if (Lexer::isWhitespace (character)) - return false; - - return true; -} - //////////////////////////////////////////////////////////////////////////////// // Full implementation of a quoted word. Includes: // '\'' diff --git a/src/Lexer.h b/src/Lexer.h index 00fec62cb..5f21ce73e 100644 --- a/src/Lexer.h +++ b/src/Lexer.h @@ -54,7 +54,6 @@ public: Lexer (const std::string&); ~Lexer (); bool token (std::string&, Lexer::Type&); - static std::vector > tokens (const std::string&); static std::vector split (const std::string&); static std::string typeToString (Lexer::Type); @@ -73,7 +72,6 @@ public: static bool isHardBoundary (int, int); static bool isPunctuation (int); static bool isAllDigits (const std::string&); - static bool isOneWord (const std::string&); static void dequote (std::string&, const std::string& quotes = "'\""); static bool wasQuoted (const std::string&); static bool readWord (const std::string&, const std::string&, std::string::size_type&, std::string&); @@ -106,7 +104,6 @@ public: bool isDOM (std::string&, Lexer::Type&); bool isIdentifier (std::string&, Lexer::Type&); bool isWord (std::string&, Lexer::Type&); - bool isContiguous (std::string&, Lexer::Type&); private: std::string _text; diff --git a/src/lex.cpp b/src/lex.cpp index ace055772..366962bc7 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -12,9 +12,11 @@ int main (int argc, char** argv) { std::cout << "argument '" << argv[i] << "'\n"; - auto all = Lexer::tokens (argv[i]); - for (auto token : Lexer::tokens (argv[i])) - std::cout << " token '" << token.first << "' " << Lexer::typeToString (token.second) << "\n"; + Lexer l (argv[i]); + std::string token; + Lexer::Type type; + while (l.token (token, type)) + std::cout << " token '" << token << "' " << Lexer::typeToString (type) << "\n"; } }