use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.
the class ExpressionParser method withoutElse.
private boolean withoutElse() {
final CodeGenerator cg = getCodeGeneratorWithTimes();
cg.onConstant(Variable.NIL);
cg.onTernaryRight(this.lookhead);
return false;
}
use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.
the class ExpressionParser method elseStatement.
private boolean elseStatement(final boolean isWhile, final boolean ifBodyHasReturn) {
if (isWhile) {
// Call __reducer_break(nil)
final CodeGenerator cg = getCodeGeneratorWithTimes();
cg.onMethodName(Constants.ReducerBreakFn);
cg.onConstant(Variable.NIL);
cg.onMethodParameter(this.lookhead);
cg.onMethodInvoke(this.lookhead);
cg.onTernaryRight(this.lookhead);
return false;
}
if (expectChar(';')) {
return withoutElse();
}
boolean hasReturn = false;
boolean hasElsif = this.lookhead == Variable.ELSIF;
boolean hasElse = this.lookhead == Variable.ELSE;
if (this.lookhead != null && (hasElse || hasElsif || ifBodyHasReturn)) {
if (hasElse) {
move(true);
if (expectChar('{')) {
this.scope.enterBrace();
move(true);
hasReturn = elseBody(false);
if (expectChar('}')) {
this.scope.leaveBrace();
move(true);
} else {
reportSyntaxError("missing '}' to close 'else' body");
}
} else {
reportSyntaxError("expect '{' for else statement");
}
} else if (hasElsif) {
hasReturn = ifStatement(false, true);
getCodeGenerator().onTernaryRight(this.lookhead);
} else if (ifBodyHasReturn) {
hasReturn = elseBody(true);
} else {
return withoutElse();
}
return hasReturn;
} else {
// Missing else statement, always nil.
return withoutElse();
}
}
use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.
the class ExpressionParser method join.
public void join() {
and();
while (true) {
Token<?> opToken = this.lookhead;
if (expectChar('|')) {
getCodeGeneratorWithTimes().onJoinLeft(opToken);
move(true);
if (expectChar('|')) {
move(true);
and();
getCodeGeneratorWithTimes().onJoinRight(opToken);
} else {
reportSyntaxError("expect '|'");
}
} else {
// Process operator alias
String alias = this.instance.getOperatorAliasToken(OperatorType.OR);
if (alias != null) {
if (opToken != null && opToken.getType() == TokenType.Variable && opToken.getLexeme().equals(alias)) {
CodeGenerator cg = getCodeGeneratorWithTimes();
cg.onJoinLeft(opToken);
move(true);
and();
cg.onJoinRight(opToken);
continue;
}
}
break;
}
}
}
use of com.googlecode.aviator.code.CodeGenerator in project aviatorscript by killme2008.
the class ExpressionParser method and.
public void and() {
bitOr();
while (true) {
Token<?> opToken = this.lookhead;
if (expectChar('&')) {
CodeGenerator cg = getCodeGeneratorWithTimes();
cg.onAndLeft(opToken);
move(true);
if (expectChar('&')) {
move(true);
bitOr();
cg.onAndRight(opToken);
} else {
reportSyntaxError("expect '&'");
}
} else {
// Process operator alias
String alias = this.instance.getOperatorAliasToken(OperatorType.AND);
if (alias != null) {
if (opToken != null && opToken.getType() == TokenType.Variable && opToken.getLexeme().equals(alias)) {
CodeGenerator cg = getCodeGeneratorWithTimes();
cg.onAndLeft(opToken);
move(true);
bitOr();
cg.onAndRight(opToken);
continue;
}
}
break;
}
}
}
Aggregations