Search in sources :

Example 11 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken 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 12 with IToken

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

the class SqlFormatter method formatMathExpr.

private void formatMathExpr(MathExpr stm, FormatContext ctx) {
    for (IToken t : stm.getChildren()) {
        if (!(t instanceof MathOp)) {
            formatSimpleExpr(t, ctx);
        } else {
            ctx.print(" ");
            formatDefault(t, ctx);
            ctx.print(" ");
        }
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) MathOp(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.MathOp)

Example 13 with IToken

use of org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken 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 14 with IToken

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

the class SqlParser method parseBracketExpr.

@SuppressWarnings("squid:S2583")
private BracketExpr parseBracketExpr(List<IToken> list, ParseContext ctx) {
    // BracketExpr = OpenBracketToken (Statement | ListExpr) CloseBracketToken
    ParseStep lock = ctx.checkAndAdd("BracketExpr", list);
    if (lock == null) {
        return null;
    }
    try {
        IToken open = null;
        IToken t = null;
        IToken close = null;
        ArrayList<IToken> backup = new ArrayList<IToken>(list);
        if ((open = removeToken(list, OpenBracketToken.class)) != null && ((t = parseStatement(list, ctx)) != null || (t = parseListExpr(list, ctx)) != null || t == null) && (close = removeToken(list, CloseBracketToken.class)) != null) {
        // NOSONAR
        // ok
        } else {
            // restore incomplete
            list.clear();
            list.addAll(backup);
            return null;
        }
        BracketExpr e = new BracketExpr();
        e.addChild(open);
        if (t != null) {
            e.addChild(t);
        }
        e.addChild(close);
        return e;
    } finally {
        ctx.remove(lock);
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) ArrayList(java.util.ArrayList) BracketExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr) OpenBracketToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken)

Example 15 with IToken

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

the class SqlParser method parseMinusExpr.

private MinusExpr parseMinusExpr(List<IToken> list, ParseContext ctx) {
    // BinaryOp['-'] Atom
    ParseStep lock = ctx.checkAndAdd("MinusExpr", list);
    if (lock == null) {
        return null;
    }
    try {
        MathOp mo = null;
        IToken a = null;
        if ((mo = removeToken(list, MathOp.class, "-")) != null && (a = parseAtom(list, ctx)) != null) {
        // ok
        } else {
            // restore incomplete
            if (mo != null) {
                list.add(0, mo);
            }
            return null;
        }
        MinusExpr e = new MinusExpr();
        e.addChild(mo);
        e.addChild(a);
        return e;
    } finally {
        ctx.remove(lock);
    }
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) MathOp(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.MathOp) MinusExpr(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.MinusExpr)

Aggregations

IToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken)16 MathOp (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.MathOp)5 SingleStatement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.SingleStatement)5 Statement (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Statement)5 ArrayList (java.util.ArrayList)4 BracketExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.BracketExpr)4 OpenBracketToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OpenBracketToken)3 UnaryPrefix (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.UnaryPrefix)3 UnionToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.UnionToken)3 AndOp (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.AndOp)2 Atom (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Atom)2 CloseBracketToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.CloseBracketToken)2 Comment (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Comment)2 ListExpr (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.ListExpr)2 Name (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Name)2 OuterJoinToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.OuterJoinToken)2 Part (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Part)2 PartToken (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.PartToken)2 Raw (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Raw)2 Unparsed (org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Unparsed)2