Skip to content

Commit

Permalink
+ Mesh Editor.
Browse files Browse the repository at this point in the history
#2 ExportAs ok
Improving TreeNode. Addition vectors 1/1 (revert to my Android Calculator App)
Game works again.
TextDialog in feature processing
Include spaces in AlgebraicTree formulas.
New class analyze StringAnalyser.+

Signed-off-by: Manuel Daniel Dahmen <[email protected]>
  • Loading branch information
manuelddahmen committed Jan 29, 2024
1 parent fdf494f commit bab9786
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 54 deletions.
107 changes: 55 additions & 52 deletions src/main/java/one/empty3/library1/tree/StringAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ public void setAction(Action action) {

public int skipBlanks(String input, int position) {
boolean passed = false;
while (position < input.length() && Character.isSpaceChar(input.charAt(position))) {
while (position < input.length() && (Character.isSpaceChar(input.charAt(position)) || Character.isWhitespace(input.charAt(position)))) {
position++;
passed = true;
}
return passed ? position - 1 : 0;
return passed ? position : 0;
}

public int parse(String input, int position) {
System.out.println(toString());
return position = skipBlanks(input, position);
position = skipBlanks(input, position);
int position1 = 0;
System.out.printf("\nClasse\t" + getClass() + "\nPosition\t" + position + "\nReste\n<<<<\n" + input.substring(position) + "\n>>>>\n");
return position1;
}

protected boolean isSuccessful() {
Expand Down Expand Up @@ -159,7 +161,7 @@ public TokenChoiceStringMandatory(String[] values) {

@Override
public int parse(String input, int position) {
position = super.skipBlanks(input, position);
position = super.parse(input, position);
input = input.substring(position);
for (String s : names) {
if (input.startsWith(s)) {
Expand All @@ -178,7 +180,7 @@ public String getChoice() {

class TokenClassScope extends TokenChoiceStringMandatory {
public TokenClassScope() {
super(new String[]{"static", ""});
super(new String[]{"public", "private", "package", "protected", ""});
}
}

Expand All @@ -196,6 +198,19 @@ public TokenCodeFile() {
aClass = new Class();
}

@Override
public int parse(String input, int position) {
position = super.parse(input, position);
input = input.substring(position);
if (getNextToken().data1d.size() > 0) {
position = getNextToken().getElem(0).parse(input, 0);
if (getNextToken().getElem(0).isSuccessful()) {
return position;
}
}
setSuccessful(false);
return position;
}
}

class TokenChoiceInclusive extends Token {
Expand Down Expand Up @@ -238,8 +253,6 @@ public TokenChoiceExclusive(Token... choices) {

@Override
public int parse(String input, int position) {
position = super.parse(input, position);
input = input.substring(position);
position = super.parse(input, position);
input = input.substring(position);
int position1 = position;
Expand All @@ -252,10 +265,6 @@ public int parse(String input, int position) {
}
}
setSuccessful(true);
for (int i = 0; i < choices.length; i++) {
getNextToken().getData1d().clear();
getNextToken().add(choices[i]);
}
return position;
}
}
Expand Down Expand Up @@ -383,8 +392,6 @@ public MultiTokenOptional(Token... options) {

@Override
public int parse(String input, int position) {
getNextToken().data1d.clear();
;
position = super.parse(input, position);
input = input.substring(position);
boolean allOk = true;
Expand All @@ -393,16 +400,18 @@ public int parse(String input, int position) {
while (allNotOk) {
allNotOk = true;
for (Token token : choices) {
position1 = token.parse(input, position1);
int position2 = token.parse(input, position1);
if (!token.isSuccessful()) {
allOk = false;
allNotOk = false;
} else {
// getNextToken().data1d.add(token);
position1 = position2;
}
}
}
setSuccessful(!allNotOk || allOk);
setSuccessful(true);
if (isSuccessful() && getNextToken().getElem(0) != null)
return getNextToken().getElem(0).parse(input, position1);
return position1;
}
}
Expand Down Expand Up @@ -478,7 +487,7 @@ public int parse(String input, int position) {
setSuccessful(false);
return position1;
}

}

private void setName(String name) {
Expand Down Expand Up @@ -685,30 +694,30 @@ public boolean action() {
return false;
}
};
Token aPackage = definitions.put(0, new TokenCodeFile().addToken(new TokenChoiceInclusive(
new MultiTokenMandatory(new TokenString("package"),
packageQualifiedName))
.addToken(new TokenClassScope()))
.addToken(isFinal).addToken(tokenClassKeyword).addToken(className).addToken(new TokenOpenBracket())
.addToken(new MultiTokenOptional(new Token[]{
// Variables
new MultiTokenOptional(new Token[]{tokenVariableScope, tokenConstantModifier})
.addToken(tokenQualifiedNameVariable)}).addToken(new TokenSemiColon()))// Commit changes
// Methods
.addToken(new MultiTokenOptional(new Token[]{tokenNameReturnType, tokenMethodScope
.addToken(tokenConstantModifierMethod).addToken(tokenMethodMemberDefinition)
// Arguments' list
.addToken(new TokenOpenParenthesized()).addToken(new MultiTokenOptional(new MultiTokenMandatory(
new TokenVariableMemberDefinitionClassName(), new TokenName(), new TokenComa()
)))
.addToken(new TokenCloseParenthesized())
// Instructions' block
.addToken(tokenBeginOfMethod.
addToken(new MultiTokenOptional(new MultiTokenMandatory(tokenVariableInMethodName
, new TokenName(), new TokenEquals())
.addToken(new TokenExpression()), new TokenComa()).addToken(endOfInstruction)// Commit changes
))}))
.addToken(closeBracket));// Commit changes
Token aPackage = definitions.put(0, new TokenCodeFile().addToken(new MultiTokenOptional(
new MultiTokenMandatory(new TokenString("package"),
packageQualifiedName, new TokenSemiColon()))
.addToken(new MultiTokenOptional(new TokenClassScope(),
isFinal).addToken(tokenClassKeyword.addToken(className).addToken(new TokenOpenBracket())
.addToken(new MultiTokenOptional(new Token[]{
// Variables
new MultiTokenOptional(new Token[]{tokenVariableScope, tokenConstantModifier})
.addToken(tokenQualifiedNameVariable)}).addToken(new TokenSemiColon()))// Commit changes
// Methods
.addToken(new MultiTokenOptional(new Token[]{tokenNameReturnType, tokenMethodScope
.addToken(tokenConstantModifierMethod).addToken(tokenMethodMemberDefinition)
// Arguments' list
.addToken(new TokenOpenParenthesized()).addToken(new MultiTokenOptional(new MultiTokenMandatory(
new TokenVariableMemberDefinitionClassName(), new TokenName(), new TokenComa()
)))
.addToken(new TokenCloseParenthesized())
// Instructions' block
.addToken(tokenBeginOfMethod.
addToken(new MultiTokenOptional(new MultiTokenMandatory(tokenVariableInMethodName
, new TokenName(), new TokenEquals())
.addToken(new TokenExpression()), new TokenComa()).addToken(endOfInstruction)// Commit changes
))})))
.addToken(closeBracket))));// Commit changes

}

Expand Down Expand Up @@ -852,16 +861,10 @@ public String toString() {
public int parse(String input) {
Token token = definitions.get(0);
int position1 = token.parse(input, 0);
input = input.substring(position1);
while (token != null && token.isSuccessful()) {
position1 = token.parse(input, position1);
input = input.substring(position1);
if (token.getNextToken() != null)
for (int i = 0; i < token.getNextToken().data1d.size(); i++) {
token.getNextToken().getElem(i);
}

if (token.isSuccessful()) {
return position1;
} else {
return -1;
}
return position1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package one.empty3.library1.tree

import junit.framework.TestCase.assertTrue
import one.empty3.library.Point2D
import one.empty3.library.Point3D
import one.empty3.library.StructureMatrix
Expand Down Expand Up @@ -761,7 +762,7 @@ class TestAlgebraicTreeVector() {
"class Numb {\n" +
"\tdouble func1(Double a, Double b, Double c) {\n" +
"\t\tDouble d = c+b/a;\n" +
"\t\treturn d\n" +
"\t\treturn d;\n" +
"\t}\n" +
"}\n"

Expand All @@ -770,10 +771,14 @@ class TestAlgebraicTreeVector() {
println(stringAnalyser.construct)
stringAnalyser.definitions.keys.sorted().forEach {
if (it != null) {
println("[" + it + "]\t" + stringAnalyser.definitions.get(it))
println(
"[" + it + "]\n" + stringAnalyser.definitions.get(it)!!
.isSuccessful() + "\n" + stringAnalyser.definitions.get(it) + "\n"
)
}
}
println(parse)
assertTrue(parse >= 0)
}

@Test
Expand Down

0 comments on commit bab9786

Please sign in to comment.