The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
schema_validation::class_source_parser Class Reference

#include <sourceparser.hpp>

Public Member Functions

 class_source_parser ()
 
 ~class_source_parser ()
 
void set_input (const std::string &s)
 
void set_output (const std::string &s)
 
bool parse_source ()
 Parses file line-by-line, checking every line to open WIKI block Please, notice that main input work is made in check_*** methods. More...
 
bool save_schema ()
 Saves tag tree to schema file. More...
 
void expand ()
 Expands all tags. More...
 
const std::vector< class_tag > & see_orphans () const
 
const class_error_containersee_errors () const
 Grants access to error container. More...
 

Private Member Functions

bool parse_block ()
 Parses WIKI block line-by-line, checking every line to open annotation block. More...
 
bool parse_tag ()
 Parses lines inside tag block. More...
 
bool parse_keys ()
 Read key table and add keys to tag on the top of the stack. More...
 
bool check_valid (const std::string &s)
 check the input line with a template check if the line is valid (still in block) More...
 
bool getline (std::string &s)
 Gets a line from file and returns it. More...
 
void close_opened_tags (int i)
 Сhecks stack of opened tags. More...
 
void add_open_tag_error (int i)
 Generates errors for each opened tag. More...
 
bool check_wiki (const std::string &s)
 Read tag form the line and add it to stack. More...
 
bool check_tag_begin (const std::string &s)
 Checks line for tag annotation. More...
 
bool check_tag_end (const std::string &s)
 Puts closed tag to child list of previous tag. More...
 
bool check_parent_begin (const std::string &s)
 Opens parrent block. More...
 
bool check_parent_end (const std::string &s)
 Closes parent block. More...
 
bool check_keys_begin (const std::string &s)
 Checks beginning of keys. More...
 
bool check_keys_end (const std::string &s)
 Checks end of keys. More...
 
bool check_allow_link (const std::string &s)
 Checks links. More...
 
bool check_allow_global (const std::string &s)
 Checks allowed global tags. More...
 
bool check_allow_type (const std::string &s)
 Checks allowed types. More...
 
bool check_remove_type (const std::string &s)
 Checks removed types. More...
 
bool check_remove_key (const std::string &s)
 Checks removed keys. More...
 

Private Attributes

std::string input_
 name of input file to be parsed More...
 
std::string output_
 name of output file to print schema More...
 
std::fstream f_
 
int line_
 number of current read line. More...
 
std::vector< class_tagcurrent_
 Stack of opened tags. More...
 
class_tag root_
 Root of the schema tree. More...
 
std::string parent_name_
 Name of current parent. More...
 
std::vector< class_tagorphan_tags_
 List of tags without parents. More...
 
class_error_container errors_
 used to store errors More...
 
std::map< std::string,
std::string
types_
 Allowed types. More...
 
std::vector< std::stringforbidden_
 Types to remove. More...
 

Detailed Description

Definition at line 69 of file sourceparser.hpp.

Constructor & Destructor Documentation

schema_validation::class_source_parser::class_source_parser ( )
inline

Definition at line 71 of file sourceparser.hpp.

schema_validation::class_source_parser::~class_source_parser ( )
inline

Definition at line 86 of file sourceparser.hpp.

Member Function Documentation

void schema_validation::class_source_parser::add_open_tag_error ( int  i = INT_MAX)
private

Generates errors for each opened tag.

Parameters
inumber of tags in stack to complain.

Definition at line 262 of file sourceparser.cpp.

References schema_validation::class_error_container::add_opened_entity_error(), current_, errors_, i, input_, and line_.

Referenced by check_tag_end(), parse_block(), parse_keys(), and parse_tag().

bool schema_validation::class_source_parser::check_allow_global ( const std::string s)
private

Checks allowed global tags.

Definition at line 523 of file sourceparser.cpp.

References current_, schema_validation::get_allow_global(), and schema_validation::sub().

Referenced by parse_tag().

bool schema_validation::class_source_parser::check_allow_link ( const std::string s)
private
bool schema_validation::class_source_parser::check_allow_type ( const std::string s)
private
bool schema_validation::class_source_parser::check_keys_begin ( const std::string s)
private

Checks beginning of keys.

Definition at line 564 of file sourceparser.cpp.

References schema_validation::get_table_key_begin().

Referenced by parse_tag().

bool schema_validation::class_source_parser::check_keys_end ( const std::string s)
private

Checks end of keys.

Definition at line 570 of file sourceparser.cpp.

References schema_validation::get_table_end().

Referenced by parse_keys().

bool schema_validation::class_source_parser::check_parent_begin ( const std::string s)
private
bool schema_validation::class_source_parser::check_parent_end ( const std::string s)
private
bool schema_validation::class_source_parser::check_remove_key ( const std::string s)
private

Checks removed keys.

Definition at line 609 of file sourceparser.cpp.

References current_, schema_validation::get_remove_key(), and schema_validation::sub().

Referenced by parse_tag().

bool schema_validation::class_source_parser::check_remove_type ( const std::string s)
private
bool schema_validation::class_source_parser::check_tag_begin ( const std::string s)
private
bool schema_validation::class_source_parser::check_tag_end ( const std::string s)
private

Puts closed tag to child list of previous tag.

Also closes all opened child tags, if they are, and generates warnings.

Definition at line 481 of file sourceparser.cpp.

References add_open_tag_error(), schema_validation::class_error_container::add_unopened_entity_error(), close_opened_tags(), current_, errors_, schema_validation::get_tag_end(), input_, line_, and schema_validation::sub().

Referenced by parse_tag().

bool schema_validation::class_source_parser::check_valid ( const std::string s)
private

check the input line with a template check if the line is valid (still in block)

