computerscare-vcv-modules

computerscare modules for VCV Rack
Log | Files | Refs

commit bbf071626407e3b39a4bd2f93152e7c1725efcd9
parent e3052b2f4cf2a6ae0c9f524031dd533faa698a54
Author: Adam Malone <1319733+freddyz@users.noreply.github.com>
Date:   Mon, 31 Dec 2018 16:03:26 -0600

ChanceOfInteger parsing for Laundry

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

diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp @@ -498,7 +498,7 @@ Parser::Parser(std::string expr) { inError = false; } void Parser::setForLaundry() { - std::vector<std::string> laundryInterleaveAny = {"Letter","Integer","Digit","LeftParen","RightParen"}; + std::vector<std::string> laundryInterleaveAny = {"Letter","Integer","ChanceOfInteger","Digit","LeftParen","RightParen"}; if(tokens.size() > 0) { currentIndex=0; setForExactIntegers(tokens[0]); @@ -506,7 +506,13 @@ void Parser::setForLaundry() { currentIndex=0; tokens=tokenStack; tokenStack = {}; + setForChanceOfIntegers(peekToken()); + if(!inError) { + currentIndex=0; + tokens=tokenStack; + tokenStack = {}; setForInterleave(peekToken(),laundryInterleaveAny); +} } } printTokenVector(tokenStack); @@ -622,6 +628,31 @@ void Parser::setForExactIntegers(Token t) { t = skipAndPeekToken(); } } +void Parser::setForChanceOfIntegers(Token t) { + while(t.type!="NULL") { + ParseChanceOfInteger(t); + if(peekToken().type !="NULL") { + tokenStack.push_back(peekToken()); + } + t = skipAndPeekToken(); + } +} + +void Parser::ParseChanceOfInteger(Token t) { + Token last = Token("NULL","-1"); + if(t.type=="Integer" || t.type=="Digit") { + last = t; + t = skipAndPeekToken(); + if(t.type=="Question") { + tokenStack.push_back(Token("ChanceOfInteger",last.value)); + t=skipAndPeekToken(); + } + else { + tokenStack.push_back(Token("Integer",last.value)); + } + setForChanceOfIntegers(t); + } +} void Parser::ParseExactInteger(Token t) { if(t.type=="LeftAngle") { t=skipAndPeekToken(); @@ -631,8 +662,8 @@ void Parser::ParseExactInteger(Token t) { t = skipAndPeekToken(); } if(t.type=="RightAngle") { - tokenStack.push_back(Token("Integer",num)); t=skipAndPeekToken(); + tokenStack.push_back(Token("Integer",num)); setForExactIntegers(t); } else { diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp @@ -42,6 +42,7 @@ class Parser { void skipToken(); void setExactValue(Token t); void setForExactIntegers(Token t); + void setForChanceOfIntegers(Token t); void setForRandoms(Token t); void setForInterleave(Token t,std::vector<std::string> whitelist); void setForAtExpand(Token t); @@ -61,6 +62,7 @@ class Parser { void ParseInterleave(Token t,std::vector<std::string> whitelist); void ParseAtExpand(Token t); void ParseSquareBrackets(Token t); + void ParseChanceOfInteger(Token t); int ParseAtPart(Token t); }; class AbsoluteSequence {