commit bbeb552440816d3af448d37a0a1479d1da83a5fe
parent bbf071626407e3b39a4bd2f93152e7c1725efcd9
Author: Adam M <aemalone@gmail.com>
Date: Mon, 31 Dec 2018 18:17:32 -0600
Gettin after parsing by tokens for LaundrySoup
Diffstat:
3 files changed, 48 insertions(+), 72 deletions(-)
diff --git a/src/ComputerscareLaundrySoup.cpp b/src/ComputerscareLaundrySoup.cpp
@@ -283,43 +283,10 @@ void ComputerscareLaundrySoup::step() {
}
}
-/////////////////////////////////////////////////
-struct NumberDisplayWidget3 : TransparentWidget {
-
- int *value;
- std::shared_ptr<Font> font;
-
- NumberDisplayWidget3() {
- font = Font::load(assetPlugin(plugin, "res/digital-7.ttf"));
- };
-
- void draw(NVGcontext *vg) override
- {
- // Background
- NVGcolor backgroundColor = nvgRGB(0x00, 0x00, 0x00);
-
- nvgBeginPath(vg);
- nvgRoundedRect(vg, 0.0, 0.0, box.size.x, box.size.y, 4.0);
- nvgFillColor(vg, backgroundColor);
- nvgFill(vg);
-
- // text
- nvgFontSize(vg, 13);
- nvgFontFaceId(vg, font->handle);
- nvgTextLetterSpacing(vg, 2.5);
-
- std::stringstream to_display;
- to_display << std::setw(3) << *value;
-
- Vec textPos = Vec(6.0f, 17.0f);
- NVGcolor textColor = nvgRGB(0xC0, 0xE7, 0xDE);
- nvgFillColor(vg, textColor);
- nvgText(vg, textPos.x, textPos.y, to_display.str().c_str(), NULL);
- }
-};
-
void MyTextField::onTextChange() {
module->setNextAbsoluteSequence(this->rowIndex);
+ std::string value = module->textFields[this->rowIndex]->text;
+ whoKnowsLaundry(value);
}
struct ComputerscareLaundrySoupWidget : ModuleWidget {
@@ -361,18 +328,7 @@ struct ComputerscareLaundrySoupWidget : ModuleWidget {
addChild(textField);
module->textFields[i] = textField;
- //active step display
- /*NumberDisplayWidget3 *display = new NumberDisplayWidget3();
- display->box.pos = mm2px(Vec(24,verticalStart - 7.2 +verticalSpacing*i));
- display->box.size = Vec(50, 20);
- if(&module->numSteps[i]) {
- display->value = &module->absoluteStep[i];
- }
- else {
- display->value = 0;
- }
- addChild(display);*/
-
+ // active / total steps display
smallLetterDisplay = new SmallLetterDisplay();
smallLetterDisplay->box.pos = mm2px(Vec(20,verticalStart - 9.2 +verticalSpacing*i));
smallLetterDisplay->box.size = Vec(60, 30);
diff --git a/src/dtpulse.cpp b/src/dtpulse.cpp
@@ -499,27 +499,38 @@ Parser::Parser(std::string expr) {
}
void Parser::setForLaundry() {
std::vector<std::string> laundryInterleaveAny = {"Letter","Integer","ChanceOfInteger","Digit","LeftParen","RightParen"};
+ std::vector<std::string> laundryAtExpandAny = {"Letter","Digit","ChanceOfInteger","Integer"};
+
if(tokens.size() > 0) {
- currentIndex=0;
- setForExactIntegers(tokens[0]);
- if(!inError) {
- currentIndex=0;
- tokens=tokenStack;
- tokenStack = {};
- setForChanceOfIntegers(peekToken());
+ currentIndex=0;
+ setForExactIntegers(tokens[0]);
+ if(!inError) {
+ currentIndex=0;
+ tokens=tokenStack;
+ tokenStack = {};
+ setForChanceOfIntegers(peekToken());
if(!inError) {
currentIndex=0;
tokens=tokenStack;
tokenStack = {};
setForInterleave(peekToken(),laundryInterleaveAny);
-}
- }
+ if(!inError) {
+ currentIndex=0;
+ tokens=tokenStack;
+ tokenStack = {};
+ setForAtExpand(peekToken(),laundryAtExpandAny, true);
+ }
+ }
+ }
}
+ printf(" Laundry tokenStack:\n");
printTokenVector(tokenStack);
}
void Parser::setForCookies() {
std::vector<std::string> interleaveAny = {"Letter","ExactValue","RandomSequence","LeftParen","RightParen"};
+ std::vector<std::string> atExpandAny = {"Letter" ,"RandomSequence","ExactValue"};
+
if(tokens.size() > 0) {
currentIndex=0;
setExactValue(tokens[0]);
@@ -539,19 +550,19 @@ void Parser::setForCookies() {
currentIndex = 0;
tokens = tokenStack;
tokenStack = {};
- setForAtExpand(peekToken());
+ setForAtExpand(peekToken(),atExpandAny, false);
if(!inError) {
currentIndex = 0;
tokens=tokenStack;
tokenStack = {};
setForSquareBrackets(peekToken());
- if(!inError) {
- currentIndex = 0;
- tokens=tokenStack;
- tokenStack = {};
- setFinal(peekToken());
- }
+ if(!inError) {
+ currentIndex = 0;
+ tokens=tokenStack;
+ tokenStack = {};
+ setFinal(peekToken());
+ }
}
}
}
@@ -601,9 +612,9 @@ void Parser::setForInterleave(Token t,std::vector<std::string> whitelist) {
t = skipAndPeekToken();
}
}
-void Parser::setForAtExpand(Token t) {
+void Parser::setForAtExpand(Token t, std::vector<std::string> whitelist, bool laundryMode) {
while (t.type!="NULL") {
- ParseAtExpand(t);
+ ParseAtExpand(t, whitelist, laundryMode);
if(peekToken().type !="NULL") {
tokenStack.push_back(peekToken());
}
@@ -648,7 +659,7 @@ void Parser::ParseChanceOfInteger(Token t) {
t=skipAndPeekToken();
}
else {
- tokenStack.push_back(Token("Integer",last.value));
+ tokenStack.push_back(Token(last.type,last.value));
}
setForChanceOfIntegers(t);
}
@@ -773,20 +784,25 @@ void Parser::ParseInterleave(Token t,std::vector<std::string> whitelist) {
tokenStack.insert(tokenStack.end(),output.begin(),output.end());
}
}
-void Parser::ParseAtExpand(Token t) {
+void Parser::ParseAtExpand(Token t, std::vector<std::string> whitelist, bool laundryMode) {
// for letter,{},<> followed by an optional "@" and an integer
// ab@3 da@2 cad
std::vector<std::vector<Token>> tokenVec;
std::vector<Token> proposedTokens;
tokenVec.push_back({});
int atNum = -1;
- if(t.type=="Letter" || t.type=="RandomSequence" || t.type=="ExactValue") {
- while(t.type=="Letter" || t.type=="RandomSequence"||t.type=="ExactValue") {
+ if(matchesAny(t.type,whitelist)) {
+ while(matchesAny(t.type,whitelist)) {
tokenVec.back().push_back(t);
t = skipAndPeekToken();
}
atNum = ParseAtPart(t);
- proposedTokens = countExpandTokens(tokenVec,atNum);
+ if(laundryMode) {
+
+ }
+ else {
+ proposedTokens = countExpandTokens(tokenVec,atNum);
+ }
tokenStack.insert(tokenStack.end(),proposedTokens.begin(),proposedTokens.end());
}
}
@@ -818,6 +834,9 @@ void Parser::ParseSquareBrackets(Token t) {
}
}
std::vector<Token> Parser::countExpandTokens(std::vector<std::vector<Token>> tokenVecVec, int atNum) {
+ return countExpandTokens(tokenVecVec,atNum,false);
+}
+std::vector<Token> Parser::countExpandTokens(std::vector<std::vector<Token>> tokenVecVec, int atNum, bool laundryMode) {
std::vector<Token> output;
printTokenVector(tokenVecVec);
for(unsigned int i=0; i < tokenVecVec.size(); i++) {
diff --git a/src/dtpulse.hpp b/src/dtpulse.hpp
@@ -45,7 +45,7 @@ class Parser {
void setForChanceOfIntegers(Token t);
void setForRandoms(Token t);
void setForInterleave(Token t,std::vector<std::string> whitelist);
- void setForAtExpand(Token t);
+ void setForAtExpand(Token t, std::vector<std::string> whitelist, bool laundryMode);
void setForSquareBrackets(Token t);
void setFinal(Token t);
bool inError;
@@ -54,13 +54,14 @@ class Parser {
std::vector<float> exactFloats;
std::vector<std::vector<Token>> randomVector;
std::vector<Token> countExpandTokens(std::vector<std::vector<Token>> tokenVecVec, int atNum);
+ std::vector<Token> countExpandTokens(std::vector<std::vector<Token>> tokenVecVec, int atNum, bool laundryMode);
private:
int currentIndex;
void ParseExactValue(Token t);
void ParseExactInteger(Token t);
void ParseRandomSequence(Token t);
void ParseInterleave(Token t,std::vector<std::string> whitelist);
- void ParseAtExpand(Token t);
+ void ParseAtExpand(Token t, std::vector<std::string> whitelist, bool laundryMode);
void ParseSquareBrackets(Token t);
void ParseChanceOfInteger(Token t);
int ParseAtPart(Token t);