File indexing completed on 2024-05-19 08:27:44
0001 /****************************************************************************** 0002 * Copyright (c) 2005, 2006 Jakob Petsovits <jpetso@gmx.at> * 0003 * * 0004 * Permission to use, copy, modify, distribute, and sell this software and * 0005 * its documentation for any purpose is hereby granted without fee, provided * 0006 * that the above copyright notice appear in all copies and that both that * 0007 * copyright notice and this permission notice appear in supporting * 0008 * documentation. * 0009 * * 0010 * The above copyright notice and this permission notice shall be included * 0011 * in all copies or substantial portions of the Software. * 0012 * * 0013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * 0014 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 0015 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * 0016 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * 0017 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 0018 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 0019 *****************************************************************************/ 0020 0021 #include "coolparser.h" 0022 0023 #include <iostream> 0024 0025 #include <QString> 0026 #include <string> 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; \ 0035 m_tokenEnd += yyleng; 0036 0037 0038 namespace cool 0039 { 0040 0041 class Lexer : public yyFlexLexer 0042 { 0043 public: 0044 Lexer( cool::Parser *parser, char *contents ); 0045 void restart( cool::Parser *parser, char *contents ); 0046 0047 int yylex(); 0048 char *contents() { return m_contents; } 0049 std::size_t tokenBegin() { return m_tokenBegin; } 0050 std::size_t tokenEnd() { return m_tokenEnd; } 0051 0052 protected: 0053 // custom input, replacing the Flex default input stdin 0054 virtual int LexerInput( char *buf, int max_size ); 0055 0056 // dismisses any lexer output (which should not happen anyways) 0057 virtual void LexerOutput( const char * /*buf*/, int /*max_size*/ ) { return; } 0058 virtual void LexerError( const char */*msg*/ ) { return; } 0059 0060 private: 0061 cool::Parser* m_parser; 0062 char *m_contents; 0063 std::size_t m_tokenBegin, m_tokenEnd; 0064 std::size_t m_currentOffset; 0065 KDevPG::LocationTable *m_locationTable; 0066 }; 0067 0068 } // end of namespace cool 0069 0070 // kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on