File indexing completed on 2024-04-21 04:34:27

0001 /*****************************************************************************
0002  * Copyright 2005, 2006 Jakob Petsovits <jpetso@gmx.at>                      *
0003  * Copyright 2010 Niko Sams <niko.sams@gmail.com>                            *
0004  *                                                                           *
0005  * This program is free software; you can redistribute it and/or             *
0006  * modify it under the terms of the GNU Library General Public               *
0007  * License as published by the Free Software Foundation; either              *
0008  * version 2 of the License, or (at your option) any later version.          *
0009  *                                                                           *
0010  * This grammar is distributed in the hope that it will be useful,           *
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
0013  * Lesser General Public License for more details.                           *
0014  *                                                                           *
0015  * You should have received a copy of the GNU Library General Public License *
0016  * along with this library; see the file COPYING.LIB.  If not, write to      *
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
0018  * Boston, MA 02110-1301, USA.                                               *
0019  *****************************************************************************/
0020 #ifndef CSS_TOKENIZER_H
0021 #define CSS_TOKENIZER_H
0022 
0023 #include "parserexport.h"
0024 
0025 #include <QByteArray>
0026 #include <QString>
0027 
0028 #ifndef DONT_INCLUDE_FLEXLEXER
0029 #include "FlexLexer.h"
0030 #endif
0031 
0032 // The YY_USER_ACTION macro is called whenever a token is found by Flex
0033 #define YY_USER_ACTION \
0034 m_tokenBegin = m_tokenEnd + 1; \
0035 m_tokenEnd += yyleng;
0036 
0037 namespace KDevPG {
0038     class LocationTable;
0039     class TokenStream;
0040 }
0041 namespace Css
0042 {
0043 
0044 class KDEVCSSPARSER_EXPORT Tokenizer : public yyFlexLexer
0045 {
0046 public:
0047     explicit Tokenizer( KDevPG::TokenStream *tokenStream, const QByteArray &contents );
0048     explicit Tokenizer( KDevPG::TokenStream *tokenStream, const char* contents );
0049     explicit Tokenizer( KDevPG::TokenStream *tokenStream, const QString &contents );
0050     void restart( KDevPG::TokenStream *tokenStream, const QByteArray &contents );
0051 
0052     int yylex() override;
0053     int nextTokenKind() { return yylex(); }
0054     std::size_t tokenBegin() const { return m_tokenBegin; }
0055     std::size_t tokenEnd()   const { return m_tokenEnd;   }
0056 
0057 protected:
0058     // custom input, replacing the Flex default input stdin
0059     int LexerInput( char *buf, int max_size ) override;
0060 
0061     // dismisses any lexer output (which should not happen anyways)
0062     void LexerOutput( const char * /*buf*/, int /*max_size*/ ) override { return; }
0063     void LexerError( const char */*msg*/ ) override { return; }
0064 
0065 private:
0066     QByteArray m_contents;
0067     int m_tokenBegin, m_tokenEnd;
0068     int m_currentOffset;
0069     KDevPG::LocationTable *m_locationTable;
0070 };
0071 
0072 } // end of namespace Css
0073 
0074 #endif
0075 
0076 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on
0077