Skip to content

Commit

Permalink
strict StringToChoiceType processing
Browse files Browse the repository at this point in the history
  • Loading branch information
ponapalt committed Nov 12, 2021
1 parent ef9dd4f commit 434709f
Showing 3 changed files with 36 additions and 19 deletions.
6 changes: 2 additions & 4 deletions parser0.cpp
Original file line number Diff line number Diff line change
@@ -816,8 +816,7 @@ char CParser0::DefineFunctions(std::vector<yaya::string_t> &s, const yaya::strin
// 重複回避オプションの判定
choicetype_t chtype = CHOICETYPE_RANDOM;
if (d1.size()) {
chtype = CSelecter::StringToChoiceType(d1);
//vm.logger().Error(E_E, 30, d1, dicfilename, linecount);
chtype = CSelecter::StringToChoiceType(d1, vm, dicfilename, linecount);
}
// 作成
targetfunction = MakeFunction(d0, chtype, dicfilename, linecount);
@@ -901,8 +900,7 @@ char CParser0::StoreInternalStatement(int targetfunc, yaya::string_t &str, int&
m_defaultBlockChoicetypeStack.emplace_back(chtype);
yaya::string_t d0, d1;
if (Split(str, d0, d1, L":")){
chtype = CSelecter::StringToChoiceType(d0);
//vm.logger().Error(E_E, 30, d0, dicfilename, linecount);
chtype = CSelecter::StringToChoiceType(d0, vm, dicfilename, linecount);
}
depth++;
targetfunction.statement.emplace_back(CStatement(ST_OPEN, linecount, new CDuplEvInfo(chtype)));
47 changes: 33 additions & 14 deletions selecter.cpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
#include "globaldef.h"
#include "sysfunc.h"
#include "ayavm.h"
#include "wsex.h"
#include "messages.h"

//////////DEBUG/////////////////////////
#ifdef _WINDOWS
@@ -272,31 +274,48 @@ choicetype_t CSelecter::GetDefaultBlockChoicetype(choicetype_t nowtype)
* 機能概要: 文字列->choicetype_t
* -----------------------------------------------------------------------
*/
choicetype_t CSelecter::StringToChoiceType(const yaya::string_t& ctypestr)
choicetype_t CSelecter::StringToChoiceType(const yaya::string_t& ctypestr, CAyaVM &vm, const yaya::string_t& dicfilename, int linecount)
{
unsigned int outtype = CHOICETYPE_PICKONE_FLAG;

if ( ctypestr.find(L"pool") != yaya::string_t::npos ) {
yaya::string_t checkstr = ctypestr;

if ( checkstr.find(L"pool") != yaya::string_t::npos ) {
outtype = CHOICETYPE_POOL_FLAG;
yaya::ws_replace(checkstr,L"pool",L"");
}
else if ( ctypestr.find(L"void") != yaya::string_t::npos ) {
else if ( checkstr.find(L"void") != yaya::string_t::npos ) {
outtype = CHOICETYPE_VOID_FLAG;
yaya::ws_replace(checkstr,L"void",L"");
}

if ( outtype == CHOICETYPE_VOID_FLAG ) {
return static_cast<choicetype_t>(outtype);
}
unsigned int choicetype = 0;

unsigned int choicetype = CHOICETYPE_RANDOM_FLAG;
if ( outtype != CHOICETYPE_VOID_FLAG ) {
choicetype = CHOICETYPE_RANDOM_FLAG;

if ( ctypestr.find(L"sequential") != yaya::string_t::npos ) {
choicetype = CHOICETYPE_SEQUENTIAL_FLAG;
}
else if ( ctypestr.find(L"array") != yaya::string_t::npos ) {
choicetype = CHOICETYPE_ARRAY_FLAG;
if ( checkstr.find(L"sequential") != yaya::string_t::npos ) {
choicetype = CHOICETYPE_SEQUENTIAL_FLAG;
yaya::ws_replace(checkstr,L"sequential",L"");
}
else if ( checkstr.find(L"array") != yaya::string_t::npos ) {
choicetype = CHOICETYPE_ARRAY_FLAG;
yaya::ws_replace(checkstr,L"array",L"");
}
else if ( checkstr.find(L"nonoverlap") != yaya::string_t::npos ) {
choicetype = CHOICETYPE_NONOVERLAP_FLAG;
yaya::ws_replace(checkstr,L"nonoverlap",L"");
}
else {
yaya::ws_replace(checkstr,L"random",L"");
}
}
else if ( ctypestr.find(L"nonoverlap") != yaya::string_t::npos ) {
choicetype = CHOICETYPE_NONOVERLAP_FLAG;

yaya::ws_replace(checkstr,L"_",L"");

if ( checkstr.size() > 0 ) {
//なにか余分なものがあったぞ
vm.logger().Error(E_E, 30, ctypestr, dicfilename, linecount);
}

return static_cast<choicetype_t>(outtype | choicetype);
2 changes: 1 addition & 1 deletion selecter.h
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ class CSelecter
CValue Output(void);

static choicetype_t GetDefaultBlockChoicetype(choicetype_t nowtype);
static choicetype_t StringToChoiceType(const yaya::string_t& ctypestr);
static choicetype_t StringToChoiceType(const yaya::string_t& ctypestr, CAyaVM &vm, const yaya::string_t& dicfilename, int linecount);
static const yaya::char_t* ChoiceTypeToString(choicetype_t ctype);

protected:

0 comments on commit 434709f

Please sign in to comment.