31#ifndef CFGFILE__PARSER_HPP__INCLUDED
32#define CFGFILE__PARSER_HPP__INCLUDED
48#if defined( CFGFILE_QT_SUPPORT ) && defined( CFGFILE_XML_SUPPORT )
50#include <QDomDocument>
64template<
typename Trait =
string_trait_t >
77 virtual void parse(
const typename Trait::string_t & file_name ) = 0;
85 Trait::from_ascii(
"Unexpected end of file. "
86 "Still unfinished tag \"" ) +
m_stack.top()->name() +
87 Trait::from_ascii(
"\"." ) );
91 Trait::from_ascii(
"Undefined mandatory tag: \"" ) +
92 m_tag.
name() + Trait::from_ascii(
"\"." ) );
108template<
typename Trait =
string_trait_t >
125 void parse(
const typename Trait::string_t & file_name )
override
127 if( !start_first_tag_parsing() )
132 while( !
lexeme.is_null() )
136 switch( lexeme.type() )
139 start_tag_parsing( *this->
m_stack.top(),
140 this->m_stack.top()->children() );
147 m_lex.column_number() ),
156 m_lex.column_number() ) );
167 Trait::from_ascii(
"Unexpected content. "
168 "We've finished parsing, but we've got this: \"" ) +
169 lexeme.value() + Trait::from_ascii(
"\". " ) +
170 Trait::from_ascii(
"In file \"" ) + file_name +
171 Trait::from_ascii(
"\" on line " ) +
172 Trait::to_string( m_lex.line_number() ) +
173 Trait::from_ascii(
"." ) );
176 lexeme = m_lex.next_lexeme();
184 bool start_first_tag_parsing()
190 Trait::from_ascii(
"Unexpected end of file. "
191 "Undefined mandatory tag \"" ) + this->
m_tag.
name() +
192 Trait::from_ascii(
"\". In file \"" ) +
193 m_lex.input_stream().file_name() +
194 Trait::from_ascii(
"\" on line " ) +
195 Trait::to_string( m_lex.line_number() ) +
196 Trait::from_ascii(
"." ) );
202 Trait::from_ascii(
"Expected start curl brace, "
203 "but we've got \"" ) +
lexeme.value() +
204 Trait::from_ascii(
"\". In file \"" ) +
205 m_lex.input_stream().file_name() +
206 Trait::from_ascii(
"\" on line " ) +
207 Trait::to_string( m_lex.line_number() ) +
208 Trait::from_ascii(
"." ) );
210 lexeme = m_lex.next_lexeme();
214 Trait::from_ascii(
"Unexpected tag name. "
215 "We expected \"" ) + this->
m_tag.
name() +
216 Trait::from_ascii(
"\", but we've got \"" ) +
lexeme.value() +
217 Trait::from_ascii(
"\". In file \"" ) +
218 m_lex.input_stream().file_name() +
219 Trait::from_ascii(
"\" on line " ) +
220 Trait::to_string( m_lex.line_number() ) +
221 Trait::from_ascii(
"." ) );
231 Trait::from_ascii(
"Unexpected start curl brace. "
232 "We expected tag name, but we've got start curl brace. "
233 "In file \"" ) + m_lex.input_stream().file_name() +
234 Trait::from_ascii(
"\" on line " ) +
235 Trait::to_string( m_lex.line_number() ) +
236 Trait::from_ascii(
"." ) );
239 Trait::from_ascii(
"Unexpected finish curl brace. "
240 "We expected tag name, but we've got finish curl brace. "
241 "In file \"" ) + m_lex.input_stream().file_name() +
242 Trait::from_ascii(
"\" on line " ) +
243 Trait::to_string( m_lex.line_number() ) +
244 Trait::from_ascii(
"." ) );
247 Trait::from_ascii(
"Unexpected end of file. "
248 "In file \"" ) + m_lex.input_stream().file_name() +
249 Trait::from_ascii(
"\" on line " ) +
250 Trait::to_string( m_lex.line_number() ) +
251 Trait::from_ascii(
"." ) );
257 m_lex.input_stream().file_name(),
259 m_lex.column_number() ) );
268 const typename tag_t< Trait >::child_tags_list_t & list )
270 lexeme_t< Trait > lexeme = m_lex.next_lexeme();
272 bool tag_found =
false;
276 if( start_tag_parsing( lexeme, *tag ) )
285 throw exception_t< Trait >(
286 Trait::from_ascii(
"Unexpected tag name. "
287 "We expected one child tag of tag \"" ) +
289 Trait::from_ascii(
"\", but we've got \"" ) + lexeme.value() +
290 Trait::from_ascii(
"\". In file \"" ) +
291 m_lex.input_stream().file_name() +
292 Trait::from_ascii(
"\" on line " ) +
293 Trait::to_string( m_lex.line_number() ) +
294 Trait::from_ascii(
"." ) );
299 lexical_analyzer_t< Trait > m_lex;
302#if defined( CFGFILE_QT_SUPPORT ) && defined( CFGFILE_XML_SUPPORT )
309template<
typename Trait = q
string_trait_t >
325 void parse(
const typename Trait::string_t & file_name )
override
329 if(
element.isNull() &&
this->m_tag.is_mandatory() )
331 Trait::from_ascii(
"Unexpected end of file. "
332 "Undefined mandatory tag \"" ) + this->
m_tag.
name() +
333 Trait::from_ascii(
"\". In file \"" ) + file_name +
334 Trait::from_ascii(
"\" on line " ) +
335 Trait::to_string(
element.lineNumber() ) +
336 Trait::from_ascii(
"." ) );
342 Trait::from_ascii(
"Unexpected tag name. "
343 "We expected \"" ) + this->
m_tag.
name() +
344 Trait::from_ascii(
"\", but we've got \"" ) +
345 typename Trait::string_t(
element.tagName() ) +
346 Trait::from_ascii(
"\". In file \"" ) + file_name +
347 Trait::from_ascii(
"\" on line " ) +
348 Trait::to_string(
element.lineNumber() ) +
349 Trait::from_ascii(
"." ) );
358 parse_tag(
element, file_name );
376 const typename Trait::string_t & file_name )
379 n =
n.nextSibling() )
383 if( !
child.isNull() )
386 this->m_stack.top()->children() );
390 Trait::from_ascii(
"Unexpected tag name. "
391 "We expected one child tag of tag \"" ) +
393 Trait::from_ascii(
"\", but we've got \"" ) +
394 typename Trait::string_t(
child.tagName() ) +
395 Trait::from_ascii(
"\". In file \"" ) + file_name +
396 Trait::from_ascii(
"\" on line " ) +
397 Trait::to_string(
child.lineNumber() ) +
398 Trait::from_ascii(
"." ) );
404 child.columnNumber() ) );
411 QString(
"a" ) + QString::number(
i ) ).toAttr();
415 typename Trait::string_t value;
425 Trait::from_ascii(
" In file \"" ) + file_name +
426 Trait::from_ascii(
"\" on line " ) +
427 Trait::to_string(
attr.lineNumber() ) +
428 Trait::from_ascii(
"." ) );
434 attr.columnNumber() ),
439 parse_tag( child, file_name );
444 child.columnNumber() ) );
450 if( !n.toComment().isNull() )
453 QDomText text = n.toText();
457 typename Trait::string_t value;
460 value = from_cfgfile_format< Trait >( text.data() );
462 catch(
const exception_t< Trait > & x )
464 throw exception_t< Trait > ( x.desc() +
465 Trait::from_ascii(
" In file \"" ) + file_name +
466 Trait::from_ascii(
"\" on line " ) +
467 Trait::to_string( text.lineNumber() ) +
468 Trait::from_ascii(
"." ) );
471 this->
m_stack.top()->on_string( parser_info_t< Trait >(
474 text.columnNumber() ),
478 throw exception_t< Trait >(
479 Trait::from_ascii(
"Unexpected tag name. "
480 "We expected one child tag of tag \"" ) +
482 Trait::from_ascii(
"\", but we've got \"" ) +
483 typename Trait::string_t( n.nodeName() ) +
484 Trait::from_ascii(
"\". In file \"" ) + file_name +
485 Trait::from_ascii(
"\" on line " ) +
486 Trait::to_string( n.lineNumber() ) +
487 Trait::from_ascii(
"." ) );
494 const typename tag_t< Trait >::child_tags_list_t & list )
498 if( tag->
name() == name )
506 const QDomDocument & m_dom;
519template<
typename Trait =
string_trait_t >
528#if defined( CFGFILE_QT_SUPPORT ) && defined( CFGFILE_XML_SUPPORT )
540 void parse(
const typename Trait::string_t & file_name )
542 m_d->parse( file_name );
548 std::unique_ptr< details::parser_base_t< Trait > > m_d;
Base implementation of parser.
Definition parser.hpp:65
tag_t< Trait > & m_tag
Tag.
Definition parser.hpp:97
void check_parser_state_after_parsing()
Definition parser.hpp:81
std::stack< tag_t< Trait > * > m_stack
Stack of tags.
Definition parser.hpp:99
parser_base_t(tag_t< Trait > &tag)
Definition parser.hpp:67
virtual ~parser_base_t()
Definition parser.hpp:72
virtual void parse(const typename Trait::string_t &file_name)=0
Do parsing.
Implementation of parser in cfgfile format.
Definition parser.hpp:111
~parser_conffile_impl_t()
Definition parser.hpp:120
parser_conffile_impl_t(tag_t< Trait > &tag, input_stream_t< Trait > &stream)
Definition parser.hpp:113
void parse(const typename Trait::string_t &file_name) override
Do parsing.
Definition parser.hpp:125
Implementation of parser in XML format.
Definition parser.hpp:312
parser_dom_impl_t(tag_t< Trait > &tag, const QDomDocument &dom)
Definition parser.hpp:314
~parser_dom_impl_t()
Definition parser.hpp:320
void parse(const typename Trait::string_t &file_name) override
Do parsing.
Definition parser.hpp:325
Exception in the library.
Definition exceptions.hpp:51
const Trait::string_t & desc() const noexcept
Definition exceptions.hpp:65
Parser of the configuration file.
Definition parser.hpp:520
parser_t(tag_t< Trait > &tag, input_stream_t< Trait > &stream)
Definition parser.hpp:522
parser_t(tag_t< Trait > &tag, const QDomDocument &dom)
Definition parser.hpp:529
void parse(const typename Trait::string_t &file_name)
Parse input stream.
Definition parser.hpp:540
virtual void on_string(const parser_info_t< Trait > &info, const typename Trait::string_t &str)=0
Called when string found.
bool is_mandatory() const
Definition tag.hpp:146
virtual void on_start(const parser_info_t< Trait > &info)
Called when tag parsing started.
Definition tag.hpp:197
bool is_defined() const
Definition tag.hpp:152
const Trait::string_t & name() const
Definition tag.hpp:140
virtual void on_finish(const parser_info_t< Trait > &info)=0
Called when tag parsing finished.
@ finish
Finish tag lexeme "}".
@ start
Start tag lexeme "{".
#define DISABLE_COPY(Class)
Macro for disabling copy.
Definition types.hpp:580