Search in sources :

Example 1 with ExprArray

use of org.csstudio.autocomplete.parser.engine.expr.ExprArray in project yamcs-studio by yamcs.

the class ExprParser method parseArray.

private void parseArray(ExprLexer lexer) throws ExprException, IOException {
    Expr c = current;
    current = null;
    ExprToken e = null;
    int cols = -1;
    int count = 0;
    ArrayList<Expr> args = new ArrayList<Expr>();
    while ((e = lexer.next()) != null) {
        if (e.type.equals(ExprTokenType.Comma)) {
            // if (current == null)
            // throw new ExprException("Arrays cannot contain empty values");
            args.add(current == null ? new ExprMissing() : current);
            current = null;
            count++;
        } else if (e.type.equals(ExprTokenType.SemiColon)) {
            // if (current == null)
            // throw new ExprException("Arrays cannot contain empty values");
            args.add(current == null ? new ExprMissing() : current);
            current = null;
            count++;
            // if (count == 0) {
            // throw new ExprException("Array rows must contain at least one element");
            // }
            // if (cols != -1 && count != cols) {
            // throw new ExprException("Array rows must be equal sizes");
            // }
            cols = count;
            count = 0;
        } else if (e.type.equals(ExprTokenType.CloseBrace)) {
            args.add(current == null ? new ExprMissing() : current);
            current = c;
            int rows = 1;
            if (cols == -1)
                cols = args.size();
            else
                rows = args.size() / cols;
            ExprArray a = new ExprArray(rows, cols);
            for (int i = 0; i < args.size(); i++) {
                a.set(0, i, (Expr) args.get(i));
            }
            setValue(a);
            break;
        } else {
            parseToken(lexer, e);
        }
    }
}
Also used : Expr(org.csstudio.autocomplete.parser.engine.expr.Expr) ArrayList(java.util.ArrayList) ExprArray(org.csstudio.autocomplete.parser.engine.expr.ExprArray) ExprMissing(org.csstudio.autocomplete.parser.engine.expr.ExprMissing)

Aggregations

ArrayList (java.util.ArrayList)1 Expr (org.csstudio.autocomplete.parser.engine.expr.Expr)1 ExprArray (org.csstudio.autocomplete.parser.engine.expr.ExprArray)1 ExprMissing (org.csstudio.autocomplete.parser.engine.expr.ExprMissing)1