changed:
functions can have more than one parameter and the parameters can be used in [if...] statements too sample: [normal_function "par1" "par2" "par3"] [if-one function "par1" "par2" "par3"]...[end] each function can have its own parameters: [if-one function1 "par1" "par2" "par3" function2 "par" "par2"]...[end] changed: [is] is now [if] (not exactly but very similar) [is-no] is now [if-no] (the same) [if] and [if-no] are taking one function (with or without arguments) sample: [if function]...[end] [if function "par1"]...[end] [if function "par1" "par2" "par3" "par4"]...[end] [is] is taking two functions now and evaluates them to boolean value (variables are also evaluated to boolean - if not empty that means true) [is function1 function2]...[end] [is variable1 variable2] either variable1 and variable2 are empty or both are not empty (they don't have to be equal)[end] added: [if-any-no fun1 fun2 fun3] the three functions have to return false [end] [if-one-no fun1 fun2 fun3] one the the three functions have to return false [end] removed: extracting the unix directory from the file name (in patterns) you have to call Pattern::Directory() method first to set directories git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@298 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
c807d1c9b3
commit
573d241dc1
1051
src/ezc.cpp
1051
src/ezc.cpp
File diff suppressed because it is too large
Load Diff
155
src/ezc.h
155
src/ezc.h
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This file is a part of EZC -- Easy templating in C++
|
* This file is a part of EZC -- Easy templating in C++
|
||||||
* and is distributed under the (new) BSD licence.
|
* and is distributed under the (new) BSD licence.
|
||||||
* Author: Tomasz Sowa <t.sowa@slimaczek.pl>
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -51,18 +51,11 @@
|
||||||
namespace Ezc
|
namespace Ezc
|
||||||
{
|
{
|
||||||
|
|
||||||
void CreateMsg(std::ostringstream & o, const char * type, const char * arg = 0);
|
|
||||||
std::string CreateMsg(const char * type, const char * arg = 0);
|
|
||||||
void SplitUnixDirectory(const char * name, std::string & dir, std::string & file);
|
|
||||||
void SplitUnixDirectory(const std::string & name, std::string & dir, std::string & file);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Pattern
|
class Pattern
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Pattern();
|
Pattern();
|
||||||
|
|
||||||
void ParseFile(const std::string & file_name);
|
void ParseFile(const std::string & file_name);
|
||||||
|
@ -76,30 +69,41 @@ public:
|
||||||
void Directory(const char * dir, const char * dir2 = 0);
|
void Directory(const char * dir, const char * dir2 = 0);
|
||||||
void Directory(const std::string & dir);
|
void Directory(const std::string & dir);
|
||||||
void Directory(const std::string & dir, const std::string & dir2);
|
void Directory(const std::string & dir, const std::string & dir2);
|
||||||
|
|
||||||
|
void AllowInclude(bool allow);
|
||||||
|
void DeleteWhiteTextItems(bool del);
|
||||||
|
|
||||||
|
void SetCommentary(const char * com_start, const char * com_stop);
|
||||||
|
void SetCommentary(const std::string & com_start, const std::string & com_stop);
|
||||||
|
|
||||||
|
void SetIncludeMax(int include_max);
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
|
||||||
|
void CreateMsg(std::ostringstream & o, const char * type, const char * arg = 0);
|
||||||
|
std::string CreateMsg(const char * type, const char * arg = 0);
|
||||||
|
|
||||||
|
|
||||||
struct Item
|
struct Item
|
||||||
{
|
{
|
||||||
// change the name to 'Type'
|
enum Type
|
||||||
enum ItemType
|
|
||||||
{
|
{
|
||||||
item_none, item_container, item_text, item_ifany, item_ifno, item_for,
|
item_none, item_container, item_text, item_normal, item_is, item_isno,
|
||||||
item_else, item_end, item_err, item_normal, item_ifindex,
|
item_if, item_ifno, item_ifany, item_ifone, item_ifanyno, item_ifoneno, item_ifindex,
|
||||||
item_include, item_is, item_isno, item_ifone, item_comment, item_def
|
item_for, item_else, item_end, item_err, item_include, item_comment, item_def
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Directive
|
struct Function
|
||||||
{
|
{
|
||||||
bool is_text; // if true that means a directive in quotes "static text"
|
std::string name; // function name
|
||||||
std::string name;
|
std::vector<std::string> params; // function parameters
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Type type;
|
||||||
ItemType type;
|
std::string text; // used in: item_text, item_include (as a file name)
|
||||||
std::string text;
|
std::vector<Item*> item_table; // !! zamienic na 'items'?
|
||||||
std::vector<Item*> item_table;
|
std::vector<Function> functions;
|
||||||
std::vector<Directive> directives;
|
|
||||||
|
|
||||||
Item();
|
Item();
|
||||||
Item(const Item & i);
|
Item(const Item & i);
|
||||||
|
@ -107,16 +111,21 @@ public:
|
||||||
void CopyItemTable(const Item & i);
|
void CopyItemTable(const Item & i);
|
||||||
~Item();
|
~Item();
|
||||||
|
|
||||||
Item * AddItem(const Item * porg = 0);
|
Item * AddItem(const Item * porg = 0);
|
||||||
Item * AddItem(const Item & porg);
|
Item * AddItem(const Item & porg);
|
||||||
void ClearItems();
|
void ClearItems();
|
||||||
ItemType LastItemType();
|
Type LastItemType();
|
||||||
void DeleteLastItem();
|
void DeleteLastItem();
|
||||||
void Clear();
|
void Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
Item item_root;
|
Item item_root;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const char * itext;
|
||||||
|
|
||||||
// allowing include tag
|
// allowing include tag
|
||||||
// default: true
|
// default: true
|
||||||
bool allow_include;
|
bool allow_include;
|
||||||
|
@ -126,37 +135,48 @@ public:
|
||||||
// this not actually delete the whole item but only the string
|
// this not actually delete the whole item but only the string
|
||||||
// the item will be present with an empty string
|
// the item will be present with an empty string
|
||||||
// default: false
|
// default: false
|
||||||
bool delete_all_white;
|
bool delete_white_text_items;
|
||||||
|
|
||||||
private:
|
|
||||||
const char * itext;
|
|
||||||
|
|
||||||
// first we're trying to read a file from 'directory'
|
// first we're trying to read a file from 'directory'
|
||||||
// if there is no such a file there then we try read from 'directory2'
|
// 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
|
// we read from these directories only if they are not empty
|
||||||
std::string directory, directory2;
|
std::string directory, directory2;
|
||||||
|
|
||||||
int include_level;
|
int include_level, include_level_max;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::string commentary_start, commentary_stop;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool CheckFileName(const char * name);
|
|
||||||
std::string ReadFile(const std::string & name);
|
std::string ReadFile(const std::string & name);
|
||||||
std::string ReadFile(const char * name);
|
std::string ReadFile(const char * name);
|
||||||
|
bool CheckFileName(const char * name);
|
||||||
bool ReadFileFromDir(const std::string & dir, const char * name, std::string & result);
|
bool ReadFileFromDir(const std::string & dir, const char * name, std::string & result);
|
||||||
|
|
||||||
int ReadCharInText();
|
int ReadCharInText();
|
||||||
bool IsWhite(int c);
|
bool IsWhite(int c);
|
||||||
void SkipWhiteCharacters();
|
void SkipWhite();
|
||||||
void CheckWhiteAndDelete(std::string & s);
|
void CheckWhiteAndDelete(std::string & s);
|
||||||
|
|
||||||
Item::Directive ReadDirective();
|
bool IsNameChar(int c);
|
||||||
Item::Directive ReadString();
|
bool IsDigit(int c);
|
||||||
Item::Directive ReadDirectiveOrString();
|
bool IsPositiveNumber(const std::string & str);
|
||||||
|
|
||||||
void CreateTreeReadItemDirectiveCheckEnding(Item & item);
|
bool ReadName(std::string & name);
|
||||||
|
bool ReadString(std::string & str);
|
||||||
|
bool ReadFunction(Item::Function & function);
|
||||||
|
bool ReadParams(Item::Function & function);
|
||||||
|
bool ReadFunctions(Item & item);
|
||||||
|
|
||||||
void ReadDirectiveIfany(Item & item);
|
void ReadDirectiveIf(Item & item);
|
||||||
void ReadDirectiveIfno(Item & item);
|
void ReadDirectiveIfno(Item & item);
|
||||||
|
void ReadDirectiveIfany(Item & item);
|
||||||
void ReadDirectiveIfone(Item & item);
|
void ReadDirectiveIfone(Item & item);
|
||||||
|
void ReadDirectiveIfanyno(Item & item);
|
||||||
|
void ReadDirectiveIfoneno(Item & item);
|
||||||
void ReadDirectiveIs(Item & item);
|
void ReadDirectiveIs(Item & item);
|
||||||
void ReadDirectiveIsno(Item & item);
|
void ReadDirectiveIsno(Item & item);
|
||||||
void ReadDirectiveIfindex(Item & item);
|
void ReadDirectiveIfindex(Item & item);
|
||||||
|
@ -164,21 +184,19 @@ private:
|
||||||
void ReadDirectiveComment(Item & item);
|
void ReadDirectiveComment(Item & item);
|
||||||
void ReadDirectiveInclude(Item & item);
|
void ReadDirectiveInclude(Item & item);
|
||||||
void ReadDirectiveDef(Item & item);
|
void ReadDirectiveDef(Item & item);
|
||||||
void ReadDirectiveNormal(Item::Directive & directive, Item & item);
|
void ReadDirectiveNormal(const std::string & name, Item & item);
|
||||||
|
|
||||||
|
void CreateTreeReadItemDirectiveCheckEnding(Item & item);
|
||||||
void CreateTreeReadItemDirective(Item & item);
|
void CreateTreeReadItemDirective(Item & item);
|
||||||
|
|
||||||
void CreateTreeReadItemText(Item & item);
|
void CreateTreeReadItemText(Item & item);
|
||||||
bool CreateTreeReadItem(Item & item);
|
bool CreateTreeReadItem(Item & item);
|
||||||
|
|
||||||
void CreateTreeReadIf(Item & item);
|
void CreateTreeReadIf(Item & item);
|
||||||
void CreateTreeReadFor(Item & item);
|
void CreateTreeReadFor(Item & item);
|
||||||
void CreateTree(Item & item);
|
void CreateTree(Item & item);
|
||||||
|
|
||||||
void CreateTreeReadInclude(Item & item);
|
void CreateTreeReadInclude(Item & item);
|
||||||
void CreateTreeReadIncludeSkipAllowFlag(Item & item);
|
void CreateTreeReadIncludeSkipAllowFlag(Item & item);
|
||||||
|
|
||||||
}; // Pattern
|
}; // class Pattern
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,9 +207,12 @@ struct Info
|
||||||
// output stream
|
// output stream
|
||||||
std::ostringstream & out;
|
std::ostringstream & out;
|
||||||
|
|
||||||
// an optional string parameter in a normal statement [user_function "parameter"]
|
// table of parameters
|
||||||
// or in "is" statement [is user_function "parameter"]
|
std::vector<std::string> & params;
|
||||||
// or in "for" statement [for user_function "parameter"]
|
|
||||||
|
// the first parameter
|
||||||
|
// you can always use it even if there is not any parameters
|
||||||
|
// in such a way the reference points to an empty valid string
|
||||||
const std::string & par;
|
const std::string & par;
|
||||||
|
|
||||||
// this is set by Generator
|
// this is set by Generator
|
||||||
|
@ -203,8 +224,8 @@ struct Info
|
||||||
// for a variable it is set to true if the variable is not empty
|
// for a variable it is set to true if the variable is not empty
|
||||||
bool res;
|
bool res;
|
||||||
|
|
||||||
// arguments: output_stream, string_parameter
|
// arguments: output_stream, table_of_parameters, the_first_parameter
|
||||||
Info(std::ostringstream & o, const std::string & p);
|
Info(std::ostringstream & o, std::vector<std::string> & pars, const std::string & p);
|
||||||
void Clear();
|
void Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -223,12 +244,12 @@ public:
|
||||||
{
|
{
|
||||||
Type type;
|
Type type;
|
||||||
|
|
||||||
UserFunction user_function;
|
UserFunction user_function; // used when type is 'function'
|
||||||
std::string variable;
|
std::string variable; // used when type is 'variable'
|
||||||
|
|
||||||
int iter;
|
int iter;
|
||||||
bool is_for; // true if is used by a [for] statement
|
bool is_for; // true if is used by a [for] statement
|
||||||
bool is_running; // true if this function (if is) is currently running
|
bool is_running; // true if this function is currently executed
|
||||||
|
|
||||||
Function();
|
Function();
|
||||||
};
|
};
|
||||||
|
@ -259,9 +280,10 @@ public:
|
||||||
Generator();
|
Generator();
|
||||||
Generator(std::ostringstream & o, Pattern & p, Functions & f);
|
Generator(std::ostringstream & o, Pattern & p, Functions & f);
|
||||||
|
|
||||||
void SetOutStream(std::ostringstream & o);
|
void Set(std::ostringstream & o, Pattern & p, Functions & f);
|
||||||
void SetPattern(Pattern & p);
|
void Set(std::ostringstream & o);
|
||||||
void SetFunctions(Functions & f);
|
void Set(Pattern & p);
|
||||||
|
void Set(Functions & f);
|
||||||
void SetMax(int max_items_, int max_for_items_);
|
void SetMax(int max_items_, int max_for_items_);
|
||||||
|
|
||||||
void Generate();
|
void Generate();
|
||||||
|
@ -269,9 +291,10 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::ostringstream * output_stream;
|
std::ostringstream * output_stream;
|
||||||
Pattern * pattern;
|
Pattern * pattern;
|
||||||
Functions * functions;
|
Functions * functions;
|
||||||
|
|
||||||
|
bool break_generating;
|
||||||
int current_item;
|
int current_item;
|
||||||
int max_items;
|
int max_items;
|
||||||
int max_for_items;
|
int max_for_items;
|
||||||
|
@ -281,30 +304,32 @@ private:
|
||||||
|
|
||||||
bool Find(const std::string & key, Functions::Function ** function);
|
bool Find(const std::string & key, Functions::Function ** function);
|
||||||
|
|
||||||
|
|
||||||
void Call(Functions::Function * function, Info & info);
|
void Call(Functions::Function * function, Info & info);
|
||||||
bool Call(const std::string & name, Info & info, Functions::Function ** pfun = 0);
|
bool Call(const std::string & name, Info & info, Functions::Function ** pfun = 0);
|
||||||
|
bool Call(Pattern::Item::Function & function, bool * info_res = 0, Functions::Function ** pfun = 0);
|
||||||
|
|
||||||
void CallUserFunction(Functions::Function * function, Info & info);
|
void CallUserFunction(Functions::Function * function, Info & info);
|
||||||
void CallVariable(Functions::Function * function, Info & info);
|
void CallVariable(Functions::Function * function, Info & info);
|
||||||
|
|
||||||
void MakeTextIf_go(Pattern::Item & item, bool result);
|
void MakeTextIf_go(Pattern::Item & item, bool result);
|
||||||
bool MakeTextIfindexnumber(Pattern::Item & item, Functions::Function * function, bool & result);
|
bool MakeTextIfindexnumber(Pattern::Item & item, Functions::Function * function, bool & result);
|
||||||
void MakeTextIfany(Pattern::Item & item);
|
void MakeTextIf(Pattern::Item & item);
|
||||||
void MakeTextIfno(Pattern::Item & item);
|
void MakeTextIfno(Pattern::Item & item);
|
||||||
|
void MakeTextIfany(Pattern::Item & item);
|
||||||
void MakeTextIfone(Pattern::Item & item);
|
void MakeTextIfone(Pattern::Item & item);
|
||||||
|
void MakeTextIfanyno(Pattern::Item & item);
|
||||||
|
void MakeTextIfoneno(Pattern::Item & item);
|
||||||
void MakeTextIfindex(Pattern::Item & item);
|
void MakeTextIfindex(Pattern::Item & item);
|
||||||
void MakeTextForLoop(Pattern::Item & item, Functions::Function * function);
|
void MakeTextForLoop(Pattern::Item & item, Functions::Function * function);
|
||||||
void MakeTextFor(Pattern::Item & item);
|
void MakeTextFor(Pattern::Item & item);
|
||||||
void MakeTextContainer(Pattern::Item & item);
|
void MakeTextContainer(Pattern::Item & item);
|
||||||
void MakeTextNormal(Pattern::Item & item);
|
void MakeTextNormal(Pattern::Item & item);
|
||||||
bool MakeTextIsFunText(const std::string & fun_name, const std::string & text, bool & res);
|
void MakeTextIs(Pattern::Item & item);
|
||||||
bool MakeTextIsFunFun(const std::string & fun_name1, const std::string & fun_name2, bool & res);
|
void MakeTextIsno(Pattern::Item & item);
|
||||||
void MakeTextIs(Pattern::Item & item, bool isno = false);
|
|
||||||
void MakeTextDefine(Pattern::Item & item);
|
void MakeTextDefine(Pattern::Item & item);
|
||||||
void MakeText(Pattern::Item & item);
|
void MakeText(Pattern::Item & item);
|
||||||
|
|
||||||
}; // Generator
|
}; // class Generator
|
||||||
|
|
||||||
} // namespace Ezc
|
} // namespace Ezc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue