mirror of
https://github.com/louisrubet/rpn
synced 2024-11-17 07:47:50 +01:00
Recursive programs entry
This commit is contained in:
parent
b27ca47894
commit
db400c28dc
1 changed files with 44 additions and 10 deletions
54
src/parse.h
54
src/parse.h
|
@ -54,26 +54,60 @@ static bool _cut(const string& entry, vector<string>& entries)
|
|||
entries.push_back(tmp);
|
||||
tmp.clear();
|
||||
}
|
||||
if (i<(entry.size()-1) && entry.at(i+1)=='<')
|
||||
|
||||
if (entry.substr(i, 2) == "<<")
|
||||
{
|
||||
//get expression
|
||||
int up = 1;
|
||||
|
||||
// found a program begin
|
||||
i+=2;
|
||||
tmp = "<<";
|
||||
tmp="<< ";
|
||||
// trim leading spaces
|
||||
while (i<entry.size() && (entry.at(i)==' ' || entry.at(i)=='\t'))
|
||||
i++;
|
||||
//get the rest
|
||||
i++;
|
||||
|
||||
while(i<entry.size())
|
||||
{
|
||||
tmp+=entry.at(i);
|
||||
i++;
|
||||
if (entry.substr(i, 2) == "<<")
|
||||
{
|
||||
up++;
|
||||
i+=2;
|
||||
tmp+=" << ";
|
||||
// trim leading spaces
|
||||
while (i<entry.size() && (entry.at(i)==' ' || entry.at(i)=='\t'))
|
||||
i++;
|
||||
}
|
||||
else if (entry.substr(i, 2) == ">>")
|
||||
{
|
||||
up--;
|
||||
i+=2;
|
||||
tmp+=" >>";
|
||||
// trim trailing spaces
|
||||
while (i<entry.size() && (entry.at(i)==' ' || entry.at(i)=='\t'))
|
||||
i++;
|
||||
// found end
|
||||
if (up == 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp+=entry[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
while((up--)>0)
|
||||
{
|
||||
tmp += " >>";
|
||||
}
|
||||
if (tmp.size()>0)
|
||||
{
|
||||
entries.push_back(tmp);
|
||||
tmp.clear();
|
||||
}
|
||||
entries.push_back(tmp);
|
||||
tmp.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reinject < which is not a program begin
|
||||
// reinject '<'' which is not a prog begin
|
||||
tmp = "<";
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue