KHTML
tokenizer.h
Go to the documentation of this file.
00001 /* 00002 * tokenizer.h - Copyright 2005 Maksim Orlovich <maksim@kde.org> 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 #ifndef TOKENIZER_H 00026 #define TOKENIZER_H 00027 00028 #include <QSet> 00029 #include <QString> 00030 #include <QHash> 00031 00032 #include "step.h" 00033 #include "path.h" 00034 #include "predicate.h" 00035 #include "expression.h" 00036 #include "util.h" 00037 #include "parser.h" 00038 00039 namespace khtml { 00040 namespace XPath { 00041 00042 00043 struct Token 00044 { 00045 int type; 00046 QString value; 00047 int intValue; //0 if not set 00048 bool hasString; 00049 00050 Token(int _type): type(_type), intValue(0), hasString(false) {} 00051 Token(QString _value): type(ERROR+1), value(_value), intValue(0), hasString(true) {} 00052 Token(int _type, QString _value): type(_type), value(_value), intValue(0), hasString(true) {} 00053 Token(int _type, int _value): type(_type), intValue(_value), hasString(false) {} 00054 }; 00055 00056 class Tokenizer 00057 { 00058 private: 00059 int m_nextPos; 00060 QString m_data; 00061 int m_lastTokenType; 00062 00063 static QHash<QString, Step::AxisType>* s_axisNamesDict; 00064 static QSet<QString>* s_nodeTypeNamesDict; 00065 00066 enum XMLCat { 00067 NameStart, 00068 NameCont, 00069 NotPartOfName 00070 }; 00071 00072 XMLCat charCat(QChar aChar); 00073 00074 bool isAxisName(QString name, Step::AxisType *type = 0); 00075 bool isNodeTypeName(QString name); 00076 bool isOperatorContext(); 00077 00078 void skipWS(); 00079 Token makeTokenAndAdvance(int code, int advance = 1); 00080 Token makeIntTokenAndAdvance(int code, int val, int advance = 1); 00081 char peekAheadHelper(); 00082 char peekCurHelper(); 00083 00084 Token lexString(); 00085 Token lexNumber(); 00086 Token lexNCName(); 00087 Token lexQName(); 00088 00089 Token nextTokenInternal(); 00090 Tokenizer(); 00091 Tokenizer(const Tokenizer &rhs); // disabled 00092 Tokenizer &operator=(const Tokenizer &rhs); // disabled 00093 ~Tokenizer(); 00094 public: 00095 static Tokenizer &self(); 00096 00097 void reset(QString); 00098 Token nextToken(); 00099 }; 00100 00101 // Interface to the parser 00102 int khtmlxpathyylex(); 00103 void khtmlxpathyyerror(const char *str); 00104 void initTokenizer(const DOM::DOMString& string); 00105 00106 } // namespace XPath 00107 00108 } // namespace khtml 00109 00110 00111 #endif 00112 // kate: indent-width 4; replace-tabs off; tab-width 4; indent-spaces: off;
KDE 4.6 API Reference