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 /*! \file 00029 \brief 7 bit ASCII encoder. 00030 00031 Definition of encoder_ascii7 class performing 7 bit ASCII character set encoding. 00032 \author pt 00033 */ 00034 #include <lestes/common.hh> 00035 #include <lestes/lang/cplus/lex/encoder_ascii7.hh> 00036 #include <lestes/lang/cplus/lex/encoder_ascii7.m.hh> 00037 #include <lestes/lang/cplus/lex/ucn_token.hh> 00038 #include <lestes/std/source_location.hh> 00039 #include <lestes/msg/message.hh> 00040 00041 //TODO #include <iostream> 00042 00043 package(lestes); 00044 package(lang); 00045 package(cplus); 00046 package(lex); 00047 00048 using namespace ::std; 00049 00050 /*! 00051 Creates the encoder. 00052 */ 00053 encoder_ascii7::encoder_ascii7(void) 00054 { 00055 } 00056 00057 /*! 00058 Reads next token. Performs encoding from 7 bit ASCII character set. 00059 Checks whether the input contains valid characters. 00060 If error is encountered, it returns token with type ucn_token::TOK_ERROR. 00061 \pre Input into the filter is set. 00062 \return The next token encoded from 7 bit ASCII. 00063 \return Token with type ucn_token::TOK_ERROR if the source character is invalid (out of range). 00064 \return Token with type ucn_token::TOK_EOF in case of previous error. 00065 */ 00066 ptr<ucn_token> encoder_ascii7::read(void) 00067 { 00068 ptr<ucn_token> t = input_read(); 00069 ulint x = character::extract_value(t->value_get()); 00070 ucn_token_type utt = t->type_get(); 00071 00072 if (utt == ucn_token::TOK_NOT_EOF) { 00073 // check that the value is in range 0..127 00074 if ((x & 0x7F) != x) { 00075 // TODO report error: value out of range for ASCII 00076 t = ucn_token::create_error(invalid_ascii_character->format()); 00077 } else { 00078 // encode value in source charset 00079 t = t->clone_value(character::create_internal(x)); 00080 } 00081 } 00082 00083 return t; 00084 } 00085 00086 /*! 00087 Marks the object. 00088 */ 00089 void encoder_ascii7::gc_mark(void) 00090 { 00091 bad.gc_mark(); 00092 encoder::gc_mark(); 00093 } 00094 00095 /*! 00096 Returns new instance of the encoder. 00097 \return The new instance. 00098 */ 00099 ptr<encoder_ascii7> encoder_ascii7::create(void) 00100 { 00101 return new encoder_ascii7(); 00102 } 00103 00104 end_package(lex); 00105 end_package(cplus); 00106 end_package(lang); 00107 end_package(lestes); 00108 00109 /* vim: set ft=lestes : */
1.5.1-20070107