computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit 0ab267f43d13445e674cb92b5ee0590d0512a309
parent c28e1186d4c1d5520acebc97c4ba2baba1e05b71
Author: Adam M <aemalone@gmail.com>
Date:   Wed, 12 Dec 2018 06:32:19 -0600

add inError condition in Parser

Diffstat:
Msrc/dtpulse.cpp | 55++++++++++++++++++++++++++++++++++---------------------
Msrc/dtpulse.hpp | 1+
2 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -377,10 +377,15 @@ AbsoluteSequence::AbsoluteSequence() { AbsoluteSequence("a",knobandinputlookup); } AbsoluteSequence::AbsoluteSequence(std::string expr, std::string lookup) { - expr = expr=="" ? "a" : expr; + std::vector<Token> defaultStack; + defaultStack.push_back(Token("Letter", "a")); + expr = expr=="" ? "a" : expr; Parser p = Parser(expr); exactFloats = p.exactFloats; randomTokens=p.randomVector; + if(p.inError) { + tokenStack = defaultStack; + } tokenStack = p.tokenStack; numTokens = tokenStack.size(); indexSequence = getIndicesFromTokenStack(tokenStack); @@ -469,28 +474,34 @@ Token::Token(std::string t, std::string v, int dex) { Parser::Parser(std::string expr) { tokens = tokenizeString(expr); expression=expr; + inError = false; if(tokens.size() > 0) { - currentIndex=0; - setExpression(tokens[0]); - - //printTokenVector(tokenStack); - currentIndex=0; - tokens=tokenStack; - tokenStack = {}; - setForRandoms(tokens[0]); + currentIndex=0; + setExpression(tokens[0]); - //printTokenVector(tokenStack); - currentIndex = 0; - tokens = tokenStack; - tokenStack={}; - setForInterleave(tokens[0]); - - //printTokenVector(tokenStack); - currentIndex = 0; - tokens = tokenStack; - tokenStack = {}; - setForAtExpand(tokens[0]); - } + //printTokenVector(tokenStack); + if(!inError) { + currentIndex=0; + tokens=tokenStack; + tokenStack = {}; + setForRandoms(tokens[0]); + if(!inError) { + //printTokenVector(tokenStack); + currentIndex = 0; + tokens = tokenStack; + tokenStack={}; + setForInterleave(tokens[0]); + + if(!inError) { + //printTokenVector(tokenStack); + currentIndex = 0; + tokens = tokenStack; + tokenStack = {}; + setForAtExpand(tokens[0]); + } + } + } + } } void Parser::setExpression(Token t) { while (t.type!="NULL") { @@ -549,6 +560,7 @@ void Parser::ParseExactValue(Token t) { exactFloats.push_back(std::stof(num)); } if(t.type !="RightAngle") { + inError = true; printf("ERROR: no closing angle bracket. it was (%s)\n",t.value.c_str()); } setExpression(peekToken()); @@ -579,6 +591,7 @@ void Parser::ParseRandomSequence(Token t) { tokenStack.push_back(Token("RandomSequence",stringDex,myIndex)); } else { + inError = true; printf("ERROR: no closing RightCurly. it was \"%s\" (%s)\n",t.value.c_str(),t.type.c_str()); } ParseRandomSequence(peekToken()); diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -42,6 +42,7 @@ class Parser { void setForRandoms(Token t); void setForInterleave(Token t); void setForAtExpand(Token t); + bool inError = false; std::string parseFloat(Token t); std::vector<Token> tokenStack; std::vector<float> exactFloats;