computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 3b316409c32d19f3a15237f88fa9259f2b137161
parent 4b2db00805634f9b495af52b95544b63a16116a3
Author: Adam Malone <[email protected]>
Date:   Tue, 18 Dec 2018 17:02:24 -0600

check for many more errors in dtpulse for ilovecookies.  Empty input, empty token stack all checked for

Diffstat:
Msrc/dtpulse.cpp | 74++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Msrc/dtpulse.hpp | 3++-
2 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -379,15 +379,20 @@ AbsoluteSequence::AbsoluteSequence() { AbsoluteSequence::AbsoluteSequence(std::string expr, std::string lookup) { std::vector<Token> defaultStack; defaultStack.push_back(Token("Error", "error",-1)); - expr = expr=="" ? "a" : expr; - Parser p = Parser(expr); - exactFloats = p.exactFloats; - randomTokens=p.randomVector; - if(p.inError) { - tokenStack = defaultStack; - } + //expr = expr=="" ? "a" : expr; + if(expr != "") { + Parser p = Parser(expr); + exactFloats = p.exactFloats; + randomTokens=p.randomVector; + if(p.inError || !p.tokenStack.size()) { + tokenStack = defaultStack; + } + else { + tokenStack = p.tokenStack; + } + } else { - tokenStack = p.tokenStack; + tokenStack = defaultStack; } numTokens = tokenStack.size(); indexSequence = getIndicesFromTokenStack(tokenStack); @@ -479,7 +484,7 @@ Parser::Parser(std::string expr) { inError = false; if(tokens.size() > 0) { currentIndex=0; - setExpression(tokens[0]); + setExactValue(tokens[0]); //printTokenVector(tokenStack); if(!inError) { @@ -506,13 +511,35 @@ Parser::Parser(std::string expr) { tokens=tokenStack; tokenStack = {}; setForSquareBrackets(tokens[0]); + if(!inError) { + currentIndex = 0; + tokens=tokenStack; + tokenStack = {}; + setFinal(tokens[0]); + } } } } } } } -void Parser::setExpression(Token t) { +void Parser::setFinal(Token t) { + while (t.type!="NULL") { + if(t.type=="Letter" || t.type=="ExactValue" || t.type=="RandomSequence" || t.type =="Zero") { + tokenStack.push_back(t); + } + else if(t.type=="Comma") { + + } + else { + inError = true; + break; + } + t = skipAndPeekToken(); + } +} + +void Parser::setExactValue(Token t) { while (t.type!="NULL") { ParseExactValue(t); if(peekToken().type !="NULL") { @@ -568,19 +595,22 @@ void Parser::ParseExactValue(Token t) { } if(t.type=="Digit" || t.type=="Period") { num += parseFloat(t); + t=peekToken(); + if(!inError && t.type=="RightAngle") { + skipToken(); + int sizeInt = static_cast<int>(exactFloats.size()); + num = ((num.length() == 0) || num=="." || num=="-") ? "0" : num; + tokenStack.push_back(Token("ExactValue",num,sizeInt + 52)); + exactFloats.push_back(std::stof(num)); + setExactValue(peekToken()); + } + else { + inError = true; + } } - t=peekToken(); - if(t.type=="RightAngle") { - skipToken(); - int sizeInt = static_cast<int>(exactFloats.size()); - num = ((num.length() == 0) || num=="." || num=="-") ? "0" : num; - tokenStack.push_back(Token("ExactValue",num,sizeInt + 52)); - exactFloats.push_back(std::stof(num)); - } - else { - inError = true; + else { + inError=true; } - setExpression(peekToken()); } // not a LeftAngle, dont do shit } void Parser::ParseRandomSequence(Token t) { @@ -775,7 +805,7 @@ std::string Parser::parseFloat(Token t) return number; } void Token::print() { - printf("type:%s value:%s index:%i\n",type.c_str(),value.c_str(),index); + printf("type: %s value: %s index: %i\n",type.c_str(),value.c_str(),index); } std::vector<Token> tokenizeString(std::string input) { std::vector<Token> stack; diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -38,11 +38,12 @@ class Parser { Token peekToken(); Token skipAndPeekToken(); void skipToken(); - void setExpression(Token t); + void setExactValue(Token t); void setForRandoms(Token t); void setForInterleave(Token t); void setForAtExpand(Token t); void setForSquareBrackets(Token t); + void setFinal(Token t); bool inError; std::string parseFloat(Token t); std::vector<Token> tokenStack;