Browse Source

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
master
Tomasz Sowa 12 years ago
parent
commit
573d241dc1
  1. 1015
      src/ezc.cpp
  2. 155
      src/ezc.h

1015
src/ezc.cpp

File diff suppressed because it is too large

155
src/ezc.h

@ -1,7 +1,7 @@
/*
* This file is a part of EZC -- Easy templating in C++
* 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
{
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
{
public:
Pattern();
void ParseFile(const std::string & file_name);
@ -76,30 +69,41 @@ public:
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 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 CreateMsg(std::ostringstream & o, const char * type, const char * arg = 0);
std::string CreateMsg(const char * type, const char * arg = 0);
struct Item
{
// change the name to 'Type'
enum ItemType
enum Type
{
item_none, item_container, item_text, item_ifany, item_ifno, item_for,
item_else, item_end, item_err, item_normal, item_ifindex,
item_include, item_is, item_isno, item_ifone, item_comment, item_def
item_none, item_container, item_text, item_normal, item_is, item_isno,
item_if, item_ifno, item_ifany, item_ifone, item_ifanyno, item_ifoneno, item_ifindex,
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;
std::string name; // function name
std::vector<std::string> params; // function parameters
};
ItemType type;
std::string text;
std::vector<Item*> item_table;
std::vector<Directive> directives;
Type type;
std::string text; // used in: item_text, item_include (as a file name)
std::vector<Item*> item_table; // !! zamienic na 'items'?
std::vector<Function> functions;
Item();
Item(const Item & i);
@ -107,16 +111,21 @@ public:
void CopyItemTable(const Item & i);
~Item();
Item * AddItem(const Item * porg = 0);
Item * AddItem(const Item & porg);
void ClearItems();
ItemType LastItemType();
void DeleteLastItem();
void Clear();
Item * AddItem(const Item * porg = 0);
Item * AddItem(const Item & porg);
void ClearItems();
Type LastItemType();
void DeleteLastItem();
void Clear();
};
Item item_root;
private:
const char * itext;
// allowing include tag
// default: true
bool allow_include;
@ -126,37 +135,48 @@ public:
// this not actually delete the whole item but only the string
// the item will be present with an empty string
// default: false
bool delete_all_white;
private:
const char * itext;
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::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 char * name);
bool CheckFileName(const char * name);
bool ReadFileFromDir(const std::string & dir, const char * name, std::string & result);
int ReadCharInText();
bool IsWhite(int c);
void SkipWhiteCharacters();
void SkipWhite();
void CheckWhiteAndDelete(std::string & s);
Item::Directive ReadDirective();
Item::Directive ReadString();
Item::Directive ReadDirectiveOrString();
bool IsNameChar(int c);
bool IsDigit(int c);
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 ReadDirectiveIfany(Item & item);
void ReadDirectiveIfone(Item & item);
void ReadDirectiveIfanyno(Item & item);
void ReadDirectiveIfoneno(Item & item);
void ReadDirectiveIs(Item & item);
void ReadDirectiveIsno(Item & item);
void ReadDirectiveIfindex(Item & item);
@ -164,21 +184,19 @@ private:
void ReadDirectiveComment(Item & item);
void ReadDirectiveInclude(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 CreateTreeReadItemText(Item & item);
bool CreateTreeReadItem(Item & item);
void CreateTreeReadIf(Item & item);
void CreateTreeReadFor(Item & item);
void CreateTree(Item & item);
void CreateTreeReadInclude(Item & item);
void CreateTreeReadIncludeSkipAllowFlag(Item & item);
}; // Pattern
}; // class Pattern
@ -189,9 +207,12 @@ struct Info
// output stream
std::ostringstream & out;
// an optional string parameter in a normal statement [user_function "parameter"]
// or in "is" statement [is user_function "parameter"]
// or in "for" statement [for user_function "parameter"]
// table of parameters
std::vector<std::string> & params;
// 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;
// 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
bool res;
// arguments: output_stream, string_parameter
Info(std::ostringstream & o, const std::string & p);
// arguments: output_stream, table_of_parameters, the_first_parameter
Info(std::ostringstream & o, std::vector<std::string> & pars, const std::string & p);
void Clear();
};
@ -223,12 +244,12 @@ public:
{
Type type;
UserFunction user_function;
std::string variable;
UserFunction user_function; // used when type is 'function'
std::string variable; // used when type is 'variable'
int iter;
bool is_for; // true if is used by a [for] statement
bool is_running; // true if this function (if is) is currently running
int iter;
bool is_for; // true if is used by a [for] statement
bool is_running; // true if this function is currently executed
Function();
};
@ -259,9 +280,10 @@ public:
Generator();
Generator(std::ostringstream & o, Pattern & p, Functions & f);
void SetOutStream(std::ostringstream & o);
void SetPattern(Pattern & p);
void SetFunctions(Functions & f);
void Set(std::ostringstream & o, Pattern & p, Functions & f);
void Set(std::ostringstream & o);
void Set(Pattern & p);
void Set(Functions & f);
void SetMax(int max_items_, int max_for_items_);
void Generate();
@ -269,9 +291,10 @@ public:
private:
std::ostringstream * output_stream;
Pattern * pattern;
Pattern * pattern;
Functions * functions;
bool break_generating;
int current_item;
int max_items;
int max_for_items;
@ -281,30 +304,32 @@ private:
bool Find(const std::string & key, Functions::Function ** function);
void Call(Functions::Function * function, Info & info);
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 CallVariable(Functions::Function * function, Info & info);
void MakeTextIf_go(Pattern::Item & item, 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 MakeTextIfany(Pattern::Item & item);
void MakeTextIfone(Pattern::Item & item);
void MakeTextIfanyno(Pattern::Item & item);
void MakeTextIfoneno(Pattern::Item & item);
void MakeTextIfindex(Pattern::Item & item);
void MakeTextForLoop(Pattern::Item & item, Functions::Function * function);
void MakeTextFor(Pattern::Item & item);
void MakeTextContainer(Pattern::Item & item);
void MakeTextNormal(Pattern::Item & item);
bool MakeTextIsFunText(const std::string & fun_name, const std::string & text, bool & res);
bool MakeTextIsFunFun(const std::string & fun_name1, const std::string & fun_name2, bool & res);
void MakeTextIs(Pattern::Item & item, bool isno = false);
void MakeTextIs(Pattern::Item & item);
void MakeTextIsno(Pattern::Item & item);
void MakeTextDefine(Pattern::Item & item);
void MakeText(Pattern::Item & item);
}; // Generator
}; // class Generator
} // namespace Ezc

Loading…
Cancel
Save