Definition at line 448 of file sourceparser.cpp.

References schema_validation::get_valid(), and schema_validation::valid.

Referenced by parse_block(), parse_keys(), and parse_tag().

bool schema_validation::class_source_parser::check_wiki ( const std::string s)
private

Read tag form the line and add it to stack.

Definition at line 454 of file sourceparser.cpp.

References schema_validation::get_wiki().

Referenced by parse_source().

void schema_validation::class_source_parser::close_opened_tags ( int  i = INT_MAX)
private

Сhecks stack of opened tags.

If any tags is opened - closes it and adds to sublist of next tag in stack. Add last tag in stack to parent

Parameters
inumber of tags in stack to close.

Definition at line 270 of file sourceparser.cpp.

References schema_validation::class_error_container::add_orphan_error(), schema_validation::class_tag::add_tag(), current_, errors_, i, input_, line_, orphan_tags_, parent_name_, schema_validation::class_error_container::remove_link_errors(), and root_.

Referenced by check_tag_end(), parse_block(), parse_keys(), parse_source(), and parse_tag().

void schema_validation::class_source_parser::expand ( )
inline

Expands all tags.

While expanding tag copies list of keys and links from super-tag And adds links to super-tag children to links list. Useful when debugging the schema_markup

Definition at line 115 of file sourceparser.hpp.

References schema_validation::class_tag::expand_all(), and root_.

Referenced by main().

bool schema_validation::class_source_parser::getline ( std::string s)
private

Gets a line from file and returns it.

Is used to manage exceptions while IO.

Definition at line 246 of file sourceparser.cpp.

References schema_validation::class_error_container::add_read_error(), errors_, f_, input_, and line_.

Referenced by parse_block(), parse_keys(), parse_source(), and parse_tag().

bool schema_validation::class_source_parser::parse_block ( )
private

Parses WIKI block line-by-line, checking every line to open annotation block.

Definition at line 357 of file sourceparser.cpp.

References add_open_tag_error(), check_allow_type(), check_parent_begin(), check_parent_end(), check_remove_type(), check_tag_begin(), check_valid(), close_opened_tags(), current_, f_, getline(), and parse_tag().

Referenced by parse_source().

bool schema_validation::class_source_parser::parse_keys ( )
private
bool schema_validation::class_source_parser::parse_source ( )

Parses file line-by-line, checking every line to open WIKI block Please, notice that main input work is made in check_*** methods.

Methods parse_*** are used to organize alhoritm and set which regex template can be used in this context. The only exception is parse_keys, where table of keys is read and add to top of stack tags.

Definition at line 311 of file sourceparser.cpp.

References schema_validation::class_error_container::add_simple_error(), check_wiki(), close_opened_tags(), errors_, f_, getline(), input_, line_, parent_name_, and parse_block().

Referenced by main().

bool schema_validation::class_source_parser::parse_tag ( )
private

Parses lines inside tag block.

Calls checkers that are allowed in tag block

Definition at line 387 of file sourceparser.cpp.

References add_open_tag_error(), check_allow_global(), check_allow_link(), check_keys_begin(), check_remove_key(), check_tag_begin(), check_tag_end(), check_valid(), close_opened_tags(), current_, f_, getline(), and parse_keys().

Referenced by parse_block().

bool schema_validation::class_source_parser::save_schema ( )
const class_error_container& schema_validation::class_source_parser::see_errors ( ) const
inline

Grants access to error container.

Definition at line 124 of file sourceparser.hpp.

References errors_.

Referenced by main().

const std::vector<class_tag>& schema_validation::class_source_parser::see_orphans ( ) const
inline

Definition at line 120 of file sourceparser.hpp.

References orphan_tags_.

void schema_validation::class_source_parser::set_input ( const std::string s)
inline

Definition at line 89 of file sourceparser.hpp.

References input_.

Referenced by main().

void schema_validation::class_source_parser::set_output ( const std::string s)
inline

Definition at line 92 of file sourceparser.hpp.

References output_.

Referenced by main().

Member Data Documentation

std::vector<class_tag> schema_validation::class_source_parser::current_
private
class_error_container schema_validation::class_source_parser::errors_
private
std::fstream schema_validation::class_source_parser::f_
private

Definition at line 132 of file sourceparser.hpp.

Referenced by getline(), parse_block(), parse_source(), and parse_tag().

std::vector<std::string> schema_validation::class_source_parser::forbidden_
private

Types to remove.

Definition at line 150 of file sourceparser.hpp.

Referenced by check_remove_type(), and save_schema().

std::string schema_validation::class_source_parser::input_
private
int schema_validation::class_source_parser::line_
private
std::vector<class_tag> schema_validation::class_source_parser::orphan_tags_
private

List of tags without parents.

Definition at line 144 of file sourceparser.hpp.

Referenced by close_opened_tags(), and see_orphans().

std::string schema_validation::class_source_parser::output_
private

name of output file to print schema

Definition at line 131 of file sourceparser.hpp.

Referenced by save_schema(), and set_output().

std::string schema_validation::class_source_parser::parent_name_
private

Name of current parent.

Definition at line 142 of file sourceparser.hpp.

Referenced by check_parent_begin(), check_parent_end(), close_opened_tags(), and parse_source().

class_tag schema_validation::class_source_parser::root_
private

Root of the schema tree.

Definition at line 140 of file sourceparser.hpp.

Referenced by check_allow_link(), check_tag_begin(), close_opened_tags(), expand(), and save_schema().

std::map<std::string,std::string> schema_validation::class_source_parser::types_
private

Allowed types.

Definition at line 148 of file sourceparser.hpp.

Referenced by check_allow_type(), check_remove_type(), parse_keys(), and save_schema().


The documentation for this class was generated from the following files: