Skip to content

Commit

Permalink
introduce a worker/visitor solution for regenerating blockly and textly
Browse files Browse the repository at this point in the history
the blockly regeneration is slightly refactored.
the textly regeneration is build as an advanced prototype.

because textly is not used currently, this should NOT introduce any
error.
  • Loading branch information
rbudde committed Sep 10, 2024
1 parent 2d885d1 commit 5cbe202
Show file tree
Hide file tree
Showing 22 changed files with 1,523 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public final class Project {
private static final Logger LOG = LoggerFactory.getLogger(Project.class);
private final Map<String, JSONObject> confAnnotationList = new HashMap<String, JSONObject>();
private final ClassToInstanceMap<IProjectBean> workerResults = MutableClassToInstanceMap.create();
private final StringBuilder indentationBuilder = new StringBuilder();
private final Map<String, String> resultParams = new HashMap<>();
private String token;
private String robot;
Expand All @@ -58,11 +57,13 @@ public final class Project {
private ProgramAst program = null;
private ConfigurationAst configuration = null;
private StringBuilder sourceCodeBuilder = new StringBuilder();
private StringBuilder indentationBuilder = null;
private String compiledHex = "";
private Key result = Key.COMPILERWORKFLOW_PROJECT_BUILD_SUCCESS;
private int errorCounter = 0;
private JSONObject configurationJSON;
private String programAsBlocklyXML = null;
private String programAsTextly = null;
private String configurationAsBlocklyXML = null;
private List<String> errorAndWarningMessages = null;

Expand Down Expand Up @@ -171,18 +172,36 @@ public void appendWorkerResult(IProjectBean bean) {
}
}

public StringBuilder getSourceCode() {
/**
* very dangerous, this allows to pass the source code builder between worker. It is assumed, that only ONE worker
* will write. This is not true anymore. The RegenerateNepoWorker sets own source builder, but compensates this
* dangerous desing
* @return the UNIQUE builder for the whole worker chain
*/
public StringBuilder getSourceCodeBuilder() {
return this.sourceCodeBuilder;
}

/**
* very dangerous, this allows to pass the source code builder between worker. It is assumed, that only ONE worker
* will write. This is not true anymore. The RegenerateNepoWorker sets own source builder, but compensates this
* dangerous desing
* @return the UNIQUE builder for the whole worker chain
*/
public StringBuilder getIndentationBuilder() {
return this.indentationBuilder;
}

public void setSourceCode(String sourceCode) {
this.sourceCodeBuilder = new StringBuilder(sourceCode);
}

public StringBuilder getIndentation() {
return this.indentationBuilder;
public void setIndentationBuilder(StringBuilder indentationBuilder) {
this.indentationBuilder = indentationBuilder;
}



/**
* @return this will actually return either Intel Hex or base 64 encoded binary
*/
Expand Down Expand Up @@ -235,15 +254,25 @@ public List<String> getErrorAndWarningMessages() {
}

public String getProgramAsBlocklyXML() {
Assert.notNull(programAsBlocklyXML, "Transformation of program AST into NEPO not executed by the worker chain.");
Assert.notNull(programAsBlocklyXML, "Transformation of program AST into NEPO not executed by the worker chain (blockly).");
return programAsBlocklyXML;
}

public String getProgramAsTextly() {
Assert.notNull(programAsTextly, "Transformation of program AST into NEPO not executed by the worker chain (textly).");
return programAsTextly;
}

public void setProgramAsBlocklyXML(String programAsBlocklyXML) {
Assert.isNull(this.programAsBlocklyXML);
this.programAsBlocklyXML = programAsBlocklyXML;
}

public void setProgramAsTextly(String programAsTextly) {
Assert.isNull(this.programAsTextly);
this.programAsTextly = programAsTextly;
}

public String getConfigurationAsBlocklyXML() {
Assert.notNull(configurationAsBlocklyXML, "Transformation of configuration AST into NEPO not executed by the worker chain.");
return configurationAsBlocklyXML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.Collection;
import java.util.stream.Collectors;

import de.fhg.iais.roberta.syntax.Phrase;
import de.fhg.iais.roberta.visitor.IVisitor;

public class SourceBuilder {
private static final String INDENT = " ";
private int indentation = 0;
Expand Down Expand Up @@ -47,8 +50,10 @@ public SourceBuilder indent() {
public SourceBuilder nlI() {
// removes trailing whitespace, e.g. \n \n -> \n\n
int last = this.sb.length() - 1;
while ( this.sb.charAt(last) == ' ' ) {
this.sb.deleteCharAt(last--);
if (last > 0) {
while ( this.sb.charAt(last) == ' ' ) {
this.sb.deleteCharAt(last--);
}
}
this.sb.append("\n");
indent();
Expand All @@ -69,6 +74,11 @@ public boolean addIf(boolean first, Object val) {
return false;
}

public SourceBuilder accept(Phrase phrase, IVisitor<?> visitor) {
phrase.accept(visitor);
return this;
}

public SourceBuilder collect(Collection<? extends CharSequence> collection, String separator) {
add(collection.stream().collect(Collectors.joining(separator)));
return this;
Expand Down
Loading

0 comments on commit 5cbe202

Please sign in to comment.