Search in sources :

Example 1 with Part

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part in project scout.rt by eclipse.

the class SqlFormatter method formatPart.

private void formatPart(Part stm, FormatContext ctx) {
    boolean hasList = false;
    for (IToken t : stm.getChildren()) {
        if (t instanceof PartToken) {
            formatDefault(t, ctx);
        } else if (t instanceof Part) {
            ctx.in();
            formatPart((Part) t, ctx);
            ctx.out();
        } else if (t instanceof ListExpr) {
            hasList = true;
            ctx.in();
            formatListExpr((ListExpr) t, true, ctx);
            ctx.out();
        } else {
            formatDefault(t, ctx);
        }
    }
    if (!hasList) {
        ctx.in();
        ctx.print(" ");
        ctx.out();
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) Part(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part) PartToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.PartToken) ListExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.ListExpr)

Example 2 with Part

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part in project scout.rt by eclipse.

the class SqlParser method parseSingleStatement.

/**
 * return {@link SingleStatement} or {@link BracketExpr}
 */
private IToken parseSingleStatement(List<IToken> list, ParseContext ctx) {
    ParseStep lock = ctx.checkAndAdd("SingleStatement", list);
    if (lock == null) {
        return null;
    }
    try {
        // brackets
        ArrayList<IToken> backup = new ArrayList<IToken>(list);
        BracketExpr be = parseBracketExpr(list, ctx);
        if (be != null) {
            BracketExpr tmp = be;
            while (tmp != null) {
                // open, token, close
                IToken ch = tmp.getChildren().get(1);
                if (ch instanceof BracketExpr) {
                    tmp = (BracketExpr) ch;
                } else if (ch instanceof Statement) {
                    return be;
                } else if (ch instanceof SingleStatement) {
                    return be;
                } else {
                    tmp = null;
                }
            }
            // restore
            list.clear();
            list.addAll(backup);
            return null;
        }
        // 
        // Part+
        Part p;
        SingleStatement ss = new SingleStatement();
        if ((p = parsePart(list, ctx, true)) != null) {
            // ok
            ss.addChild(p);
        } else {
            return null;
        }
        while ((p = parsePart(list, ctx, false)) != null) {
            ss.addChild(p);
        }
        if (ss.getChildren().size() == 0) {
            return null;
        }
        return ss;
    } finally {
        ctx.remove(lock);
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) Statement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) Part(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part) ArrayList(java.util.ArrayList) SingleStatement(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement) BracketExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)

Example 3 with Part

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part in project scout.rt by eclipse.

the class SqlParser method parsePart.

private Part parsePart(List<IToken> list, ParseContext ctx, boolean rootPart) {
    // PartToken ListExpr
    ParseStep lock = ctx.checkAndAdd("Part", list);
    if (lock == null) {
        return null;
    }
    try {
        PartToken pt;
        ListExpr le;
        if ((pt = removeToken(list, PartToken.class)) != null && (!rootPart || isRootPartToken(pt))) {
            // ok
            le = parseListExpr(list, ctx);
        } else {
            // restore incomplete
            if (pt != null) {
                list.add(0, pt);
            }
            return null;
        }
        Part p = new Part();
        p.addChild(pt);
        if (le != null) {
            p.addChild(le);
        }
        return p;
    } finally {
        ctx.remove(lock);
    }
}
Also used : Part(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part) PartToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.PartToken) ListExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.ListExpr)

Aggregations

Part (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part)3 IToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken)2 ListExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.ListExpr)2 PartToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.PartToken)2 ArrayList (java.util.ArrayList)1 BracketExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)1 SingleStatement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement)1 Statement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement)1