Skip to content

Commit

Permalink
Formula engine: support wfl/wflend instead of fai/faiend
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 18, 2016
1 parent 1ae426c commit 0674f2a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/formula.cpp
Expand Up @@ -1030,6 +1030,8 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :

//set true when 'fai' keyword is found
bool fai_keyword = false;
//set true when 'wfl' keyword is found
bool wfl_keyword = false;
//used to locally keep the track of which file we parse actually and in which line we are
std::vector< std::pair< std::string, int> > files;
//used as a source of strings - we point to these strings from tokens
Expand Down Expand Up @@ -1067,6 +1069,10 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :
fai_keyword = true;
tokens.pop_back();
} else
if( ( current_type == TOKEN_KEYWORD) && ( std::string(tokens.back().begin,tokens.back().end) == "wfl") ) {
wfl_keyword = true;
tokens.pop_back();
} else
if( ( current_type == TOKEN_KEYWORD) && ( std::string(tokens.back().begin,tokens.back().end) == "faiend") ) {
if (files.size() > 1) {
files.pop_back();
Expand All @@ -1076,7 +1082,16 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :
throw formula_error("Unexpected 'faiend' found", "", "", 0);
}
} else
if (fai_keyword) {
if( ( current_type == TOKEN_KEYWORD) && ( std::string(tokens.back().begin,tokens.back().end) == "wflend") ) {
if (files.size() > 1) {
files.pop_back();
filenames_it = filenames.find( files.back().first );
tokens.pop_back();
} else {
throw formula_error("Unexpected 'wflend' found", "", "", 0);
}
} else
if (fai_keyword || wfl_keyword) {
if(current_type == TOKEN_STRING_LITERAL) {
std::string str = std::string(tokens.back().begin,tokens.back().end);
files.push_back( std::make_pair( str , 1 ) );
Expand All @@ -1085,12 +1100,17 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :
if(ret.second==true) {
filenames_it = ret.first;
} else {
throw formula_error("Faifile already included", "fai" + str, "", 0);
if (fai_keyword)
throw formula_error("Faifile already included", "fai" + str, "", 0);
else throw formula_error("Wflfile already included", "wfl" + str, "", 0);
}
tokens.pop_back();
fai_keyword = false;
wfl_keyword = false;
} else {
throw formula_error("Expected string after the 'fai'", "fai", "", 0);
if (fai_keyword)
throw formula_error("Expected string after the 'fai'", "fai", "", 0);
else throw formula_error("Expected string after the 'wfl'", "wfl", "", 0);
}
} else {
//in every token not specified above, store line number and name of file it came from
Expand All @@ -1116,7 +1136,7 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :
}

if(files.size() > 1) {
throw formula_error("Missing 'faiend', make sure each .fai file ends with it", "", "", 0);
throw formula_error("Missing 'wflend', make sure each .wfl file ends with it", "", "", 0);
}

if(!tokens.empty()) {
Expand Down
5 changes: 5 additions & 0 deletions src/formula_tokenizer.cpp
Expand Up @@ -72,6 +72,9 @@ token get_token(iterator& i1, iterator i2) {
} else if( *it == 'f' ) { //fai
if( *(it+1) == 'a' && *(it+2) == 'i' )
t = TOKEN_KEYWORD;
} else if( *it == 'w' ) { //wfl
if( *(it+1) == 'f' && *(it+2) == 'l' )
t = TOKEN_KEYWORD;
}
} else if( diff == 5 ) {
std::string s(it, i1);
Expand All @@ -81,6 +84,8 @@ token get_token(iterator& i1, iterator i2) {
std::string s(it, i1);
if( s == "faiend" )
t = TOKEN_KEYWORD;
else if( s == "wflend" )
t = TOKEN_KEYWORD;
} else if( diff == 9 ) {
std::string s(it, i1);
if( s == "functions" )
Expand Down

0 comments on commit 0674f2a

Please sign in to comment.