mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Lexer
- Renamed ::split to ::word_split, for clarity and because of the need for a full token split, coming next.
This commit is contained in:
parent
e753473dc4
commit
0af9bbdc03
5 changed files with 18 additions and 18 deletions
|
@ -92,7 +92,7 @@ void Alias::resolve (Tree* tree)
|
|||
something = true;
|
||||
|
||||
std::vector <std::string> words;
|
||||
Lexer::split (words, context.aliases[raw]);
|
||||
Lexer::word_split (words, context.aliases[raw]);
|
||||
|
||||
std::vector <std::string>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
|
|
|
@ -619,7 +619,7 @@ bool Lexer::is_ws (int c)
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Split 'input' into 'words' on Lexer::is_ws boundaries, observing quotes.
|
||||
void Lexer::split (std::vector <std::string>& words, const std::string& input)
|
||||
void Lexer::word_split (std::vector <std::string>& words, const std::string& input)
|
||||
{
|
||||
words.clear ();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
static const std::string type_name (const Type&);
|
||||
static bool is_ws (int);
|
||||
static void split (std::vector <std::string>&, const std::string&);
|
||||
static void word_split (std::vector <std::string>&, const std::string&);
|
||||
|
||||
private:
|
||||
bool is_punct (int) const;
|
||||
|
|
|
@ -468,7 +468,7 @@ void Parser::injectDefaults ()
|
|||
// because captureFirst inserts args immediately after the command, and
|
||||
// so has the effect of reversing the list.
|
||||
std::vector <std::string> args;
|
||||
Lexer::split (args, defaultCommand);
|
||||
Lexer::word_split (args, defaultCommand);
|
||||
std::vector <std::string>::reverse_iterator r;
|
||||
for (r = args.rbegin (); r != args.rend (); ++r)
|
||||
{
|
||||
|
|
|
@ -299,25 +299,25 @@ int main (int argc, char** argv)
|
|||
t.is (tokens[20].first, ")", "tokens[20] == ')'");
|
||||
t.is (tokens[20].second, Lexer::typeOperator, "tokens[20] == typeOperator"); // 170
|
||||
|
||||
// void splitq (std::vector<std::string>&, const std::string&);
|
||||
// void word_split (std::vector<std::string>&, const std::string&);
|
||||
std::string unsplit = " ( A or B ) ";
|
||||
std::vector <std::string> items;
|
||||
Lexer::split (items, unsplit);
|
||||
t.is (items.size (), (size_t) 5, "split ' ( A or B ) '");
|
||||
t.is (items[0], "(", "split ' ( A or B ) ' -> [0] '('");
|
||||
t.is (items[1], "A", "split ' ( A or B ) ' -> [1] 'A'");
|
||||
t.is (items[2], "or", "split ' ( A or B ) ' -> [2] 'or'");
|
||||
t.is (items[3], "B", "split ' ( A or B ) ' -> [3] 'B'");
|
||||
t.is (items[4], ")", "split ' ( A or B ) ' -> [4] ')'");
|
||||
Lexer::word_split (items, unsplit);
|
||||
t.is (items.size (), (size_t) 5, "word_split ' ( A or B ) '");
|
||||
t.is (items[0], "(", "word_split ' ( A or B ) ' -> [0] '('");
|
||||
t.is (items[1], "A", "word_split ' ( A or B ) ' -> [1] 'A'");
|
||||
t.is (items[2], "or", "word_split ' ( A or B ) ' -> [2] 'or'");
|
||||
t.is (items[3], "B", "word_split ' ( A or B ) ' -> [3] 'B'");
|
||||
t.is (items[4], ")", "word_split ' ( A or B ) ' -> [4] ')'");
|
||||
|
||||
// Test simple mode with contrived tokens that ordinarily split.
|
||||
unsplit = " +-* a+b 12.3e4 'c d'";
|
||||
Lexer::split (items, unsplit);
|
||||
t.is (items.size (), (size_t) 4, "split ' +-* a+b 12.3e4 'c d''");
|
||||
t.is (items[0], "+-*", "split ' +-* a+b 12.3e4 'c d'' -> [0] '+-*'");
|
||||
t.is (items[1], "a+b", "split ' +-* a+b 12.3e4 'c d'' -> [1] 'a+b'");
|
||||
t.is (items[2], "12.3e4", "split ' +-* a+b 12.3e4 'c d'' -> [2] '12.3e4'");
|
||||
t.is (items[3], "c d", "split ' +-* a+b 12.3e4 'c d'' -> [3] 'c d'");
|
||||
Lexer::word_split (items, unsplit);
|
||||
t.is (items.size (), (size_t) 4, "word_split ' +-* a+b 12.3e4 'c d''");
|
||||
t.is (items[0], "+-*", "word_split ' +-* a+b 12.3e4 'c d'' -> [0] '+-*'");
|
||||
t.is (items[1], "a+b", "word_split ' +-* a+b 12.3e4 'c d'' -> [1] 'a+b'");
|
||||
t.is (items[2], "12.3e4", "word_split ' +-* a+b 12.3e4 'c d'' -> [2] '12.3e4'");
|
||||
t.is (items[3], "c d", "word_split ' +-* a+b 12.3e4 'c d'' -> [3] 'c d'");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue