File indexing completed on 2024-04-21 15:24:19

0001 /*
0002     SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef PHPLEXER_H
0008 #define PHPLEXER_H
0009 
0010 #include <QtCore/QStack>
0011 #include <QtCore/QString>
0012 
0013 #include "parserexport.h"
0014 
0015 class QString;
0016 
0017 namespace KDevPG
0018 {
0019 class TokenStream;
0020 }
0021 
0022 namespace Php
0023 {
0024 class TokenStream;
0025 
0026 /**
0027  * Hand-written Lexer that generates the same tokens as php uses.
0028  * This includes also a whitespace and comment token.
0029  *
0030  * For debugging output can be compared to php-tokens using the
0031  * test/test-tokenize.php script
0032  **/
0033 class KDEVPHPPARSER_EXPORT Lexer
0034 {
0035 public:
0036     Lexer(TokenStream *tokenStream, const QString& contents, int initialState = HtmlState);
0037 
0038     int nextTokenKind();
0039     qint64 tokenBegin() const;
0040     qint64 tokenEnd() const;
0041 
0042 private:
0043     QString m_content;
0044     TokenStream* m_tokenStream;
0045     int m_curpos;
0046     int m_contentSize;
0047     qint64 m_tokenBegin;
0048     qint64 m_tokenEnd;
0049 
0050     int state(int deepness = 0) const;
0051     void pushState(int state);
0052     void popState();
0053     void printState();
0054 
0055     bool processVariable(const QChar* it);
0056     bool isValidVariableIdentifier(const QChar* it);
0057     void createNewline(int pos);
0058     bool isEscapedWithBackslash(const QChar* it, int curPos, int startPos);
0059     bool isHereNowDocEnd(const QChar* it);
0060 
0061     QStack<int> m_state;
0062 
0063     QString m_hereNowDocIdentifier;
0064     int m_haltCompiler;
0065 
0066 public:
0067     enum State {
0068         ErrorState = -1,
0069         HtmlState = 0,
0070         DefaultState = 1,
0071         String = 2,
0072         StringVariable = 3,
0073         StringVariableBracket = 4,
0074         StringVariableObjectOperator = 5,
0075         StringVariableCurly = 6,
0076         StringVarname = 7,
0077         StringHeredoc = 8,
0078         StringBacktick = 9,
0079         StringNowdoc = 10
0080     };
0081 };
0082 
0083 }
0084 
0085 #endif
0086 
0087 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on