Skip to content

Commit

Permalink
Added ||| and &&& (dor and dand)
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Aug 4, 2016
1 parent 52af8f4 commit 75adf32
Show file tree
Hide file tree
Showing 7 changed files with 2,964 additions and 2,600 deletions.
36 changes: 27 additions & 9 deletions src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
Expand Up @@ -403,6 +403,24 @@ public static List<Token> lex(String script, File file, boolean inPureMScript) t
i++;
continue;
}
if (c == '&' && c2 == '&' && c3 == '&' && !state_in_quote) {
if(buf.length() > 0) {
token_list.add(new Token(TType.UNKNOWN, buf.toString(), target));
buf = new StringBuilder();
}
token_list.add(new Token(TType.DEFAULT_AND, "&&&", target));
i++; i++;
continue;
}
if (c == '|' && c2 == '|' && c3 == '|' && !state_in_quote) {
if(buf.length() > 0) {
token_list.add(new Token(TType.UNKNOWN, buf.toString(), target));
buf = new StringBuilder();
}
token_list.add(new Token(TType.DEFAULT_OR, "|||", target));
i++; i++;
continue;
}
if (c == '&' && c2 == '&' && !state_in_quote) {
if (buf.length() > 0) {
token_list.add(new Token(TType.UNKNOWN, buf.toString(), target));
Expand Down Expand Up @@ -731,7 +749,7 @@ public static List<Token> lex(String script, File file, boolean inPureMScript) t

if (t.type == TType.UNKNOWN && prev1.type.isPlusMinus() && !prev2.type.isIdentifier()
&& !prev2.type.equals(TType.FUNC_END)
&& !IVAR_PATTERN.matcher(t.val()).matches()
&& !IVAR_PATTERN.matcher(t.val()).matches()
&& !VAR_PATTERN.matcher(t.val()).matches()) { // Last boolean makes -@b equal to - @b, instead of a string.
//It is a negative/positive number. Absorb the sign
t.value = prev1.value + t.value;
Expand Down Expand Up @@ -954,10 +972,10 @@ public static ParseTree compile(List<Token> stream) throws ConfigCompileExceptio
*/
Stack<AtomicInteger> arrayStack = new Stack<>();
arrayStack.add(new AtomicInteger(-1));

Stack<AtomicInteger> minusArrayStack = new Stack<>();
Stack<AtomicInteger> minusFuncStack = new Stack<>();

int parens = 0;
Token t = null;

Expand Down Expand Up @@ -1071,7 +1089,7 @@ public static ParseTree compile(List<Token> stream) throws ConfigCompileExceptio
ParseTree arrayGet = new ParseTree(new CFunction("array_get", t.target), fileOptions);
arrayGet.addChild(myArray);
arrayGet.addChild(myIndex);

// Check if the @var[...] had a negating "-" in front. If so, add a neg().
if (minusArrayStack.size() != 0 && arrayStack.size() + 1 == minusArrayStack.peek().get()) {
if (!next1.type.equals(TType.LSQUARE_BRACKET)) { // Wait if there are more array_get's comming.
Expand Down Expand Up @@ -1162,7 +1180,7 @@ public static ParseTree compile(List<Token> stream) throws ConfigCompileExceptio
} catch (EmptyStackException e) {
throw new ConfigCompileException("Unexpected end parenthesis", t.target);
}

// Handle "-func(args)" and "-func(args)[index]".
if (minusFuncStack.size() != 0 && minusFuncStack.peek().get() == parens + 1) {
if(next1.type.equals(TType.LSQUARE_BRACKET)) {
Expand All @@ -1177,7 +1195,7 @@ public static ParseTree compile(List<Token> stream) throws ConfigCompileExceptio
}
minusFuncStack.pop();
}

} else if (t.type.equals(TType.COMMA)) {
if (constructCount.peek().get() > 1) {
int stacks = constructCount.peek().get();
Expand Down Expand Up @@ -1314,14 +1332,14 @@ public static ParseTree compile(List<Token> stream) throws ConfigCompileExceptio
tree.addChild(new ParseTree(Static.resolveConstruct(t.val(), t.target), fileOptions));
constructCount.peek().incrementAndGet();
} else if (t.type.isSymbol()) { //Logic and math symbols

// Attempt to find "-@var" and change it to "neg(@var)" if it's not @a - @b. Else just add the symbol.
// Also handles "-function()" and "-@var[index]".
if (t.type.equals(TType.MINUS) && !prev1.type.isAtomicLit() && !prev1.type.equals(TType.IVARIABLE)
&& !prev1.type.equals(TType.VARIABLE) && !prev1.type.equals(TType.RCURLY_BRACKET)
&& !prev1.type.equals(TType.RSQUARE_BRACKET) && !prev1.type.equals(TType.FUNC_END)
&& (next1.type.equals(TType.IVARIABLE) || next1.type.equals(TType.VARIABLE) || next1.type.equals(TType.FUNC_NAME))) {

// Check if we are negating a value from an array, function or variable.
if (next2.type.equals(TType.LSQUARE_BRACKET)) {
minusArrayStack.push(new AtomicInteger(arrayStack.size() + 1)); // +1 because the bracket isn't counted yet.
Expand All @@ -1338,7 +1356,7 @@ public static ParseTree compile(List<Token> stream) throws ConfigCompileExceptio
tree.addChild(new ParseTree(new CSymbol(t.val(), t.type, t.target), fileOptions));
constructCount.peek().incrementAndGet();
}

} else if (t.type == TType.DOT){
// Check for doubles that start with a decimal, otherwise concat
Construct c = null;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/laytonsmith/core/constructs/CSymbol.java
@@ -1,8 +1,10 @@
package com.laytonsmith.core.constructs;

import com.laytonsmith.annotations.breakable;

/**
*
*
*
*/
public class CSymbol extends Construct {

Expand Down Expand Up @@ -58,6 +60,12 @@ public CSymbol(String symbol, Token.TType type, Target target) {
case LOGICAL_OR:
conversion = "or";
break;
case DEFAULT_AND:
conversion = "dand";
break;
case DEFAULT_OR:
conversion = "dor";
break;
case LOGICAL_NOT:
conversion = "not";
break;
Expand Down Expand Up @@ -136,6 +144,14 @@ public boolean isLogicalOr() {
return symbolType.isLogicalOr();
}

public boolean isDefaultAnd() {
return symbolType.isDefaultAnd();
}

public boolean isDefaultOr() {
return symbolType.isDefaultOr();
}

@Override
public boolean isDynamic() {
//It gets turned into a function, but only after the __autoconcat__ features take over,
Expand Down

0 comments on commit 75adf32

Please sign in to comment.