diff options
author | Michi Henning <michi@zeroc.com> | 2002-06-28 02:26:19 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2002-06-28 02:26:19 +0000 |
commit | 50e451ca4e2c8e38453521a4e000e79cb7222411 (patch) | |
tree | ddd1842c66675dce93097b7724f5bcafbe05d3ae /cpp/src/Slice/GrammarUtil.h | |
parent | removed backlog cleanup code (diff) | |
download | ice-50e451ca4e2c8e38453521a4e000e79cb7222411.tar.bz2 ice-50e451ca4e2c8e38453521a4e000e79cb7222411.tar.xz ice-50e451ca4e2c8e38453521a4e000e79cb7222411.zip |
Added case-insensitive keyword comparison. Major restructuring of the
scanner and parser. Quite a few style fixes. Improved diagnostics in
many places and eliminated several more "parse error" conditions.
Diffstat (limited to 'cpp/src/Slice/GrammarUtil.h')
-rw-r--r-- | cpp/src/Slice/GrammarUtil.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/cpp/src/Slice/GrammarUtil.h b/cpp/src/Slice/GrammarUtil.h index d26447b9fe6..642815afc7b 100644 --- a/cpp/src/Slice/GrammarUtil.h +++ b/cpp/src/Slice/GrammarUtil.h @@ -12,9 +12,53 @@ #define SLICE_GRAMMER_UTIL_H #include <Slice/Parser.h> +#include <map> namespace Slice { +// +// Function object to do case-insensitive string comparison. +// +struct CICompare : public std::binary_function<std::string, std::string, bool> +{ + bool operator()(const std::string& s1, const std::string& s2) const + { + std::string::const_iterator p1 = s1.begin(); + std::string::const_iterator p2 = s2.begin(); + while(p1 != s1.end() && p2 != s2.end() && tolower(*p1) == tolower(*p2)) + { + ++p1; + ++p2; + } + if(p1 == s1.end() && p2 == s2.end()) + { + return false; + } + else if(p1 == s1.end()) + { + return true; + } + else if(p2 == s2.end()) + { + return false; + } + else + { + return tolower(*p1) < tolower(*p2); + } + } +}; + +// +// Definitions for the case-insensitive keyword-token map. +// +typedef std::map<std::string, int, CICompare> stringTokenMap; +extern stringTokenMap keywordMap; + +// +// initialize() fills the keyword map with all keyword-token pairs. +// +void initialize(); class StringTok; class StringListTok; |