public static int captureToEOS(char[] expression, int cursor) { int length = expression.length; while (cursor != length) { switch (expression[cursor]) { case '(': case '[': case '{': cursor = balancedCapture(expression, cursor, expression[cursor]); break; case ';': case '}': return cursor; } cursor++; } return cursor; }
public ExpressionNode(int begin, String name, char[] template, int start, int end) { this.begin = begin; this.name = name; this.contents = subset(template, this.cStart = start, (this.end = this.cEnd = end) - start - 1); }
public static boolean isNumericallyCoercible(Class target, Class parm) { Class boxedTarget = target.isPrimitive() ? boxPrimitive(target) : target; if (boxedTarget != null && Number.class.isAssignableFrom(target)) { if ((boxedTarget = parm.isPrimitive() ? boxPrimitive(parm) : parm) != null) { return Number.class.isAssignableFrom(boxedTarget); } } return false; }
/** * Checks to see if the next part of the statement is an identifier part. * * @return boolean true if next part is identifier part. */ protected boolean isNextIdentifier() { while (cursor != end && isWhitespace(expr[cursor])) cursor++; return cursor != end && isIdentifierPart(expr[cursor]); }
public static String[] parseMethodOrConstructor(char[] parm) { int start = -1; for (int i = 0; i < parm.length; i++) { if (parm[i] == '(') { start = ++i; break; } } if (start != -1) { return parseParameterList(parm, --start + 1, balancedCapture(parm, start, '(') - start - 1); } return EMPTY_STR_ARR; }
private Object getWithProperty(Object ctx) { int st; String nestParm = start == cursor ? null : new String(property, start, cursor - start - 1).trim(); parseWithExpressions(nestParm, property, st = cursor + 1, (cursor = balancedCaptureWithLineAccounting(property, cursor, end, '{', pCtx)) - st, ctx, variableFactory); cursor++; return ctx; }
score += 8; else if (actualParamType.isPrimitive() && boxPrimitive(actualParamType) == arguments[i]) { score += 7; else if (arguments[i].isPrimitive() && unboxPrimitive(arguments[i]) == actualParamType) { score += 7; score += 6; else if (isPrimitiveSubtype(arguments[i], actualParamType)) { score += 5; else if (isNumericallyCoercible(arguments[i], actualParamType)) { score += 4; else if (boxPrimitive(actualParamType).isAssignableFrom(boxPrimitive(arguments[i])) && Object.class != arguments[i]) { score += 3 + scoreInterface(actualParamType, arguments[i]);
public void updateClassName(char[] name, int start, int offset, int fields) { this.expr = name; if (offset == 0 || !ParseTools.isIdentifierPart(name[start]) || isDigit(name[start])) return; while (endRange < end && isWhitespace(name[endRange])) endRange++; throw new CompileException("unexpected token in constructor", name, endRange); to = balancedCapture(name, endRange, start + offset, '['); sizes.add(subset(name, ++endRange, to - endRange)); endRange = to + 1; compiledArraySize = new ExecutableStatement[arraySize.length]; for (int i = 0; i < compiledArraySize.length; i++) compiledArraySize[i] = (ExecutableStatement) subCompileExpression(arraySize[i].value);
if (isReservedWord(name = createStringTrimmed(expr, st, cursor - st)) || isNotValidNameorLabel(name)) throw new CompileException("illegal function name or use of reserved word", expr, cursor); captureToNextTokenJunction(); if (isReservedWord(name = createStringTrimmed(expr, st, cursor - st)) || isNotValidNameorLabel(name)) throw new CompileException("illegal prototype name or use of reserved word", expr, cursor); cursor = balancedCaptureWithLineAccounting(expr, st = cursor + 1, end, '{', pCtx); cursor = balancedCaptureWithLineAccounting(expr, st = cursor + 1, end, '{', pCtx); endCond = cursor = balancedCaptureWithLineAccounting(expr, startCond = cursor, end, '(', pCtx); blockEnd = cursor = balancedCaptureWithLineAccounting(expr, blockStart = cursor, end, '{', pCtx); skipWhitespace(); startCond = cursor + 1; endCond = cursor = balancedCaptureWithLineAccounting(expr, cursor, end, '(', pCtx); return createBlockToken(startCond, endCond, trimRight(blockStart + 1), trimLeft(blockEnd), type); skipWhitespace(); startCond = cursor + 1; endCond = cursor = balancedCaptureWithLineAccounting(expr, cursor, end, '(', pCtx); return createBlockToken(startCond, endCond, trimRight(blockStart + 1), trimLeft(blockEnd), ASTNode.BLOCK_DO_UNTIL);
ExecutableStatement c = (ExecutableStatement) subCompileExpression(a.getExpression(), pCtx); && unboxPrimitive(c.getKnownEgressType()).equals(returnType)) { String[] parms = ParseTools.parseMethodOrConstructor(tk.getNameAsArray()); if (parms != null) { for (String p : parms) {
private int captureOrbToken() { int newStart = ++cursor; while ((cursor != length) && ParseTools.isIdentifierPart(template[cursor])) cursor++; if (cursor != length && template[cursor] == '{') return newStart; return -1; }
private Class getWithProperty(Class ctx) { String root = new String(expr, 0, cursor - 1).trim(); int start = cursor + 1; cursor = balancedCaptureWithLineAccounting(expr, cursor, '{', pCtx); new WithAccessor(root, subset(expr, start, cursor++ - start), ctx, pCtx.isStrictTypeEnforcement()); return ctx; }
public Negation(char[] expr, int start, int offset, int fields, ParserContext pCtx) { super(pCtx); this.expr = expr; this.start = start; this.offset = offset; if ((fields & COMPILE_IMMEDIATE) != 0) { if (((this.stmt = (ExecutableStatement) subCompileExpression(expr, start, offset, pCtx)).getKnownEgressType() != null) && (!ParseTools.boxPrimitive(stmt.getKnownEgressType()).isAssignableFrom(Boolean.class))) { throw new CompileException("negation operator cannot be applied to non-boolean type", expr, start); } } }
private void whiteSpaceSkip() { if (cursor < end) //noinspection StatementWithEmptyBody while (isWhitespace(property[cursor]) && ++cursor < end) ; }
public static void checkNameSafety(String name) { if (isReservedWord(name)) { throw new RuntimeException("illegal use of reserved word: " + name); } else if (isDigit(name.charAt(0))) { throw new RuntimeException("not an identifier: " + name); } }
@SuppressWarnings({"SuspiciousMethodCalls"}) protected void setName(char[] name) { if (isNumber(name, start, offset)) { egressType = (literal = handleNumericConversion(name, start, offset)).getClass(); if (((fields |= NUMERIC | LITERAL | IDENTIFIER) & INVERT) != 0) { try {
protected boolean ifThenElseBlockContinues() { skipWhitespace(); if ((cursor + 4) < length) { if (expr[cursor] != ';') { cursor--; } skipWhitespace(); if ((expr[cursor] == 'e') && (expr[cursor + 1] == 'l') && (expr[cursor + 2] == 's') && (expr[cursor + 3] == 'e') && (isWhitespace(expr[cursor + 4]) || (expr[cursor + 4] == '{'))) { cursor += 4; skipWhitespace(); if (((cursor + 1) < length) && (expr[cursor] == 'i') && (expr[cursor + 1] == 'f')) { cursor += 2; expectNext('('); cursor = balancedCapture(expr, cursor, '(') + 1; } skipWhitespace(); return true; } } return false; }
private static boolean isBooleanOption(final Class<?> type) { return ParseTools.unboxPrimitive(type) == boolean.class; }
private Class getWithProperty(Class ctx) { String root = new String(expr, 0, cursor - 1).trim(); int start = cursor + 1; cursor = balancedCaptureWithLineAccounting(expr, cursor, end, '{', pCtx); new WithAccessor(pCtx, root, expr, start, cursor++ - start, ctx); return ctx; }
public Object parseCollection(char[] property, int start, int offset, boolean subcompile, Class colType, ParserContext pCtx) { if (colType != null) this.colType = getBaseComponentType(colType); this.property = property; this.end = start + offset; while (start < end && isWhitespace(property[start])) { start++; } this.start = this.cursor = start; this.pCtx = pCtx; return parseCollection(subcompile); }