/* * This file is a part of EZC -- Easy templating in C++ library * and is distributed under the BSD 3-Clause licence. * Author: Tomasz Sowa */ /* * Copyright (c) 2007-2016, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name Tomasz Sowa nor the names of contributors to this * project may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef headerfile_ezc_patternparser #define headerfile_ezc_patternparser #include "blocks.h" #include "pattern.h" #include "utf8/utf8.h" namespace Ezc { class PatternParser { public: PatternParser(); // first we're trying to read a file from directory dir // if there is no such a file there then we try read from dir2 // (the second dir2 can be empty - it will not be used) void Directory(const char * dir, const char * dir2 = 0); void Directory(const std::string & dir); void Directory(const std::string & dir, const std::string & dir2); void Directory(const wchar_t * dir, const wchar_t * dir2 = 0); void Directory(const std::wstring & dir); void Directory(const std::wstring & dir, const std::wstring & dir2); void ParseFile(const char * file_name, Pattern & pattern); void ParseFile(const std::string & file_name, Pattern & pattern); void ParseFile(const wchar_t * file_name, Pattern & pattern); void ParseFile(const std::wstring & file_name, Pattern & pattern); void ParseString(const char * str, Pattern & pattern); void ParseString(const std::string & str, Pattern & pattern); void ParseString(const wchar_t * str, Pattern & pattern); void ParseString(const std::wstring & str, Pattern & pattern); void AllowInclude(bool allow); void DeleteWhiteTextItems(bool del); void SetIncludeMax(int include_max); void SetBlocks(Blocks & blocks); void SetCommentary(const char * com_start, const char * com_stop); void SetCommentary(const std::string & com_start, const std::string & com_stop); void SetCommentary(const wchar_t * com_start, const wchar_t * com_stop); void SetCommentary(const std::wstring & com_start, const std::wstring & com_stop); private: // the output object Pattern * pat; // the main pointer to the parsed text const wchar_t * itext; // allowing include tag // default: true bool allow_include; // if true all text-items which have only white characters (with new lines as well) // will be deleted - useful in *.txt templates // this not actually delete the whole item but only the string // the item will be present with an empty string // default: false bool delete_white_text_items; // first we're trying to read a file from 'directory' // if there is no such a file there then we try read from 'directory2' // we read from these directories only if they are not empty std::wstring directory, directory2; std::wstring commentary_start, commentary_stop; int include_level, include_level_max; // temporary content for ParseString(const char*) method std::wstring string_content; // temporary object for a file name std::wstring file_name; // temporary object for a file name std::string afile_name; // temporary object for a EZC function Item::Function temp_function; Blocks * pblocks; void CreateMsg(std::wstring & out, const wchar_t * type, const wchar_t * arg = 0); void ReadFile(const std::wstring & name, std::wstring & result); void ReadFile(const wchar_t * name, std::wstring & result); bool HasFileAtBeginning(const wchar_t * path, const wchar_t * file); bool IsFileCorrect(const wchar_t * name); bool ReadFileFromDir(const std::wstring & dir, const wchar_t * name, std::wstring & result); void ReadFile(std::ifstream & file, std::wstring & result); int ReadCharInText(); bool IsWhite(wchar_t c); void SkipWhite(); void SkipOneStatement(); void CheckWhiteAndDelete(std::wstring & s); void CheckFunctionIsNumber(Item::Function & function); bool IsNameChar(wchar_t c); bool IsDigit(wchar_t c); bool IsPositiveNumber(const std::wstring & str); bool ReadName(std::wstring & name); bool ReadFunctionName(std::wstring & name, std::wstring & postfix); bool ReadString(std::wstring & str); bool ReadNestedFunction(Item::Function & function); bool ReadParamString(Item::Function & function); bool ReadParams(Item::Function & function); bool ReadFunction(Item::Function & function, bool with_params, const std::wstring * function_name = 0); bool ReadFunction(Item & item); void ReadDirectiveIf(Item & item); void ReadDirectiveEnd(Item & item); void ReadDirectiveElse(Item & item); void ReadDirectiveFor(Item & item); void ReadDirectiveComment(Item & item); void ReadDirectiveInclude(Item & item); void ReadDirectiveDef(Item & item); void ReadDirectiveFilter(Item & item); void ReadDirectiveEzc(Item & item); void ReadDirectiveOut(Item & item); void ReadDirectiveBlock(Item & item); void ReadDirectiveReturn(Item & item); void ReadDirectiveNormal(const std::wstring & name, Item & item); void CreateTreeReadItemDirectiveCheckEnding(Item & item); void CreateTreeReadItemDirective(Item & item); void CreateTreeReadItemText(Item & item); bool CreateTreeReadItem(Item & item); void CreateTreeReadIf(Item & item); void CreateTreeReadBlock(Item & item); void CreateTreeReadFor(Item & item); void CreateTree(Item & item); void CreateTreeReadInclude(Item & item); void CreateTreeReadIncludeSkipAllowFlag(Item & item); }; // class PatternParser } // namespace Ezc #endif