• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/xml/xpath/private/XPathLex.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _xpathlex_h
00018 #define _xpathlex_h
00019 
00020 #include <spl/Memory.h>
00021 #include <spl/String.h>
00022 #include <spl/text/StringBuffer.h>
00023 #include <spl/collection/Vector.h>
00024 
00030 class XPathLex : public IMemoryValidate
00031 {
00032 public:
00033         typedef enum _XPathLexToken
00034         {
00035                 XP_UNKNOWN = 0,
00036                 XP_EOF = 1,
00037                 XP_STRING = 2,
00038                 XP_LPAR = 3,
00039                 XP_RPAR = 4,
00040                 XP_LBRAC = 5,
00041                 XP_RBRAC = 6,
00042                 XP_DOT = 7,
00043                 XP_DOTDOT = 8,
00044                 XP_AT = 9,
00045                 XP_COMMA = 10,
00046                 XP_COLONCOLON = 11,
00047                 XP_INT = 12,
00048                 XP_FLOAT = 13,
00049                 XP_SLASH = 14,
00050                 XP_SLASHSLASH = 15,
00051                 XP_PIPE = 16,
00052                 XP_PLUS = 17,
00053                 XP_MIN = 18,
00054                 XP_EQ = 19,
00055                 XP_NEQ = 20,
00056                 XP_LT = 21,
00057                 XP_LTEQ = 22,
00058                 XP_GT = 23,
00059                 XP_GTEQ = 24,
00060                 XP_AND = 25,
00061                 XP_OR = 26,
00062                 XP_MOD = 27,
00063                 XP_DIV = 28,
00064                 XP_STAR = 29,
00065                 XP_DOLLAR = 30,
00066                 XP_COLON = 31,
00067                 XP_EQEQ = 32,
00068                 XP_LITERAL = 33
00069         } XPathLexToken;
00070 
00071 private:
00072         enum XPathLexState
00073         {
00074                 XPS_START = 0,
00075                 XPS_NUMERIC = 1,
00076                 XPS_NAME = 2,
00077                 XPS_DOT = 3,
00078                 XPS_COLON = 4,
00079                 XPS_TICK = 5,
00080                 XPS_QUOTE = 6,
00081                 XPS_SLASH = 7,
00082                 XPS_BANG = 8,
00083                 XPS_LT = 9,
00084                 XPS_GT = 10,
00085                 XPS_FLOAT = 11,
00086                 XPS_FLOAT_EXP = 12,
00087                 XPS_NEG = 13,
00088                 XPS_EQ = 14
00089         };
00090 
00091         Vector<XPathLexToken> m_tokens;
00092         Vector<StringPtr> m_lexums;
00093         Vector<int> m_lexCharPoses;
00094         int m_pos;
00095         XPathLexState m_state;
00096 
00097         void TokenizeString(StringBuffer& token, char ch, char termchar, int pos);
00098         void TokenizeChar2(StringBuffer& token, int& pos, char ch, char chChar2, XPathLexToken char2Token, XPathLexToken char1Token);
00099 
00100 public:
00101         XPathLex();
00102         XPathLex(const XPathLex& lex);
00103         virtual ~XPathLex();
00104 
00105         XPathLex& operator =(const XPathLex& lex);
00106 
00110         void Tokenize(const String& text);
00111 
00112         XPathLexToken Match(XPathLex::XPathLexToken token);
00113 
00114         XPathLexToken GetRelativeToken(int distance) const;
00115 
00116         inline int Count() const { return m_tokens.Count(); }
00117         
00118         inline XPathLexToken CurrentToken() const { return m_tokens.ElementAt(m_pos); }
00119 
00120         inline const String& CurrentLexum() const { return *m_lexums.ElementAtRef(m_pos); }
00121 
00122         inline int CurrentLexumInputCharPos() const { return m_lexCharPoses[m_pos]; }
00123 
00124         inline bool HasMoreTokens() const { return m_pos < m_tokens.Count() - 1; }
00125 
00126         inline bool IsNameChar(char ch) const
00127         {
00128                 return Char::IsLetterOrDigit(ch) ||
00129                         '_' == ch || 
00130                         '-' == ch ||
00131                         '.' == ch;
00132         }
00133         
00134 #if defined(DEBUG) || defined(_DEBUG)
00135         void CheckMem() const;
00136         void ValidateMem() const;
00137 #endif
00138 };
00139 
00140 #endif