Search in sources :

Example 16 with IToken

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

the class SqlParser method tokenizeRaw.

@SuppressWarnings("squid:S1643")
private List<IToken> tokenizeRaw(List<IToken> list, Pattern p, Class<? extends IToken> tokenType, boolean transcodeDelimiters) {
    ArrayList<IToken> newList = new ArrayList<IToken>(list.size());
    for (IToken item : list) {
        if (item instanceof Raw) {
            String s = ((Raw) item).getText();
            if (transcodeDelimiters) {
                s = encodeDelimiters(s);
            }
            // extend s to start and end with an empty text (simpler regex can be used then)
            s = " " + s + " ";
            Matcher m = p.matcher(s);
            int lastEnd = 0;
            while (lastEnd < s.length() && m.find(lastEnd)) {
                String r = s.substring(lastEnd, m.start(1));
                if (transcodeDelimiters) {
                    r = decodeDelimiters(r);
                }
                newList.add(new Raw(r.trim()));
                // 
                r = m.group(1);
                if (transcodeDelimiters) {
                    r = decodeDelimiters(r);
                }
                IToken t;
                try {
                    t = tokenType.newInstance();
                } catch (Exception e) {
                    throw new ProcessingException("Could not create new instance of {}", tokenType, e);
                }
                t.setText(r);
                newList.add(t);
                // 
                lastEnd = m.end(1);
            }
            // remaining part
            if (lastEnd < s.length()) {
                String r = s.substring(lastEnd);
                if (transcodeDelimiters) {
                    r = decodeDelimiters(r);
                }
                newList.add(new Raw(r.trim()));
            }
        } else {
            newList.add(item);
        }
    }
    return newList;
}
Also used : IToken(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.IToken) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Raw(org.eclipse.scout.rt.server.jdbc.parsers.sql.SqlParserToken.Raw) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ParseException(java.text.ParseException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

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