A programming language for manipulation of streams.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

110 lignes
1.9 KiB

#pragma once
#include "tool.h"
#include <vector>
#include <algorithm>
#include <cassert>
#include <deque>
enum class m_t{
key = 0, value = 1
};
template<typename iterator>
tool_env parse_toolenv(tool_env source, iterator env_start, iterator env_end)
{
std::pair<std::string, std::string> entry;
tool_env lenv = source;
m_t mode = m_t::key;
int rec = 0;
auto it = env_start;
if(it!=env_end) ++it;
for(;it!=env_end;++it)
{
if(*it=='\\')
{
++it;
char c = *it;
switch(c)
{
case 'n':
c = '\n';
break;
case 't':
c = '\t';
break;
}
switch(mode)
{
case m_t::key:
entry.first+=c;
break;
case m_t::value:
entry.second+=c;
break;
}
continue;
}
if(*it=='[')
rec++;
if(*it==']')
rec--;
if(*it=='=' && rec==0 && mode==m_t::key)
{
mode=m_t::value;
continue;
}
if(*it!=',' || rec!=0)
{
switch(mode)
{
case m_t::key:
entry.first+=*it;
break;
case m_t::value:
entry.second+=*it;
break;
}
}
else
{
assert(rec==0);
assert(mode==m_t::value);
mode=m_t::key;
lenv[entry.first]=std::string{entry.second};
entry=std::make_pair(std::string{},std::string{});
}
}
if(mode==m_t::value)
{
lenv[entry.first]=std::string{entry.second};
}
return lenv;
}
class parse_tool : public tool
{
std::optional<std::shared_ptr<tool>> next;
std::deque<std::string> queue;
std::vector<std::shared_ptr<tool>> pipeline;
public:
parse_tool(std::string tool, tool_env env);
virtual void init(std::optional<std::shared_ptr<tool>> next);
virtual void execute();
virtual void enqueue(std::string message)
{
queue.push_back(message);
}
virtual bool has_queue()
{
return queue.size()!=0 || std::any_of(pipeline.begin(), pipeline.end(), [](auto& t){
return t->has_queue();
});
}
};
class pipe : public parse_tool
{
public:
pipe(tool_env env);
};