31#ifndef CFGFILE__LEX_HPP__INCLUDED
32#define CFGFILE__LEX_HPP__INCLUDED
64template<
typename Trait =
string_trait_t >
85 const typename Trait::string_t &
value()
const
100 typename Trait::string_t m_value;
109template<
typename Trait =
string_trait_t >
126 typename Trait::string_t
result;
134 m_line_number = m_stream.line_number();
135 m_column_number = m_stream.column_number();
137 if( m_stream.at_end() )
139 typename Trait::string_t() );
143 typename Trait::char_t
ch = m_stream.get();
153 m_stream.put_back(
ch );
160 typename Trait::char_t
new_char( 0x00 );
164 else if( process_back_slash(
new_char ) )
168 Trait::from_ascii(
"Unrecognized back-slash "
170 typename Trait::string_t( 1,
new_char ) +
171 Trait::from_ascii(
"\". In file \"" ) +
172 m_stream.file_name() +
173 Trait::from_ascii(
"\" on line " ) +
175 Trait::from_ascii(
"." ) );
181 typename Trait::string_t( 1,
ch ) );
186 m_stream.put_back(
ch );
195 typename Trait::string_t( 1,
ch ) );
200 m_stream.put_back(
ch );
218 Trait::from_ascii(
"Unfinished quoted lexeme. " ) +
219 Trait::from_ascii(
"New line detected. In file \"" ) +
220 m_stream.file_name() +
221 Trait::from_ascii(
"\" on line " ) +
223 Trait::from_ascii(
"." ) );
233 if( !m_stream.at_end() )
235 typename Trait::char_t
next_char = m_stream.get();
241 skip_one_line_comment();
252 skip_multi_line_comment();
273 if( m_stream.at_end() )
277 Trait::from_ascii(
"Unfinished quoted lexeme. " ) +
278 Trait::from_ascii(
"End of file riched. In file \"" ) +
279 m_stream.file_name() +
280 Trait::from_ascii(
"\" on line " ) +
282 Trait::from_ascii(
"." ) );
285 typename Trait::string_t() );
308 return m_line_number;
314 return m_column_number;
319 bool is_space_char(
typename Trait::char_t
ch )
332 if( m_stream.at_end() )
335 typename Trait::char_t ch = m_stream.get();
337 while( is_space_char( ch ) )
339 if( m_stream.at_end() )
345 m_stream.put_back( ch );
349 bool process_back_slash(
typename Trait::char_t & ch )
351 if( m_stream.at_end() )
352 throw exception_t< Trait >(
353 Trait::from_ascii(
"Unexpected end of file. "
354 "Unfinished back slash sequence. In file \"" ) +
355 m_stream.file_name() + Trait::from_ascii(
"\" on line " ) +
356 Trait::to_string( m_stream.line_number() ) +
357 Trait::from_ascii(
"." ) );
378 void skip_one_line_comment()
380 if( !m_stream.at_end() )
382 typename Trait::char_t ch = m_stream.get();
392 void skip_multi_line_comment()
394 if( !m_stream.at_end() )
396 typename Trait::char_t ch = m_stream.get();
398 if( m_stream.at_end() )
401 typename Trait::char_t next_char = m_stream.get();
407 while( !m_stream.at_end() )
411 next_char = m_stream.get();
424 input_stream_t< Trait > & m_stream;
426 typename Trait::pos_t m_line_number;
428 typename Trait::pos_t m_column_number;
Exception in the library.
Definition exceptions.hpp:51
Lexeme.
Definition lex.hpp:65
const Trait::string_t & value() const
Definition lex.hpp:85
lexeme_type_t type() const
Definition lex.hpp:79
lexeme_t()
Definition lex.hpp:67
bool is_null() const
Definition lex.hpp:91
lexeme_t(lexeme_type_t type, const typename Trait::string_t &value)
Definition lex.hpp:72
Lexical analyzer.
Definition lex.hpp:110
Trait::pos_t line_number() const
Definition lex.hpp:306
lexeme_t< Trait > next_lexeme()
Definition lex.hpp:124
Trait::pos_t column_number() const
Definition lex.hpp:312
input_stream_t< Trait > & input_stream()
Definition lex.hpp:300
lexical_analyzer_t(input_stream_t< Trait > &stream)
Definition lex.hpp:112
lexeme_type_t
Type of the lexeme.
Definition lex.hpp:47
@ finish
Finish tag lexeme "}".
@ start
Start tag lexeme "{".
static const Trait::char_t c_sharp
Definition const.hpp:58
static const Trait::char_t c_line_feed
Definition const.hpp:56
static const Trait::char_t c_back_slash
Definition const.hpp:52
static const Trait::char_t c_r
Definition const.hpp:51
static const Trait::char_t c_tab
Definition const.hpp:54
static const Trait::char_t c_n
Definition const.hpp:49
static const Trait::char_t c_vertical_bar
Definition const.hpp:57
static const Trait::char_t c_quotes
Definition const.hpp:48
static const Trait::char_t c_t
Definition const.hpp:50
static const Trait::char_t c_carriage_return
Definition const.hpp:55
#define DISABLE_COPY(Class)
Macro for disabling copy.
Definition types.hpp:580