added copy and fixed cleaning of semicolons

This commit is contained in:
gnembon committed 2019-11-04 00:35:32 -04:00
1 parent e2c614c6de
commit efb87c8497
7 files changed
+86 -17

No files matched your search

+3 -16
View File
@@ -46,7 +46,6 @@ import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static java.lang.Math.abs;
import static java.lang.Math.max;
@@ -2775,6 +2774,8 @@ public class Expression implements Cloneable
{
addUnaryFunction("hash_code", v -> new NumericValue(v.hashCode()));
addUnaryFunction("copy", Value::deepcopy);
addLazyFunction("bool", 1, (c, t, lv) -> {
Value v = lv.get(0).evalValue(c, Context.BOOLEAN);
if (v instanceof StringValue)
@@ -3044,21 +3045,7 @@ public class Expression implements Cloneable
Tokenizer tokenizer = new Tokenizer(this, expression, allowComments, allowNewlineSubstitutions);
// stripping lousy but acceptable semicolons
Iterable<Tokenizer.Token> iterable = () -> tokenizer;
List<Tokenizer.Token> originalTokens = StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
List<Tokenizer.Token> cleanedTokens = new ArrayList<>();
Tokenizer.Token last = null;
while (originalTokens.size() > 0)
{
Tokenizer.Token current = originalTokens.remove(originalTokens.size()-1);
if (current.type != Tokenizer.Token.TokenType.OPERATOR
|| !current.surface.equals(";")
|| (last != null && last.type != Tokenizer.Token.TokenType.CLOSE_PAREN && last.type != Tokenizer.Token.TokenType.COMMA && !last.surface.equals(";")))
cleanedTokens.add(current);
if (current.type != Tokenizer.Token.TokenType.MARKER)
last = current;
}
Collections.reverse(cleanedTokens);
List<Tokenizer.Token> cleanedTokens = tokenizer.fixSemicolons();
Tokenizer.Token lastFunction = null;
Tokenizer.Token previousToken = null;