00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #ifndef lestes__lang__cplus__lex___ucn_token_buffer_hh___included 00029 #define lestes__lang__cplus__lex___ucn_token_buffer_hh___included 00030 00031 /*! \file 00032 \brief Token buffer. 00033 00034 Declaration of ucn_token_buffer class representing buffer 00035 of simple tokens. 00036 \author pt 00037 */ 00038 #include <lestes/common.hh> 00039 #include <lestes/std/list.hh> 00040 00041 package(lestes); 00042 package(lang); 00043 package(cplus); 00044 package(lex); 00045 00046 // forward declaration to avoid cycle 00047 class ucn_token; 00048 class token_value; 00049 class line_control; 00050 00051 /*! 00052 \brief Token buffer. 00053 00054 Represents flexible buffer holding ucn_token items. 00055 Items are added mostly one by one at the end and afterwards 00056 removed from the beginning in longer runs, forming literals 00057 and identifiers. 00058 */ 00059 class ucn_token_buffer: public ::lestes::std::object { 00060 private: 00061 //! Type of buffer to hold stored data. 00062 typedef list< srp<ucn_token> > buffer_type; 00063 public: 00064 /*! 00065 \brief Type for size of the buffer. 00066 \author TMA 00067 */ 00068 typedef buffer_type::size_type size_type; 00069 //! Adds single item to the end. 00070 void add_back(const ptr<ucn_token> &item); 00071 //! Discards items from the beginning. 00072 void advance(size_type len); 00073 //! Returns item at the beginning. 00074 ptr<ucn_token> peek_front(void) const; 00075 //! Extracts value until stop character without interpreting. 00076 ptr<token_value> extract_until(ucn stop); 00077 //! Extracts value without interpreting. 00078 ptr<token_value> extract_ordinary(size_type len); 00079 //! Extracts identifiers and numbers with ucn. 00080 ptr<token_value> extract_simple_ucn(size_type len, bool identifier); 00081 //! Extracts identifiers and numbers with bad ucn. 00082 ptr<token_value> extract_invalid_ucn(size_type len, bool identifier); 00083 //! Extracts literal with escaped ucn. 00084 ptr<token_value> extract_ucn_literal(size_type len); 00085 //! Extracts malformed literal. 00086 ptr<token_value> extract_bad_literal(size_type len); 00087 //! Returns length of the buffer. 00088 size_type length(void) const; 00089 //! Returns new buffer. 00090 static ptr<ucn_token_buffer> create(const ptr<line_control> &a_lines); 00091 protected: 00092 //! Creates empty buffer. 00093 ucn_token_buffer(const ptr<line_control> &a_lines); 00094 //! Marks the object. 00095 virtual void gc_mark(void); 00096 private: 00097 //! Buffer to hold stored data. 00098 srp<buffer_type> buffer; 00099 //! Line control to transform locations. 00100 srp<line_control> lines; 00101 //! Hides copy constructor. 00102 ucn_token_buffer(const ucn_token_buffer &); 00103 //! Hides assignment operator. 00104 ucn_token_buffer &operator=(const ucn_token_buffer &); 00105 }; 00106 00107 end_package(lex); 00108 end_package(cplus); 00109 end_package(lang); 00110 end_package(lestes); 00111 00112 #endif 00113 /* vim: set ft=lestes : */
1.5.1-20070107